mirror of
https://github.com/BX-Team/DivineMC.git
synced 2025-12-19 14:59:25 +00:00
130 lines
7.2 KiB
Diff
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 2723d5377567241921fef61952e474c1c0ee9bbf..ee9f84b33a34b5b9d7c3f8928c958c298f780a03 100644
|
|
--- a/net/minecraft/server/commands/LocateCommand.java
|
|
+++ b/net/minecraft/server/commands/LocateCommand.java
|
|
@@ -103,44 +103,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(
|
|
@@ -195,7 +228,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;
|
|
}
|
|
|