9
0
mirror of https://github.com/BX-Team/DivineMC.git synced 2025-12-19 14:59:25 +00:00
Files
DivineMC/divinemc-server/minecraft-patches/features/0006-Async-locate-command.patch
Artem Ostrasev 109c57a637 1.21.6 (#25)
* start 1.21.6 update

* change workflow

* apply some patches

* set experimental to true

* some compile fixes

* Updated Upstream (Purpur)

Upstream has released updates that appear to apply and compile correctly

Purpur Changes:
PurpurMC/Purpur@5d3463aa Updated Upstream (Paper)

* Updated Upstream (Purpur)

Upstream has released updates that appear to apply and compile correctly

Purpur Changes:
PurpurMC/Purpur@5d3463aa Updated Upstream (Paper)

* remove data converter for 1.21.6; move clumps to unapplied

* Updated Upstream (Purpur)

Upstream has released updates that appear to apply and compile correctly

* Updated Upstream (Purpur)

Upstream has released updates that appear to apply and compile correctly

* Update upstream

* Update upstream

* update to 1.21.6-pre4

* update patches

* fix compile

* set readme version to 1.21.6

* Updated Upstream (Purpur)

Upstream has released updates that appear to apply and compile correctly

Purpur Changes:
PurpurMC/Purpur@439f15db Updated Upstream (Paper)
PurpurMC/Purpur@46a28b93 [ci/skip] update version in README
2025-06-18 17:36:28 +03:00

130 lines
7.2 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
Date: Wed, 29 Jan 2025 00:54:19 +0300
Subject: [PATCH] Async locate command
diff --git a/net/minecraft/server/commands/LocateCommand.java b/net/minecraft/server/commands/LocateCommand.java
index a734b2597c3491db35d9660e169f8e8b6320900b..1692724f5406a22702f185f66073dd5e836ce7f8 100644
--- a/net/minecraft/server/commands/LocateCommand.java
+++ b/net/minecraft/server/commands/LocateCommand.java
@@ -100,44 +100,77 @@ public class LocateCommand {
}
private static int locateStructure(CommandSourceStack source, ResourceOrTagKeyArgument.Result<Structure> structure) throws CommandSyntaxException {
- Registry<Structure> registry = source.getLevel().registryAccess().lookupOrThrow(Registries.STRUCTURE);
- HolderSet<Structure> holderSet = (HolderSet<Structure>)getHolders(structure, registry)
- .orElseThrow(() -> ERROR_STRUCTURE_INVALID.create(structure.asPrintable()));
- BlockPos blockPos = BlockPos.containing(source.getPosition());
- ServerLevel level = source.getLevel();
- Stopwatch stopwatch = Stopwatch.createStarted(Util.TICKER);
- Pair<BlockPos, Holder<Structure>> pair = level.getChunkSource().getGenerator().findNearestMapStructure(level, holderSet, blockPos, 100, false);
- stopwatch.stop();
- if (pair == null) {
- throw ERROR_STRUCTURE_NOT_FOUND.create(structure.asPrintable());
- } else {
- return showLocateResult(source, structure, blockPos, pair, "commands.locate.structure.success", false, stopwatch.elapsed());
- }
+ // DivineMC start - Async structure locate
+ io.papermc.paper.util.MCUtil.scheduleAsyncTask(() -> {
+ Registry<Structure> registry = source.getLevel().registryAccess().lookupOrThrow(Registries.STRUCTURE);
+ HolderSet<Structure> holderSet;
+ try {
+ holderSet = getHolders(structure, registry)
+ .orElseThrow(() -> ERROR_STRUCTURE_INVALID.create(structure.asPrintable()));
+ } catch (CommandSyntaxException e) {
+ source.sendFailure(Component.literal(e.getMessage()));
+ return;
+ }
+ BlockPos blockPos = BlockPos.containing(source.getPosition());
+ ServerLevel level = source.getLevel();
+ Stopwatch stopwatch = Stopwatch.createStarted(Util.TICKER);
+ Pair<BlockPos, Holder<Structure>> pair = level.getChunkSource().getGenerator().findNearestMapStructure(level, holderSet, blockPos, 100, false);
+ stopwatch.stop();
+ if (pair == null) {
+ try {
+ throw ERROR_STRUCTURE_NOT_FOUND.create(structure.asPrintable());
+ } catch (CommandSyntaxException e) {
+ source.sendFailure(Component.literal(e.getMessage()));
+ }
+ } else {
+ showLocateResult(source, structure, blockPos, pair, "commands.locate.structure.success", false, stopwatch.elapsed());
+ }
+ });
+ return 0;
+ // DivineMC end - Async structure locate
}
private static int locateBiome(CommandSourceStack source, ResourceOrTagArgument.Result<Biome> biome) throws CommandSyntaxException {
- BlockPos blockPos = BlockPos.containing(source.getPosition());
- Stopwatch stopwatch = Stopwatch.createStarted(Util.TICKER);
- Pair<BlockPos, Holder<Biome>> pair = source.getLevel().findClosestBiome3d(biome, blockPos, 6400, 32, 64);
- stopwatch.stop();
- if (pair == null) {
- throw ERROR_BIOME_NOT_FOUND.create(biome.asPrintable());
- } else {
- return showLocateResult(source, biome, blockPos, pair, "commands.locate.biome.success", true, stopwatch.elapsed());
- }
+ // DivineMC start - Async biome locate
+ io.papermc.paper.util.MCUtil.scheduleAsyncTask(() -> {
+ BlockPos blockPos = BlockPos.containing(source.getPosition());
+ Stopwatch stopwatch = Stopwatch.createStarted(Util.TICKER);
+ Pair<BlockPos, Holder<Biome>> pair = source.getLevel().findClosestBiome3d(biome, blockPos, 6400, 32, 64);
+ stopwatch.stop();
+ if (pair == null) {
+ try {
+ throw ERROR_BIOME_NOT_FOUND.create(biome.asPrintable());
+ } catch (CommandSyntaxException e) {
+ source.sendFailure(Component.literal(e.getMessage()));
+ }
+ } else {
+ showLocateResult(source, biome, blockPos, pair, "commands.locate.biome.success", true, stopwatch.elapsed());
+ }
+ });
+ return 0;
+ // DivineMC end - Async biome locate
}
private static int locatePoi(CommandSourceStack source, ResourceOrTagArgument.Result<PoiType> poiType) throws CommandSyntaxException {
- BlockPos blockPos = BlockPos.containing(source.getPosition());
- ServerLevel level = source.getLevel();
- Stopwatch stopwatch = Stopwatch.createStarted(Util.TICKER);
- Optional<Pair<Holder<PoiType>, BlockPos>> optional = level.getPoiManager().findClosestWithType(poiType, blockPos, 256, PoiManager.Occupancy.ANY);
- stopwatch.stop();
- if (optional.isEmpty()) {
- throw ERROR_POI_NOT_FOUND.create(poiType.asPrintable());
- } else {
- return showLocateResult(source, poiType, blockPos, optional.get().swap(), "commands.locate.poi.success", false, stopwatch.elapsed());
- }
+ // DivineMC start - Async poi locate
+ io.papermc.paper.util.MCUtil.scheduleAsyncTask(() -> {
+ BlockPos blockPos = BlockPos.containing(source.getPosition());
+ ServerLevel level = source.getLevel();
+ Stopwatch stopwatch = Stopwatch.createStarted(Util.TICKER);
+ Optional<Pair<Holder<PoiType>, BlockPos>> optional = level.getPoiManager().findClosestWithType(poiType, blockPos, 256, PoiManager.Occupancy.ANY);
+ stopwatch.stop();
+ if (optional.isEmpty()) {
+ try {
+ throw ERROR_POI_NOT_FOUND.create(poiType.asPrintable());
+ } catch (CommandSyntaxException e) {
+ source.sendFailure(Component.literal(e.getMessage()));
+ }
+ } else {
+ showLocateResult(source, poiType, blockPos, optional.get().swap(), "commands.locate.poi.success", false, stopwatch.elapsed());
+ }
+ });
+ return 0;
+ // DivineMC end - Async poi locate
}
public static int showLocateResult(
@@ -192,7 +225,7 @@ public class LocateCommand {
.withHoverEvent(new HoverEvent.ShowText(Component.translatable("chat.coordinates.tooltip")))
);
source.sendSuccess(() -> Component.translatable(translationKey, elementName, component, i), false);
- LOGGER.info("Locating element " + elementName + " took " + duration.toMillis() + " ms");
+ LOGGER.info("Locating element {} on Thread:{} took {} ms", elementName, Thread.currentThread().getName(), duration.toMillis()); // DivineMC - Log thread name
return i;
}