2018-07-27 12:44:53 +08:00
|
|
|
From c193383e12907fb2df80cbef83d0368fa99829d0 Mon Sep 17 00:00:00 2001
|
2017-11-24 15:28:57 +08:00
|
|
|
From: Aikar <aikar@aikar.co>
|
|
|
|
Date: Mon, 6 Nov 2017 21:08:22 -0500
|
|
|
|
Subject: [PATCH] API to get a BlockState without a snapshot
|
|
|
|
|
|
|
|
This allows you to get a BlockState without creating a snapshot, operating
|
|
|
|
on the real tile entity.
|
|
|
|
|
|
|
|
This is useful for where performance is needed
|
|
|
|
|
2018-06-30 13:40:52 +08:00
|
|
|
also Avoid NPE during CraftBlockEntityState load if could not get TE
|
|
|
|
|
|
|
|
If Tile Entity was null, correct Sign to return empty lines instead of null
|
|
|
|
|
2017-11-24 15:28:57 +08:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/TileEntity.java b/src/main/java/net/minecraft/server/TileEntity.java
|
2018-07-27 12:44:53 +08:00
|
|
|
index 6021a3401f..536fd37254 100644
|
2017-11-24 15:28:57 +08:00
|
|
|
--- a/src/main/java/net/minecraft/server/TileEntity.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/TileEntity.java
|
2018-07-27 12:44:53 +08:00
|
|
|
@@ -206,7 +206,12 @@ public abstract class TileEntity implements KeyedObject { // Paper
|
2017-11-24 15:28:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// CraftBukkit start - add method
|
|
|
|
+ // Paper start
|
|
|
|
public InventoryHolder getOwner() {
|
|
|
|
+ return getOwner(true);
|
|
|
|
+ }
|
|
|
|
+ public InventoryHolder getOwner(boolean useSnapshot) {
|
|
|
|
+ // Paper end
|
|
|
|
if (world == null) return null;
|
|
|
|
// Spigot start
|
|
|
|
org.bukkit.block.Block block = world.getWorld().getBlockAt(position.getX(), position.getY(), position.getZ());
|
2018-07-27 12:44:53 +08:00
|
|
|
@@ -215,7 +220,7 @@ public abstract class TileEntity implements KeyedObject { // Paper
|
2017-11-24 15:28:57 +08:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
// Spigot end
|
|
|
|
- org.bukkit.block.BlockState state = block.getState();
|
|
|
|
+ org.bukkit.block.BlockState state = block.getState(useSnapshot); // Paper
|
|
|
|
if (state instanceof InventoryHolder) return (InventoryHolder) state;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
|
2018-07-27 12:44:53 +08:00
|
|
|
index d6e4adf147..8cb08c5584 100644
|
2017-11-24 15:28:57 +08:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
|
2018-07-19 12:42:43 +08:00
|
|
|
@@ -263,6 +263,20 @@ public class CraftBlock implements Block {
|
2017-11-24 15:28:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public BlockState getState() {
|
|
|
|
+ // Paper start - allow disabling the use of snapshots
|
|
|
|
+ return getState(true);
|
|
|
|
+ }
|
|
|
|
+ public BlockState getState(boolean useSnapshot) {
|
|
|
|
+ boolean prev = CraftBlockEntityState.DISABLE_SNAPSHOT;
|
|
|
|
+ CraftBlockEntityState.DISABLE_SNAPSHOT = !useSnapshot;
|
|
|
|
+ try {
|
|
|
|
+ return getState0();
|
|
|
|
+ } finally {
|
|
|
|
+ CraftBlockEntityState.DISABLE_SNAPSHOT = prev;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ public BlockState getState0() {
|
|
|
|
+ // Paper end
|
|
|
|
Material material = getType();
|
|
|
|
|
|
|
|
switch (material) {
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockEntityState.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlockEntityState.java
|
2018-07-23 16:39:55 +08:00
|
|
|
index 0558cafe31..d4d9c5fc50 100644
|
2017-11-24 15:28:57 +08:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockEntityState.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlockEntityState.java
|
2018-07-18 08:08:13 +08:00
|
|
|
@@ -23,20 +23,40 @@ public class CraftBlockEntityState<T extends TileEntity> extends CraftBlockState
|
2017-11-24 15:28:57 +08:00
|
|
|
CraftWorld world = (CraftWorld) this.getWorld();
|
|
|
|
this.tileEntity = tileEntityClass.cast(world.getTileEntityAt(this.getX(), this.getY(), this.getZ()));
|
|
|
|
|
|
|
|
+ // Paper start
|
|
|
|
+ this.snapshotDisabled = DISABLE_SNAPSHOT;
|
|
|
|
+ if (DISABLE_SNAPSHOT) {
|
2018-06-30 13:40:52 +08:00
|
|
|
+ this.snapshot = this.tileEntity;
|
|
|
|
+ } else {
|
2018-07-18 08:08:13 +08:00
|
|
|
+ this.snapshot = this.createSnapshot(this.tileEntity, world.getHandle());
|
2017-11-24 15:28:57 +08:00
|
|
|
+ }
|
|
|
|
// copy tile entity data:
|
2018-07-18 08:08:13 +08:00
|
|
|
- this.snapshot = this.createSnapshot(tileEntity, world.getHandle());
|
2018-06-30 13:40:52 +08:00
|
|
|
- this.load(snapshot);
|
|
|
|
+ if(this.snapshot != null) {
|
|
|
|
+ this.load(this.snapshot);
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
2017-11-24 15:28:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
+ public final boolean snapshotDisabled; // Paper
|
|
|
|
+ public static boolean DISABLE_SNAPSHOT = false; // Paper
|
|
|
|
+
|
|
|
|
public CraftBlockEntityState(Material material, T tileEntity) {
|
|
|
|
super(material);
|
|
|
|
|
|
|
|
this.tileEntityClass = (Class<T>) tileEntity.getClass();
|
|
|
|
this.tileEntity = tileEntity;
|
2018-06-30 13:40:52 +08:00
|
|
|
-
|
2017-11-24 15:28:57 +08:00
|
|
|
+ // Paper start
|
|
|
|
+ this.snapshotDisabled = DISABLE_SNAPSHOT;
|
|
|
|
+ if (DISABLE_SNAPSHOT) {
|
2018-06-30 13:40:52 +08:00
|
|
|
+ this.snapshot = this.tileEntity;
|
|
|
|
+ } else {
|
2018-07-18 08:08:13 +08:00
|
|
|
+ this.snapshot = this.createSnapshot(this.tileEntity, null);
|
2018-06-30 13:40:52 +08:00
|
|
|
+ }
|
|
|
|
// copy tile entity data:
|
2018-07-18 08:08:13 +08:00
|
|
|
- this.snapshot = this.createSnapshot(tileEntity, null);
|
2018-06-30 13:40:52 +08:00
|
|
|
- this.load(snapshot);
|
|
|
|
+ if(this.snapshot != null) {
|
|
|
|
+ this.load(this.snapshot);
|
2017-11-24 15:28:57 +08:00
|
|
|
+ }
|
|
|
|
+ // Paper end
|
2018-06-30 13:40:52 +08:00
|
|
|
}
|
2017-11-24 15:28:57 +08:00
|
|
|
|
2018-07-18 08:08:13 +08:00
|
|
|
private T createSnapshot(T tileEntity, World world) {
|
2018-06-30 13:40:52 +08:00
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftSign.java b/src/main/java/org/bukkit/craftbukkit/block/CraftSign.java
|
2018-07-23 16:39:55 +08:00
|
|
|
index 7a8d445299..97b4e6910d 100644
|
2018-06-30 13:40:52 +08:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftSign.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftSign.java
|
|
|
|
@@ -14,10 +14,12 @@ public class CraftSign extends CraftBlockEntityState<TileEntitySign> implements
|
|
|
|
|
|
|
|
public CraftSign(final Block block) {
|
|
|
|
super(block, TileEntitySign.class);
|
|
|
|
+ if (lines == null) { lines = new String[]{"", "", "", ""}; } // Paper
|
|
|
|
}
|
|
|
|
|
|
|
|
public CraftSign(final Material material, final TileEntitySign te) {
|
|
|
|
super(material, te);
|
|
|
|
+ if (lines == null) { lines = new String[]{"", "", "", ""}; } // Paper
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-11-24 15:28:57 +08:00
|
|
|
--
|
2018-06-30 13:40:52 +08:00
|
|
|
2.18.0
|
2017-11-24 15:28:57 +08:00
|
|
|
|