2016-04-13 22:57:34 +02:00
|
|
|
From a73a37ed1c7987b84c1fe0b8f033c72ababd0d43 Mon Sep 17 00:00:00 2001
|
2016-03-19 04:55:31 +01:00
|
|
|
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
|
2016-04-13 22:57:34 +02:00
|
|
|
index f811cd2..c6f15b8 100644
|
2016-03-19 04:55:31 +01:00
|
|
|
--- a/src/main/java/net/minecraft/server/World.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/World.java
|
2016-04-13 22:57:34 +02:00
|
|
|
@@ -153,6 +153,12 @@ public abstract class World implements IBlockAccess {
|
2016-03-19 04:55:31 +01:00
|
|
|
return (CraftServer) Bukkit.getServer();
|
|
|
|
}
|
|
|
|
|
|
|
|
+ // Paper start
|
|
|
|
+ public Chunk getChunkIfLoaded(BlockPosition blockposition) {
|
2016-03-20 05:13:20 +01:00
|
|
|
+ return this.chunkProvider.getLoadedChunkAt(blockposition.getX() >> 4, blockposition.getZ() >> 4);
|
2016-03-19 04:55:31 +01:00
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
+
|
|
|
|
public Chunk getChunkIfLoaded(int x, int z) {
|
2016-03-20 05:53:34 +01:00
|
|
|
return ((ChunkProviderServer) this.chunkProvider).getChunkIfLoaded(x, z);
|
2016-03-19 04:55:31 +01:00
|
|
|
}
|
2016-04-13 22:57:34 +02:00
|
|
|
@@ -635,6 +641,41 @@ public abstract class World implements IBlockAccess {
|
2016-03-19 04:55:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
+ // Paper start - test if meets light level, return faster
|
|
|
|
+ // logic copied from below
|
|
|
|
+ public boolean isLightLevel(BlockPosition blockposition, int level) {
|
|
|
|
+ if (isValidLocation(blockposition)) {
|
|
|
|
+ if (this.getType(blockposition).f()) {
|
|
|
|
+ if (this.c(blockposition.up(), false) >= level) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ if (this.c(blockposition.east(), false) >= level) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ if (this.c(blockposition.west(), false) >= level) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ if (this.c(blockposition.south(), false) >= level) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ if (this.c(blockposition.north(), false) >= level) {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
|
|
+ } else {
|
|
|
|
+ if (blockposition.getY() >= 256) {
|
|
|
|
+ blockposition = new BlockPosition(blockposition.getX(), 255, blockposition.getZ());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Chunk chunk = this.getChunkAtWorldCoords(blockposition);
|
|
|
|
+ return chunk.a(blockposition, this.J) >= level;
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
+
|
|
|
|
public int getLightLevel(BlockPosition blockposition) {
|
|
|
|
return this.c(blockposition, true);
|
|
|
|
}
|
2016-04-13 22:57:34 +02:00
|
|
|
@@ -749,6 +790,27 @@ public abstract class World implements IBlockAccess {
|
2016-03-19 04:55:31 +01:00
|
|
|
return this.worldProvider.n()[this.getLightLevel(blockposition)];
|
|
|
|
}
|
|
|
|
|
|
|
|
+ // Paper start - reduces need to do isLoaded before getType
|
|
|
|
+ public IBlockData getTypeIfLoaded(BlockPosition blockposition) {
|
|
|
|
+ // CraftBukkit start - tree generation
|
|
|
|
+ if (captureTreeGeneration) {
|
|
|
|
+ Iterator<BlockState> it = capturedBlockStates.iterator();
|
|
|
|
+ while (it.hasNext()) {
|
|
|
|
+ BlockState previous = it.next();
|
|
|
|
+ if (previous.getX() == blockposition.getX() && previous.getY() == blockposition.getY() && previous.getZ() == blockposition.getZ()) {
|
|
|
|
+ return CraftMagicNumbers.getBlock(previous.getTypeId()).fromLegacyData(previous.getRawData());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // CraftBukkit end
|
|
|
|
+ Chunk chunk = this.getChunkIfLoaded(blockposition);
|
|
|
|
+ if (chunk != null) {
|
|
|
|
+ return this.isValidLocation(blockposition) ? chunk.getBlockData(blockposition) : Blocks.AIR.getBlockData();
|
|
|
|
+ }
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
+
|
|
|
|
public IBlockData getType(BlockPosition blockposition) {
|
|
|
|
// CraftBukkit start - tree generation
|
|
|
|
if (captureTreeGeneration) {
|
|
|
|
--
|
2016-03-31 02:50:23 +02:00
|
|
|
2.8.0
|
2016-03-19 04:55:31 +01:00
|
|
|
|