Paper/Spigot-Server-Patches/0065-Add-World-Util-Methods.patch
Shane Freeder 0faaa7da92 Updated Upstream (Bukkit/CraftBukkit)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing

Bukkit Changes:
19b7b7bd #561: Add clear weather World API
5929c808 #552: Add the ability to retrieve hit, step, fall, and other sounds from blocks.

CraftBukkit Changes:
e1ebdd92 #771: Add clear weather World API
424598d2 #752: Add the ability to retrieve hit, step, fall, and other sounds from blocks.
2020-11-25 23:45:25 +00:00

66 lines
3.5 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/World.java b/src/main/java/net/minecraft/server/World.java
index db637b5f9ed4180844ddc12dc53050a89a4d163d..bfa9b3482251341947da8e6c4def762bf7d725b7 100644
--- a/src/main/java/net/minecraft/server/World.java
+++ b/src/main/java/net/minecraft/server/World.java
@@ -245,11 +245,27 @@ public abstract class World implements GeneratorAccess, AutoCloseable {
}
@Override
- public Fluid getFluidIfLoaded(BlockPosition blockposition) {
+ public final Fluid getFluidIfLoaded(BlockPosition blockposition) {
IChunkAccess chunk = this.getChunkIfLoadedImmediately(blockposition.getX() >> 4, blockposition.getZ() >> 4);
return chunk == null ? null : chunk.getFluid(blockposition);
}
+
+ public final boolean isLoadedAndInBounds(BlockPosition blockposition) { // Paper - final for inline
+ return getWorldBorder().isInBounds(blockposition) && getChunkIfLoadedImmediately(blockposition.getX() >> 4, blockposition.getZ() >> 4) != null;
+ }
+
+ public Chunk getChunkIfLoaded(int x, int z) { // Overridden in WorldServer for ABI compat which has final
+ return ((WorldServer) this).getChunkProvider().getChunkAtIfLoadedImmediately(x, z);
+ }
+ public final Chunk getChunkIfLoaded(BlockPosition blockposition) {
+ return ((WorldServer) this).getChunkProvider().getChunkAtIfLoadedImmediately(blockposition.getX() >> 4, blockposition.getZ() >> 4);
+ }
+
+ // reduces need to do isLoaded before getType
+ public final 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 bb0f30f182856d2701fde9b1a65eeb987462104a..717f495abd63218bb7ce9241e7cfeac809ef02de 100644
--- a/src/main/java/net/minecraft/server/WorldBorder.java
+++ b/src/main/java/net/minecraft/server/WorldBorder.java
@@ -21,6 +21,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.e() && (double) blockposition.getX() < this.g() && (double) (blockposition.getZ() + 1) > this.f() && (double) blockposition.getZ() < this.h();
}
diff --git a/src/main/java/net/minecraft/server/WorldServer.java b/src/main/java/net/minecraft/server/WorldServer.java
index ef7b76c4a9b5bafa4780922558538bbdcd783120..01fde964fa2fae3cfefc4b9e8e2c59a997d09539 100644
--- a/src/main/java/net/minecraft/server/WorldServer.java
+++ b/src/main/java/net/minecraft/server/WorldServer.java
@@ -88,7 +88,7 @@ public class WorldServer extends World implements GeneratorAccessSeed {
public final Convertable.ConversionSession convertable;
public final UUID uuid;
- public Chunk getChunkIfLoaded(int x, int z) {
+ @Override public Chunk getChunkIfLoaded(int x, int z) { // Paper - this was added in world too but keeping here for NMS ABI
return this.chunkProvider.getChunkAt(x, z, false);
}