2019-12-16 02:58:10 +00:00
|
|
|
From ae21a2ecfd6ab6db948e04a340c54fde01e7162d Mon Sep 17 00:00:00 2001
|
2017-11-24 07:28:57 +00: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 05:40:52 +00: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 07:28:57 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/TileEntity.java b/src/main/java/net/minecraft/server/TileEntity.java
|
2019-12-16 02:58:10 +00:00
|
|
|
index 630b279158..958279249f 100644
|
2017-11-24 07:28:57 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/TileEntity.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/TileEntity.java
|
2019-12-11 23:43:22 +00:00
|
|
|
@@ -231,7 +231,12 @@ public abstract class TileEntity implements KeyedObject { // Paper
|
2017-11-24 07:28:57 +00: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());
|
2019-12-11 23:43:22 +00:00
|
|
|
@@ -240,7 +245,7 @@ public abstract class TileEntity implements KeyedObject { // Paper
|
2017-11-24 07:28:57 +00: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
|
2019-12-16 02:58:10 +00:00
|
|
|
index c0f557568d..fa840c3d38 100644
|
2017-11-24 07:28:57 +00:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
|
2019-12-10 23:23:50 +00:00
|
|
|
@@ -309,6 +309,20 @@ public class CraftBlock implements Block {
|
2017-11-24 07:28:57 +00:00
|
|
|
|
2019-05-06 02:58:04 +00:00
|
|
|
@Override
|
2017-11-24 07:28:57 +00: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
|
2019-12-16 02:58:10 +00:00
|
|
|
index 17d80b5c6e..f6401e2cde 100644
|
2017-11-24 07:28:57 +00:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockEntityState.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlockEntityState.java
|
2019-07-05 02:13:38 +00:00
|
|
|
@@ -26,20 +26,40 @@ public class CraftBlockEntityState<T extends TileEntity> extends CraftBlockState
|
2018-12-23 17:04:13 +00:00
|
|
|
this.tileEntity = tileEntityClass.cast(world.getHandle().getTileEntity(this.getPosition()));
|
2019-05-06 02:58:04 +00:00
|
|
|
Preconditions.checkState(this.tileEntity != null, "Tile is null, asynchronous access? " + block);
|
2017-11-24 07:28:57 +00:00
|
|
|
|
|
|
|
+ // Paper start
|
|
|
|
+ this.snapshotDisabled = DISABLE_SNAPSHOT;
|
|
|
|
+ if (DISABLE_SNAPSHOT) {
|
2018-06-30 05:40:52 +00:00
|
|
|
+ this.snapshot = this.tileEntity;
|
|
|
|
+ } else {
|
2019-07-05 02:13:38 +00:00
|
|
|
+ this.snapshot = this.createSnapshot(this.tileEntity);
|
2017-11-24 07:28:57 +00:00
|
|
|
+ }
|
|
|
|
// copy tile entity data:
|
2019-07-05 02:13:38 +00:00
|
|
|
- this.snapshot = this.createSnapshot(tileEntity);
|
2018-06-30 05:40:52 +00:00
|
|
|
- this.load(snapshot);
|
|
|
|
+ if(this.snapshot != null) {
|
|
|
|
+ this.load(this.snapshot);
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
2017-11-24 07:28:57 +00: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 05:40:52 +00:00
|
|
|
-
|
2017-11-24 07:28:57 +00:00
|
|
|
+ // Paper start
|
|
|
|
+ this.snapshotDisabled = DISABLE_SNAPSHOT;
|
|
|
|
+ if (DISABLE_SNAPSHOT) {
|
2018-06-30 05:40:52 +00:00
|
|
|
+ this.snapshot = this.tileEntity;
|
|
|
|
+ } else {
|
2019-07-05 02:13:38 +00:00
|
|
|
+ this.snapshot = this.createSnapshot(this.tileEntity);
|
2018-06-30 05:40:52 +00:00
|
|
|
+ }
|
|
|
|
// copy tile entity data:
|
2019-07-05 02:13:38 +00:00
|
|
|
- this.snapshot = this.createSnapshot(tileEntity);
|
2018-06-30 05:40:52 +00:00
|
|
|
- this.load(snapshot);
|
|
|
|
+ if(this.snapshot != null) {
|
|
|
|
+ this.load(this.snapshot);
|
2017-11-24 07:28:57 +00:00
|
|
|
+ }
|
|
|
|
+ // Paper end
|
2018-06-30 05:40:52 +00:00
|
|
|
}
|
2017-11-24 07:28:57 +00:00
|
|
|
|
2019-07-05 02:13:38 +00:00
|
|
|
private T createSnapshot(T tileEntity) {
|
2018-06-30 05:40:52 +00:00
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftSign.java b/src/main/java/org/bukkit/craftbukkit/block/CraftSign.java
|
2019-12-16 02:58:10 +00:00
|
|
|
index 15022ada0c..af15656cc4 100644
|
2018-06-30 05:40:52 +00:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftSign.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftSign.java
|
2019-05-06 02:58:04 +00:00
|
|
|
@@ -17,10 +17,12 @@ public class CraftSign extends CraftBlockEntityState<TileEntitySign> implements
|
2018-06-30 05:40:52 +00:00
|
|
|
|
|
|
|
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 07:28:57 +00:00
|
|
|
--
|
2019-12-16 02:58:10 +00:00
|
|
|
2.24.1
|
2017-11-24 07:28:57 +00:00
|
|
|
|