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/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java index c9ee1a12b6fe92db6896cd4abd7e7833b094c9da..41dab560595a6d052c82b4474d824a584756371a 100644 --- a/src/main/java/net/minecraft/server/level/ServerLevel.java +++ b/src/main/java/net/minecraft/server/level/ServerLevel.java @@ -199,7 +199,7 @@ public class ServerLevel extends Level implements WorldGenLevel { 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 a5cf87f9ef0756e9940cdaef7811aa106194aaa5..ef6289d67f54d81497edc0d7e4f3789d5bcb28f9 100644 --- a/src/main/java/net/minecraft/world/level/Level.java +++ b/src/main/java/net/minecraft/world/level/Level.java @@ -310,11 +310,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().isWithinBounds(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().isWithinBounds(blockposition) ? getTypeIfLoaded(blockposition) : null; + } // Paper end @Override