Fix NPE from using wrong ProtoChunk ctor (#6147)

This commit is contained in:
Jake Potrebic 2021-07-10 13:17:47 -07:00
parent dcdec7d59c
commit f359da1843
4 changed files with 33 additions and 38 deletions

View File

@ -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<net.minecraft.world.level.chunk.ChunkAccess> 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);

View File

@ -1190,13 +1190,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
}
return levelChunkSections[yIndex];
}
+ net.minecraft.world.level.Level getLevel(); // Paper - Anti-Xray - Add parameters
+
Collection<Entry<Heightmap.Types, Heightmap>> 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<T> 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

View File

@ -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<GenerationStep.Carving, BitSet> 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<Block> blockTickScheduler, ProtoTickList<Fluid> fluidTickScheduler, LevelHeightAccessor world) {
+ // Paper start - add level
+ @Deprecated public ProtoChunk(ChunkPos pos, UpgradeData upgradeData, @Nullable LevelChunkSection[] levelChunkSections, ProtoTickList<Block> blockTickScheduler, ProtoTickList<Fluid> 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<Block> blockTickScheduler, ProtoTickList<Fluid> 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<Block> blockTickScheduler, ProtoTickList<Fluid> fluidTickScheduler, LevelHeightAccessor world, net.minecraft.server.level.ServerLevel level) {
+ this.level = level;
+ // Paper end

View File

@ -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