mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-08 19:34:09 +01:00
#672: Add PersistentDataHolder to Chunk
By: Nesaak <52047222+Nesaak@users.noreply.github.com>
This commit is contained in:
parent
a3cf5aea1a
commit
071360817a
3 changed files with 79 additions and 13 deletions
|
@ -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) {
|
||||
|
|
57
paper-server/nms-patches/ChunkRegionLoader.patch
Normal file
57
paper-server/nms-patches/ChunkRegionLoader.patch
Normal file
|
@ -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) {
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in a new issue