From c8aa8733694d015fb47328c873d22147cda65839 Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Sat, 4 Mar 2023 08:36:00 +1100 Subject: [PATCH] SPIGOT-7261: Add AsyncStructureSpawnEvent By: Lauriichan --- .../minecraft/world/level/StructureManager.patch | 11 +++++++++++ .../world/level/chunk/ChunkGenerator.patch | 15 +++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 paper-server/nms-patches/net/minecraft/world/level/StructureManager.patch diff --git a/paper-server/nms-patches/net/minecraft/world/level/StructureManager.patch b/paper-server/nms-patches/net/minecraft/world/level/StructureManager.patch new file mode 100644 index 0000000000..964c556e4f --- /dev/null +++ b/paper-server/nms-patches/net/minecraft/world/level/StructureManager.patch @@ -0,0 +1,11 @@ +--- a/net/minecraft/world/level/StructureManager.java ++++ b/net/minecraft/world/level/StructureManager.java +@@ -32,7 +32,7 @@ + + public class StructureManager { + +- private final GeneratorAccess level; ++ public final GeneratorAccess level; // PAIL private -> public + private final WorldOptions worldOptions; + private final StructureCheck structureCheck; + diff --git a/paper-server/nms-patches/net/minecraft/world/level/chunk/ChunkGenerator.patch b/paper-server/nms-patches/net/minecraft/world/level/chunk/ChunkGenerator.patch index b1e8eabbe7..28b0aff2fd 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/chunk/ChunkGenerator.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/chunk/ChunkGenerator.patch @@ -61,3 +61,18 @@ private static StructureBoundingBox getWritableArea(IChunkAccess ichunkaccess) { ChunkCoordIntPair chunkcoordintpair = ichunkaccess.getPos(); int i = chunkcoordintpair.getMinBlockX(); +@@ -576,6 +603,14 @@ + StructureStart structurestart = structure.generate(iregistrycustom, this, this.biomeSource, randomstate, structuretemplatemanager, i, chunkcoordintpair, j, ichunkaccess, predicate); + + if (structurestart.isValid()) { ++ // CraftBukkit start ++ StructureBoundingBox box = structurestart.getBoundingBox(); ++ org.bukkit.event.world.AsyncStructureSpawnEvent event = new org.bukkit.event.world.AsyncStructureSpawnEvent(structuremanager.level.getMinecraftWorld().getWorld(), org.bukkit.craftbukkit.generator.strucutre.CraftStructure.minecraftToBukkit(structure, iregistrycustom), new org.bukkit.util.BoundingBox(box.minX(), box.minY(), box.minZ(), box.maxX(), box.maxY(), box.maxZ()), chunkcoordintpair.x, chunkcoordintpair.z); ++ org.bukkit.Bukkit.getPluginManager().callEvent(event); ++ if (event.isCancelled()) { ++ return true; ++ } ++ // CraftBukkit end + structuremanager.setStartForStructure(sectionposition, structure, structurestart, ichunkaccess); + return true; + } else {