9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-22 08:29:28 +00:00
Files
Leaf/leaf-server/paper-patches/features/0047-Async-structure-locate-api.patch
Dreeam 3af60cbe46 Updated Upstream (Paper)
Upstream has released updates that appear to apply and compile correctly

Paper Changes:
PaperMC/Paper@de410d13 Fix reobf mappings regression in GameRules.Type (#12437)
PaperMC/Paper@33e8928f Add support for bonus chest configuration in WorldCreator (#12344)
PaperMC/Paper@723b511f Clone exit location passed to teleport event (#12354)
PaperMC/Paper@ed322043 Clone blockpos in InsideBlockEffectApplier record
PaperMC/Paper@6b4ad082 Add PlayerRespawnEvent#isMissingRespawnBlock (#12422)
PaperMC/Paper@c0bd5688 Add logic for Human canUseEquipmentSlot (#12433)
2025-04-14 21:30:21 -04:00

61 lines
3.2 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: HaHaWTH <102713261+HaHaWTH@users.noreply.github.com>
Date: Mon, 1 Nov 2077 00:00:00 +0800
Subject: [PATCH] Async structure locate api
This patch depends on Asynchronous locator patch.
Added some asynchronous structure locate methods in World,
requires async-locator to be enabled in Leaf config, or else it will fall back to sync methods.
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
index 28ece1167907558c21d292cb36960a026d0c0897..7d0874e3a4da1bfce80a83635c904c7d257c276b 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
@@ -2277,6 +2277,45 @@ public class CraftWorld extends CraftRegionAccessor implements World {
return new CraftStructureSearchResult(CraftStructure.minecraftToBukkit(found.getSecond().value()), CraftLocation.toBukkit(found.getFirst(), this));
}
+ // Leaf start - Async structure locate api
+ @Override
+ public void locateNearestStructureAsync(Location origin, StructureType structureType, int radius, boolean findUnexplored, Consumer<StructureSearchResult> afterComplete) {
+ List<Structure> structures = new ArrayList<>();
+ for (Structure structure : RegistryAccess.registryAccess().getRegistry(RegistryKey.STRUCTURE)) {
+ if (structure.getStructureType() == structureType) {
+ structures.add(structure);
+ }
+ }
+
+ this.locateNearestStructureAsync(origin, structures, radius, findUnexplored, afterComplete);
+ }
+
+ @Override
+ public void locateNearestStructureAsync(Location origin, Structure structure, int radius, boolean findUnexplored, Consumer<StructureSearchResult> afterComplete) {
+ this.locateNearestStructureAsync(origin, List.of(structure), radius, findUnexplored, afterComplete);
+ }
+
+ public void locateNearestStructureAsync(Location origin, List<Structure> structures, int radius, boolean findUnexplored, Consumer<@Nullable StructureSearchResult> afterComplete) {
+ if (!org.dreeam.leaf.config.modules.async.AsyncLocator.enabled) afterComplete.accept(locateNearestStructure(origin, structures, radius, findUnexplored));
+ BlockPos originPos = BlockPos.containing(origin.getX(), origin.getY(), origin.getZ());
+ List<Holder<net.minecraft.world.level.levelgen.structure.Structure>> holders = new ArrayList<>();
+
+ for (Structure structure : structures) {
+ holders.add(Holder.direct(CraftStructure.bukkitToMinecraft(structure)));
+ }
+
+ org.dreeam.leaf.async.locate.AsyncLocator.locate(
+ this.getHandle(), HolderSet.direct(holders), originPos, radius, findUnexplored
+ ).thenOnServerThread(found -> {
+ if (found == null) {
+ afterComplete.accept(null);
+ return;
+ }
+ afterComplete.accept(new CraftStructureSearchResult(CraftStructure.minecraftToBukkit(found.getSecond().value()), CraftLocation.toBukkit(found.getFirst(), this)));
+ });
+ }
+ // Leaf end - Async structure locate api
+
// Paper start
@Override
public double getCoordinateScale() {