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,181 @@
--- a/net/minecraft/world/level/chunk/Chunk.java
+++ b/net/minecraft/world/level/chunk/Chunk.java
@@ -79,7 +79,7 @@
};
private final Map<BlockPosition, Chunk.d> tickersInLevel;
public boolean loaded;
- public final World level;
+ public final WorldServer level; // CraftBukkit - type
@Nullable
private Supplier<FullChunkStatus> fullStatus;
@Nullable
@@ -98,7 +98,7 @@
this.tickersInLevel = Maps.newHashMap();
this.unsavedListener = (chunkcoordintpair1) -> {
};
- this.level = world;
+ this.level = (WorldServer) world; // CraftBukkit - type
this.gameEventListenerRegistrySections = new Int2ObjectOpenHashMap();
HeightMap.Type[] aheightmap_type = HeightMap.Type.values();
int j = aheightmap_type.length;
@@ -116,6 +116,11 @@
this.fluidTicks = levelchunkticks1;
}
+ // CraftBukkit start
+ public boolean mustNotSave;
+ public boolean needsDecoration;
+ // CraftBukkit end
+
public Chunk(WorldServer worldserver, ProtoChunk protochunk, @Nullable Chunk.c chunk_c) {
this(worldserver, protochunk.getPos(), protochunk.getUpgradeData(), protochunk.unpackBlockTicks(), protochunk.unpackFluidTicks(), protochunk.getInhabitedTime(), protochunk.getSections(), chunk_c, protochunk.getBlendingData());
if (!Collections.disjoint(protochunk.pendingBlockEntities.keySet(), protochunk.blockEntities.keySet())) {
@@ -151,6 +156,10 @@
this.skyLightSources = protochunk.skyLightSources;
this.setLightCorrect(protochunk.isLightCorrect());
this.markUnsaved();
+ this.needsDecoration = true; // CraftBukkit
+ // CraftBukkit start
+ this.persistentDataContainer = protochunk.persistentDataContainer; // SPIGOT-6814: copy PDC to account for 1.17 to 1.18 chunk upgrading.
+ // CraftBukkit end
}
public void setUnsavedListener(Chunk.e chunk_e) {
@@ -272,9 +281,16 @@
}
}
+ // CraftBukkit start
@Nullable
@Override
public IBlockData setBlockState(BlockPosition blockposition, IBlockData iblockdata, boolean flag) {
+ return this.setBlockState(blockposition, iblockdata, flag, true);
+ }
+
+ @Nullable
+ public IBlockData setBlockState(BlockPosition blockposition, IBlockData iblockdata, boolean flag, boolean doPlace) {
+ // CraftBukkit end
int i = blockposition.getY();
ChunkSection chunksection = this.getSection(this.getSectionIndex(i));
boolean flag1 = chunksection.hasOnlyAir();
@@ -324,7 +340,8 @@
if (!chunksection.getBlockState(j, k, l).is(block)) {
return null;
} else {
- if (!this.level.isClientSide) {
+ // CraftBukkit - Don't place while processing the BlockPlaceEvent, unless it's a BlockContainer. Prevents blocks such as TNT from activating when cancelled.
+ if (!this.level.isClientSide && doPlace && (!this.level.captureBlockStates || block instanceof net.minecraft.world.level.block.BlockTileEntity)) {
iblockdata.onPlace(this.level, blockposition, iblockdata1, flag);
}
@@ -375,7 +392,12 @@
@Nullable
public TileEntity getBlockEntity(BlockPosition blockposition, Chunk.EnumTileEntityState chunk_enumtileentitystate) {
- TileEntity tileentity = (TileEntity) this.blockEntities.get(blockposition);
+ // CraftBukkit start
+ TileEntity tileentity = level.capturedTileEntities.get(blockposition);
+ if (tileentity == null) {
+ tileentity = (TileEntity) this.blockEntities.get(blockposition);
+ }
+ // CraftBukkit end
if (tileentity == null) {
NBTTagCompound nbttagcompound = (NBTTagCompound) this.pendingBlockEntities.remove(blockposition);
@@ -447,6 +469,7 @@
if (!iblockdata.hasBlockEntity()) {
Chunk.LOGGER.warn("Trying to set block entity {} at position {}, but state {} does not allow it", new Object[]{tileentity, blockposition, iblockdata});
+ new Exception().printStackTrace(); // CraftBukkit
} else {
IBlockData iblockdata1 = tileentity.getBlockState();
@@ -500,6 +523,12 @@
if (this.isInLevel()) {
TileEntity tileentity = (TileEntity) this.blockEntities.remove(blockposition);
+ // CraftBukkit start - SPIGOT-5561: Also remove from pending map
+ if (!pendingBlockEntities.isEmpty()) {
+ pendingBlockEntities.remove(blockposition);
+ }
+ // CraftBukkit end
+
if (tileentity != null) {
World world = this.level;
@@ -553,6 +582,57 @@
}
+ // CraftBukkit start
+ public void loadCallback() {
+ org.bukkit.Server server = this.level.getCraftServer();
+ if (server != null) {
+ /*
+ * If it's a new world, the first few chunks are generated inside
+ * the World constructor. We can't reliably alter that, so we have
+ * no way of creating a CraftWorld/CraftServer at that point.
+ */
+ org.bukkit.Chunk bukkitChunk = new org.bukkit.craftbukkit.CraftChunk(this);
+ server.getPluginManager().callEvent(new org.bukkit.event.world.ChunkLoadEvent(bukkitChunk, this.needsDecoration));
+
+ if (this.needsDecoration) {
+ this.needsDecoration = false;
+ java.util.Random random = new java.util.Random();
+ random.setSeed(level.getSeed());
+ long xRand = random.nextLong() / 2L * 2L + 1L;
+ long zRand = random.nextLong() / 2L * 2L + 1L;
+ random.setSeed((long) this.chunkPos.x * xRand + (long) this.chunkPos.z * zRand ^ level.getSeed());
+
+ org.bukkit.World world = this.level.getWorld();
+ if (world != null) {
+ this.level.populating = true;
+ try {
+ for (org.bukkit.generator.BlockPopulator populator : world.getPopulators()) {
+ populator.populate(world, random, bukkitChunk);
+ }
+ } finally {
+ this.level.populating = false;
+ }
+ }
+ server.getPluginManager().callEvent(new org.bukkit.event.world.ChunkPopulateEvent(bukkitChunk));
+ }
+ }
+ }
+
+ public void unloadCallback() {
+ org.bukkit.Server server = this.level.getCraftServer();
+ org.bukkit.Chunk bukkitChunk = new org.bukkit.craftbukkit.CraftChunk(this);
+ org.bukkit.event.world.ChunkUnloadEvent unloadEvent = new org.bukkit.event.world.ChunkUnloadEvent(bukkitChunk, this.isUnsaved());
+ server.getPluginManager().callEvent(unloadEvent);
+ // note: saving can be prevented, but not forced if no saving is actually required
+ this.mustNotSave = !unloadEvent.isSaveChunk();
+ }
+
+ @Override
+ public boolean isUnsaved() {
+ return super.isUnsaved() && !this.mustNotSave;
+ }
+ // CraftBukkit end
+
public boolean isEmpty() {
return false;
}
@@ -750,7 +830,7 @@
private <T extends TileEntity> void updateBlockEntityTicker(T t0) {
IBlockData iblockdata = t0.getBlockState();
- BlockEntityTicker<T> blockentityticker = iblockdata.getTicker(this.level, t0.getType());
+ BlockEntityTicker<T> blockentityticker = iblockdata.getTicker(this.level, (TileEntityTypes<T>) t0.getType()); // CraftBukkit - decompile error
if (blockentityticker == null) {
this.removeBlockEntityTicker(t0.getBlockPos());
@@ -841,7 +921,7 @@
private boolean loggedInvalidBlockState;
a(final TileEntity tileentity, final BlockEntityTicker blockentityticker) {
- this.blockEntity = tileentity;
+ this.blockEntity = (T) tileentity; // CraftBukkit - decompile error
this.ticker = blockentityticker;
}

View File

@@ -0,0 +1,69 @@
--- a/net/minecraft/world/level/chunk/ChunkGenerator.java
+++ b/net/minecraft/world/level/chunk/ChunkGenerator.java
@@ -312,7 +312,7 @@
}
}
- public void applyBiomeDecoration(GeneratorAccessSeed generatoraccessseed, IChunkAccess ichunkaccess, StructureManager structuremanager) {
+ public void addVanillaDecorations(GeneratorAccessSeed generatoraccessseed, IChunkAccess ichunkaccess, StructureManager structuremanager) { // CraftBukkit
ChunkCoordIntPair chunkcoordintpair = ichunkaccess.getPos();
if (!SharedConstants.debugVoidTerrain(chunkcoordintpair)) {
@@ -334,7 +334,7 @@
for (int k = 0; k < j; ++k) {
ChunkSection chunksection = achunksection[k];
- PalettedContainerRO palettedcontainerro = chunksection.getBiomes();
+ PalettedContainerRO<Holder<BiomeBase>> palettedcontainerro = chunksection.getBiomes(); // CraftBukkit - decompile error
Objects.requireNonNull(set);
palettedcontainerro.getAll(set::add);
@@ -445,6 +445,33 @@
}
}
+ // CraftBukkit start
+ public void applyBiomeDecoration(GeneratorAccessSeed generatoraccessseed, IChunkAccess ichunkaccess, StructureManager structuremanager) {
+ applyBiomeDecoration(generatoraccessseed, ichunkaccess, structuremanager, true);
+ }
+
+ public void applyBiomeDecoration(GeneratorAccessSeed generatoraccessseed, IChunkAccess ichunkaccess, StructureManager structuremanager, boolean vanilla) {
+ if (vanilla) {
+ addVanillaDecorations(generatoraccessseed, ichunkaccess, structuremanager);
+ }
+
+ org.bukkit.World world = generatoraccessseed.getMinecraftWorld().getWorld();
+ // only call when a populator is present (prevents unnecessary entity conversion)
+ if (!world.getPopulators().isEmpty()) {
+ org.bukkit.craftbukkit.generator.CraftLimitedRegion limitedRegion = new org.bukkit.craftbukkit.generator.CraftLimitedRegion(generatoraccessseed, ichunkaccess.getPos());
+ int x = ichunkaccess.getPos().x;
+ int z = ichunkaccess.getPos().z;
+ for (org.bukkit.generator.BlockPopulator populator : world.getPopulators()) {
+ SeededRandom seededrandom = new SeededRandom(new net.minecraft.world.level.levelgen.LegacyRandomSource(generatoraccessseed.getSeed()));
+ seededrandom.setDecorationSeed(generatoraccessseed.getSeed(), x, z);
+ populator.populate(world, new org.bukkit.craftbukkit.util.RandomSourceWrapper.RandomWrapper(seededrandom), x, z, limitedRegion);
+ }
+ limitedRegion.saveEntities();
+ limitedRegion.breakLink();
+ }
+ }
+ // CraftBukkit end
+
private static StructureBoundingBox getWritableArea(IChunkAccess ichunkaccess) {
ChunkCoordIntPair chunkcoordintpair = ichunkaccess.getPos();
int i = chunkcoordintpair.getMinBlockX();
@@ -582,6 +609,14 @@
StructureStart structurestart = structure.generate(structureset_a.structure(), resourcekey, iregistrycustom, this, this.biomeSource, randomstate, structuretemplatemanager, i, chunkcoordintpair, j, ichunkaccess, predicate);
if (structurestart.isValid()) {
+ // CraftBukkit start
+ StructureBoundingBox box = structurestart.getBoundingBox();
+ org.bukkit.event.world.AsyncStructureSpawnEvent event = new org.bukkit.event.world.AsyncStructureSpawnEvent(structuremanager.level.getMinecraftWorld().getWorld(), org.bukkit.craftbukkit.generator.structure.CraftStructure.minecraftToBukkit(structure), new org.bukkit.util.BoundingBox(box.minX(), box.minY(), box.minZ(), box.maxX(), box.maxY(), box.maxZ()), chunkcoordintpair.x, chunkcoordintpair.z);
+ org.bukkit.Bukkit.getPluginManager().callEvent(event);
+ if (event.isCancelled()) {
+ return true;
+ }
+ // CraftBukkit end
structuremanager.setStartForStructure(sectionposition, structure, structurestart, ichunkaccess);
return true;
} else {

View File

@@ -0,0 +1,7 @@
--- a/net/minecraft/world/level/chunk/ChunkGeneratorStructureState.java
+++ b/net/minecraft/world/level/chunk/ChunkGeneratorStructureState.java
@@ -1,3 +1,4 @@
+// mc-dev import
package net.minecraft.world.level.chunk;
import com.google.common.base.Stopwatch;

View File

@@ -0,0 +1,33 @@
--- a/net/minecraft/world/level/chunk/ChunkSection.java
+++ b/net/minecraft/world/level/chunk/ChunkSection.java
@@ -23,7 +23,7 @@
private short tickingBlockCount;
private short tickingFluidCount;
private final DataPaletteBlock<IBlockData> states;
- private PalettedContainerRO<Holder<BiomeBase>> biomes;
+ private DataPaletteBlock<Holder<BiomeBase>> biomes; // CraftBukkit - read/write
private ChunkSection(ChunkSection chunksection) {
this.nonEmptyBlockCount = chunksection.nonEmptyBlockCount;
@@ -33,7 +33,7 @@
this.biomes = chunksection.biomes.copy();
}
- public ChunkSection(DataPaletteBlock<IBlockData> datapaletteblock, PalettedContainerRO<Holder<BiomeBase>> palettedcontainerro) {
+ public ChunkSection(DataPaletteBlock<IBlockData> datapaletteblock, DataPaletteBlock<Holder<BiomeBase>> palettedcontainerro) { // CraftBukkit - read/write
this.states = datapaletteblock;
this.biomes = palettedcontainerro;
this.recalcBlockCounts();
@@ -196,6 +196,12 @@
return (Holder) this.biomes.get(i, j, k);
}
+ // CraftBukkit start
+ public void setBiome(int i, int j, int k, Holder<BiomeBase> biome) {
+ this.biomes.set(i, j, k, biome);
+ }
+ // CraftBukkit end
+
public void fillBiomesFromNoise(BiomeResolver biomeresolver, Climate.Sampler climate_sampler, int i, int j, int k) {
DataPaletteBlock<Holder<BiomeBase>> datapaletteblock = this.biomes.recreate();
boolean flag = true;

View File

@@ -0,0 +1,71 @@
--- a/net/minecraft/world/level/chunk/IChunkAccess.java
+++ b/net/minecraft/world/level/chunk/IChunkAccess.java
@@ -85,6 +85,11 @@
protected final LevelHeightAccessor levelHeightAccessor;
protected final ChunkSection[] sections;
+ // CraftBukkit start - SPIGOT-6814: move to IChunkAccess to account for 1.17 to 1.18 chunk upgrading.
+ 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);
+ // CraftBukkit end
+
public IChunkAccess(ChunkCoordIntPair chunkcoordintpair, ChunkConverter chunkconverter, LevelHeightAccessor levelheightaccessor, IRegistry<BiomeBase> iregistry, long i, @Nullable ChunkSection[] achunksection, @Nullable BlendingData blendingdata) {
this.chunkPos = chunkcoordintpair;
this.upgradeData = chunkconverter;
@@ -103,7 +108,11 @@
}
replaceMissingSections(iregistry, this.sections);
+ // CraftBukkit start
+ this.biomeRegistry = iregistry;
}
+ public final IRegistry<BiomeBase> biomeRegistry;
+ // CraftBukkit end
private static void replaceMissingSections(IRegistry<BiomeBase> iregistry, ChunkSection[] achunksection) {
for (int i = 0; i < achunksection.length; ++i) {
@@ -275,6 +284,7 @@
public boolean tryMarkSaved() {
if (this.unsaved) {
this.unsaved = false;
+ this.persistentDataContainer.dirty(false); // CraftBukkit - SPIGOT-6814: chunk was saved, pdc is no longer dirty
return true;
} else {
return false;
@@ -282,7 +292,7 @@
}
public boolean isUnsaved() {
- return this.unsaved;
+ return this.unsaved || this.persistentDataContainer.dirty(); // CraftBukkit - SPIGOT-6814: chunk is unsaved if pdc was mutated
}
public abstract ChunkStatus getPersistedStatus();
@@ -463,6 +473,27 @@
}
}
+ // CraftBukkit start
+ public void setBiome(int i, int j, int k, Holder<BiomeBase> biome) {
+ try {
+ int l = QuartPos.fromBlock(this.getMinY());
+ int i1 = l + QuartPos.fromBlock(this.getHeight()) - 1;
+ int j1 = MathHelper.clamp(j, l, i1);
+ int k1 = this.getSectionIndex(QuartPos.toBlock(j1));
+
+ this.sections[k1].setBiome(i & 3, j1 & 3, k & 3, biome);
+ } catch (Throwable throwable) {
+ CrashReport crashreport = CrashReport.forThrowable(throwable, "Setting biome");
+ CrashReportSystemDetails crashreportsystemdetails = crashreport.addCategory("Biome being set");
+
+ crashreportsystemdetails.setDetail("Location", () -> {
+ return CrashReportSystemDetails.formatLocation(this, i, j, k);
+ });
+ throw new ReportedException(crashreport);
+ }
+ }
+ // CraftBukkit end
+
public void fillBiomesFromNoise(BiomeResolver biomeresolver, Climate.Sampler climate_sampler) {
ChunkCoordIntPair chunkcoordintpair = this.getPos();
int i = QuartPos.fromBlock(chunkcoordintpair.getMinBlockX());

View File

@@ -0,0 +1,7 @@
--- a/net/minecraft/world/level/chunk/NibbleArray.java
+++ b/net/minecraft/world/level/chunk/NibbleArray.java
@@ -1,3 +1,4 @@
+// mc-dev import
package net.minecraft.world.level.chunk;
import java.util.Arrays;

View File

@@ -0,0 +1,30 @@
--- a/net/minecraft/world/level/chunk/status/ChunkStatusTasks.java
+++ b/net/minecraft/world/level/chunk/status/ChunkStatusTasks.java
@@ -36,7 +36,7 @@
static CompletableFuture<IChunkAccess> generateStructureStarts(WorldGenContext worldgencontext, ChunkStep chunkstep, StaticCache2D<GenerationChunkHolder> staticcache2d, IChunkAccess ichunkaccess) {
WorldServer worldserver = worldgencontext.level();
- if (worldserver.getServer().getWorldData().worldGenOptions().generateStructures()) {
+ if (worldserver.serverLevelData.worldGenOptions().generateStructures()) { // CraftBukkit
worldgencontext.generator().createStructures(worldserver.registryAccess(), worldserver.getChunkSource().getGeneratorState(), worldserver.structureManager(), ichunkaccess, worldgencontext.structureManager(), worldserver.dimension());
}
@@ -170,7 +170,17 @@
private static void postLoadProtoChunk(WorldServer worldserver, List<NBTTagCompound> list) {
if (!list.isEmpty()) {
- worldserver.addWorldGenChunkEntities(EntityTypes.loadEntitiesRecursive(list, worldserver, EntitySpawnReason.LOAD));
+ // CraftBukkit start - these are spawned serialized (DefinedStructure) and we don't call an add event below at the moment due to ordering complexities
+ worldserver.addWorldGenChunkEntities(EntityTypes.loadEntitiesRecursive(list, worldserver, EntitySpawnReason.LOAD).filter((entity) -> {
+ boolean needsRemoval = false;
+ net.minecraft.server.dedicated.DedicatedServer server = worldserver.getCraftServer().getServer();
+ if (!worldserver.getChunkSource().spawnFriendlies && (entity instanceof net.minecraft.world.entity.animal.EntityAnimal || entity instanceof net.minecraft.world.entity.animal.EntityWaterAnimal)) {
+ entity.discard(null); // CraftBukkit - add Bukkit remove cause
+ needsRemoval = true;
+ }
+ return !needsRemoval;
+ }));
+ // CraftBukkit end
}
}

View File

@@ -0,0 +1,95 @@
--- a/net/minecraft/world/level/chunk/storage/IChunkLoader.java
+++ b/net/minecraft/world/level/chunk/storage/IChunkLoader.java
@@ -22,6 +22,15 @@
import net.minecraft.world.level.levelgen.structure.PersistentStructureLegacy;
import net.minecraft.world.level.storage.WorldPersistentData;
+// CraftBukkit start
+import java.util.concurrent.ExecutionException;
+import net.minecraft.server.level.ChunkProviderServer;
+import net.minecraft.server.level.WorldServer;
+import net.minecraft.world.level.GeneratorAccess;
+import net.minecraft.world.level.chunk.status.ChunkStatus;
+import net.minecraft.world.level.dimension.WorldDimension;
+// CraftBukkit end
+
public class IChunkLoader implements AutoCloseable {
public static final int LAST_MONOLYTH_STRUCTURE_DATA_VERSION = 1493;
@@ -39,13 +48,57 @@
return this.worker.isOldChunkAround(chunkcoordintpair, i);
}
- public NBTTagCompound upgradeChunkTag(ResourceKey<World> resourcekey, Supplier<WorldPersistentData> supplier, NBTTagCompound nbttagcompound, Optional<ResourceKey<MapCodec<? extends ChunkGenerator>>> optional) {
+ // CraftBukkit start
+ private boolean check(ChunkProviderServer cps, int x, int z) {
+ ChunkCoordIntPair pos = new ChunkCoordIntPair(x, z);
+ if (cps != null) {
+ com.google.common.base.Preconditions.checkState(org.bukkit.Bukkit.isPrimaryThread(), "primary thread");
+ if (cps.hasChunk(x, z)) {
+ return true;
+ }
+ }
+
+ NBTTagCompound nbt;
+ try {
+ nbt = read(pos).get().orElse(null);
+ } catch (InterruptedException | ExecutionException ex) {
+ throw new RuntimeException(ex);
+ }
+ if (nbt != null) {
+ NBTTagCompound level = nbt.getCompound("Level");
+ if (level.getBoolean("TerrainPopulated")) {
+ return true;
+ }
+
+ ChunkStatus status = ChunkStatus.byName(level.getString("Status"));
+ if (status != null && status.isOrAfter(ChunkStatus.FEATURES)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ public NBTTagCompound upgradeChunkTag(ResourceKey<WorldDimension> resourcekey, Supplier<WorldPersistentData> supplier, NBTTagCompound nbttagcompound, Optional<ResourceKey<MapCodec<? extends ChunkGenerator>>> optional, ChunkCoordIntPair pos, @Nullable GeneratorAccess generatoraccess) {
+ // CraftBukkit end
int i = getVersion(nbttagcompound);
if (i == SharedConstants.getCurrentVersion().getDataVersion().getVersion()) {
return nbttagcompound;
} else {
try {
+ // CraftBukkit start
+ if (i < 1466) {
+ NBTTagCompound level = nbttagcompound.getCompound("Level");
+ if (level.getBoolean("TerrainPopulated") && !level.getBoolean("LightPopulated")) {
+ ChunkProviderServer cps = (generatoraccess == null) ? null : ((WorldServer) generatoraccess).getChunkSource();
+ if (check(cps, pos.x - 1, pos.z) && check(cps, pos.x - 1, pos.z - 1) && check(cps, pos.x, pos.z - 1)) {
+ level.putBoolean("LightPopulated", true);
+ }
+ }
+ }
+ // CraftBukkit end
+
if (i < 1493) {
nbttagcompound = DataFixTypes.CHUNK.update(this.fixerUpper, nbttagcompound, i, 1493);
if (nbttagcompound.getCompound("Level").getBoolean("hasLegacyStructureData")) {
@@ -70,7 +123,7 @@
}
}
- private PersistentStructureLegacy getLegacyStructureHandler(ResourceKey<World> resourcekey, Supplier<WorldPersistentData> supplier) {
+ private PersistentStructureLegacy getLegacyStructureHandler(ResourceKey<WorldDimension> resourcekey, Supplier<WorldPersistentData> supplier) { // CraftBukkit
PersistentStructureLegacy persistentstructurelegacy = this.legacyStructureHandler;
if (persistentstructurelegacy == null) {
@@ -85,7 +138,7 @@
return persistentstructurelegacy;
}
- public static void injectDatafixingContext(NBTTagCompound nbttagcompound, ResourceKey<World> resourcekey, Optional<ResourceKey<MapCodec<? extends ChunkGenerator>>> optional) {
+ public static void injectDatafixingContext(NBTTagCompound nbttagcompound, ResourceKey<WorldDimension> resourcekey, Optional<ResourceKey<MapCodec<? extends ChunkGenerator>>> optional) { // CraftBukkit
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
nbttagcompound1.putString("dimension", resourcekey.location().toString());

View File

@@ -0,0 +1,81 @@
--- a/net/minecraft/world/level/chunk/storage/RegionFile.java
+++ b/net/minecraft/world/level/chunk/storage/RegionFile.java
@@ -1,3 +1,4 @@
+// mc-dev import
package net.minecraft.world.level.chunk.storage;
import com.google.common.annotations.VisibleForTesting;
@@ -63,8 +64,8 @@
} else {
this.externalFileDir = path1;
this.offsets = this.header.asIntBuffer();
- this.offsets.limit(1024);
- this.header.position(4096);
+ ((java.nio.Buffer) this.offsets).limit(1024); // CraftBukkit - decompile error
+ ((java.nio.Buffer) this.header).position(4096); // CraftBukkit - decompile error
this.timestamps = this.header.asIntBuffer();
if (flag) {
this.file = FileChannel.open(path, StandardOpenOption.CREATE, StandardOpenOption.READ, StandardOpenOption.WRITE, StandardOpenOption.DSYNC);
@@ -73,7 +74,7 @@
}
this.usedSectors.force(0, 2);
- this.header.position(0);
+ ((java.nio.Buffer) this.header).position(0); // CraftBukkit - decompile error
int i = this.file.read(this.header, 0L);
if (i != -1) {
@@ -132,7 +133,7 @@
ByteBuffer bytebuffer = ByteBuffer.allocate(l);
this.file.read(bytebuffer, (long) (j * 4096));
- bytebuffer.flip();
+ ((java.nio.Buffer) bytebuffer).flip(); // CraftBukkit - decompile error
if (bytebuffer.remaining() < 5) {
RegionFile.LOGGER.error("Chunk {} header is truncated: expected {} but read {}", new Object[]{chunkcoordintpair, l, bytebuffer.remaining()});
return null;
@@ -246,7 +247,7 @@
try {
this.file.read(bytebuffer, (long) (j * 4096));
- bytebuffer.flip();
+ ((java.nio.Buffer) bytebuffer).flip(); // CraftBukkit - decompile error
if (bytebuffer.remaining() != 5) {
return false;
} else {
@@ -349,7 +350,7 @@
bytebuffer.putInt(1);
bytebuffer.put((byte) (this.version.getId() | 128));
- bytebuffer.flip();
+ ((java.nio.Buffer) bytebuffer).flip(); // CraftBukkit - decompile error
return bytebuffer;
}
@@ -358,7 +359,7 @@
FileChannel filechannel = FileChannel.open(path1, StandardOpenOption.CREATE, StandardOpenOption.WRITE);
try {
- bytebuffer.position(5);
+ ((java.nio.Buffer) bytebuffer).position(5); // CraftBukkit - decompile error
filechannel.write(bytebuffer);
} catch (Throwable throwable) {
if (filechannel != null) {
@@ -382,7 +383,7 @@
}
private void writeHeader() throws IOException {
- this.header.position(0);
+ ((java.nio.Buffer) this.header).position(0); // CraftBukkit - decompile error
this.file.write(this.header, 0L);
}
@@ -418,7 +419,7 @@
if (i != j) {
ByteBuffer bytebuffer = RegionFile.PADDING_BUFFER.duplicate();
- bytebuffer.position(0);
+ ((java.nio.Buffer) bytebuffer).position(0); // CraftBukkit - decompile error
this.file.write(bytebuffer, (long) (j - 1));
}

View File

@@ -0,0 +1,56 @@
--- a/net/minecraft/world/level/chunk/storage/RegionFileCache.java
+++ b/net/minecraft/world/level/chunk/storage/RegionFileCache.java
@@ -32,7 +32,7 @@
this.info = regionstorageinfo;
}
- private RegionFile getRegionFile(ChunkCoordIntPair chunkcoordintpair) throws IOException {
+ private RegionFile getRegionFile(ChunkCoordIntPair chunkcoordintpair, boolean existingOnly) throws IOException { // CraftBukkit
long i = ChunkCoordIntPair.asLong(chunkcoordintpair.getRegionX(), chunkcoordintpair.getRegionZ());
RegionFile regionfile = (RegionFile) this.regionCache.getAndMoveToFirst(i);
@@ -47,6 +47,7 @@
Path path = this.folder;
int j = chunkcoordintpair.getRegionX();
Path path1 = path.resolve("r." + j + "." + chunkcoordintpair.getRegionZ() + ".mca");
+ if (existingOnly && !java.nio.file.Files.exists(path1)) return null; // CraftBukkit
RegionFile regionfile1 = new RegionFile(this.info, path1, this.folder, this.sync);
this.regionCache.putAndMoveToFirst(i, regionfile1);
@@ -56,7 +57,12 @@
@Nullable
public NBTTagCompound read(ChunkCoordIntPair chunkcoordintpair) throws IOException {
- RegionFile regionfile = this.getRegionFile(chunkcoordintpair);
+ // CraftBukkit start - SPIGOT-5680: There's no good reason to preemptively create files on read, save that for writing
+ RegionFile regionfile = this.getRegionFile(chunkcoordintpair, true);
+ if (regionfile == null) {
+ return null;
+ }
+ // CraftBukkit end
DataInputStream datainputstream = regionfile.getChunkDataInputStream(chunkcoordintpair);
NBTTagCompound nbttagcompound;
@@ -96,7 +102,12 @@
}
public void scanChunk(ChunkCoordIntPair chunkcoordintpair, StreamTagVisitor streamtagvisitor) throws IOException {
- RegionFile regionfile = this.getRegionFile(chunkcoordintpair);
+ // CraftBukkit start - SPIGOT-5680: There's no good reason to preemptively create files on read, save that for writing
+ RegionFile regionfile = this.getRegionFile(chunkcoordintpair, true);
+ if (regionfile == null) {
+ return;
+ }
+ // CraftBukkit end
DataInputStream datainputstream = regionfile.getChunkDataInputStream(chunkcoordintpair);
try {
@@ -122,7 +133,7 @@
}
protected void write(ChunkCoordIntPair chunkcoordintpair, @Nullable NBTTagCompound nbttagcompound) throws IOException {
- RegionFile regionfile = this.getRegionFile(chunkcoordintpair);
+ RegionFile regionfile = this.getRegionFile(chunkcoordintpair, false); // CraftBukkit
if (nbttagcompound == null) {
regionfile.clear(chunkcoordintpair);

View File

@@ -0,0 +1,146 @@
--- a/net/minecraft/world/level/chunk/storage/SerializableChunkData.java
+++ b/net/minecraft/world/level/chunk/storage/SerializableChunkData.java
@@ -76,7 +76,8 @@
import net.minecraft.world.ticks.TickListChunk;
import org.slf4j.Logger;
-public record SerializableChunkData(IRegistry<BiomeBase> biomeRegistry, ChunkCoordIntPair chunkPos, int minSectionY, long lastUpdateTime, long inhabitedTime, ChunkStatus chunkStatus, @Nullable BlendingData.d blendingData, @Nullable BelowZeroRetrogen belowZeroRetrogen, ChunkConverter upgradeData, @Nullable long[] carvingMask, Map<HeightMap.Type, long[]> heightmaps, IChunkAccess.a packedTicks, ShortList[] postProcessingSections, boolean lightCorrect, List<SerializableChunkData.b> sectionData, List<NBTTagCompound> entities, List<NBTTagCompound> blockEntities, NBTTagCompound structureData) {
+// CraftBukkit - persistentDataContainer
+public record SerializableChunkData(IRegistry<BiomeBase> biomeRegistry, ChunkCoordIntPair chunkPos, int minSectionY, long lastUpdateTime, long inhabitedTime, ChunkStatus chunkStatus, @Nullable BlendingData.d blendingData, @Nullable BelowZeroRetrogen belowZeroRetrogen, ChunkConverter upgradeData, @Nullable long[] carvingMask, Map<HeightMap.Type, long[]> heightmaps, IChunkAccess.a packedTicks, ShortList[] postProcessingSections, boolean lightCorrect, List<SerializableChunkData.b> sectionData, List<NBTTagCompound> entities, List<NBTTagCompound> blockEntities, NBTTagCompound structureData, @Nullable NBTBase persistentDataContainer) {
public static final Codec<DataPaletteBlock<IBlockData>> BLOCK_STATE_CODEC = DataPaletteBlock.codecRW(Block.BLOCK_STATE_REGISTRY, IBlockData.CODEC, DataPaletteBlock.d.SECTION_STATES, Blocks.AIR.defaultBlockState());
private static final Logger LOGGER = LogUtils.getLogger();
@@ -110,7 +111,7 @@
dataresult = BlendingData.d.CODEC.parse(DynamicOpsNBT.INSTANCE, nbttagcompound.getCompound("blending_data"));
logger = SerializableChunkData.LOGGER;
Objects.requireNonNull(logger);
- blendingdata_d = (BlendingData.d) dataresult.resultOrPartial(logger::error).orElse((Object) null);
+ blendingdata_d = (BlendingData.d) ((DataResult<BlendingData.d>) dataresult).resultOrPartial(logger::error).orElse(null); // CraftBukkit - decompile error
} else {
blendingdata_d = null;
}
@@ -121,7 +122,7 @@
dataresult = BelowZeroRetrogen.CODEC.parse(DynamicOpsNBT.INSTANCE, nbttagcompound.getCompound("below_zero_retrogen"));
logger = SerializableChunkData.LOGGER;
Objects.requireNonNull(logger);
- belowzeroretrogen = (BelowZeroRetrogen) dataresult.resultOrPartial(logger::error).orElse((Object) null);
+ belowzeroretrogen = (BelowZeroRetrogen) ((DataResult<BelowZeroRetrogen>) dataresult).resultOrPartial(logger::error).orElse(null); // CraftBukkit - decompile error
} else {
belowzeroretrogen = null;
}
@@ -178,7 +179,7 @@
NBTTagList nbttaglist2 = nbttagcompound.getList("sections", 10);
List<SerializableChunkData.b> list4 = new ArrayList(nbttaglist2.size());
IRegistry<BiomeBase> iregistry = iregistrycustom.lookupOrThrow(Registries.BIOME);
- Codec<PalettedContainerRO<Holder<BiomeBase>>> codec = makeBiomeCodec(iregistry);
+ Codec<DataPaletteBlock<Holder<BiomeBase>>> codec = makeBiomeCodecRW(iregistry); // CraftBukkit - read/write
for (int i1 = 0; i1 < nbttaglist2.size(); ++i1) {
NBTTagCompound nbttagcompound3 = nbttaglist2.getCompound(i1);
@@ -196,17 +197,17 @@
datapaletteblock = new DataPaletteBlock<>(Block.BLOCK_STATE_REGISTRY, Blocks.AIR.defaultBlockState(), DataPaletteBlock.d.SECTION_STATES);
}
- Object object;
+ DataPaletteBlock object; // CraftBukkit - read/write
if (nbttagcompound3.contains("biomes", 10)) {
- object = (PalettedContainerRO) codec.parse(DynamicOpsNBT.INSTANCE, nbttagcompound3.getCompound("biomes")).promotePartial((s1) -> {
+ object = codec.parse(DynamicOpsNBT.INSTANCE, nbttagcompound3.getCompound("biomes")).promotePartial((s1) -> { // CraftBukkit - read/write
logErrors(chunkcoordintpair, b0, s1);
}).getOrThrow(SerializableChunkData.a::new);
} else {
object = new DataPaletteBlock<>(iregistry.asHolderIdMap(), iregistry.getOrThrow(Biomes.PLAINS), DataPaletteBlock.d.SECTION_BIOMES);
}
- chunksection = new ChunkSection(datapaletteblock, (PalettedContainerRO) object);
+ chunksection = new ChunkSection(datapaletteblock, (DataPaletteBlock) object); // CraftBukkit - read/write
} else {
chunksection = null;
}
@@ -217,7 +218,8 @@
list4.add(new SerializableChunkData.b(b0, chunksection, nibblearray, nibblearray1));
}
- return new SerializableChunkData(iregistry, chunkcoordintpair, levelheightaccessor.getMinSectionY(), i, j, chunkstatus, blendingdata_d, belowzeroretrogen, chunkconverter, along, map, ichunkaccess_a, ashortlist, flag, list4, list2, list3, nbttagcompound2);
+ // CraftBukkit - ChunkBukkitValues
+ return new SerializableChunkData(iregistry, chunkcoordintpair, levelheightaccessor.getMinSectionY(), i, j, chunkstatus, blendingdata_d, belowzeroretrogen, chunkconverter, along, map, ichunkaccess_a, ashortlist, flag, list4, list2, list3, nbttagcompound2, nbttagcompound.get("ChunkBukkitValues"));
}
}
@@ -289,6 +291,12 @@
}
}
+ // CraftBukkit start - load chunk persistent data from nbt - SPIGOT-6814: Already load PDC here to account for 1.17 to 1.18 chunk upgrading.
+ if (persistentDataContainer instanceof NBTTagCompound) {
+ ((IChunkAccess) object).persistentDataContainer.putAll((NBTTagCompound) persistentDataContainer);
+ }
+ // CraftBukkit end
+
((IChunkAccess) object).setLightCorrect(this.lightCorrect);
EnumSet<HeightMap.Type> enumset = EnumSet.noneOf(HeightMap.Type.class);
Iterator iterator1 = ((IChunkAccess) object).getPersistedStatus().heightmapsAfter().iterator();
@@ -348,6 +356,12 @@
return DataPaletteBlock.codecRO(iregistry.asHolderIdMap(), iregistry.holderByNameCodec(), DataPaletteBlock.d.SECTION_BIOMES, iregistry.getOrThrow(Biomes.PLAINS));
}
+ // CraftBukkit start - read/write
+ private static Codec<DataPaletteBlock<Holder<BiomeBase>>> makeBiomeCodecRW(IRegistry<BiomeBase> iregistry) {
+ return DataPaletteBlock.codecRW(iregistry.asHolderIdMap(), iregistry.holderByNameCodec(), DataPaletteBlock.d.SECTION_BIOMES, iregistry.getOrThrow(Biomes.PLAINS));
+ }
+ // CraftBukkit end
+
public static SerializableChunkData copyOf(WorldServer worldserver, IChunkAccess ichunkaccess) {
if (!ichunkaccess.canBeSerialized()) {
throw new IllegalArgumentException("Chunk can't be serialized: " + String.valueOf(ichunkaccess));
@@ -419,7 +433,14 @@
});
NBTTagCompound nbttagcompound1 = packStructureData(StructurePieceSerializationContext.fromLevel(worldserver), chunkcoordintpair, ichunkaccess.getAllStarts(), ichunkaccess.getAllReferences());
- return new SerializableChunkData(worldserver.registryAccess().lookupOrThrow(Registries.BIOME), chunkcoordintpair, ichunkaccess.getMinSectionY(), worldserver.getGameTime(), ichunkaccess.getInhabitedTime(), ichunkaccess.getPersistedStatus(), (BlendingData.d) Optionull.map(ichunkaccess.getBlendingData(), BlendingData::pack), ichunkaccess.getBelowZeroRetrogen(), ichunkaccess.getUpgradeData().copy(), along, map, ichunkaccess_a, ashortlist, ichunkaccess.isLightCorrect(), list, list2, list1, nbttagcompound1);
+ // CraftBukkit start - store chunk persistent data in nbt
+ NBTTagCompound persistentDataContainer = null;
+ if (!ichunkaccess.persistentDataContainer.isEmpty()) { // SPIGOT-6814: Always save PDC to account for 1.17 to 1.18 chunk upgrading.
+ persistentDataContainer = ichunkaccess.persistentDataContainer.toTagCompound();
+ }
+
+ return new SerializableChunkData(worldserver.registryAccess().lookupOrThrow(Registries.BIOME), chunkcoordintpair, ichunkaccess.getMinSectionY(), worldserver.getGameTime(), ichunkaccess.getInhabitedTime(), ichunkaccess.getPersistedStatus(), (BlendingData.d) Optionull.map(ichunkaccess.getBlendingData(), BlendingData::pack), ichunkaccess.getBelowZeroRetrogen(), ichunkaccess.getUpgradeData().copy(), along, map, ichunkaccess_a, ashortlist, ichunkaccess.isLightCorrect(), list, list2, list1, nbttagcompound1, persistentDataContainer);
+ // CraftBukkit end
}
}
@@ -432,7 +453,7 @@
nbttagcompound.putLong("LastUpdate", this.lastUpdateTime);
nbttagcompound.putLong("InhabitedTime", this.inhabitedTime);
nbttagcompound.putString("Status", BuiltInRegistries.CHUNK_STATUS.getKey(this.chunkStatus).toString());
- DataResult dataresult;
+ DataResult<NBTBase> dataresult; // CraftBukkit - decompile error
Logger logger;
if (this.blendingData != null) {
@@ -513,6 +534,11 @@
});
nbttagcompound.put("Heightmaps", nbttagcompound2);
nbttagcompound.put("structures", this.structureData);
+ // CraftBukkit start - store chunk persistent data in nbt
+ if (persistentDataContainer != null) { // SPIGOT-6814: Always save PDC to account for 1.17 to 1.18 chunk upgrading.
+ nbttagcompound.put("ChunkBukkitValues", persistentDataContainer);
+ }
+ // CraftBukkit end
return nbttagcompound;
}
@@ -623,6 +649,12 @@
StructureStart structurestart = StructureStart.loadStaticStart(structurepieceserializationcontext, nbttagcompound1.getCompound(s), i);
if (structurestart != null) {
+ // CraftBukkit start - load persistent data for structure start
+ net.minecraft.nbt.NBTBase persistentBase = nbttagcompound1.getCompound(s).get("StructureBukkitValues");
+ if (persistentBase instanceof NBTTagCompound) {
+ structurestart.persistentDataContainer.putAll((NBTTagCompound) persistentBase);
+ }
+ // CraftBukkit end
map.put(structure, structurestart);
}
}