From f359da1843292e0b0ba32265df28146beb830918 Mon Sep 17 00:00:00 2001 From: Jake Potrebic Date: Sat, 10 Jul 2021 13:17:47 -0700 Subject: [PATCH] Fix NPE from using wrong ProtoChunk ctor (#6147) --- ...llow-delegation-to-vanilla-chunk-gen.patch | 2 +- patches/server/Anti-Xray.patch | 23 ---------- patches/server/Generator-Settings.patch | 44 +++++++++++++------ patches/server/incremental-chunk-saving.patch | 2 +- 4 files changed, 33 insertions(+), 38 deletions(-) diff --git a/patches/server/Allow-delegation-to-vanilla-chunk-gen.patch b/patches/server/Allow-delegation-to-vanilla-chunk-gen.patch index cb3e9865ef..c19158c6c2 100644 --- a/patches/server/Allow-delegation-to-vanilla-chunk-gen.patch +++ b/patches/server/Allow-delegation-to-vanilla-chunk-gen.patch @@ -19,7 +19,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + CraftChunkData data = (CraftChunkData) createChunkData(world); + // do bunch of vanilla shit + net.minecraft.server.level.ServerLevel nmsWorld = ((CraftWorld) world).getHandle(); -+ net.minecraft.world.level.chunk.ProtoChunk protoChunk = new net.minecraft.world.level.chunk.ProtoChunk(new net.minecraft.world.level.ChunkPos(x, z), null, nmsWorld); ++ net.minecraft.world.level.chunk.ProtoChunk protoChunk = new net.minecraft.world.level.chunk.ProtoChunk(new net.minecraft.world.level.ChunkPos(x, z), null, nmsWorld, nmsWorld); + List list = new ArrayList<>(); + list.add(protoChunk); + net.minecraft.server.level.WorldGenRegion genRegion = new net.minecraft.server.level.WorldGenRegion(nmsWorld, list, net.minecraft.world.level.chunk.ChunkStatus.EMPTY, -1); diff --git a/patches/server/Anti-Xray.patch b/patches/server/Anti-Xray.patch index 7e4e81bc34..9963099bd4 100644 --- a/patches/server/Anti-Xray.patch +++ b/patches/server/Anti-Xray.patch @@ -1190,13 +1190,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 } return levelChunkSections[yIndex]; - } - -+ net.minecraft.world.level.Level getLevel(); // Paper - Anti-Xray - Add parameters -+ - Collection> getHeightmaps(); - - default void setHeightmap(Heightmap.Types type, long[] heightmap) { diff --git a/src/main/java/net/minecraft/world/level/chunk/EmptyLevelChunk.java b/src/main/java/net/minecraft/world/level/chunk/EmptyLevelChunk.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/world/level/chunk/EmptyLevelChunk.java @@ -1398,22 +1391,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 int j = data.length * 64 / 4096; if (this.palette == this.globalPalette) { Palette palette = new HashMapPalette<>(this.registry, i, this.dummyPaletteResize, this.reader, this.writer); -diff --git a/src/main/java/net/minecraft/world/level/chunk/ProtoChunk.java b/src/main/java/net/minecraft/world/level/chunk/ProtoChunk.java -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 implements ChunkAccess { - public int getHeight() { - return this.levelHeightAccessor.getHeight(); - } -+ -+ // Paper start - Anti-Xray - Add parameters -+ @Override -+ public net.minecraft.world.level.Level getLevel() { -+ return level; -+ } -+ // Paper end - } diff --git a/src/main/java/net/minecraft/world/level/chunk/storage/ChunkSerializer.java b/src/main/java/net/minecraft/world/level/chunk/storage/ChunkSerializer.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/world/level/chunk/storage/ChunkSerializer.java diff --git a/patches/server/Generator-Settings.patch b/patches/server/Generator-Settings.patch index 797b08595d..147b879e8c 100644 --- a/patches/server/Generator-Settings.patch +++ b/patches/server/Generator-Settings.patch @@ -42,14 +42,13 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + // Paper start + default boolean generateFlatBedrock() { -+ if (this instanceof ProtoChunk) { -+ return ((ProtoChunk)this).level.paperConfig.generateFlatBedrock; -+ } else if (this instanceof LevelChunk) { -+ return ((LevelChunk)this).level.paperConfig.generateFlatBedrock; -+ } else { -+ return false; ++ if (this.getLevel() != null) { ++ return this.getLevel().paperConfig.generateFlatBedrock; + } ++ return false; + } ++ ++ net.minecraft.world.level.Level getLevel(); + // Paper end + BlockState getType(final int x, final int y, final int z); // Paper @@ -76,11 +75,24 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 private long inhabitedTime; private final Map carvingMasks = new Object2ObjectArrayMap<>(); private volatile boolean isLightCorrect; -+ final net.minecraft.world.level.Level level; // Paper - Add level ++ // Paper start - Add level ++ final net.minecraft.world.level.Level level; ++ @Override ++ public net.minecraft.world.level.Level getLevel() { ++ return this.level; ++ } ++ // Paper end ++ private static boolean PRINTED_OUTDATED_CTOR_MSG = false; // Paper - Add level -- public ProtoChunk(ChunkPos pos, UpgradeData upgradeData, LevelHeightAccessor world) { -+ // Paper start - add level -+ @Deprecated public ProtoChunk(ChunkPos pos, UpgradeData upgradeData, LevelHeightAccessor world) { this(pos, upgradeData, world, null); } ++ @Deprecated // Paper start - add level + public ProtoChunk(ChunkPos pos, UpgradeData upgradeData, LevelHeightAccessor world) { ++ // Paper start ++ this(pos, upgradeData, world, null); ++ if (!PRINTED_OUTDATED_CTOR_MSG) { ++ new IllegalArgumentException("Must use ProtoChunk constructor with the ServerLevel parameter").printStackTrace(); ++ PRINTED_OUTDATED_CTOR_MSG = true; ++ } ++ } + public ProtoChunk(ChunkPos pos, UpgradeData upgradeData, LevelHeightAccessor world, net.minecraft.server.level.ServerLevel level) { + // Paper end this(pos, upgradeData, (LevelChunkSection[])null, new ProtoTickList<>((block) -> { @@ -91,9 +103,15 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + }, pos, world), world, level); // Paper - add level } -- public ProtoChunk(ChunkPos pos, UpgradeData upgradeData, @Nullable LevelChunkSection[] levelChunkSections, ProtoTickList blockTickScheduler, ProtoTickList fluidTickScheduler, LevelHeightAccessor world) { -+ // Paper start - add level -+ @Deprecated public ProtoChunk(ChunkPos pos, UpgradeData upgradeData, @Nullable LevelChunkSection[] levelChunkSections, ProtoTickList blockTickScheduler, ProtoTickList fluidTickScheduler, LevelHeightAccessor world) { this(pos, upgradeData, levelChunkSections, blockTickScheduler, fluidTickScheduler, world, null); } ++ @Deprecated // Paper start - add level + public ProtoChunk(ChunkPos pos, UpgradeData upgradeData, @Nullable LevelChunkSection[] levelChunkSections, ProtoTickList blockTickScheduler, ProtoTickList fluidTickScheduler, LevelHeightAccessor world) { ++ // Paper start ++ this(pos, upgradeData, levelChunkSections, blockTickScheduler, fluidTickScheduler, world, null); ++ if (!PRINTED_OUTDATED_CTOR_MSG) { ++ new IllegalArgumentException("Must use ProtoChunk constructor with the ServerLevel parameter").printStackTrace(); ++ PRINTED_OUTDATED_CTOR_MSG = true; ++ } ++ } + public ProtoChunk(ChunkPos pos, UpgradeData upgradeData, @Nullable LevelChunkSection[] levelChunkSections, ProtoTickList blockTickScheduler, ProtoTickList fluidTickScheduler, LevelHeightAccessor world, net.minecraft.server.level.ServerLevel level) { + this.level = level; + // Paper end diff --git a/patches/server/incremental-chunk-saving.patch b/patches/server/incremental-chunk-saving.patch index 019eaa3319..ee96026fd7 100644 --- a/patches/server/incremental-chunk-saving.patch +++ b/patches/server/incremental-chunk-saving.patch @@ -312,7 +312,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + default void setLastSaved(long ticks) {} // Paper start default boolean generateFlatBedrock() { - if (this instanceof ProtoChunk) { + if (this.getLevel() != null) { diff --git a/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java b/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java