net.minecraft.world.level.levelgen.structure
This commit is contained in:
@@ -1,32 +0,0 @@
|
||||
--- a/net/minecraft/world/level/levelgen/structure/LegacyStructureDataHandler.java
|
||||
+++ b/net/minecraft/world/level/levelgen/structure/LegacyStructureDataHandler.java
|
||||
@@ -18,7 +18,7 @@
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.util.datafix.DataFixTypes;
|
||||
import net.minecraft.world.level.ChunkPos;
|
||||
-import net.minecraft.world.level.Level;
|
||||
+import net.minecraft.world.level.dimension.LevelStem;
|
||||
import net.minecraft.world.level.storage.DimensionDataStorage;
|
||||
|
||||
public class LegacyStructureDataHandler {
|
||||
@@ -233,16 +233,16 @@
|
||||
}
|
||||
}
|
||||
|
||||
- public static LegacyStructureDataHandler getLegacyStructureHandler(ResourceKey<Level> world, @Nullable DimensionDataStorage persistentStateManager) {
|
||||
- if (world == Level.OVERWORLD) {
|
||||
+ public static LegacyStructureDataHandler getLegacyStructureHandler(ResourceKey<LevelStem> world, @Nullable DimensionDataStorage persistentStateManager) { // CraftBukkit
|
||||
+ if (world == LevelStem.OVERWORLD) { // CraftBukkit
|
||||
return new LegacyStructureDataHandler(persistentStateManager, 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 (world == Level.NETHER) {
|
||||
+ if (world == LevelStem.NETHER) { // CraftBukkit
|
||||
immutablelist = ImmutableList.of("Fortress");
|
||||
return new LegacyStructureDataHandler(persistentStateManager, immutablelist, immutablelist);
|
||||
- } else if (world == Level.END) {
|
||||
+ } else if (world == LevelStem.END) { // CraftBukkit
|
||||
immutablelist = ImmutableList.of("EndCity");
|
||||
return new LegacyStructureDataHandler(persistentStateManager, immutablelist, immutablelist);
|
||||
} else {
|
||||
@@ -1,50 +0,0 @@
|
||||
--- a/net/minecraft/world/level/levelgen/structure/StructureCheck.java
|
||||
+++ b/net/minecraft/world/level/levelgen/structure/StructureCheck.java
|
||||
@@ -40,7 +40,7 @@
|
||||
private final ChunkScanAccess storageAccess;
|
||||
private final RegistryAccess registryAccess;
|
||||
private final StructureTemplateManager structureTemplateManager;
|
||||
- private final ResourceKey<Level> dimension;
|
||||
+ private final ResourceKey<net.minecraft.world.level.dimension.LevelStem> dimension; // Paper - fix missing CB diff
|
||||
private final ChunkGenerator chunkGenerator;
|
||||
private final RandomState randomState;
|
||||
private final LevelHeightAccessor heightAccessor;
|
||||
@@ -54,7 +54,7 @@
|
||||
ChunkScanAccess chunkIoWorker,
|
||||
RegistryAccess registryManager,
|
||||
StructureTemplateManager structureTemplateManager,
|
||||
- ResourceKey<Level> worldKey,
|
||||
+ ResourceKey<net.minecraft.world.level.dimension.LevelStem> worldKey, // Paper - fix missing CB diff
|
||||
ChunkGenerator chunkGenerator,
|
||||
RandomState noiseConfig,
|
||||
LevelHeightAccessor world,
|
||||
@@ -74,6 +74,20 @@
|
||||
this.fixerUpper = dataFixer;
|
||||
}
|
||||
|
||||
+ // Paper start - add missing structure salt configs
|
||||
+ @Nullable
|
||||
+ private Integer getSaltOverride(Structure type) {
|
||||
+ if (this.heightAccessor instanceof net.minecraft.server.level.ServerLevel serverLevel) {
|
||||
+ if (type instanceof net.minecraft.world.level.levelgen.structure.structures.MineshaftStructure) {
|
||||
+ return serverLevel.spigotConfig.mineshaftSeed;
|
||||
+ } else if (type instanceof net.minecraft.world.level.levelgen.structure.structures.BuriedTreasureStructure) {
|
||||
+ return serverLevel.spigotConfig.buriedTreasureSeed;
|
||||
+ }
|
||||
+ }
|
||||
+ return null;
|
||||
+ }
|
||||
+ // Paper end - add missing structure seed configs
|
||||
+
|
||||
public StructureCheckResult checkStart(ChunkPos pos, Structure type, StructurePlacement placement, boolean skipReferencedStructures) {
|
||||
long l = pos.toLong();
|
||||
Object2IntMap<Structure> object2IntMap = this.loadedChunks.get(l);
|
||||
@@ -83,7 +97,7 @@
|
||||
StructureCheckResult structureCheckResult = this.tryLoadFromStorage(pos, type, skipReferencedStructures, l);
|
||||
if (structureCheckResult != null) {
|
||||
return structureCheckResult;
|
||||
- } else if (!placement.applyAdditionalChunkRestrictions(pos.x, pos.z, this.seed)) {
|
||||
+ } else if (!placement.applyAdditionalChunkRestrictions(pos.x, pos.z, this.seed, this.getSaltOverride(type))) { // Paper - add missing structure seed configs
|
||||
return StructureCheckResult.START_NOT_PRESENT;
|
||||
} else {
|
||||
boolean bl = this.featureChecks
|
||||
@@ -1,164 +0,0 @@
|
||||
--- a/net/minecraft/world/level/levelgen/structure/StructurePiece.java
|
||||
+++ b/net/minecraft/world/level/levelgen/structure/StructurePiece.java
|
||||
@@ -29,8 +29,6 @@
|
||||
import net.minecraft.world.level.block.Mirror;
|
||||
import net.minecraft.world.level.block.Rotation;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
-import net.minecraft.world.level.block.entity.ChestBlockEntity;
|
||||
-import net.minecraft.world.level.block.entity.DispenserBlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.chunk.ChunkGenerator;
|
||||
import net.minecraft.world.level.levelgen.Heightmap;
|
||||
@@ -51,7 +49,7 @@
|
||||
private Rotation rotation;
|
||||
protected int genDepth;
|
||||
private final StructurePieceType 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(StructurePieceType type, int length, BoundingBox boundingBox) {
|
||||
this.type = type;
|
||||
@@ -80,13 +78,11 @@
|
||||
CompoundTag nbttagcompound = new CompoundTag();
|
||||
|
||||
nbttagcompound.putString("id", BuiltInRegistries.STRUCTURE_PIECE.getKey(this.getType()).toString());
|
||||
- DataResult dataresult = BoundingBox.CODEC.encodeStart(NbtOps.INSTANCE, this.boundingBox);
|
||||
- Logger logger = StructurePiece.LOGGER;
|
||||
-
|
||||
- Objects.requireNonNull(logger);
|
||||
- dataresult.resultOrPartial(logger::error).ifPresent((nbtbase) -> {
|
||||
- nbttagcompound.put("BB", nbtbase);
|
||||
+ // CraftBukkit start - decompile error
|
||||
+ BoundingBox.CODEC.encodeStart(NbtOps.INSTANCE, this.boundingBox).resultOrPartial(Objects.requireNonNull(StructurePiece.LOGGER)::error).ifPresent((nbtbase) -> {
|
||||
+ nbttagcompound.put("BB", nbtbase);
|
||||
});
|
||||
+ // CraftBukkit end
|
||||
Direction enumdirection = this.getOrientation();
|
||||
|
||||
nbttagcompound.putInt("O", enumdirection == null ? -1 : enumdirection.get2DDataValue());
|
||||
@@ -186,6 +182,11 @@
|
||||
}
|
||||
|
||||
world.setBlock(blockposition_mutableblockposition, block, 2);
|
||||
+ // CraftBukkit start - fluid handling is already done if we have a transformer generator access
|
||||
+ if (world instanceof org.bukkit.craftbukkit.util.TransformerGeneratorAccess) {
|
||||
+ return;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
FluidState fluid = world.getFluidState(blockposition_mutableblockposition);
|
||||
|
||||
if (!fluid.isEmpty()) {
|
||||
@@ -195,10 +196,42 @@
|
||||
if (StructurePiece.SHAPE_CHECK_BLOCKS.contains(block.getBlock())) {
|
||||
world.getChunk(blockposition_mutableblockposition).markPosForPostprocessing(blockposition_mutableblockposition);
|
||||
}
|
||||
+
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ // CraftBukkit start
|
||||
+ protected boolean placeCraftBlockEntity(ServerLevelAccessor worldAccess, BlockPos 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);
|
||||
+ BlockEntity tileEntity = worldAccess.getBlockEntity(position);
|
||||
+ if (tileEntity != null) {
|
||||
+ tileEntity.loadWithComponents(craftBlockEntityState.getSnapshotNBT(), worldAccess.registryAccess());
|
||||
+ }
|
||||
+ return result;
|
||||
+ }
|
||||
|
||||
+ protected void placeCraftSpawner(ServerLevelAccessor worldAccess, BlockPos 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);
|
||||
+ this.placeCraftBlockEntity(worldAccess, position, spawner, i);
|
||||
+ }
|
||||
+
|
||||
+ protected void setCraftLootTable(ServerLevelAccessor worldAccess, BlockPos 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.BlockEntity tileEntity = worldAccess.getBlockEntity(position);
|
||||
+ if (tileEntity instanceof net.minecraft.world.level.block.entity.RandomizableContainerBlockEntity 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(LevelReader world, int x, int y, int z, BoundingBox box) {
|
||||
return true;
|
||||
@@ -393,12 +426,20 @@
|
||||
block = StructurePiece.reorient(world, pos, Blocks.CHEST.defaultBlockState());
|
||||
}
|
||||
|
||||
- world.setBlock(pos, block, 2);
|
||||
- BlockEntity tileentity = world.getBlockEntity(pos);
|
||||
+ // CraftBukkit start
|
||||
+ /*
|
||||
+ worldaccess.setBlock(blockposition, iblockdata, 2);
|
||||
+ TileEntity tileentity = worldaccess.getBlockEntity(blockposition);
|
||||
|
||||
- if (tileentity instanceof ChestBlockEntity) {
|
||||
- ((ChestBlockEntity) tileentity).setLootTable(lootTable, random.nextLong());
|
||||
+ 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(world, pos, block, null);
|
||||
+ chestState.setLootTable(org.bukkit.craftbukkit.CraftLootTable.minecraftToBukkit(lootTable));
|
||||
+ chestState.setSeed(random.nextLong());
|
||||
+ this.placeCraftBlockEntity(world, pos, chestState, 2);
|
||||
+ // CraftBukkit end
|
||||
|
||||
return true;
|
||||
} else {
|
||||
@@ -410,13 +451,32 @@
|
||||
BlockPos.MutableBlockPos blockposition_mutableblockposition = this.getWorldPos(x, y, z);
|
||||
|
||||
if (boundingBox.isInside(blockposition_mutableblockposition) && !world.getBlockState(blockposition_mutableblockposition).is(Blocks.DISPENSER)) {
|
||||
- this.placeBlock(world, (BlockState) Blocks.DISPENSER.defaultBlockState().setValue(DispenserBlock.FACING, facing), x, y, z, boundingBox);
|
||||
- BlockEntity tileentity = world.getBlockEntity(blockposition_mutableblockposition);
|
||||
+ // 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 DispenserBlockEntity) {
|
||||
- ((DispenserBlockEntity) tileentity).setLootTable(lootTable, random.nextLong());
|
||||
+ if (tileentity instanceof TileEntityDispenser) {
|
||||
+ ((TileEntityDispenser) tileentity).setLootTable(resourcekey, randomsource.nextLong());
|
||||
}
|
||||
+ */
|
||||
+ if (!this.canBeReplaced(world, x, y, z, boundingBox)) {
|
||||
+ return true;
|
||||
+ }
|
||||
+ BlockState iblockdata = Blocks.DISPENSER.defaultBlockState().setValue(DispenserBlock.FACING, facing);
|
||||
+ if (this.mirror != Mirror.NONE) {
|
||||
+ iblockdata = iblockdata.mirror(this.mirror);
|
||||
+ }
|
||||
+ if (this.rotation != Rotation.NONE) {
|
||||
+ iblockdata = iblockdata.rotate(this.rotation);
|
||||
+ }
|
||||
|
||||
+ org.bukkit.craftbukkit.block.CraftDispenser dispenserState = (org.bukkit.craftbukkit.block.CraftDispenser) org.bukkit.craftbukkit.block.CraftBlockStates.getBlockState(world, blockposition_mutableblockposition, iblockdata, null);
|
||||
+ dispenserState.setLootTable(org.bukkit.craftbukkit.CraftLootTable.minecraftToBukkit(lootTable));
|
||||
+ dispenserState.setSeed(random.nextLong());
|
||||
+ this.placeCraftBlockEntity(world, blockposition_mutableblockposition, dispenserState, 2);
|
||||
+ // CraftBukkit end
|
||||
+
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
@@ -428,7 +488,7 @@
|
||||
}
|
||||
|
||||
public static BoundingBox createBoundingBox(Stream<StructurePiece> pieces) {
|
||||
- Stream stream1 = pieces.map(StructurePiece::getBoundingBox);
|
||||
+ Stream<BoundingBox> stream1 = pieces.map(StructurePiece::getBoundingBox); // CraftBukkit - decompile error
|
||||
|
||||
Objects.requireNonNull(stream1);
|
||||
return (BoundingBox) BoundingBox.encapsulatingBoxes(stream1::iterator).orElseThrow(() -> {
|
||||
@@ -1,59 +0,0 @@
|
||||
--- 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 BoundingBox 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(StructureStart.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, ChunkPos pos, int references, PiecesContainer children) {
|
||||
this.structure = structure;
|
||||
this.chunkPos = pos;
|
||||
@@ -91,15 +97,29 @@
|
||||
BoundingBox structureboundingbox1 = ((StructurePiece) list.get(0)).boundingBox;
|
||||
BlockPos blockposition = structureboundingbox1.getCenter();
|
||||
BlockPos blockposition1 = new BlockPos(blockposition.getX(), structureboundingbox1.minY(), blockposition.getZ());
|
||||
+ // CraftBukkit start
|
||||
+ /*
|
||||
Iterator iterator = list.iterator();
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
StructurePiece structurepiece = (StructurePiece) iterator.next();
|
||||
|
||||
- if (structurepiece.getBoundingBox().intersects(chunkBox)) {
|
||||
- structurepiece.postProcess(world, structureAccessor, chunkGenerator, random, chunkBox, chunkPos, blockposition1);
|
||||
+ if (structurepiece.getBoundingBox().intersects(structureboundingbox)) {
|
||||
+ structurepiece.postProcess(generatoraccessseed, structuremanager, chunkgenerator, randomsource, structureboundingbox, chunkcoordintpair, blockposition1);
|
||||
}
|
||||
}
|
||||
+ */
|
||||
+ List<StructurePiece> pieces = list.stream().filter(piece -> piece.getBoundingBox().intersects(chunkBox)).toList();
|
||||
+ if (!pieces.isEmpty()) {
|
||||
+ org.bukkit.craftbukkit.util.TransformerGeneratorAccess transformerAccess = new org.bukkit.craftbukkit.util.TransformerGeneratorAccess();
|
||||
+ transformerAccess.setHandle(world);
|
||||
+ transformerAccess.setStructureTransformer(new org.bukkit.craftbukkit.util.CraftStructureTransformer(this.generationEventCause, world, structureAccessor, this.structure, chunkBox, chunkPos));
|
||||
+ for (StructurePiece piece : pieces) {
|
||||
+ piece.postProcess(transformerAccess, structureAccessor, chunkGenerator, random, chunkBox, chunkPos, blockposition1);
|
||||
+ }
|
||||
+ transformerAccess.getStructureTransformer().discard();
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
|
||||
this.structure.afterPlace(world, structureAccessor, chunkGenerator, random, chunkBox, chunkPos, this.pieceContainer);
|
||||
}
|
||||
@@ -107,6 +127,11 @@
|
||||
|
||||
public CompoundTag createTag(StructurePieceSerializationContext context, ChunkPos chunkPos) {
|
||||
CompoundTag nbttagcompound = new CompoundTag();
|
||||
+ // CraftBukkit start - store persistent data in nbt
|
||||
+ if (!this.persistentDataContainer.isEmpty()) {
|
||||
+ nbttagcompound.put("StructureBukkitValues", this.persistentDataContainer.toTagCompound());
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
|
||||
if (this.isValid()) {
|
||||
nbttagcompound.putString("id", context.registryAccess().lookupOrThrow(Registries.STRUCTURE).getKey(this.structure).toString());
|
||||
Reference in New Issue
Block a user