From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Aikar 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/World.java b/src/main/java/net/minecraft/server/World.java index 6e4329d21d7877e46369361e55954f2f9371bd6e..7f1f0111373fa409e52894e59ac49d5278d0bd58 100644 --- a/src/main/java/net/minecraft/server/World.java +++ b/src/main/java/net/minecraft/server/World.java @@ -223,6 +223,18 @@ public abstract class World implements GeneratorAccess, AutoCloseable { return chunk == null ? null : chunk.getFluid(blockposition); } + + public boolean isLoadedAndInBounds(BlockPosition blockposition) { + return getWorldBorder().isInBounds(blockposition) && getChunkIfLoadedImmediately(blockposition.getX() >> 4, blockposition.getZ() >> 4) != null; + } + public Chunk getChunkIfLoaded(BlockPosition blockposition) { + return getChunkIfLoaded(blockposition.getX() >> 4, blockposition.getZ() >> 4); + } + + // reduces need to do isLoaded before getType + public IBlockData getTypeIfLoadedAndInBounds(BlockPosition blockposition) { + return getWorldBorder().isInBounds(blockposition) ? getTypeIfLoaded(blockposition) : null; + } // Paper end @Override diff --git a/src/main/java/net/minecraft/server/WorldBorder.java b/src/main/java/net/minecraft/server/WorldBorder.java index 3db276f176301ebf15d5a2ba44d0edb5c7ec6097..73730fe25c84a867b8d95525c9d76d60a5797396 100644 --- a/src/main/java/net/minecraft/server/WorldBorder.java +++ b/src/main/java/net/minecraft/server/WorldBorder.java @@ -19,6 +19,7 @@ public class WorldBorder { public WorldBorder() {} + public final boolean isInBounds(BlockPosition blockposition) { return this.a(blockposition); } // Paper - OBFHELPER public boolean a(BlockPosition blockposition) { return (double) (blockposition.getX() + 1) > this.c() && (double) blockposition.getX() < this.e() && (double) (blockposition.getZ() + 1) > this.d() && (double) blockposition.getZ() < this.f(); }