Fix getBlockStateIfLoaded world bounds check

Closes #8922
This commit is contained in:
Nassim Jahnke 2023-02-28 12:27:38 +01:00
parent 08e6622b81
commit 4ae202eb82
No known key found for this signature in database
GPG key ID: 6BE3B555EBC5982B
20 changed files with 63 additions and 62 deletions

View file

@ -6826,7 +6826,7 @@ index 3c707d6674b2594b09503b959a31c1f4ad3981e6..db61b6b0158a9bcc0e1d735e34fe3671
public BlockState getBlockState(BlockPos pos) {
return Blocks.AIR.defaultBlockState();
diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java
index ca5cbd7c43d7e263f76d8719a259514c0748a430..3bf5b8429a25b0f1347cc287f919dec7a66d9b6c 100644
index ca5cbd7c43d7e263f76d8719a259514c0748a430..a0bd6c4df76fac867e1862273ce31dbe067de624 100644
--- a/src/main/java/net/minecraft/world/level/Level.java
+++ b/src/main/java/net/minecraft/world/level/Level.java
@@ -88,6 +88,7 @@ import org.bukkit.craftbukkit.CraftServer;
@ -6837,7 +6837,7 @@ index ca5cbd7c43d7e263f76d8719a259514c0748a430..3bf5b8429a25b0f1347cc287f919dec7
import org.bukkit.craftbukkit.block.data.CraftBlockData;
import org.bukkit.craftbukkit.util.CraftSpawnCategory;
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
@@ -287,18 +288,51 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
@@ -287,18 +288,52 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
return y < -20000000 || y >= 20000000;
}
@ -6863,21 +6863,22 @@ index ca5cbd7c43d7e263f76d8719a259514c0748a430..3bf5b8429a25b0f1347cc287f919dec7
+
+ @Override
+ @Nullable
+ public final BlockState getBlockStateIfLoaded(BlockPos blockposition) {
+ public final BlockState getBlockStateIfLoaded(BlockPos pos) {
+ // CraftBukkit start - tree generation
+ if (captureTreeGeneration) {
+ CraftBlockState previous = capturedBlockStates.get(blockposition);
+ if (this.captureTreeGeneration) {
+ CraftBlockState previous = this.capturedBlockStates.get(pos);
+ if (previous != null) {
+ return previous.getHandle();
+ }
+ }
+ // CraftBukkit end
+ if (!isInWorldBounds(blockposition)) {
+ return Blocks.AIR.defaultBlockState();
+ }
+ ChunkAccess chunk = this.getChunkIfLoadedImmediately(blockposition.getX() >> 4, blockposition.getZ() >> 4);
+ if (this.isOutsideBuildHeight(pos)) {
+ return Blocks.VOID_AIR.defaultBlockState();
+ } else {
+ ChunkAccess chunk = this.getChunkIfLoadedImmediately(pos.getX() >> 4, pos.getZ() >> 4);
+
+ return chunk == null ? null : chunk.getBlockState(blockposition);
+ return chunk == null ? null : chunk.getBlockState(pos);
+ }
+ }
+
+ @Override
@ -6893,7 +6894,7 @@ index ca5cbd7c43d7e263f76d8719a259514c0748a430..3bf5b8429a25b0f1347cc287f919dec7
ChunkAccess ichunkaccess = this.getChunkSource().getChunk(chunkX, chunkZ, leastStatus, create);
if (ichunkaccess == null && create) {
@@ -309,7 +343,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
@@ -309,7 +344,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
}
@Override
@ -6902,7 +6903,7 @@ index ca5cbd7c43d7e263f76d8719a259514c0748a430..3bf5b8429a25b0f1347cc287f919dec7
return this.setBlock(pos, state, flags, 512);
}
@@ -553,7 +587,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
@@ -553,7 +588,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
if (this.isOutsideBuildHeight(pos)) {
return Blocks.VOID_AIR.defaultBlockState();
} else {