From be034cd98577578c31291101720c09344cf4b71d Mon Sep 17 00:00:00 2001 From: Spottedleaf Date: Mon, 16 Oct 2023 18:57:45 -0700 Subject: [PATCH] Initialise default nibble arrays in ChunkAccess directly When ChunkAccess was converted to an abstract class some versions ago, the code to initialise nibble arrays should have been moved. However, the code was not moved and so now mods constructing their own implementations of ChunkAccess would not have the nibble arrays initialised. This is ported to Paper from Starlight to keep the code base in sync, not because it fixes anything known. --- patches/server/Anti-Xray.patch | 6 +++--- patches/server/Starlight.patch | 32 ++++++++------------------------ 2 files changed, 11 insertions(+), 27 deletions(-) diff --git a/patches/server/Anti-Xray.patch b/patches/server/Anti-Xray.patch index 9449a49e2..f563025d9 100644 --- a/patches/server/Anti-Xray.patch +++ b/patches/server/Anti-Xray.patch @@ -1222,9 +1222,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 public LevelChunk(Level world, ChunkPos pos, UpgradeData upgradeData, LevelChunkTicks blockTickScheduler, LevelChunkTicks fluidTickScheduler, long inhabitedTime, @Nullable LevelChunkSection[] sectionArrayInitializer, @Nullable LevelChunk.PostLoadProcessor entityLoader, @Nullable BlendingData blendingData) { - super(pos, upgradeData, world, world.registryAccess().registryOrThrow(Registries.BIOME), inhabitedTime, sectionArrayInitializer, blendingData); + super(pos, upgradeData, world, net.minecraft.server.MinecraftServer.getServer().registryAccess().registryOrThrow(Registries.BIOME), inhabitedTime, sectionArrayInitializer, blendingData); // Paper - Anti-Xray - The world isn't ready yet, use server singleton for registry - // Paper start - rewrite light engine - this.setBlockNibbles(ca.spottedleaf.starlight.common.light.StarLightEngine.getFilledEmptyLight(world)); - this.setSkyNibbles(ca.spottedleaf.starlight.common.light.StarLightEngine.getFilledEmptyLight(world)); + this.tickersInLevel = Maps.newHashMap(); + this.level = (ServerLevel) world; // CraftBukkit - type + this.gameEventListenerRegistrySections = new Int2ObjectOpenHashMap(); diff --git a/src/main/java/net/minecraft/world/level/chunk/LevelChunkSection.java b/src/main/java/net/minecraft/world/level/chunk/LevelChunkSection.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/world/level/chunk/LevelChunkSection.java diff --git a/patches/server/Starlight.patch b/patches/server/Starlight.patch index 8c44f1ab4..54a61f940 100644 --- a/patches/server/Starlight.patch +++ b/patches/server/Starlight.patch @@ -4981,7 +4981,15 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + // Paper end - rewrite light engine public ChunkAccess(ChunkPos pos, UpgradeData upgradeData, LevelHeightAccessor heightLimitView, Registry biomeRegistry, long inhabitedTime, @Nullable LevelChunkSection[] sectionArray, @Nullable BlendingData blendingData) { ++ // Paper start - rewrite light engine ++ if (!(this instanceof ImposterProtoChunk)) { ++ this.setBlockNibbles(ca.spottedleaf.starlight.common.light.StarLightEngine.getFilledEmptyLight(heightLimitView)); ++ this.setSkyNibbles(ca.spottedleaf.starlight.common.light.StarLightEngine.getFilledEmptyLight(heightLimitView)); ++ } ++ // Paper end - rewrite light engine this.locX = pos.x; this.locZ = pos.z; // Paper - reduce need for field lookups + this.chunkPos = pos; this.coordinateKey = ChunkPos.asLong(locX, locZ); // Paper - cache long key + this.upgradeData = upgradeData; @@ -0,0 +0,0 @@ public abstract class ChunkAccess implements BlockGetter, BiomeManager.NoiseBiom this.inhabitedTime = inhabitedTime; this.postProcessing = new ShortList[heightLimitView.getSectionsCount()]; @@ -5132,17 +5140,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 +++ b/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java @@ -0,0 +0,0 @@ public class LevelChunk extends ChunkAccess { - public LevelChunk(Level world, ChunkPos pos, UpgradeData upgradeData, LevelChunkTicks blockTickScheduler, LevelChunkTicks fluidTickScheduler, long inhabitedTime, @Nullable LevelChunkSection[] sectionArrayInitializer, @Nullable LevelChunk.PostLoadProcessor entityLoader, @Nullable BlendingData blendingData) { - super(pos, upgradeData, world, world.registryAccess().registryOrThrow(Registries.BIOME), inhabitedTime, sectionArrayInitializer, blendingData); -+ // Paper start - rewrite light engine -+ this.setBlockNibbles(ca.spottedleaf.starlight.common.light.StarLightEngine.getFilledEmptyLight(world)); -+ this.setSkyNibbles(ca.spottedleaf.starlight.common.light.StarLightEngine.getFilledEmptyLight(world)); -+ // Paper end - rewrite light engine - this.tickersInLevel = Maps.newHashMap(); - this.level = (ServerLevel) world; // CraftBukkit - type - this.gameEventListenerRegistrySections = new Int2ObjectOpenHashMap(); -@@ -0,0 +0,0 @@ public class LevelChunk extends ChunkAccess { - public LevelChunk(ServerLevel world, ProtoChunk protoChunk, @Nullable LevelChunk.PostLoadProcessor entityLoader) { this(world, protoChunk.getPos(), protoChunk.getUpgradeData(), protoChunk.unpackBlockTicks(), protoChunk.unpackFluidTicks(), protoChunk.getInhabitedTime(), protoChunk.getSections(), entityLoader, protoChunk.getBlendingData()); + // Paper start - rewrite light engine @@ -5189,19 +5186,6 @@ diff --git a/src/main/java/net/minecraft/world/level/chunk/ProtoChunk.java b/src index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/world/level/chunk/ProtoChunk.java +++ b/src/main/java/net/minecraft/world/level/chunk/ProtoChunk.java -@@ -0,0 +0,0 @@ public class ProtoChunk extends ChunkAccess { - - public ProtoChunk(ChunkPos pos, UpgradeData upgradeData, @Nullable LevelChunkSection[] sections, ProtoChunkTicks blockTickScheduler, ProtoChunkTicks fluidTickScheduler, LevelHeightAccessor world, Registry biomeRegistry, @Nullable BlendingData blendingData) { - super(pos, upgradeData, world, biomeRegistry, 0L, sections, blendingData); -+ // Paper start - rewrite light engine -+ if (!(this instanceof ImposterProtoChunk)) { -+ this.setBlockNibbles(ca.spottedleaf.starlight.common.light.StarLightEngine.getFilledEmptyLight(world)); -+ this.setSkyNibbles(ca.spottedleaf.starlight.common.light.StarLightEngine.getFilledEmptyLight(world)); -+ } -+ // Paper end - rewrite light engine - this.blockTicks = blockTickScheduler; - this.fluidTicks = fluidTickScheduler; - } @@ -0,0 +0,0 @@ public class ProtoChunk extends ChunkAccess { }