Move patches to unapplied

This commit is contained in:
Nassim Jahnke
2024-12-12 12:22:12 +01:00
parent ff75689b08
commit 45ddf764d9
821 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
--- a/net/minecraft/world/level/levelgen/DensityFunctions.java
+++ b/net/minecraft/world/level/levelgen/DensityFunctions.java
@@ -509,6 +509,16 @@
);
private static final float ISLAND_THRESHOLD = -0.9F;
private final SimplexNoise islandNoise;
+ // Paper start - Perf: Optimize end generation
+ private static final class NoiseCache {
+ public long[] keys = new long[8192];
+ public float[] values = new float[8192];
+ public NoiseCache() {
+ java.util.Arrays.fill(keys, Long.MIN_VALUE);
+ }
+ }
+ private static final ThreadLocal<java.util.Map<SimplexNoise, NoiseCache>> noiseCache = ThreadLocal.withInitial(java.util.WeakHashMap::new);
+ // Paper end - Perf: Optimize end generation
public EndIslandDensityFunction(long seed) {
RandomSource randomSource = new LegacyRandomSource(seed);
@@ -521,15 +531,29 @@
int j = z / 2;
int k = x % 2;
int l = z % 2;
- float f = 100.0F - Mth.sqrt((float)(x * x + z * z)) * 8.0F;
+ float f = 100.0F - Mth.sqrt((long) x * (long) x + (long) z * (long) z) * 8.0F; // Paper - cast ints to long to avoid integer overflow
f = Mth.clamp(f, -100.0F, 80.0F);
+ NoiseCache cache = noiseCache.get().computeIfAbsent(sampler, noiseKey -> new NoiseCache()); // Paper - Perf: Optimize end generation
for (int m = -12; m <= 12; m++) {
for (int n = -12; n <= 12; n++) {
long o = (long)(i + m);
long p = (long)(j + n);
- if (o * o + p * p > 4096L && sampler.getValue((double)o, (double)p) < -0.9F) {
- float g = (Mth.abs((float)o) * 3439.0F + Mth.abs((float)p) * 147.0F) % 13.0F + 9.0F;
+ // Paper start - Perf: Optimize end generation by using a noise cache
+ long key = net.minecraft.world.level.ChunkPos.asLong((int) o, (int) p);
+ int index = (int) it.unimi.dsi.fastutil.HashCommon.mix(key) & 8191;
+ float g = Float.MIN_VALUE;
+ if (cache.keys[index] == key) {
+ g = cache.values[index];
+ } else {
+ if (o * o + p * p > 4096L && sampler.getValue((double)o, (double)p) < -0.9F) {
+ g = (Mth.abs((float)o) * 3439.0F + Mth.abs((float)p) * 147.0F) % 13.0F + 9.0F;
+ }
+ cache.keys[index] = key;
+ cache.values[index] = g;
+ }
+ if (g != Float.MIN_VALUE) {
+ // Paper end - Perf: Optimize end generation
float h = (float)(k - m * 2);
float q = (float)(l - n * 2);
float r = 100.0F - Mth.sqrt(h * h + q * q) * g;

View File

@@ -0,0 +1,38 @@
--- a/net/minecraft/world/level/levelgen/FlatLevelSource.java
+++ b/net/minecraft/world/level/levelgen/FlatLevelSource.java
@@ -34,22 +34,28 @@
private final FlatLevelGeneratorSettings settings;
public FlatLevelSource(FlatLevelGeneratorSettings config) {
- FixedBiomeSource worldchunkmanagerhell = new FixedBiomeSource(config.getBiome());
+ // CraftBukkit start
+ // WorldChunkManagerHell worldchunkmanagerhell = new WorldChunkManagerHell(generatorsettingsflat.getBiome());
- Objects.requireNonNull(config);
- super(worldchunkmanagerhell, Util.memoize(config::adjustGenerationSettings));
- this.settings = config;
+ // Objects.requireNonNull(generatorsettingsflat);
+ this(config, new FixedBiomeSource(config.getBiome()));
}
+ public FlatLevelSource(FlatLevelGeneratorSettings generatorsettingsflat, net.minecraft.world.level.biome.BiomeSource worldchunkmanager) {
+ super(worldchunkmanager, Util.memoize(generatorsettingsflat::adjustGenerationSettings));
+ // CraftBukkit end
+ this.settings = generatorsettingsflat;
+ }
+
@Override
- public ChunkGeneratorStructureState createState(HolderLookup<StructureSet> structureSetRegistry, RandomState noiseConfig, long seed) {
+ public ChunkGeneratorStructureState createState(HolderLookup<StructureSet> holderlookup, RandomState randomstate, long i, org.spigotmc.SpigotWorldConfig conf) { // Spigot
Stream<Holder<StructureSet>> stream = (Stream) this.settings.structureOverrides().map(HolderSet::stream).orElseGet(() -> {
- return structureSetRegistry.listElements().map((holder_c) -> {
+ return holderlookup.listElements().map((holder_c) -> {
return holder_c;
});
});
- return ChunkGeneratorStructureState.createForFlat(noiseConfig, seed, this.biomeSource, stream);
+ return ChunkGeneratorStructureState.createForFlat(randomstate, i, this.biomeSource, stream, conf); // Spigot
}
@Override

View File

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

View File

@@ -0,0 +1,79 @@
--- a/net/minecraft/world/level/levelgen/PatrolSpawner.java
+++ b/net/minecraft/world/level/levelgen/PatrolSpawner.java
@@ -24,6 +24,7 @@
@Override
public int tick(ServerLevel world, boolean spawnMonsters, boolean spawnAnimals) {
+ if (world.paperConfig().entities.behavior.pillagerPatrols.disable || world.paperConfig().entities.behavior.pillagerPatrols.spawnChance == 0) return 0; // Paper - Add option to disable pillager patrols & Pillager patrol spawn settings and per player options
if (!spawnMonsters) {
return 0;
} else if (!world.getGameRules().getBoolean(GameRules.RULE_DO_PATROL_SPAWNING)) {
@@ -31,23 +32,51 @@
} else {
RandomSource randomsource = world.random;
- --this.nextTick;
- if (this.nextTick > 0) {
+ // Paper start - Pillager patrol spawn settings and per player options
+ // Random player selection moved up for per player spawning and configuration
+ int j = world.players().size();
+ if (j < 1) {
return 0;
+ }
+
+ net.minecraft.server.level.ServerPlayer entityhuman = world.players().get(randomsource.nextInt(j));
+ if (entityhuman.isSpectator()) {
+ return 0;
+ }
+
+ int patrolSpawnDelay;
+ if (world.paperConfig().entities.behavior.pillagerPatrols.spawnDelay.perPlayer) {
+ --entityhuman.patrolSpawnDelay;
+ patrolSpawnDelay = entityhuman.patrolSpawnDelay;
} else {
- this.nextTick += 12000 + randomsource.nextInt(1200);
- long i = world.getDayTime() / 24000L;
+ this.nextTick--;
+ patrolSpawnDelay = this.nextTick;
+ }
- if (i >= 5L && world.isDay()) {
- if (randomsource.nextInt(5) != 0) {
+ if (patrolSpawnDelay > 0) {
+ return 0;
+ } else {
+ long days;
+ if (world.paperConfig().entities.behavior.pillagerPatrols.start.perPlayer) {
+ days = entityhuman.getStats().getValue(net.minecraft.stats.Stats.CUSTOM.get(net.minecraft.stats.Stats.PLAY_TIME)) / 24000L; // PLAY_ONE_MINUTE is actually counting in ticks, a misnomer by Mojang
+ } else {
+ days = world.getDayTime() / 24000L;
+ }
+ if (world.paperConfig().entities.behavior.pillagerPatrols.spawnDelay.perPlayer) {
+ entityhuman.patrolSpawnDelay += world.paperConfig().entities.behavior.pillagerPatrols.spawnDelay.ticks + randomsource.nextInt(1200);
+ } else {
+ this.nextTick += world.paperConfig().entities.behavior.pillagerPatrols.spawnDelay.ticks + randomsource.nextInt(1200);
+ }
+
+ if (days >= world.paperConfig().entities.behavior.pillagerPatrols.start.day && world.isDay()) {
+ if (randomsource.nextDouble() >= world.paperConfig().entities.behavior.pillagerPatrols.spawnChance) {
+ // Paper end - Pillager patrol spawn settings and per player options
return 0;
} else {
- int j = world.players().size();
if (j < 1) {
return 0;
} else {
- Player entityhuman = (Player) world.players().get(randomsource.nextInt(j));
if (entityhuman.isSpectator()) {
return 0;
@@ -116,7 +145,7 @@
entitymonsterpatrolling.setPos((double) pos.getX(), (double) pos.getY(), (double) pos.getZ());
entitymonsterpatrolling.finalizeSpawn(world, world.getCurrentDifficultyAt(pos), EntitySpawnReason.PATROL, (SpawnGroupData) null);
- world.addFreshEntityWithPassengers(entitymonsterpatrolling);
+ world.addFreshEntityWithPassengers(entitymonsterpatrolling, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.PATROL); // CraftBukkit
return true;
} else {
return false;

View File

@@ -0,0 +1,68 @@
--- a/net/minecraft/world/level/levelgen/PhantomSpawner.java
+++ b/net/minecraft/world/level/levelgen/PhantomSpawner.java
@@ -32,13 +32,22 @@
} else if (!world.getGameRules().getBoolean(GameRules.RULE_DOINSOMNIA)) {
return 0;
} else {
+ // Paper start - Ability to control player's insomnia and phantoms
+ if (world.paperConfig().entities.behavior.phantomsSpawnAttemptMaxSeconds <= 0) {
+ return 0;
+ }
+ // Paper end - Ability to control player's insomnia and phantoms
RandomSource randomsource = world.random;
--this.nextTick;
if (this.nextTick > 0) {
return 0;
} else {
- this.nextTick += (60 + randomsource.nextInt(60)) * 20;
+ // Paper start - Ability to control player's insomnia and phantoms
+ int spawnAttemptMinSeconds = world.paperConfig().entities.behavior.phantomsSpawnAttemptMinSeconds;
+ int spawnAttemptMaxSeconds = world.paperConfig().entities.behavior.phantomsSpawnAttemptMaxSeconds;
+ this.nextTick += (spawnAttemptMinSeconds + randomsource.nextInt(spawnAttemptMaxSeconds - spawnAttemptMinSeconds + 1)) * 20;
+ // Paper end - Ability to control player's insomnia and phantoms
if (world.getSkyDarken() < 5 && world.dimensionType().hasSkyLight()) {
return 0;
} else {
@@ -48,7 +57,7 @@
while (iterator.hasNext()) {
ServerPlayer entityplayer = (ServerPlayer) iterator.next();
- if (!entityplayer.isSpectator()) {
+ if (!entityplayer.isSpectator() && (!world.paperConfig().entities.behavior.phantomsDoNotSpawnOnCreativePlayers || !entityplayer.isCreative())) { // Paper - Add phantom creative and insomniac controls
BlockPos blockposition = entityplayer.blockPosition();
if (!world.dimensionType().hasSkyLight() || blockposition.getY() >= world.getSeaLevel() && world.canSeeSky(blockposition)) {
@@ -59,7 +68,7 @@
int j = Mth.clamp(serverstatisticmanager.getValue(Stats.CUSTOM.get(Stats.TIME_SINCE_REST)), 1, Integer.MAX_VALUE);
boolean flag2 = true;
- if (randomsource.nextInt(j) >= 72000) {
+ if (randomsource.nextInt(j) >= world.paperConfig().entities.behavior.playerInsomniaStartTicks) { // Paper - Ability to control player's insomnia and phantoms
BlockPos blockposition1 = blockposition.above(20 + randomsource.nextInt(15)).east(-10 + randomsource.nextInt(21)).south(-10 + randomsource.nextInt(21));
BlockState iblockdata = world.getBlockState(blockposition1);
FluidState fluid = world.getFluidState(blockposition1);
@@ -69,12 +78,22 @@
int k = 1 + randomsource.nextInt(difficultydamagescaler.getDifficulty().getId() + 1);
for (int l = 0; l < k; ++l) {
+ // Paper start - PhantomPreSpawnEvent
+ com.destroystokyo.paper.event.entity.PhantomPreSpawnEvent event = new com.destroystokyo.paper.event.entity.PhantomPreSpawnEvent(io.papermc.paper.util.MCUtil.toLocation(world, blockposition1), entityplayer.getBukkitEntity(), org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.NATURAL);
+ if (!event.callEvent()) {
+ if (event.shouldAbortSpawn()) {
+ break;
+ }
+ continue;
+ }
+ // Paper end - PhantomPreSpawnEvent
Phantom entityphantom = (Phantom) EntityType.PHANTOM.create(world, EntitySpawnReason.NATURAL);
if (entityphantom != null) {
+ entityphantom.setSpawningEntity(entityplayer.getUUID()); // Paper - PhantomPreSpawnEvent
entityphantom.moveTo(blockposition1, 0.0F, 0.0F);
groupdataentity = entityphantom.finalizeSpawn(world, difficultydamagescaler, EntitySpawnReason.NATURAL, groupdataentity);
- world.addFreshEntityWithPassengers(entityphantom);
+ world.addFreshEntityWithPassengers(entityphantom, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.NATURAL); // CraftBukkit
++i;
}
}

View File

@@ -0,0 +1,72 @@
--- a/net/minecraft/world/level/levelgen/feature/EndPlatformFeature.java
+++ b/net/minecraft/world/level/levelgen/feature/EndPlatformFeature.java
@@ -7,6 +7,11 @@
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
+// CraftBukkit start
+import java.util.List;
+import org.bukkit.block.BlockState;
+import org.bukkit.event.world.PortalCreateEvent;
+// CraftBukkit end
public class EndPlatformFeature extends Feature<NoneFeatureConfiguration> {
@@ -21,24 +26,51 @@
}
public static void createEndPlatform(ServerLevelAccessor world, BlockPos pos, boolean breakBlocks) {
- BlockPos.MutableBlockPos blockposition_mutableblockposition = pos.mutable();
+ EndPlatformFeature.createEndPlatform(world, pos, breakBlocks, null);
+ // CraftBukkit start
+ }
+ public static void createEndPlatform(ServerLevelAccessor worldaccess, BlockPos blockposition, boolean flag, Entity entity) {
+ org.bukkit.craftbukkit.util.BlockStateListPopulator blockList = new org.bukkit.craftbukkit.util.BlockStateListPopulator(worldaccess);
+ // CraftBukkit end
+ BlockPos.MutableBlockPos blockposition_mutableblockposition = blockposition.mutable();
+
for (int i = -2; i <= 2; ++i) {
for (int j = -2; j <= 2; ++j) {
for (int k = -1; k < 3; ++k) {
- BlockPos.MutableBlockPos blockposition_mutableblockposition1 = blockposition_mutableblockposition.set(pos).move(j, k, i);
+ BlockPos.MutableBlockPos blockposition_mutableblockposition1 = blockposition_mutableblockposition.set(blockposition).move(j, k, i);
Block block = k == -1 ? Blocks.OBSIDIAN : Blocks.AIR;
- if (!world.getBlockState(blockposition_mutableblockposition1).is(block)) {
- if (breakBlocks) {
- world.destroyBlock(blockposition_mutableblockposition1, true, (Entity) null);
+ // CraftBukkit start
+ if (!blockList.getBlockState(blockposition_mutableblockposition1).is(block)) {
+ if (flag) {
+ blockList.destroyBlock(blockposition_mutableblockposition1, true, (Entity) null);
}
- world.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,10 @@
--- a/net/minecraft/world/level/levelgen/feature/SpikeFeature.java
+++ b/net/minecraft/world/level/levelgen/feature/SpikeFeature.java
@@ -115,6 +115,7 @@
endCrystal.moveTo(
(double)spike.getCenterX() + 0.5, (double)(spike.getHeight() + 1), (double)spike.getCenterZ() + 0.5, random.nextFloat() * 360.0F, 0.0F
);
+ endCrystal.generatedByDragonFight = true; // Paper - Fix invulnerable end crystals
world.addFreshEntity(endCrystal);
BlockPos blockPos2 = endCrystal.blockPosition();
this.setBlock(world, blockPos2.below(), Blocks.BEDROCK.defaultBlockState());

View File

@@ -0,0 +1,10 @@
--- a/net/minecraft/world/level/levelgen/feature/treedecorators/CocoaDecorator.java
+++ b/net/minecraft/world/level/levelgen/feature/treedecorators/CocoaDecorator.java
@@ -26,6 +26,7 @@
@Override
public void place(TreeDecorator.Context generator) {
+ if (generator.logs().isEmpty()) return; // Paper - Fix crash when trying to generate without logs
RandomSource randomSource = generator.random();
if (!(randomSource.nextFloat() >= this.probability)) {
List<BlockPos> list = generator.logs();

View File

@@ -0,0 +1,32 @@
--- 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 {

View File

@@ -0,0 +1,50 @@
--- 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

View File

@@ -0,0 +1,164 @@
--- 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(() -> {

View File

@@ -0,0 +1,59 @@
--- 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());

View File

@@ -0,0 +1,93 @@
--- a/net/minecraft/world/level/levelgen/structure/placement/StructurePlacement.java
+++ b/net/minecraft/world/level/levelgen/structure/placement/StructurePlacement.java
@@ -79,14 +79,30 @@
return this.exclusionZone;
}
+ @Deprecated @io.papermc.paper.annotation.DoNotUse // Paper - Add missing structure set seed configs
public boolean isStructureChunk(ChunkGeneratorStructureState calculator, int chunkX, int chunkZ) {
+ // Paper start - Add missing structure set seed configs
+ return this.isStructureChunk(calculator, chunkX, chunkZ, null);
+ }
+ public boolean isStructureChunk(ChunkGeneratorStructureState calculator, int chunkX, int chunkZ, @org.jetbrains.annotations.Nullable net.minecraft.resources.ResourceKey<StructureSet> structureSetKey) {
+ Integer saltOverride = null;
+ if (structureSetKey != null) {
+ if (structureSetKey == net.minecraft.world.level.levelgen.structure.BuiltinStructureSets.MINESHAFTS) {
+ saltOverride = calculator.conf.mineshaftSeed;
+ } else if (structureSetKey == net.minecraft.world.level.levelgen.structure.BuiltinStructureSets.BURIED_TREASURES) {
+ saltOverride = calculator.conf.buriedTreasureSeed;
+ }
+ }
+ // Paper end - Add missing structure set seed configs
return this.isPlacementChunk(calculator, chunkX, chunkZ)
- && this.applyAdditionalChunkRestrictions(chunkX, chunkZ, calculator.getLevelSeed())
+ && this.applyAdditionalChunkRestrictions(chunkX, chunkZ, calculator.getLevelSeed(), saltOverride) // Paper - Add missing structure set seed configs
&& this.applyInteractionsWithOtherStructures(calculator, chunkX, chunkZ);
}
- public boolean applyAdditionalChunkRestrictions(int chunkX, int chunkZ, long seed) {
- return !(this.frequency < 1.0F) || this.frequencyReductionMethod.shouldGenerate(seed, this.salt, chunkX, chunkZ, this.frequency);
+ // Paper start - Add missing structure set seed configs
+ public boolean applyAdditionalChunkRestrictions(int chunkX, int chunkZ, long seed, @org.jetbrains.annotations.Nullable Integer saltOverride) {
+ return !(this.frequency < 1.0F) || this.frequencyReductionMethod.shouldGenerate(seed, this.salt, chunkX, chunkZ, this.frequency, saltOverride);
+ // Paper end - Add missing structure set seed configs
}
public boolean applyInteractionsWithOtherStructures(ChunkGeneratorStructureState calculator, int centerChunkX, int centerChunkZ) {
@@ -101,25 +117,31 @@
public abstract StructurePlacementType<?> type();
- private static boolean probabilityReducer(long seed, int salt, int chunkX, int chunkZ, float frequency) {
+ private static boolean probabilityReducer(long seed, int salt, int chunkX, int chunkZ, float frequency, @org.jetbrains.annotations.Nullable Integer saltOverride) { // Paper - Add missing structure set seed configs; ignore here
WorldgenRandom worldgenRandom = new WorldgenRandom(new LegacyRandomSource(0L));
worldgenRandom.setLargeFeatureWithSalt(seed, salt, chunkX, chunkZ);
return worldgenRandom.nextFloat() < frequency;
}
- private static boolean legacyProbabilityReducerWithDouble(long seed, int salt, int chunkX, int chunkZ, float frequency) {
+ private static boolean legacyProbabilityReducerWithDouble(long seed, int salt, int chunkX, int chunkZ, float frequency, @org.jetbrains.annotations.Nullable Integer saltOverride) { // Paper - Add missing structure set seed configs
WorldgenRandom worldgenRandom = new WorldgenRandom(new LegacyRandomSource(0L));
+ if (saltOverride == null) { // Paper - Add missing structure set seed configs
worldgenRandom.setLargeFeatureSeed(seed, chunkX, chunkZ);
+ // Paper start - Add missing structure set seed configs
+ } else {
+ worldgenRandom.setLargeFeatureWithSalt(seed, chunkX, chunkZ, saltOverride);
+ }
+ // Paper end - Add missing structure set seed configs
return worldgenRandom.nextDouble() < (double)frequency;
}
- private static boolean legacyArbitrarySaltProbabilityReducer(long seed, int salt, int chunkX, int chunkZ, float frequency) {
+ private static boolean legacyArbitrarySaltProbabilityReducer(long seed, int salt, int chunkX, int chunkZ, float frequency, @org.jetbrains.annotations.Nullable Integer saltOverride) { // Paper - Add missing structure set seed configs
WorldgenRandom worldgenRandom = new WorldgenRandom(new LegacyRandomSource(0L));
- worldgenRandom.setLargeFeatureWithSalt(seed, chunkX, chunkZ, 10387320);
+ worldgenRandom.setLargeFeatureWithSalt(seed, chunkX, chunkZ, saltOverride != null ? saltOverride : HIGHLY_ARBITRARY_RANDOM_SALT); // Paper - Add missing structure set seed configs
return worldgenRandom.nextFloat() < frequency;
}
- private static boolean legacyPillagerOutpostReducer(long seed, int salt, int chunkX, int chunkZ, float frequency) {
+ private static boolean legacyPillagerOutpostReducer(long seed, int salt, int chunkX, int chunkZ, float frequency, @org.jetbrains.annotations.Nullable Integer saltOverride) { // Paper - Add missing structure set seed configs; ignore here
int i = chunkX >> 4;
int j = chunkZ >> 4;
WorldgenRandom worldgenRandom = new WorldgenRandom(new LegacyRandomSource(0L));
@@ -147,7 +169,7 @@
@FunctionalInterface
public interface FrequencyReducer {
- boolean shouldGenerate(long seed, int salt, int chunkX, int chunkZ, float chance);
+ boolean shouldGenerate(long seed, int salt, int chunkX, int chunkZ, float chance, @org.jetbrains.annotations.Nullable Integer saltOverride); // Paper - Add missing structure set seed configs
}
public static enum FrequencyReductionMethod implements StringRepresentable {
@@ -167,8 +189,8 @@
this.reducer = generationPredicate;
}
- public boolean shouldGenerate(long seed, int salt, int chunkX, int chunkZ, float chance) {
- return this.reducer.shouldGenerate(seed, salt, chunkX, chunkZ, chance);
+ public boolean shouldGenerate(long seed, int salt, int chunkX, int chunkZ, float chance, @org.jetbrains.annotations.Nullable Integer saltOverride) { // Paper - Add missing structure set seed configs
+ return this.reducer.shouldGenerate(seed, salt, chunkX, chunkZ, chance, saltOverride); // Paper - Add missing structure set seed configs
}
@Override

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(BoundingBox box, WorldGenLevel world, BlockPos pos) {
if (box.isInside(pos)) {
+ // CraftBukkit start
+ if (world instanceof org.bukkit.craftbukkit.util.TransformerGeneratorAccess transformerAccess) {
+ org.bukkit.craftbukkit.block.CraftBrushableBlock brushableState = (org.bukkit.craftbukkit.block.CraftBrushableBlock) org.bukkit.craftbukkit.block.CraftBlockStates.getBlockState(world, pos, Blocks.SUSPICIOUS_SAND.defaultBlockState(), null);
+ brushableState.setLootTable(org.bukkit.craftbukkit.CraftLootTable.minecraftToBukkit(BuiltInLootTables.DESERT_PYRAMID_ARCHAEOLOGY));
+ brushableState.setSeed(pos.asLong());
+ transformerAccess.setCraftBlock(pos, brushableState, 2);
+ return;
+ }
+ // CraftBukkit end
world.setBlock(pos, Blocks.SUSPICIOUS_SAND.defaultBlockState(), 2);
world.getBlockEntity(pos, BlockEntityType.BRUSHABLE_BLOCK).ifPresent((brushableblockentity) -> {
brushableblockentity.setLootTable(BuiltInLootTables.DESERT_PYRAMID_ARCHAEOLOGY, pos.asLong());

View File

@@ -0,0 +1,16 @@
--- a/net/minecraft/world/level/levelgen/structure/structures/EndCityPieces.java
+++ b/net/minecraft/world/level/levelgen/structure/structures/EndCityPieces.java
@@ -285,7 +285,12 @@
BlockPos blockposition1 = pos.below();
if (boundingBox.isInside(blockposition1)) {
- RandomizableContainer.setBlockEntityLootTable(world, random, blockposition1, BuiltInLootTables.END_CITY_TREASURE);
+ // CraftBukkit start - ensure block transformation
+ /*
+ RandomizableContainer.setBlockEntityLootTable(worldaccess, randomsource, blockposition1, LootTables.END_CITY_TREASURE);
+ */
+ this.setCraftLootTable(world, blockposition1, random, BuiltInLootTables.END_CITY_TREASURE);
+ // CraftBukkit end
}
} else if (boundingBox.isInside(pos) && Level.isInSpawnableBounds(pos)) {
if (metadata.startsWith("Sentry")) {

View File

@@ -0,0 +1,31 @@
--- a/net/minecraft/world/level/levelgen/structure/structures/IglooPieces.java
+++ b/net/minecraft/world/level/levelgen/structure/structures/IglooPieces.java
@@ -14,8 +14,6 @@
import net.minecraft.world.level.block.Blocks;
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.state.BlockState;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.levelgen.Heightmap;
@@ -86,11 +84,16 @@
protected void handleDataMarker(String metadata, BlockPos pos, ServerLevelAccessor world, RandomSource random, BoundingBox boundingBox) {
if ("chest".equals(metadata)) {
world.setBlock(pos, Blocks.AIR.defaultBlockState(), 3);
- BlockEntity tileentity = world.getBlockEntity(pos.below());
+ // CraftBukkit start - ensure block transformation
+ /*
+ TileEntity tileentity = worldaccess.getBlockEntity(blockposition.below());
- if (tileentity instanceof ChestBlockEntity) {
- ((ChestBlockEntity) tileentity).setLootTable(BuiltInLootTables.IGLOO_CHEST, random.nextLong());
+ if (tileentity instanceof TileEntityChest) {
+ ((TileEntityChest) tileentity).setLootTable(LootTables.IGLOO_CHEST, randomsource.nextLong());
}
+ */
+ this.setCraftLootTable(world, pos.below(), random, BuiltInLootTables.IGLOO_CHEST);
+ // CraftBukkit end
}
}

View File

@@ -0,0 +1,68 @@
--- a/net/minecraft/world/level/levelgen/structure/structures/MineshaftPieces.java
+++ b/net/minecraft/world/level/levelgen/structure/structures/MineshaftPieces.java
@@ -12,6 +12,7 @@
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtOps;
+import net.minecraft.nbt.Tag;
import net.minecraft.resources.ResourceKey;
import net.minecraft.tags.BiomeTags;
import net.minecraft.util.RandomSource;
@@ -30,8 +31,6 @@
import net.minecraft.world.level.block.FenceBlock;
import net.minecraft.world.level.block.RailBlock;
import net.minecraft.world.level.block.WallTorchBlock;
-import net.minecraft.world.level.block.entity.BlockEntity;
-import net.minecraft.world.level.block.entity.SpawnerBlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.RailShape;
import net.minecraft.world.level.chunk.ChunkGenerator;
@@ -520,14 +519,19 @@
if (chunkBox.isInside(blockposition_mutableblockposition) && this.isInterior(world, 1, 0, l, chunkBox)) {
this.hasPlacedSpider = true;
- world.setBlock(blockposition_mutableblockposition, Blocks.SPAWNER.defaultBlockState(), 2);
- BlockEntity tileentity = world.getBlockEntity(blockposition_mutableblockposition);
-
- if (tileentity instanceof SpawnerBlockEntity) {
- SpawnerBlockEntity tileentitymobspawner = (SpawnerBlockEntity) tileentity;
+ // CraftBukkit start
+ /*
+ generatoraccessseed.setBlock(blockposition_mutableblockposition, Blocks.SPAWNER.defaultBlockState(), 2);
+ TileEntity tileentity = generatoraccessseed.getBlockEntity(blockposition_mutableblockposition);
- tileentitymobspawner.setEntityId(EntityType.CAVE_SPIDER, random);
+ if (tileentity instanceof TileEntityMobSpawner) {
+ TileEntityMobSpawner tileentitymobspawner = (TileEntityMobSpawner) tileentity;
+
+ tileentitymobspawner.setEntityId(EntityTypes.CAVE_SPIDER, randomsource);
}
+ */
+ this.placeCraftSpawner(world, blockposition_mutableblockposition, org.bukkit.entity.EntityType.CAVE_SPIDER, 2);
+ // CraftBukkit end
}
}
}
@@ -819,11 +823,11 @@
public MineShaftRoom(CompoundTag nbt) {
super(StructurePieceType.MINE_SHAFT_ROOM, nbt);
- DataResult dataresult = BoundingBox.CODEC.listOf().parse(NbtOps.INSTANCE, nbt.getList("Entrances", 11));
+ DataResult<List<BoundingBox>> dataresult = BoundingBox.CODEC.listOf().parse(NbtOps.INSTANCE, nbt.getList("Entrances", 11)); // CraftBukkit - decompile error
Logger logger = MineshaftPieces.LOGGER;
Objects.requireNonNull(logger);
- Optional optional = dataresult.resultOrPartial(logger::error);
+ Optional<List<BoundingBox>> optional = dataresult.resultOrPartial(logger::error); // CraftBukkit - decompile error
List list = this.childEntranceBoxes;
Objects.requireNonNull(this.childEntranceBoxes);
@@ -929,7 +933,7 @@
@Override
protected void addAdditionalSaveData(StructurePieceSerializationContext context, CompoundTag nbt) {
super.addAdditionalSaveData(context, nbt);
- DataResult dataresult = BoundingBox.CODEC.listOf().encodeStart(NbtOps.INSTANCE, this.childEntranceBoxes);
+ DataResult<Tag> dataresult = BoundingBox.CODEC.listOf().encodeStart(NbtOps.INSTANCE, this.childEntranceBoxes); // CraftBukkit - decompile error
Logger logger = MineshaftPieces.LOGGER;
Objects.requireNonNull(logger);

View File

@@ -0,0 +1,45 @@
--- a/net/minecraft/world/level/levelgen/structure/structures/NetherFortressPieces.java
+++ b/net/minecraft/world/level/levelgen/structure/structures/NetherFortressPieces.java
@@ -8,15 +8,12 @@
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.RandomSource;
-import net.minecraft.world.entity.EntityType;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.StructureManager;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.FenceBlock;
import net.minecraft.world.level.block.StairBlock;
-import net.minecraft.world.level.block.entity.BlockEntity;
-import net.minecraft.world.level.block.entity.SpawnerBlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.levelgen.structure.BoundingBox;
@@ -428,14 +425,19 @@
if (chunkBox.isInside(blockposition_mutableblockposition)) {
this.hasPlacedSpawner = true;
- world.setBlock(blockposition_mutableblockposition, Blocks.SPAWNER.defaultBlockState(), 2);
- BlockEntity tileentity = world.getBlockEntity(blockposition_mutableblockposition);
-
- if (tileentity instanceof SpawnerBlockEntity) {
- SpawnerBlockEntity tileentitymobspawner = (SpawnerBlockEntity) tileentity;
-
- tileentitymobspawner.setEntityId(EntityType.BLAZE, random);
+ // CraftBukkit start
+ /*
+ generatoraccessseed.setBlock(blockposition_mutableblockposition, Blocks.SPAWNER.defaultBlockState(), 2);
+ TileEntity tileentity = generatoraccessseed.getBlockEntity(blockposition_mutableblockposition);
+
+ if (tileentity instanceof TileEntityMobSpawner) {
+ TileEntityMobSpawner tileentitymobspawner = (TileEntityMobSpawner) tileentity;
+
+ tileentitymobspawner.setEntityId(EntityTypes.BLAZE, randomsource);
}
+ */
+ this.placeCraftSpawner(world, blockposition_mutableblockposition, org.bukkit.entity.EntityType.BLAZE, 2);
+ // CraftBukkit end
}
}

View File

@@ -0,0 +1,37 @@
--- a/net/minecraft/world/level/levelgen/structure/structures/OceanRuinPieces.java
+++ b/net/minecraft/world/level/levelgen/structure/structures/OceanRuinPieces.java
@@ -27,8 +27,6 @@
import net.minecraft.world.level.block.ChestBlock;
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.state.BlockState;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.levelgen.Heightmap;
@@ -200,12 +198,20 @@
@Override
protected void handleDataMarker(String metadata, BlockPos pos, ServerLevelAccessor world, RandomSource random, BoundingBox boundingBox) {
if ("chest".equals(metadata)) {
- world.setBlock(pos, (BlockState) Blocks.CHEST.defaultBlockState().setValue(ChestBlock.WATERLOGGED, world.getFluidState(pos).is(FluidTags.WATER)), 2);
- BlockEntity tileentity = world.getBlockEntity(pos);
-
- if (tileentity instanceof ChestBlockEntity) {
- ((ChestBlockEntity) tileentity).setLootTable(this.isLarge ? BuiltInLootTables.UNDERWATER_RUIN_BIG : BuiltInLootTables.UNDERWATER_RUIN_SMALL, random.nextLong());
+ // 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(world, pos, Blocks.CHEST.defaultBlockState().setValue(ChestBlock.WATERLOGGED, world.getFluidState(pos).is(FluidTags.WATER)), null);
+ craftChest.setSeed(random.nextLong());
+ craftChest.setLootTable(org.bukkit.craftbukkit.CraftLootTable.minecraftToBukkit(this.isLarge ? BuiltInLootTables.UNDERWATER_RUIN_BIG : BuiltInLootTables.UNDERWATER_RUIN_SMALL));
+ this.placeCraftBlockEntity(world, pos, craftChest, 2);
+ // CraftBukkit end
} else if ("drowned".equals(metadata)) {
Drowned entitydrowned = (Drowned) EntityType.DROWNED.create(world.getLevel(), EntitySpawnReason.STRUCTURE);

View File

@@ -0,0 +1,16 @@
--- 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(metadata);
if (resourcekey != null) {
- RandomizableContainer.setBlockEntityLootTable(world, random, pos.below(), resourcekey);
+ // CraftBukkit start - ensure block transformation
+ /*
+ RandomizableContainer.setBlockEntityLootTable(worldaccess, randomsource, blockposition.below(), resourcekey);
+ */
+ this.setCraftLootTable(world, pos.below(), random, resourcekey);
+ // CraftBukkit end
}
}

View File

@@ -0,0 +1,55 @@
--- a/net/minecraft/world/level/levelgen/structure/structures/StrongholdPieces.java
+++ b/net/minecraft/world/level/levelgen/structure/structures/StrongholdPieces.java
@@ -8,7 +8,6 @@
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.RandomSource;
-import net.minecraft.world.entity.EntityType;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.StructureManager;
import net.minecraft.world.level.WorldGenLevel;
@@ -22,8 +21,6 @@
import net.minecraft.world.level.block.SlabBlock;
import net.minecraft.world.level.block.StairBlock;
import net.minecraft.world.level.block.WallTorchBlock;
-import net.minecraft.world.level.block.entity.BlockEntity;
-import net.minecraft.world.level.block.entity.SpawnerBlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.DoubleBlockHalf;
import net.minecraft.world.level.block.state.properties.SlabType;
@@ -53,7 +50,7 @@
public boolean doPlace(int chainLength) {
return super.doPlace(chainLength) && chainLength > 5;
}
- }};
+ } }; // CraftBukkit - fix decompile styling
private static List<StrongholdPieces.PieceWeight> currentPieces;
static Class<? extends StrongholdPieces.StrongholdPiece> imposedPiece;
private static int totalWeight;
@@ -1136,14 +1133,19 @@
if (chunkBox.isInside(blockposition_mutableblockposition)) {
this.hasPlacedSpawner = true;
- world.setBlock(blockposition_mutableblockposition, Blocks.SPAWNER.defaultBlockState(), 2);
- BlockEntity tileentity = world.getBlockEntity(blockposition_mutableblockposition);
-
- if (tileentity instanceof SpawnerBlockEntity) {
- SpawnerBlockEntity tileentitymobspawner = (SpawnerBlockEntity) tileentity;
-
- tileentitymobspawner.setEntityId(EntityType.SILVERFISH, random);
+ // CraftBukkit start
+ /*
+ generatoraccessseed.setBlock(blockposition_mutableblockposition, Blocks.SPAWNER.defaultBlockState(), 2);
+ TileEntity tileentity = generatoraccessseed.getBlockEntity(blockposition_mutableblockposition);
+
+ if (tileentity instanceof TileEntityMobSpawner) {
+ TileEntityMobSpawner tileentitymobspawner = (TileEntityMobSpawner) tileentity;
+
+ tileentitymobspawner.setEntityId(EntityTypes.SILVERFISH, randomsource);
}
+ */
+ this.placeCraftSpawner(world, 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(world, world.getCurrentDifficultyAt(blockposition_mutableblockposition), EntitySpawnReason.STRUCTURE, (SpawnGroupData) null);
- world.addFreshEntityWithPassengers(entitywitch);
+ world.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(world, world.getCurrentDifficultyAt(blockposition_mutableblockposition), EntitySpawnReason.STRUCTURE, (SpawnGroupData) null);
- world.addFreshEntityWithPassengers(entitycat);
+ world.addFreshEntityWithPassengers(entitycat, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.CHUNK_GEN); // CraftBukkit - add SpawnReason
}
}
}

View File

@@ -0,0 +1,25 @@
--- a/net/minecraft/world/level/levelgen/structure/templatesystem/StructurePlaceSettings.java
+++ b/net/minecraft/world/level/levelgen/structure/templatesystem/StructurePlaceSettings.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<StructureProcessor> 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 infoLists.get(this.palette);
+ // CraftBukkit end
} else {
return (StructureTemplate.Palette) infoLists.get(this.getRandom(pos).nextInt(i));
}

View File

@@ -0,0 +1,182 @@
--- a/net/minecraft/world/level/levelgen/structure/templatesystem/StructureTemplate.java
+++ b/net/minecraft/world/level/levelgen/structure/templatesystem/StructureTemplate.java
@@ -25,6 +25,7 @@
import net.minecraft.nbt.IntTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.NbtUtils;
+import net.minecraft.nbt.Tag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.RandomSource;
import net.minecraft.world.Clearable;
@@ -55,6 +56,9 @@
import net.minecraft.world.phys.Vec3;
import net.minecraft.world.phys.shapes.BitSetDiscreteVoxelShape;
import net.minecraft.world.phys.shapes.DiscreteVoxelShape;
+import org.bukkit.craftbukkit.persistence.CraftPersistentDataContainer;
+import org.bukkit.craftbukkit.persistence.CraftPersistentDataTypeRegistry;
+// CraftBukkit end
public class StructureTemplate {
@@ -74,6 +78,11 @@
private Vec3i size;
private String author;
+ // CraftBukkit start - data containers
+ private static final CraftPersistentDataTypeRegistry DATA_TYPE_REGISTRY = new CraftPersistentDataTypeRegistry();
+ public CraftPersistentDataContainer persistentDataContainer = new CraftPersistentDataContainer(StructureTemplate.DATA_TYPE_REGISTRY);
+ // CraftBukkit end
+
public StructureTemplate() {
this.size = Vec3i.ZERO;
this.author = "?";
@@ -147,7 +156,7 @@
}
private static List<StructureTemplate.StructureBlockInfo> buildInfoList(List<StructureTemplate.StructureBlockInfo> fullBlocks, List<StructureTemplate.StructureBlockInfo> blocksWithNbt, List<StructureTemplate.StructureBlockInfo> otherBlocks) {
- Comparator<StructureTemplate.StructureBlockInfo> comparator = Comparator.comparingInt((definedstructure_blockinfo) -> {
+ Comparator<StructureTemplate.StructureBlockInfo> comparator = Comparator.<StructureTemplate.StructureBlockInfo>comparingInt((definedstructure_blockinfo) -> { // CraftBukkit - decompile error
return definedstructure_blockinfo.pos.getY();
}).thenComparingInt((definedstructure_blockinfo) -> {
return definedstructure_blockinfo.pos.getX();
@@ -253,6 +262,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
+ ServerLevelAccessor wrappedAccess = world;
+ org.bukkit.craftbukkit.util.CraftStructureTransformer structureTransformer = null;
+ if (wrappedAccess instanceof org.bukkit.craftbukkit.util.TransformerGeneratorAccess transformerAccess) {
+ world = 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<StructureTemplate.StructureBlockInfo> list = placementData.getRandomPalette(this.palettes, pos).blocks();
if ((!list.isEmpty() || !placementData.isIgnoreEntities() && !this.entityInfoList.isEmpty()) && this.size.getX() >= 1 && this.size.getY() >= 1 && this.size.getZ() >= 1) {
@@ -281,9 +303,27 @@
if (definedstructure_blockinfo.nbt != null) {
tileentity = world.getBlockEntity(blockposition2);
- Clearable.tryClear(tileentity);
+ // Paper start - Fix NBT pieces overriding a block entity during worldgen deadlock
+ if (!(world instanceof net.minecraft.world.level.WorldGenLevel)) {
+ Clearable.tryClear(tileentity);
+ }
+ // Paper end - Fix NBT pieces overriding a block entity during worldgen deadlock
world.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(world, 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(random.nextLong());
+ }
+ }
+ craftBlockState = structureTransformer.transformCraftState(craftBlockState);
+ iblockdata = craftBlockState.getHandle();
+ definedstructure_blockinfo = new StructureTemplate.StructureBlockInfo(blockposition2, iblockdata, (craftBlockState instanceof org.bukkit.craftbukkit.block.CraftBlockEntityState<?> craftBlockEntityState ? craftBlockEntityState.getSnapshotNBT() : null));
+ }
+ // CraftBukkit end
if (world.setBlock(blockposition2, iblockdata, flags)) {
j = Math.min(j, blockposition2.getX());
@@ -296,7 +336,7 @@
if (definedstructure_blockinfo.nbt != null) {
tileentity = world.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", random.nextLong());
}
@@ -394,14 +434,18 @@
if (pair1.getSecond() != null) {
tileentity = world.getBlockEntity(blockposition6);
if (tileentity != null) {
- tileentity.setChanged();
+ // Paper start - Fix NBT pieces overriding a block entity during worldgen deadlock
+ if (!(world instanceof net.minecraft.world.level.WorldGenLevel)) {
+ tileentity.setChanged();
+ }
+ // Paper end - Fix NBT pieces overriding a block entity during worldgen deadlock
}
}
}
}
if (!placementData.isIgnoreEntities()) {
- this.placeEntities(world, pos, placementData.getMirror(), placementData.getRotation(), placementData.getRotationPivot(), structureboundingbox, placementData.shouldFinalizeEntities());
+ this.placeEntities(wrappedAccess, pos, placementData.getMirror(), placementData.getRotation(), placementData.getRotationPivot(), structureboundingbox, placementData.shouldFinalizeEntities()); // CraftBukkit
}
return true;
@@ -503,11 +547,13 @@
}
private static Optional<Entity> createEntityIgnoreException(ServerLevelAccessor world, CompoundTag nbt) {
- try {
- return EntityType.create(nbt, world.getLevel(), EntitySpawnReason.STRUCTURE);
- } catch (Exception exception) {
- return Optional.empty();
- }
+ // CraftBukkit start
+ // try {
+ return EntityType.create(nbt, world.getLevel(), EntitySpawnReason.STRUCTURE, true); // Paper - Don't fire sync event during generation
+ // } catch (Exception exception) {
+ // return Optional.empty();
+ // }
+ // CraftBukkit end
}
public Vec3i getSize(Rotation rotation) {
@@ -721,6 +767,11 @@
nbt.put("entities", nbttaglist3);
nbt.put("size", this.newIntegerList(this.size.getX(), this.size.getY(), this.size.getZ()));
+ // CraftBukkit start - PDC
+ if (!this.persistentDataContainer.isEmpty()) {
+ nbt.put("BukkitValues", this.persistentDataContainer.toTagCompound());
+ }
+ // CraftBukkit end
return NbtUtils.addCurrentDataVersion(nbt);
}
@@ -760,6 +811,12 @@
}
}
+ // CraftBukkit start - PDC
+ Tag base = nbt.get("BukkitValues");
+ if (base instanceof CompoundTag) {
+ this.persistentDataContainer.putAll((CompoundTag) base);
+ }
+ // CraftBukkit end
}
private void loadPalette(HolderGetter<Block> blockLookup, ListTag palette, ListTag blocks) {
@@ -840,7 +897,7 @@
public static final class Palette {
private final List<StructureTemplate.StructureBlockInfo> blocks;
- private final Map<Block, List<StructureTemplate.StructureBlockInfo>> cache = Maps.newHashMap();
+ private final Map<Block, List<StructureTemplate.StructureBlockInfo>> cache = Maps.newConcurrentMap(); // Paper - Fix CME due to this collection being shared across threads
@Nullable
private List<StructureTemplate.JigsawBlockInfo> cachedJigsaws;
@@ -924,7 +981,7 @@
public BlockState stateFor(int id) {
BlockState iblockdata = (BlockState) this.ids.byId(id);
- return iblockdata == null ? StructureTemplate.SimplePalette.DEFAULT_BLOCK_STATE : iblockdata;
+ return iblockdata == null ? SimplePalette.DEFAULT_BLOCK_STATE : iblockdata; // CraftBukkit - decompile error
}
public Iterator<BlockState> iterator() {