From 071360817aedb48c928cb029c99881fe12e255dc Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Sat, 17 Oct 2020 17:37:49 +1100 Subject: [PATCH] #672: Add PersistentDataHolder to Chunk By: Nesaak <52047222+Nesaak@users.noreply.github.com> --- paper-server/nms-patches/Chunk.patch | 29 +++++----- .../nms-patches/ChunkRegionLoader.patch | 57 +++++++++++++++++++ .../org/bukkit/craftbukkit/CraftChunk.java | 6 ++ 3 files changed, 79 insertions(+), 13 deletions(-) create mode 100644 paper-server/nms-patches/ChunkRegionLoader.patch diff --git a/paper-server/nms-patches/Chunk.patch b/paper-server/nms-patches/Chunk.patch index a673e1b833..b65a147321 100644 --- a/paper-server/nms-patches/Chunk.patch +++ b/paper-server/nms-patches/Chunk.patch @@ -18,7 +18,7 @@ this.loc = chunkcoordintpair; this.i = chunkconverter; HeightMap.Type[] aheightmap_type = HeightMap.Type.values(); -@@ -96,8 +96,19 @@ +@@ -96,8 +96,22 @@ } } @@ -33,12 +33,15 @@ + + public boolean mustNotSave; + public boolean needsDecoration; ++ ++ private static final org.bukkit.craftbukkit.persistence.CraftPersistentDataTypeRegistry DATA_TYPE_REGISTRY = new org.bukkit.craftbukkit.persistence.CraftPersistentDataTypeRegistry(); ++ public final org.bukkit.craftbukkit.persistence.CraftPersistentDataContainer persistentDataContainer = new org.bukkit.craftbukkit.persistence.CraftPersistentDataContainer(DATA_TYPE_REGISTRY); + // CraftBukkit end + public Chunk(World world, ProtoChunk protochunk) { this(world, protochunk.getPos(), protochunk.getBiomeIndex(), protochunk.p(), protochunk.n(), protochunk.o(), protochunk.getInhabitedTime(), protochunk.getSections(), (Consumer) null); Iterator iterator = protochunk.y().iterator(); -@@ -139,6 +150,7 @@ +@@ -139,6 +153,7 @@ this.b(protochunk.r()); this.s = true; @@ -46,7 +49,7 @@ } @Override -@@ -229,9 +241,16 @@ +@@ -229,9 +244,16 @@ } } @@ -63,7 +66,7 @@ int i = blockposition.getX() & 15; int j = blockposition.getY(); int k = blockposition.getZ() & 15; -@@ -283,7 +302,8 @@ +@@ -283,7 +305,8 @@ } } @@ -73,7 +76,7 @@ iblockdata.onPlace(this.world, blockposition, iblockdata1, flag); } -@@ -378,7 +398,12 @@ +@@ -378,7 +401,12 @@ @Nullable public TileEntity a(BlockPosition blockposition, Chunk.EnumTileEntityState chunk_enumtileentitystate) { @@ -87,7 +90,7 @@ if (tileentity == null) { NBTTagCompound nbttagcompound = (NBTTagCompound) this.e.remove(blockposition); -@@ -424,6 +449,13 @@ +@@ -424,6 +452,13 @@ tileentity1.al_(); } @@ -101,7 +104,7 @@ } } -@@ -473,6 +505,50 @@ +@@ -473,6 +508,50 @@ } @@ -152,7 +155,7 @@ public void markDirty() { this.s = true; } -@@ -526,7 +602,7 @@ +@@ -526,7 +605,7 @@ Iterator iterator = this.entitySlices[k].a(Entity.class).iterator(); while (iterator.hasNext()) { @@ -161,7 +164,7 @@ if ((entitytypes == null || entity.getEntityType() == entitytypes) && entity.getBoundingBox().c(axisalignedbb) && predicate.test(entity)) { list.add(entity); -@@ -547,7 +623,7 @@ +@@ -547,7 +626,7 @@ Iterator iterator = this.entitySlices[k].a(oclass).iterator(); while (iterator.hasNext()) { @@ -170,7 +173,7 @@ if (t0.getBoundingBox().c(axisalignedbb) && (predicate == null || predicate.test(t0))) { list.add(t0); -@@ -621,7 +697,7 @@ +@@ -621,7 +700,7 @@ @Override public boolean isNeedsSaving() { @@ -179,7 +182,7 @@ } public void d(boolean flag) { -@@ -763,7 +839,7 @@ +@@ -763,7 +842,7 @@ public void B() { if (this.o instanceof ProtoChunkTickList) { @@ -188,7 +191,7 @@ return this.getType(blockposition).getBlock(); }); this.o = TickListEmpty.b(); -@@ -773,7 +849,7 @@ +@@ -773,7 +852,7 @@ } if (this.p instanceof ProtoChunkTickList) { @@ -197,7 +200,7 @@ return this.getFluid(blockposition).getType(); }); this.p = TickListEmpty.b(); -@@ -785,12 +861,12 @@ +@@ -785,12 +864,12 @@ } public void a(WorldServer worldserver) { diff --git a/paper-server/nms-patches/ChunkRegionLoader.patch b/paper-server/nms-patches/ChunkRegionLoader.patch new file mode 100644 index 0000000000..762b49397b --- /dev/null +++ b/paper-server/nms-patches/ChunkRegionLoader.patch @@ -0,0 +1,57 @@ +--- a/net/minecraft/server/ChunkRegionLoader.java ++++ b/net/minecraft/server/ChunkRegionLoader.java +@@ -91,7 +91,7 @@ + + if (nbttagcompound1.hasKeyOfType("TileTicks", 9)) { + nbttaglist1 = nbttagcompound1.getList("TileTicks", 10); +- function = IRegistry.BLOCK::getKey; ++ function = (block) -> IRegistry.BLOCK.getKey((Block) block); // CraftBukkit - decompile error + registryblocks = IRegistry.BLOCK; + registryblocks.getClass(); + object1 = TickListChunk.a(nbttaglist1, function, registryblocks::get); +@@ -103,7 +103,7 @@ + + if (nbttagcompound1.hasKeyOfType("LiquidTicks", 9)) { + nbttaglist1 = nbttagcompound1.getList("LiquidTicks", 10); +- function = IRegistry.FLUID::getKey; ++ function = (fluid) -> IRegistry.FLUID.getKey((FluidType) fluid); // CraftBukkit - decompile error + registryblocks = IRegistry.FLUID; + registryblocks.getClass(); + object2 = TickListChunk.a(nbttaglist1, function, registryblocks::get); +@@ -113,6 +113,12 @@ + + object = new Chunk(worldserver.getMinecraftWorld(), chunkcoordintpair, biomestorage, chunkconverter, (TickList) object1, (TickList) object2, j, achunksection, (chunk) -> { + loadEntities(nbttagcompound1, chunk); ++ // CraftBukkit start - load chunk persistent data from nbt ++ NBTTagCompound persistentBase = nbttagcompound1.getCompound("BukkitValues"); ++ if (persistentBase != null) { ++ chunk.persistentDataContainer.putAll(nbttagcompound1); ++ } ++ // CraftBukkit end + }); + } else { + ProtoChunk protochunk = new ProtoChunk(chunkcoordintpair, chunkconverter, achunksection, protochunkticklist, protochunkticklist1); +@@ -246,8 +252,9 @@ + NBTTagCompound nbttagcompound2; + + for (int i = -1; i < 17; ++i) { ++ int finalI = i; // CraftBukkit - decompile errors + ChunkSection chunksection = (ChunkSection) Arrays.stream(achunksection).filter((chunksection1) -> { +- return chunksection1 != null && chunksection1.getYPosition() >> 4 == i; ++ return chunksection1 != null && chunksection1.getYPosition() >> 4 == finalI; // CraftBukkit - decompile errors + }).findFirst().orElse(Chunk.a); + NibbleArray nibblearray = lightenginethreaded.a(EnumSkyBlock.BLOCK).a(SectionPosition.a(chunkcoordintpair, i)); + NibbleArray nibblearray1 = lightenginethreaded.a(EnumSkyBlock.SKY).a(SectionPosition.a(chunkcoordintpair, i)); +@@ -302,6 +309,12 @@ + if (ichunkaccess.getChunkStatus().getType() == ChunkStatus.Type.LEVELCHUNK) { + Chunk chunk = (Chunk) ichunkaccess; + ++ // CraftBukkit start - store chunk persistent data in nbt ++ if (!chunk.persistentDataContainer.isEmpty()) { ++ nbttagcompound1.set("BukkitValues", chunk.persistentDataContainer.toTagCompound()); ++ } ++ // CraftBukkit end ++ + chunk.d(false); + + for (int j = 0; j < chunk.getEntitySlices().length; ++j) { diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftChunk.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftChunk.java index e78687b629..929e473917 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftChunk.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftChunk.java @@ -34,6 +34,7 @@ import org.bukkit.craftbukkit.block.CraftBlock; import org.bukkit.craftbukkit.block.data.CraftBlockData; import org.bukkit.craftbukkit.util.CraftMagicNumbers; import org.bukkit.entity.Entity; +import org.bukkit.persistence.PersistentDataContainer; import org.bukkit.plugin.Plugin; public class CraftChunk implements Chunk { @@ -296,6 +297,11 @@ public class CraftChunk implements Chunk { return new CraftChunkSnapshot(getX(), getZ(), world.getName(), world.getFullTime(), sectionBlockIDs, sectionSkyLights, sectionEmitLights, sectionEmpty, hmap, biome); } + @Override + public PersistentDataContainer getPersistentDataContainer() { + return getHandle().persistentDataContainer; + } + public static ChunkSnapshot getEmptyChunkSnapshot(int x, int z, CraftWorld world, boolean includeBiome, boolean includeBiomeTempRain) { BiomeStorage biome = null;