mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-29 22:13:42 +01:00
66 lines
3.6 KiB
Diff
66 lines
3.6 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Aikar <aikar@aikar.co>
|
|
Date: Fri, 18 Mar 2016 20:16:03 -0400
|
|
Subject: [PATCH] Add World Util Methods
|
|
|
|
Methods that can be used for other patches to help improve logic.
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
index b0ecf3c491e802aa292a0a8b7be37362c38ce084..6aab4ba5da83f523632a0a39d45a0bcb2405f0cc 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
@@ -202,7 +202,7 @@ public class ServerLevel extends net.minecraft.world.level.Level implements Worl
|
|
public final LevelStorageSource.LevelStorageAccess convertable;
|
|
public final UUID uuid;
|
|
|
|
- public LevelChunk getChunkIfLoaded(int x, int z) {
|
|
+ @Override public LevelChunk getChunkIfLoaded(int x, int z) { // Paper - this was added in world too but keeping here for NMS ABI
|
|
return this.chunkSource.getChunk(x, z, false);
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java
|
|
index a6b1572a82fd22eea5b3d4124c510d94fea5917d..aee97243cc3e73f9e07ba8ed5d6dbe8c73ba016e 100644
|
|
--- a/src/main/java/net/minecraft/world/level/Level.java
|
|
+++ b/src/main/java/net/minecraft/world/level/Level.java
|
|
@@ -309,11 +309,27 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
|
|
}
|
|
|
|
@Override
|
|
- public FluidState getFluidIfLoaded(BlockPos blockposition) {
|
|
+ public final FluidState getFluidIfLoaded(BlockPos blockposition) {
|
|
ChunkAccess chunk = this.getChunkIfLoadedImmediately(blockposition.getX() >> 4, blockposition.getZ() >> 4);
|
|
|
|
return chunk == null ? null : chunk.getFluidState(blockposition);
|
|
}
|
|
+
|
|
+ public final boolean isLoadedAndInBounds(BlockPos blockposition) { // Paper - final for inline
|
|
+ return getWorldBorder().isInBounds(blockposition) && getChunkIfLoadedImmediately(blockposition.getX() >> 4, blockposition.getZ() >> 4) != null;
|
|
+ }
|
|
+
|
|
+ public LevelChunk getChunkIfLoaded(int x, int z) { // Overridden in WorldServer for ABI compat which has final
|
|
+ return ((ServerLevel) this).getChunkSource().getChunkAtIfLoadedImmediately(x, z);
|
|
+ }
|
|
+ public final LevelChunk getChunkIfLoaded(BlockPos blockposition) {
|
|
+ return ((ServerLevel) this).getChunkSource().getChunkAtIfLoadedImmediately(blockposition.getX() >> 4, blockposition.getZ() >> 4);
|
|
+ }
|
|
+
|
|
+ // reduces need to do isLoaded before getType
|
|
+ public final BlockState getTypeIfLoadedAndInBounds(BlockPos blockposition) {
|
|
+ return getWorldBorder().isInBounds(blockposition) ? getTypeIfLoaded(blockposition) : null;
|
|
+ }
|
|
// Paper end
|
|
|
|
@Override
|
|
diff --git a/src/main/java/net/minecraft/world/level/border/WorldBorder.java b/src/main/java/net/minecraft/world/level/border/WorldBorder.java
|
|
index 72087476c65b69c86af67424a15708c463d69a43..02b10be4878b871742efb0f65980d9672f32b388 100644
|
|
--- a/src/main/java/net/minecraft/world/level/border/WorldBorder.java
|
|
+++ b/src/main/java/net/minecraft/world/level/border/WorldBorder.java
|
|
@@ -32,6 +32,7 @@ public class WorldBorder {
|
|
|
|
public WorldBorder() {}
|
|
|
|
+ public final boolean isInBounds(BlockPos blockposition) { return this.isWithinBounds(blockposition); } // Paper - OBFHELPER
|
|
public boolean isWithinBounds(BlockPos pos) {
|
|
return (double) (pos.getX() + 1) > this.getMinX() && (double) pos.getX() < this.getMaxX() && (double) (pos.getZ() + 1) > this.getMinZ() && (double) pos.getZ() < this.getMaxZ();
|
|
}
|