Move CraftBukkit per-file patches

By: Initial <noreply+automated@papermc.io>
This commit is contained in:
CraftBukkit/Spigot
2024-12-11 22:26:36 +01:00
parent a4de181b77
commit a265d64138
583 changed files with 71 additions and 857 deletions

View File

@@ -0,0 +1,7 @@
--- a/net/minecraft/world/level/levelgen/ChunkGeneratorAbstract.java
+++ b/net/minecraft/world/level/levelgen/ChunkGeneratorAbstract.java
@@ -1,3 +1,4 @@
+// keep
package net.minecraft.world.level.levelgen;
import com.google.common.annotations.VisibleForTesting;

View File

@@ -0,0 +1,22 @@
--- a/net/minecraft/world/level/levelgen/ChunkProviderFlat.java
+++ b/net/minecraft/world/level/levelgen/ChunkProviderFlat.java
@@ -34,10 +34,16 @@
private final GeneratorSettingsFlat settings;
public ChunkProviderFlat(GeneratorSettingsFlat generatorsettingsflat) {
- WorldChunkManagerHell worldchunkmanagerhell = new WorldChunkManagerHell(generatorsettingsflat.getBiome());
+ // CraftBukkit start
+ // WorldChunkManagerHell worldchunkmanagerhell = new WorldChunkManagerHell(generatorsettingsflat.getBiome());
- Objects.requireNonNull(generatorsettingsflat);
- super(worldchunkmanagerhell, SystemUtils.memoize(generatorsettingsflat::adjustGenerationSettings));
+ // Objects.requireNonNull(generatorsettingsflat);
+ this(generatorsettingsflat, new WorldChunkManagerHell(generatorsettingsflat.getBiome()));
+ }
+
+ public ChunkProviderFlat(GeneratorSettingsFlat generatorsettingsflat, net.minecraft.world.level.biome.WorldChunkManager worldchunkmanager) {
+ super(worldchunkmanager, SystemUtils.memoize(generatorsettingsflat::adjustGenerationSettings));
+ // CraftBukkit end
this.settings = generatorsettingsflat;
}

View File

@@ -0,0 +1,11 @@
--- a/net/minecraft/world/level/levelgen/MobSpawnerPatrol.java
+++ b/net/minecraft/world/level/levelgen/MobSpawnerPatrol.java
@@ -116,7 +116,7 @@
entitymonsterpatrolling.setPos((double) blockposition.getX(), (double) blockposition.getY(), (double) blockposition.getZ());
entitymonsterpatrolling.finalizeSpawn(worldserver, worldserver.getCurrentDifficultyAt(blockposition), EntitySpawnReason.PATROL, (GroupDataEntity) null);
- worldserver.addFreshEntityWithPassengers(entitymonsterpatrolling);
+ worldserver.addFreshEntityWithPassengers(entitymonsterpatrolling, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.PATROL); // CraftBukkit
return true;
} else {
return false;

View File

@@ -0,0 +1,11 @@
--- a/net/minecraft/world/level/levelgen/MobSpawnerPhantom.java
+++ b/net/minecraft/world/level/levelgen/MobSpawnerPhantom.java
@@ -74,7 +74,7 @@
if (entityphantom != null) {
entityphantom.moveTo(blockposition1, 0.0F, 0.0F);
groupdataentity = entityphantom.finalizeSpawn(worldserver, difficultydamagescaler, EntitySpawnReason.NATURAL, groupdataentity);
- worldserver.addFreshEntityWithPassengers(entityphantom);
+ worldserver.addFreshEntityWithPassengers(entityphantom, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.NATURAL); // CraftBukkit
++i;
}
}

View File

@@ -0,0 +1,69 @@
--- a/net/minecraft/world/level/levelgen/feature/EndPlatformFeature.java
+++ b/net/minecraft/world/level/levelgen/feature/EndPlatformFeature.java
@@ -8,6 +8,12 @@
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.levelgen.feature.configurations.WorldGenFeatureEmptyConfiguration;
+// CraftBukkit start
+import java.util.List;
+import org.bukkit.block.BlockState;
+import org.bukkit.event.world.PortalCreateEvent;
+// CraftBukkit end
+
public class EndPlatformFeature extends WorldGenerator<WorldGenFeatureEmptyConfiguration> {
public EndPlatformFeature(Codec<WorldGenFeatureEmptyConfiguration> codec) {
@@ -21,6 +27,13 @@
}
public static void createEndPlatform(WorldAccess worldaccess, BlockPosition blockposition, boolean flag) {
+ createEndPlatform(worldaccess, blockposition, flag, null);
+ // CraftBukkit start
+ }
+
+ public static void createEndPlatform(WorldAccess worldaccess, BlockPosition blockposition, boolean flag, Entity entity) {
+ org.bukkit.craftbukkit.util.BlockStateListPopulator blockList = new org.bukkit.craftbukkit.util.BlockStateListPopulator(worldaccess);
+ // CraftBukkit end
BlockPosition.MutableBlockPosition blockposition_mutableblockposition = blockposition.mutable();
for (int i = -2; i <= 2; ++i) {
@@ -29,16 +42,36 @@
BlockPosition.MutableBlockPosition blockposition_mutableblockposition1 = blockposition_mutableblockposition.set(blockposition).move(j, k, i);
Block block = k == -1 ? Blocks.OBSIDIAN : Blocks.AIR;
- if (!worldaccess.getBlockState(blockposition_mutableblockposition1).is(block)) {
+ // CraftBukkit start
+ if (!blockList.getBlockState(blockposition_mutableblockposition1).is(block)) {
if (flag) {
- worldaccess.destroyBlock(blockposition_mutableblockposition1, true, (Entity) null);
+ blockList.destroyBlock(blockposition_mutableblockposition1, true, (Entity) null);
}
- worldaccess.setBlock(blockposition_mutableblockposition1, block.defaultBlockState(), 3);
+ blockList.setBlock(blockposition_mutableblockposition1, block.defaultBlockState(), 3);
+ // CraftBukkit end
}
}
}
}
+ // CraftBukkit start
+ // SPIGOT-7746: Entity will only be null during world generation, which is async, so just generate without event
+ if (entity != null) {
+ org.bukkit.World bworld = worldaccess.getLevel().getWorld();
+ PortalCreateEvent portalEvent = new PortalCreateEvent((List<BlockState>) (List) blockList.getList(), bworld, entity.getBukkitEntity(), org.bukkit.event.world.PortalCreateEvent.CreateReason.END_PLATFORM);
+
+ worldaccess.getLevel().getCraftServer().getPluginManager().callEvent(portalEvent);
+ if (portalEvent.isCancelled()) {
+ return;
+ }
+ }
+
+ // SPIGOT-7856: End platform not dropping items after replacing blocks
+ if (flag) {
+ blockList.getList().forEach((state) -> worldaccess.destroyBlock(state.getPosition(), true, null));
+ }
+ blockList.updateList();
+ // CraftBukkit end
}
}

View File

@@ -0,0 +1,34 @@
--- a/net/minecraft/world/level/levelgen/structure/PersistentStructureLegacy.java
+++ b/net/minecraft/world/level/levelgen/structure/PersistentStructureLegacy.java
@@ -21,6 +21,10 @@
import net.minecraft.world.level.World;
import net.minecraft.world.level.storage.WorldPersistentData;
+// CraftBukkit start
+import net.minecraft.world.level.dimension.WorldDimension;
+// CraftBukkit end
+
public class PersistentStructureLegacy {
private static final Map<String, String> CURRENT_TO_LEGACY_MAP = (Map) SystemUtils.make(Maps.newHashMap(), (hashmap) -> {
@@ -233,16 +237,16 @@
}
}
- public static PersistentStructureLegacy getLegacyStructureHandler(ResourceKey<World> resourcekey, @Nullable WorldPersistentData worldpersistentdata) {
- if (resourcekey == World.OVERWORLD) {
+ public static PersistentStructureLegacy getLegacyStructureHandler(ResourceKey<WorldDimension> resourcekey, @Nullable WorldPersistentData worldpersistentdata) { // CraftBukkit
+ if (resourcekey == WorldDimension.OVERWORLD) { // CraftBukkit
return new PersistentStructureLegacy(worldpersistentdata, ImmutableList.of("Monument", "Stronghold", "Village", "Mineshaft", "Temple", "Mansion"), ImmutableList.of("Village", "Mineshaft", "Mansion", "Igloo", "Desert_Pyramid", "Jungle_Pyramid", "Swamp_Hut", "Stronghold", "Monument"));
} else {
ImmutableList immutablelist;
- if (resourcekey == World.NETHER) {
+ if (resourcekey == WorldDimension.NETHER) { // CraftBukkit
immutablelist = ImmutableList.of("Fortress");
return new PersistentStructureLegacy(worldpersistentdata, immutablelist, immutablelist);
- } else if (resourcekey == World.END) {
+ } else if (resourcekey == WorldDimension.END) { // CraftBukkit
immutablelist = ImmutableList.of("EndCity");
return new PersistentStructureLegacy(worldpersistentdata, immutablelist, immutablelist);
} else {

View File

@@ -0,0 +1,142 @@
--- a/net/minecraft/world/level/levelgen/structure/StructurePiece.java
+++ b/net/minecraft/world/level/levelgen/structure/StructurePiece.java
@@ -51,7 +51,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.PALE_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.PALE_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;
@@ -80,13 +80,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());
@@ -186,6 +184,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()) {
@@ -200,6 +203,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.loadWithComponents(craftBlockEntityState.getSnapshotNBT(), worldAccess.registryAccess());
+ }
+ 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(worldAccess, position, Blocks.SPAWNER.defaultBlockState(), null);
+ spawner.setSpawnedType(entityType);
+ placeCraftBlockEntity(worldAccess, position, spawner, i);
+ }
+
+ protected void setCraftLootTable(WorldAccess worldAccess, BlockPosition position, RandomSource randomSource, ResourceKey<LootTable> 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(worldAccess, position, tileEntity.getBlockState(), tileEntityLootable.saveWithFullMetadata(worldAccess.registryAccess())), 3);
+ }
+ }
+ }
+ // CraftBukkit end
+
protected boolean canBeReplaced(IWorldReader iworldreader, int i, int j, int k, StructureBoundingBox structureboundingbox) {
return true;
}
@@ -393,12 +428,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(resourcekey, randomsource.nextLong());
}
+ */
+ org.bukkit.craftbukkit.block.CraftChest chestState = (org.bukkit.craftbukkit.block.CraftChest) org.bukkit.craftbukkit.block.CraftBlockStates.getBlockState(worldaccess, blockposition, iblockdata, null);
+ chestState.setLootTable(org.bukkit.craftbukkit.CraftLootTable.minecraftToBukkit(resourcekey));
+ chestState.setSeed(randomsource.nextLong());
+ placeCraftBlockEntity(worldaccess, blockposition, chestState, 2);
+ // CraftBukkit end
return true;
} else {
@@ -410,12 +453,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(resourcekey, 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(generatoraccessseed, blockposition_mutableblockposition, iblockdata, null);
+ dispenserState.setLootTable(org.bukkit.craftbukkit.CraftLootTable.minecraftToBukkit(resourcekey));
+ dispenserState.setSeed(randomsource.nextLong());
+ placeCraftBlockEntity(generatoraccessseed, blockposition_mutableblockposition, dispenserState, 2);
+ // CraftBukkit end
return true;
} else {
@@ -428,7 +490,7 @@
}
public static StructureBoundingBox createBoundingBox(Stream<StructurePiece> stream) {
- Stream stream1 = stream.map(StructurePiece::getBoundingBox);
+ Stream<StructureBoundingBox> stream1 = stream.map(StructurePiece::getBoundingBox); // CraftBukkit - decompile error
Objects.requireNonNull(stream1);
return (StructureBoundingBox) StructureBoundingBox.encapsulatingBoxes(stream1::iterator).orElseThrow(() -> {

View File

@@ -0,0 +1,55 @@
--- a/net/minecraft/world/level/levelgen/structure/StructureStart.java
+++ b/net/minecraft/world/level/levelgen/structure/StructureStart.java
@@ -32,6 +32,12 @@
@Nullable
private volatile StructureBoundingBox cachedBoundingBox;
+ // CraftBukkit start
+ private static final org.bukkit.craftbukkit.persistence.CraftPersistentDataTypeRegistry DATA_TYPE_REGISTRY = new org.bukkit.craftbukkit.persistence.CraftPersistentDataTypeRegistry();
+ public org.bukkit.craftbukkit.persistence.DirtyCraftPersistentDataContainer persistentDataContainer = new org.bukkit.craftbukkit.persistence.DirtyCraftPersistentDataContainer(DATA_TYPE_REGISTRY);
+ public org.bukkit.event.world.AsyncStructureGenerateEvent.Cause generationEventCause = org.bukkit.event.world.AsyncStructureGenerateEvent.Cause.WORLD_GENERATION;
+ // CraftBukkit end
+
public StructureStart(Structure structure, ChunkCoordIntPair chunkcoordintpair, int i, PiecesContainer piecescontainer) {
this.structure = structure;
this.chunkPos = chunkcoordintpair;
@@ -91,6 +97,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 +108,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);
}
@@ -107,6 +127,11 @@
public NBTTagCompound createTag(StructurePieceSerializationContext structurepieceserializationcontext, ChunkCoordIntPair chunkcoordintpair) {
NBTTagCompound nbttagcompound = new NBTTagCompound();
+ // CraftBukkit start - store persistent data in nbt
+ if (!persistentDataContainer.isEmpty()) {
+ nbttagcompound.put("StructureBukkitValues", persistentDataContainer.toTagCompound());
+ }
+ // CraftBukkit end
if (this.isValid()) {
nbttagcompound.putString("id", structurepieceserializationcontext.registryAccess().lookupOrThrow(Registries.STRUCTURE).getKey(this.structure).toString());

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
@@ -68,6 +68,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(generatoraccessseed, blockposition, Blocks.SUSPICIOUS_SAND.defaultBlockState(), null);
+ brushableState.setLootTable(org.bukkit.craftbukkit.CraftLootTable.minecraftToBukkit(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
@@ -285,7 +285,12 @@
BlockPosition blockposition1 = blockposition.below();
if (structureboundingbox.isInside(blockposition1)) {
+ // CraftBukkit start - ensure block transformation
+ /*
RandomizableContainer.setBlockEntityLootTable(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
@@ -86,11 +86,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
@@ -44,6 +44,10 @@
import net.minecraft.world.level.storage.loot.LootTables;
import org.slf4j.Logger;
+// CraftBukkit start
+import net.minecraft.nbt.NBTBase;
+// CraftBukkit end
+
public class MineshaftPieces {
static final Logger LOGGER = LogUtils.getLogger();
@@ -520,6 +524,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);
@@ -528,6 +534,9 @@
tileentitymobspawner.setEntityId(EntityTypes.CAVE_SPIDER, randomsource);
}
+ */
+ placeCraftSpawner(generatoraccessseed, blockposition_mutableblockposition, org.bukkit.entity.EntityType.CAVE_SPIDER, 2);
+ // CraftBukkit end
}
}
}
@@ -819,11 +828,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);
@@ -929,7 +938,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
@@ -200,12 +200,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(worldaccess, blockposition, Blocks.CHEST.defaultBlockState().setValue(BlockChest.WATERLOGGED, worldaccess.getFluidState(blockposition).is(TagsFluid.WATER)), null);
+ craftChest.setSeed(randomsource.nextLong());
+ craftChest.setLootTable(org.bukkit.craftbukkit.CraftLootTable.minecraftToBukkit(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(), EntitySpawnReason.STRUCTURE);

View File

@@ -0,0 +1,15 @@
--- a/net/minecraft/world/level/levelgen/structure/structures/ShipwreckPieces.java
+++ b/net/minecraft/world/level/levelgen/structure/structures/ShipwreckPieces.java
@@ -79,7 +79,12 @@
ResourceKey<LootTable> resourcekey = (ResourceKey) ShipwreckPieces.MARKERS_TO_LOOT.get(s);
if (resourcekey != null) {
+ // CraftBukkit start - ensure block transformation
+ /*
RandomizableContainer.setBlockEntityLootTable(worldaccess, randomsource, blockposition.below(), resourcekey);
+ */
+ setCraftLootTable(worldaccess, blockposition.below(), randomsource, resourcekey);
+ // CraftBukkit end
}
}

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

@@ -0,0 +1,20 @@
--- a/net/minecraft/world/level/levelgen/structure/structures/SwampHutPiece.java
+++ b/net/minecraft/world/level/levelgen/structure/structures/SwampHutPiece.java
@@ -100,7 +100,7 @@
entitywitch.setPersistenceRequired();
entitywitch.moveTo((double) blockposition_mutableblockposition.getX() + 0.5D, (double) blockposition_mutableblockposition.getY(), (double) blockposition_mutableblockposition.getZ() + 0.5D, 0.0F, 0.0F);
entitywitch.finalizeSpawn(generatoraccessseed, generatoraccessseed.getCurrentDifficultyAt(blockposition_mutableblockposition), EntitySpawnReason.STRUCTURE, (GroupDataEntity) null);
- generatoraccessseed.addFreshEntityWithPassengers(entitywitch);
+ generatoraccessseed.addFreshEntityWithPassengers(entitywitch, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.CHUNK_GEN); // CraftBukkit - add SpawnReason
}
}
}
@@ -121,7 +121,7 @@
entitycat.setPersistenceRequired();
entitycat.moveTo((double) blockposition_mutableblockposition.getX() + 0.5D, (double) blockposition_mutableblockposition.getY(), (double) blockposition_mutableblockposition.getZ() + 0.5D, 0.0F, 0.0F);
entitycat.finalizeSpawn(worldaccess, worldaccess.getCurrentDifficultyAt(blockposition_mutableblockposition), EntitySpawnReason.STRUCTURE, (GroupDataEntity) null);
- worldaccess.addFreshEntityWithPassengers(entitycat);
+ worldaccess.addFreshEntityWithPassengers(entitycat, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.CHUNK_GEN); // CraftBukkit - add SpawnReason
}
}
}

View File

@@ -0,0 +1,147 @@
--- a/net/minecraft/world/level/levelgen/structure/templatesystem/DefinedStructure.java
+++ b/net/minecraft/world/level/levelgen/structure/templatesystem/DefinedStructure.java
@@ -56,6 +56,12 @@
import net.minecraft.world.phys.shapes.VoxelShapeBitSet;
import net.minecraft.world.phys.shapes.VoxelShapeDiscrete;
+// CraftBukkit start
+import net.minecraft.nbt.NBTBase;
+import org.bukkit.craftbukkit.persistence.CraftPersistentDataContainer;
+import org.bukkit.craftbukkit.persistence.CraftPersistentDataTypeRegistry;
+// CraftBukkit end
+
public class DefinedStructure {
public static final String PALETTE_TAG = "palette";
@@ -74,6 +80,11 @@
private BaseBlockPosition size;
private String author;
+ // CraftBukkit start - data containers
+ private static final CraftPersistentDataTypeRegistry DATA_TYPE_REGISTRY = new CraftPersistentDataTypeRegistry();
+ public CraftPersistentDataContainer persistentDataContainer = new CraftPersistentDataContainer(DATA_TYPE_REGISTRY);
+ // CraftBukkit end
+
public DefinedStructure() {
this.size = BaseBlockPosition.ZERO;
this.author = "?";
@@ -147,7 +158,7 @@
}
private static List<DefinedStructure.BlockInfo> buildInfoList(List<DefinedStructure.BlockInfo> list, List<DefinedStructure.BlockInfo> list1, List<DefinedStructure.BlockInfo> list2) {
- Comparator<DefinedStructure.BlockInfo> comparator = Comparator.comparingInt((definedstructure_blockinfo) -> {
+ Comparator<DefinedStructure.BlockInfo> comparator = Comparator.<DefinedStructure.BlockInfo>comparingInt((definedstructure_blockinfo) -> { // CraftBukkit - decompile error
return definedstructure_blockinfo.pos.getY();
}).thenComparingInt((definedstructure_blockinfo) -> {
return definedstructure_blockinfo.pos.getX();
@@ -253,6 +264,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) {
@@ -284,6 +308,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(worldaccess, 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());
@@ -296,7 +334,7 @@
if (definedstructure_blockinfo.nbt != null) {
tileentity = worldaccess.getBlockEntity(blockposition2);
if (tileentity != null) {
- if (tileentity instanceof RandomizableContainer) {
+ if (structureTransformer == null && tileentity instanceof RandomizableContainer) { // CraftBukkit - only process if don't have a transformer access (Was already set above) - SPIGOT-7520: Use structureTransformer as check, so that it is the same as above
definedstructure_blockinfo.nbt.putLong("LootTableSeed", randomsource.nextLong());
}
@@ -401,7 +439,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;
@@ -503,11 +541,13 @@
}
private static Optional<Entity> createEntityIgnoreException(WorldAccess worldaccess, NBTTagCompound nbttagcompound) {
- try {
+ // CraftBukkit start
+ // try {
return EntityTypes.create(nbttagcompound, worldaccess.getLevel(), EntitySpawnReason.STRUCTURE);
- } catch (Exception exception) {
- return Optional.empty();
- }
+ // } catch (Exception exception) {
+ // return Optional.empty();
+ // }
+ // CraftBukkit end
}
public BaseBlockPosition getSize(EnumBlockRotation enumblockrotation) {
@@ -721,6 +761,11 @@
nbttagcompound.put("entities", nbttaglist3);
nbttagcompound.put("size", this.newIntegerList(this.size.getX(), this.size.getY(), this.size.getZ()));
+ // CraftBukkit start - PDC
+ if (!this.persistentDataContainer.isEmpty()) {
+ nbttagcompound.put("BukkitValues", this.persistentDataContainer.toTagCompound());
+ }
+ // CraftBukkit end
return GameProfileSerializer.addCurrentDataVersion(nbttagcompound);
}
@@ -760,6 +805,12 @@
}
}
+ // CraftBukkit start - PDC
+ NBTBase base = nbttagcompound.get("BukkitValues");
+ if (base instanceof NBTTagCompound) {
+ this.persistentDataContainer.putAll((NBTTagCompound) base);
+ }
+ // CraftBukkit end
}
private void loadPalette(HolderGetter<Block> holdergetter, NBTTagList nbttaglist, NBTTagList nbttaglist1) {
@@ -924,7 +975,7 @@
public IBlockData stateFor(int i) {
IBlockData iblockdata = (IBlockData) this.ids.byId(i);
- return iblockdata == null ? DefinedStructure.c.DEFAULT_BLOCK_STATE : iblockdata;
+ return iblockdata == null ? DEFAULT_BLOCK_STATE : iblockdata; // CraftBukkit - decompile error
}
public Iterator<IBlockData> iterator() {

View File

@@ -0,0 +1,25 @@
--- a/net/minecraft/world/level/levelgen/structure/templatesystem/DefinedStructureInfo.java
+++ b/net/minecraft/world/level/levelgen/structure/templatesystem/DefinedStructureInfo.java
@@ -22,7 +22,7 @@
private LiquidSettings liquidSettings;
@Nullable
private RandomSource random;
- private int palette;
+ public int palette = -1; // CraftBukkit - Set initial value so we know if the palette has been set forcefully
private final List<DefinedStructureProcessor> processors;
private boolean knownShape;
private boolean finalizeEntities;
@@ -149,6 +149,13 @@
if (i == 0) {
throw new IllegalStateException("No palettes");
+ // CraftBukkit start
+ } else if (this.palette >= 0) {
+ if (this.palette >= i) {
+ throw new IllegalArgumentException("Palette index out of bounds. Got " + this.palette + " where there are only " + i + " palettes available.");
+ }
+ return list.get(this.palette);
+ // CraftBukkit end
} else {
return (DefinedStructure.b) list.get(this.getRandom(blockposition).nextInt(i));
}