SPIGOT-7283, SPIGOT-7318: Add AsyncStructureGenerateEvent and BlockState cloning

By: Lauriichan <laura.endress@playuniverse.org>
This commit is contained in:
CraftBukkit/Spigot
2023-09-29 06:54:35 +10:00
parent bbc6a0e459
commit c651c0a51b
61 changed files with 1920 additions and 4 deletions

View File

@@ -0,0 +1,10 @@
--- a/net/minecraft/server/commands/PlaceCommand.java
+++ b/net/minecraft/server/commands/PlaceCommand.java
@@ -130,6 +130,7 @@
if (!structurestart.isValid()) {
throw PlaceCommand.ERROR_STRUCTURE_FAILED.create();
} else {
+ structurestart.generationEventCause = org.bukkit.event.world.AsyncStructureGenerateEvent.Cause.COMMAND; // CraftBukkit - set AsyncStructureGenerateEvent.Cause.COMMAND as generation cause
StructureBoundingBox structureboundingbox = structurestart.getBoundingBox();
ChunkCoordIntPair chunkcoordintpair = new ChunkCoordIntPair(SectionPosition.blockToSectionCoord(structureboundingbox.minX()), SectionPosition.blockToSectionCoord(structureboundingbox.minZ()));
ChunkCoordIntPair chunkcoordintpair1 = new ChunkCoordIntPair(SectionPosition.blockToSectionCoord(structureboundingbox.maxX()), SectionPosition.blockToSectionCoord(structureboundingbox.maxZ()));

View File

@@ -0,0 +1,151 @@
--- a/net/minecraft/world/level/levelgen/structure/StructurePiece.java
+++ b/net/minecraft/world/level/levelgen/structure/StructurePiece.java
@@ -50,7 +50,7 @@
private EnumBlockRotation rotation;
protected int genDepth;
private final WorldGenFeatureStructurePieceType type;
- private static final Set<Block> SHAPE_CHECK_BLOCKS = ImmutableSet.builder().add(Blocks.NETHER_BRICK_FENCE).add(Blocks.TORCH).add(Blocks.WALL_TORCH).add(Blocks.OAK_FENCE).add(Blocks.SPRUCE_FENCE).add(Blocks.DARK_OAK_FENCE).add(Blocks.ACACIA_FENCE).add(Blocks.BIRCH_FENCE).add(Blocks.JUNGLE_FENCE).add(Blocks.LADDER).add(Blocks.IRON_BARS).build();
+ public static final Set<Block> SHAPE_CHECK_BLOCKS = ImmutableSet.<Block>builder().add(Blocks.NETHER_BRICK_FENCE).add(Blocks.TORCH).add(Blocks.WALL_TORCH).add(Blocks.OAK_FENCE).add(Blocks.SPRUCE_FENCE).add(Blocks.DARK_OAK_FENCE).add(Blocks.ACACIA_FENCE).add(Blocks.BIRCH_FENCE).add(Blocks.JUNGLE_FENCE).add(Blocks.LADDER).add(Blocks.IRON_BARS).build(); // CraftBukkit - decompile error / PAIL private -> public
protected StructurePiece(WorldGenFeatureStructurePieceType worldgenfeaturestructurepiecetype, int i, StructureBoundingBox structureboundingbox) {
this.type = worldgenfeaturestructurepiecetype;
@@ -59,14 +59,11 @@
}
public StructurePiece(WorldGenFeatureStructurePieceType worldgenfeaturestructurepiecetype, NBTTagCompound nbttagcompound) {
- int i = nbttagcompound.getInt("GD");
- DataResult dataresult = StructureBoundingBox.CODEC.parse(DynamicOpsNBT.INSTANCE, nbttagcompound.get("BB"));
- Logger logger = StructurePiece.LOGGER;
-
- Objects.requireNonNull(logger);
- this(worldgenfeaturestructurepiecetype, i, (StructureBoundingBox) dataresult.resultOrPartial(logger::error).orElseThrow(() -> {
+ // CraftBukkit start - decompile error
+ this(worldgenfeaturestructurepiecetype, nbttagcompound.getInt("GD"), (StructureBoundingBox) StructureBoundingBox.CODEC.parse(DynamicOpsNBT.INSTANCE, nbttagcompound.get("BB")).resultOrPartial(Objects.requireNonNull(StructurePiece.LOGGER)::error).orElseThrow(() -> {
return new IllegalArgumentException("Invalid boundingbox");
}));
+ // CraftBukkit end
int j = nbttagcompound.getInt("O");
this.setOrientation(j == -1 ? null : EnumDirection.from2DDataValue(j));
@@ -84,13 +81,11 @@
NBTTagCompound nbttagcompound = new NBTTagCompound();
nbttagcompound.putString("id", BuiltInRegistries.STRUCTURE_PIECE.getKey(this.getType()).toString());
- DataResult dataresult = StructureBoundingBox.CODEC.encodeStart(DynamicOpsNBT.INSTANCE, this.boundingBox);
- Logger logger = StructurePiece.LOGGER;
-
- Objects.requireNonNull(logger);
- dataresult.resultOrPartial(logger::error).ifPresent((nbtbase) -> {
- nbttagcompound.put("BB", nbtbase);
+ // CraftBukkit start - decompile error
+ StructureBoundingBox.CODEC.encodeStart(DynamicOpsNBT.INSTANCE, this.boundingBox).resultOrPartial(Objects.requireNonNull(StructurePiece.LOGGER)::error).ifPresent((nbtbase) -> {
+ nbttagcompound.put("BB", nbtbase);
});
+ // CraftBukkit end
EnumDirection enumdirection = this.getOrientation();
nbttagcompound.putInt("O", enumdirection == null ? -1 : enumdirection.get2DDataValue());
@@ -190,6 +185,11 @@
}
generatoraccessseed.setBlock(blockposition_mutableblockposition, iblockdata, 2);
+ // CraftBukkit start - fluid handling is already done if we have a transformer generator access
+ if (generatoraccessseed instanceof org.bukkit.craftbukkit.util.TransformerGeneratorAccess) {
+ return;
+ }
+ // CraftBukkit end
Fluid fluid = generatoraccessseed.getFluidState(blockposition_mutableblockposition);
if (!fluid.isEmpty()) {
@@ -204,6 +204,38 @@
}
}
+ // CraftBukkit start
+ protected boolean placeCraftBlockEntity(WorldAccess worldAccess, BlockPosition position, org.bukkit.craftbukkit.block.CraftBlockEntityState<?> craftBlockEntityState, int i) {
+ if (worldAccess instanceof org.bukkit.craftbukkit.util.TransformerGeneratorAccess transformerAccess) {
+ return transformerAccess.setCraftBlock(position, craftBlockEntityState, i);
+ }
+ boolean result = worldAccess.setBlock(position, craftBlockEntityState.getHandle(), i);
+ TileEntity tileEntity = worldAccess.getBlockEntity(position);
+ if (tileEntity != null) {
+ tileEntity.load(craftBlockEntityState.getSnapshotNBT());
+ }
+ return result;
+ }
+
+ protected void placeCraftSpawner(WorldAccess worldAccess, BlockPosition position, org.bukkit.entity.EntityType entityType, int i) {
+ // This method is used in structures that are generated by code and place spawners as they set the entity after the block was placed making it impossible for plugins to access that information
+ org.bukkit.craftbukkit.block.CraftCreatureSpawner spawner = (org.bukkit.craftbukkit.block.CraftCreatureSpawner) org.bukkit.craftbukkit.block.CraftBlockStates.getBlockState(position, Blocks.SPAWNER.defaultBlockState(), null);
+ spawner.setSpawnedType(entityType);
+ placeCraftBlockEntity(worldAccess, position, spawner, i);
+ }
+
+ protected void setCraftLootTable(WorldAccess worldAccess, BlockPosition position, RandomSource randomSource, net.minecraft.resources.MinecraftKey loottableKey) {
+ // This method is used in structures that use data markers to a loot table to loot containers as otherwise plugins won't have access to that information.
+ net.minecraft.world.level.block.entity.TileEntity tileEntity = worldAccess.getBlockEntity(position);
+ if (tileEntity instanceof net.minecraft.world.level.block.entity.TileEntityLootable tileEntityLootable) {
+ tileEntityLootable.setLootTable(loottableKey, randomSource.nextLong());
+ if (worldAccess instanceof org.bukkit.craftbukkit.util.TransformerGeneratorAccess transformerAccess) {
+ transformerAccess.setCraftBlock(position, (org.bukkit.craftbukkit.block.CraftBlockState) org.bukkit.craftbukkit.block.CraftBlockStates.getBlockState(position, tileEntity.getBlockState(), tileEntityLootable.saveWithFullMetadata()), 3);
+ }
+ }
+ }
+ // CraftBukkit end
+
protected boolean canBeReplaced(IWorldReader iworldreader, int i, int j, int k, StructureBoundingBox structureboundingbox) {
return true;
}
@@ -397,12 +429,20 @@
iblockdata = reorient(worldaccess, blockposition, Blocks.CHEST.defaultBlockState());
}
+ // CraftBukkit start
+ /*
worldaccess.setBlock(blockposition, iblockdata, 2);
TileEntity tileentity = worldaccess.getBlockEntity(blockposition);
if (tileentity instanceof TileEntityChest) {
((TileEntityChest) tileentity).setLootTable(minecraftkey, randomsource.nextLong());
}
+ */
+ org.bukkit.craftbukkit.block.CraftChest chestState = (org.bukkit.craftbukkit.block.CraftChest) org.bukkit.craftbukkit.block.CraftBlockStates.getBlockState(blockposition, iblockdata, null);
+ chestState.setLootTable(org.bukkit.Bukkit.getLootTable(org.bukkit.craftbukkit.util.CraftNamespacedKey.fromMinecraft(minecraftkey)));
+ chestState.setSeed(randomsource.nextLong());
+ placeCraftBlockEntity(worldaccess, blockposition, chestState, 2);
+ // CraftBukkit end
return true;
} else {
@@ -414,12 +454,31 @@
BlockPosition.MutableBlockPosition blockposition_mutableblockposition = this.getWorldPos(i, j, k);
if (structureboundingbox.isInside(blockposition_mutableblockposition) && !generatoraccessseed.getBlockState(blockposition_mutableblockposition).is(Blocks.DISPENSER)) {
+ // CraftBukkit start
+ /*
this.placeBlock(generatoraccessseed, (IBlockData) Blocks.DISPENSER.defaultBlockState().setValue(BlockDispenser.FACING, enumdirection), i, j, k, structureboundingbox);
TileEntity tileentity = generatoraccessseed.getBlockEntity(blockposition_mutableblockposition);
if (tileentity instanceof TileEntityDispenser) {
((TileEntityDispenser) tileentity).setLootTable(minecraftkey, randomsource.nextLong());
}
+ */
+ if (!this.canBeReplaced(generatoraccessseed, i, j, k, structureboundingbox)) {
+ return true;
+ }
+ IBlockData iblockdata = Blocks.DISPENSER.defaultBlockState().setValue(BlockDispenser.FACING, enumdirection);
+ if (this.mirror != EnumBlockMirror.NONE) {
+ iblockdata = iblockdata.mirror(this.mirror);
+ }
+ if (this.rotation != EnumBlockRotation.NONE) {
+ iblockdata = iblockdata.rotate(this.rotation);
+ }
+
+ org.bukkit.craftbukkit.block.CraftDispenser dispenserState = (org.bukkit.craftbukkit.block.CraftDispenser) org.bukkit.craftbukkit.block.CraftBlockStates.getBlockState(blockposition_mutableblockposition, iblockdata, null);
+ dispenserState.setLootTable(org.bukkit.Bukkit.getLootTable(org.bukkit.craftbukkit.util.CraftNamespacedKey.fromMinecraft(minecraftkey)));
+ dispenserState.setSeed(randomsource.nextLong());
+ placeCraftBlockEntity(generatoraccessseed, blockposition_mutableblockposition, dispenserState, 2);
+ // CraftBukkit end
return true;
} else {

View File

@@ -0,0 +1,38 @@
--- a/net/minecraft/world/level/levelgen/structure/StructureStart.java
+++ b/net/minecraft/world/level/levelgen/structure/StructureStart.java
@@ -31,6 +31,7 @@
private int references;
@Nullable
private volatile StructureBoundingBox cachedBoundingBox;
+ public org.bukkit.event.world.AsyncStructureGenerateEvent.Cause generationEventCause = org.bukkit.event.world.AsyncStructureGenerateEvent.Cause.WORLD_GENERATION; // CraftBukkit
public StructureStart(Structure structure, ChunkCoordIntPair chunkcoordintpair, int i, PiecesContainer piecescontainer) {
this.structure = structure;
@@ -91,6 +92,8 @@
StructureBoundingBox structureboundingbox1 = ((StructurePiece) list.get(0)).boundingBox;
BlockPosition blockposition = structureboundingbox1.getCenter();
BlockPosition blockposition1 = new BlockPosition(blockposition.getX(), structureboundingbox1.minY(), blockposition.getZ());
+ // CraftBukkit start
+ /*
Iterator iterator = list.iterator();
while (iterator.hasNext()) {
@@ -100,6 +103,18 @@
structurepiece.postProcess(generatoraccessseed, structuremanager, chunkgenerator, randomsource, structureboundingbox, chunkcoordintpair, blockposition1);
}
}
+ */
+ List<StructurePiece> pieces = list.stream().filter(piece -> piece.getBoundingBox().intersects(structureboundingbox)).toList();
+ if (!pieces.isEmpty()) {
+ org.bukkit.craftbukkit.util.TransformerGeneratorAccess transformerAccess = new org.bukkit.craftbukkit.util.TransformerGeneratorAccess();
+ transformerAccess.setHandle(generatoraccessseed);
+ transformerAccess.setStructureTransformer(new org.bukkit.craftbukkit.util.CraftStructureTransformer(generationEventCause, generatoraccessseed, structuremanager, structure, structureboundingbox, chunkcoordintpair));
+ for (StructurePiece piece : pieces) {
+ piece.postProcess(transformerAccess, structuremanager, chunkgenerator, randomsource, structureboundingbox, chunkcoordintpair, blockposition1);
+ }
+ transformerAccess.getStructureTransformer().discard();
+ }
+ // CraftBukkit end
this.structure.afterPlace(generatoraccessseed, structuremanager, chunkgenerator, randomsource, structureboundingbox, chunkcoordintpair, this.pieceContainer);
}

View File

@@ -0,0 +1,18 @@
--- a/net/minecraft/world/level/levelgen/structure/structures/DesertPyramidStructure.java
+++ b/net/minecraft/world/level/levelgen/structure/structures/DesertPyramidStructure.java
@@ -70,6 +70,15 @@
private static void placeSuspiciousSand(StructureBoundingBox structureboundingbox, GeneratorAccessSeed generatoraccessseed, BlockPosition blockposition) {
if (structureboundingbox.isInside(blockposition)) {
+ // CraftBukkit start
+ if (generatoraccessseed instanceof org.bukkit.craftbukkit.util.TransformerGeneratorAccess transformerAccess) {
+ org.bukkit.craftbukkit.block.CraftBrushableBlock brushableState = (org.bukkit.craftbukkit.block.CraftBrushableBlock) org.bukkit.craftbukkit.block.CraftBlockStates.getBlockState(blockposition, Blocks.SUSPICIOUS_SAND.defaultBlockState(), null);
+ brushableState.setLootTable(org.bukkit.Bukkit.getLootTable(org.bukkit.craftbukkit.util.CraftNamespacedKey.fromMinecraft(LootTables.DESERT_PYRAMID_ARCHAEOLOGY)));
+ brushableState.setSeed(blockposition.asLong());
+ transformerAccess.setCraftBlock(blockposition, brushableState, 2);
+ return;
+ }
+ // CraftBukkit end
generatoraccessseed.setBlock(blockposition, Blocks.SUSPICIOUS_SAND.defaultBlockState(), 2);
generatoraccessseed.getBlockEntity(blockposition, TileEntityTypes.BRUSHABLE_BLOCK).ifPresent((brushableblockentity) -> {
brushableblockentity.setLootTable(LootTables.DESERT_PYRAMID_ARCHAEOLOGY, blockposition.asLong());

View File

@@ -0,0 +1,15 @@
--- a/net/minecraft/world/level/levelgen/structure/structures/EndCityPieces.java
+++ b/net/minecraft/world/level/levelgen/structure/structures/EndCityPieces.java
@@ -284,7 +284,12 @@
BlockPosition blockposition1 = blockposition.below();
if (structureboundingbox.isInside(blockposition1)) {
+ // CraftBukkit start - ensure block transformation
+ /*
TileEntityLootable.setLootTable(worldaccess, randomsource, blockposition1, LootTables.END_CITY_TREASURE);
+ */
+ setCraftLootTable(worldaccess, blockposition1, randomsource, LootTables.END_CITY_TREASURE);
+ // CraftBukkit end
}
} else if (structureboundingbox.isInside(blockposition) && World.isInSpawnableBounds(blockposition)) {
if (s.startsWith("Sentry")) {

View File

@@ -0,0 +1,19 @@
--- a/net/minecraft/world/level/levelgen/structure/structures/IglooPieces.java
+++ b/net/minecraft/world/level/levelgen/structure/structures/IglooPieces.java
@@ -85,11 +85,16 @@
protected void handleDataMarker(String s, BlockPosition blockposition, WorldAccess worldaccess, RandomSource randomsource, StructureBoundingBox structureboundingbox) {
if ("chest".equals(s)) {
worldaccess.setBlock(blockposition, Blocks.AIR.defaultBlockState(), 3);
+ // CraftBukkit start - ensure block transformation
+ /*
TileEntity tileentity = worldaccess.getBlockEntity(blockposition.below());
if (tileentity instanceof TileEntityChest) {
((TileEntityChest) tileentity).setLootTable(LootTables.IGLOO_CHEST, randomsource.nextLong());
}
+ */
+ setCraftLootTable(worldaccess, blockposition.below(), randomsource, LootTables.IGLOO_CHEST);
+ // CraftBukkit end
}
}

View File

@@ -0,0 +1,55 @@
--- a/net/minecraft/world/level/levelgen/structure/structures/MineshaftPieces.java
+++ b/net/minecraft/world/level/levelgen/structure/structures/MineshaftPieces.java
@@ -42,6 +42,10 @@
import net.minecraft.world.level.storage.loot.LootTables;
import org.slf4j.Logger;
+// CraftBukkit start - imports
+import net.minecraft.nbt.NBTBase;
+// CraftBukkit end
+
public class MineshaftPieces {
static final Logger LOGGER = LogUtils.getLogger();
@@ -514,6 +518,8 @@
if (structureboundingbox.isInside(blockposition_mutableblockposition) && this.isInterior(generatoraccessseed, 1, 0, l, structureboundingbox)) {
this.hasPlacedSpider = true;
+ // CraftBukkit start
+ /*
generatoraccessseed.setBlock(blockposition_mutableblockposition, Blocks.SPAWNER.defaultBlockState(), 2);
TileEntity tileentity = generatoraccessseed.getBlockEntity(blockposition_mutableblockposition);
@@ -522,6 +528,9 @@
tileentitymobspawner.setEntityId(EntityTypes.CAVE_SPIDER, randomsource);
}
+ */
+ placeCraftSpawner(generatoraccessseed, blockposition_mutableblockposition, org.bukkit.entity.EntityType.CAVE_SPIDER, 2);
+ // CraftBukkit end
}
}
}
@@ -813,11 +822,11 @@
public d(NBTTagCompound nbttagcompound) {
super(WorldGenFeatureStructurePieceType.MINE_SHAFT_ROOM, nbttagcompound);
- DataResult dataresult = StructureBoundingBox.CODEC.listOf().parse(DynamicOpsNBT.INSTANCE, nbttagcompound.getList("Entrances", 11));
+ DataResult<List<StructureBoundingBox>> dataresult = StructureBoundingBox.CODEC.listOf().parse(DynamicOpsNBT.INSTANCE, nbttagcompound.getList("Entrances", 11)); // CraftBukkit - decompile error
Logger logger = MineshaftPieces.LOGGER;
Objects.requireNonNull(logger);
- Optional optional = dataresult.resultOrPartial(logger::error);
+ Optional<List<StructureBoundingBox>> optional = dataresult.resultOrPartial(logger::error); // CraftBukkit - decompile error
List list = this.childEntranceBoxes;
Objects.requireNonNull(this.childEntranceBoxes);
@@ -923,7 +932,7 @@
@Override
protected void addAdditionalSaveData(StructurePieceSerializationContext structurepieceserializationcontext, NBTTagCompound nbttagcompound) {
super.addAdditionalSaveData(structurepieceserializationcontext, nbttagcompound);
- DataResult dataresult = StructureBoundingBox.CODEC.listOf().encodeStart(DynamicOpsNBT.INSTANCE, this.childEntranceBoxes);
+ DataResult<NBTBase> dataresult = StructureBoundingBox.CODEC.listOf().encodeStart(DynamicOpsNBT.INSTANCE, this.childEntranceBoxes); // CraftBukkit - decompile error
Logger logger = MineshaftPieces.LOGGER;
Objects.requireNonNull(logger);

View File

@@ -0,0 +1,21 @@
--- a/net/minecraft/world/level/levelgen/structure/structures/NetherFortressPieces.java
+++ b/net/minecraft/world/level/levelgen/structure/structures/NetherFortressPieces.java
@@ -428,6 +428,8 @@
if (structureboundingbox.isInside(blockposition_mutableblockposition)) {
this.hasPlacedSpawner = true;
+ // CraftBukkit start
+ /*
generatoraccessseed.setBlock(blockposition_mutableblockposition, Blocks.SPAWNER.defaultBlockState(), 2);
TileEntity tileentity = generatoraccessseed.getBlockEntity(blockposition_mutableblockposition);
@@ -436,6 +438,9 @@
tileentitymobspawner.setEntityId(EntityTypes.BLAZE, randomsource);
}
+ */
+ placeCraftSpawner(generatoraccessseed, blockposition_mutableblockposition, org.bukkit.entity.EntityType.BLAZE, 2);
+ // CraftBukkit end
}
}

View File

@@ -0,0 +1,23 @@
--- a/net/minecraft/world/level/levelgen/structure/structures/OceanRuinPieces.java
+++ b/net/minecraft/world/level/levelgen/structure/structures/OceanRuinPieces.java
@@ -198,12 +198,20 @@
@Override
protected void handleDataMarker(String s, BlockPosition blockposition, WorldAccess worldaccess, RandomSource randomsource, StructureBoundingBox structureboundingbox) {
if ("chest".equals(s)) {
+ // CraftBukkit start - transform block to ensure loot table is accessible
+ /*
worldaccess.setBlock(blockposition, (IBlockData) Blocks.CHEST.defaultBlockState().setValue(BlockChest.WATERLOGGED, worldaccess.getFluidState(blockposition).is(TagsFluid.WATER)), 2);
TileEntity tileentity = worldaccess.getBlockEntity(blockposition);
if (tileentity instanceof TileEntityChest) {
((TileEntityChest) tileentity).setLootTable(this.isLarge ? LootTables.UNDERWATER_RUIN_BIG : LootTables.UNDERWATER_RUIN_SMALL, randomsource.nextLong());
}
+ */
+ org.bukkit.craftbukkit.block.CraftChest craftChest = (org.bukkit.craftbukkit.block.CraftChest) org.bukkit.craftbukkit.block.CraftBlockStates.getBlockState(blockposition, Blocks.CHEST.defaultBlockState().setValue(BlockChest.WATERLOGGED, worldaccess.getFluidState(blockposition).is(TagsFluid.WATER)), null);
+ craftChest.setSeed(randomsource.nextLong());
+ craftChest.setLootTable(org.bukkit.Bukkit.getLootTable(org.bukkit.craftbukkit.util.CraftNamespacedKey.fromMinecraft(this.isLarge ? LootTables.UNDERWATER_RUIN_BIG : LootTables.UNDERWATER_RUIN_SMALL)));
+ placeCraftBlockEntity(worldaccess, blockposition, craftChest, 2);
+ // CraftBukkit end
} else if ("drowned".equals(s)) {
EntityDrowned entitydrowned = (EntityDrowned) EntityTypes.DROWNED.create(worldaccess.getLevel());

View File

@@ -0,0 +1,30 @@
--- a/net/minecraft/world/level/levelgen/structure/structures/StrongholdPieces.java
+++ b/net/minecraft/world/level/levelgen/structure/structures/StrongholdPieces.java
@@ -53,7 +53,7 @@
public boolean doPlace(int i) {
return super.doPlace(i) && i > 5;
}
- }};
+ } }; // CraftBukkit - fix decompile styling
private static List<StrongholdPieces.f> currentPieces;
static Class<? extends StrongholdPieces.p> imposedPiece;
private static int totalWeight;
@@ -1136,6 +1136,8 @@
if (structureboundingbox.isInside(blockposition_mutableblockposition)) {
this.hasPlacedSpawner = true;
+ // CraftBukkit start
+ /*
generatoraccessseed.setBlock(blockposition_mutableblockposition, Blocks.SPAWNER.defaultBlockState(), 2);
TileEntity tileentity = generatoraccessseed.getBlockEntity(blockposition_mutableblockposition);
@@ -1144,6 +1146,9 @@
tileentitymobspawner.setEntityId(EntityTypes.SILVERFISH, randomsource);
}
+ */
+ placeCraftSpawner(generatoraccessseed, blockposition_mutableblockposition, org.bukkit.entity.EntityType.SILVERFISH, 2);
+ // CraftBukkit end
}
}

View File

@@ -34,7 +34,66 @@
return definedstructure_blockinfo.pos.getY();
}).thenComparingInt((definedstructure_blockinfo) -> {
return definedstructure_blockinfo.pos.getX();
@@ -472,11 +483,13 @@
@@ -229,6 +240,19 @@
if (this.palettes.isEmpty()) {
return false;
} else {
+ // CraftBukkit start
+ // We only want the TransformerGeneratorAccess at certain locations because in here are many "block update" calls that shouldn't be transformed
+ WorldAccess wrappedAccess = worldaccess;
+ org.bukkit.craftbukkit.util.CraftStructureTransformer structureTransformer = null;
+ if (wrappedAccess instanceof org.bukkit.craftbukkit.util.TransformerGeneratorAccess transformerAccess) {
+ worldaccess = transformerAccess.getHandle();
+ structureTransformer = transformerAccess.getStructureTransformer();
+ // The structureTransformer is not needed if we can not transform blocks therefore we can save a little bit of performance doing this
+ if (structureTransformer != null && !structureTransformer.canTransformBlocks()) {
+ structureTransformer = null;
+ }
+ }
+ // CraftBukkit end
List<DefinedStructure.BlockInfo> list = definedstructureinfo.getRandomPalette(this.palettes, blockposition).blocks();
if ((!list.isEmpty() || !definedstructureinfo.isIgnoreEntities() && !this.entityInfoList.isEmpty()) && this.size.getX() >= 1 && this.size.getY() >= 1 && this.size.getZ() >= 1) {
@@ -260,6 +284,20 @@
Clearable.tryClear(tileentity);
worldaccess.setBlock(blockposition2, Blocks.BARRIER.defaultBlockState(), 20);
}
+ // CraftBukkit start
+ if (structureTransformer != null) {
+ org.bukkit.craftbukkit.block.CraftBlockState craftBlockState = (org.bukkit.craftbukkit.block.CraftBlockState) org.bukkit.craftbukkit.block.CraftBlockStates.getBlockState(blockposition2, iblockdata, null);
+ if (definedstructure_blockinfo.nbt != null && craftBlockState instanceof org.bukkit.craftbukkit.block.CraftBlockEntityState<?> entityState) {
+ entityState.loadData(definedstructure_blockinfo.nbt);
+ if (craftBlockState instanceof org.bukkit.craftbukkit.block.CraftLootable<?> craftLootable) {
+ craftLootable.setSeed(randomsource.nextLong());
+ }
+ }
+ craftBlockState = structureTransformer.transformCraftState(craftBlockState);
+ iblockdata = craftBlockState.getHandle();
+ definedstructure_blockinfo = new DefinedStructure.BlockInfo(blockposition2, iblockdata, (craftBlockState instanceof org.bukkit.craftbukkit.block.CraftBlockEntityState<?> craftBlockEntityState ? craftBlockEntityState.getSnapshotNBT() : null));
+ }
+ // CraftBukkit end
if (worldaccess.setBlock(blockposition2, iblockdata, i)) {
j = Math.min(j, blockposition2.getX());
@@ -272,7 +310,7 @@
if (definedstructure_blockinfo.nbt != null) {
tileentity = worldaccess.getBlockEntity(blockposition2);
if (tileentity != null) {
- if (tileentity instanceof TileEntityLootable) {
+ if (wrappedAccess == worldaccess && tileentity instanceof TileEntityLootable) { // CraftBukkit - only process if don't have a transformer access (originalAccess == worldaccess)
definedstructure_blockinfo.nbt.putLong("LootTableSeed", randomsource.nextLong());
}
@@ -377,7 +415,7 @@
}
if (!definedstructureinfo.isIgnoreEntities()) {
- this.placeEntities(worldaccess, blockposition, definedstructureinfo.getMirror(), definedstructureinfo.getRotation(), definedstructureinfo.getRotationPivot(), structureboundingbox, definedstructureinfo.shouldFinalizeEntities());
+ this.placeEntities(wrappedAccess, blockposition, definedstructureinfo.getMirror(), definedstructureinfo.getRotation(), definedstructureinfo.getRotationPivot(), structureboundingbox, definedstructureinfo.shouldFinalizeEntities()); // CraftBukkit
}
return true;
@@ -472,11 +510,13 @@
}
private static Optional<Entity> createEntityIgnoreException(WorldAccess worldaccess, NBTTagCompound nbttagcompound) {
@@ -52,7 +111,7 @@
}
public BaseBlockPosition getSize(EnumBlockRotation enumblockrotation) {
@@ -690,6 +703,11 @@
@@ -690,6 +730,11 @@
nbttagcompound.put("entities", nbttaglist3);
nbttagcompound.put("size", this.newIntegerList(this.size.getX(), this.size.getY(), this.size.getZ()));
@@ -64,7 +123,7 @@
return GameProfileSerializer.addCurrentDataVersion(nbttagcompound);
}
@@ -729,6 +747,12 @@
@@ -729,6 +774,12 @@
}
}
@@ -77,7 +136,7 @@
}
private void loadPalette(HolderGetter<Block> holdergetter, NBTTagList nbttaglist, NBTTagList nbttaglist1) {
@@ -858,7 +882,7 @@
@@ -858,7 +909,7 @@
public IBlockData stateFor(int i) {
IBlockData iblockdata = (IBlockData) this.ids.byId(i);