SPIGOT-7261: Add AsyncStructureSpawnEvent

By: Lauriichan <laura.endress@syntaxphoenix.com>
This commit is contained in:
CraftBukkit/Spigot 2023-03-04 08:36:00 +11:00
parent ed2f6b4efc
commit c8aa873369
2 changed files with 26 additions and 0 deletions

View file

@ -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;

View file

@ -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 {