2021-06-11 14:02:28 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/block/entity/BlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/BlockEntity.java
|
2021-11-23 15:03:50 +01:00
|
|
|
index 67315a86e5db51029d0f355c6dc223e93e4141db..29167adb4eeb83c108445c37e01dc4035b4c4be7 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/net/minecraft/world/level/block/entity/BlockEntity.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/block/entity/BlockEntity.java
|
2021-11-23 15:03:50 +01:00
|
|
|
@@ -45,6 +45,7 @@ public abstract class BlockEntity implements io.papermc.paper.util.KeyedObject {
|
2021-06-11 14:02:28 +02:00
|
|
|
this.type = type;
|
2021-06-12 17:06:20 +02:00
|
|
|
this.worldPosition = pos.immutable();
|
|
|
|
this.blockState = state;
|
2021-10-02 19:21:49 +02:00
|
|
|
+ this.persistentDataContainer = new CraftPersistentDataContainer(DATA_TYPE_REGISTRY); // Paper - always init
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
|
2021-11-23 15:03:50 +01:00
|
|
|
public static BlockPos getPosFromTag(CompoundTag nbt) {
|
|
|
|
@@ -86,7 +87,7 @@ public abstract class BlockEntity implements io.papermc.paper.util.KeyedObject {
|
2021-06-11 14:02:28 +02:00
|
|
|
|
2021-06-12 17:06:20 +02:00
|
|
|
// CraftBukkit start - read container
|
|
|
|
public void load(CompoundTag nbt) {
|
|
|
|
- this.persistentDataContainer = new CraftPersistentDataContainer(BlockEntity.DATA_TYPE_REGISTRY);
|
2021-10-02 19:21:49 +02:00
|
|
|
+ this.persistentDataContainer.clear(); // Paper - clear instead of init
|
2021-06-12 17:06:20 +02:00
|
|
|
|
|
|
|
net.minecraft.nbt.Tag persistentDataTag = nbt.get("PublicBukkitValues");
|
2021-06-11 14:02:28 +02:00
|
|
|
if (persistentDataTag instanceof CompoundTag) {
|
2021-11-23 15:03:50 +01:00
|
|
|
@@ -259,10 +260,15 @@ public abstract class BlockEntity implements io.papermc.paper.util.KeyedObject {
|
2021-06-11 14:02:28 +02:00
|
|
|
|
|
|
|
// CraftBukkit start - add method
|
|
|
|
public InventoryHolder getOwner() {
|
2021-10-02 19:21:49 +02:00
|
|
|
+ // Paper start
|
2021-06-11 14:02:28 +02:00
|
|
|
+ return getOwner(true);
|
|
|
|
+ }
|
|
|
|
+ public InventoryHolder getOwner(boolean useSnapshot) {
|
|
|
|
+ // Paper end
|
2021-10-02 19:21:49 +02:00
|
|
|
if (this.level == null) return null;
|
2021-06-12 17:06:20 +02:00
|
|
|
org.bukkit.block.Block block = this.level.getWorld().getBlockAt(this.worldPosition.getX(), this.worldPosition.getY(), this.worldPosition.getZ());
|
2021-10-15 13:43:19 +02:00
|
|
|
if (block.getType() == org.bukkit.Material.AIR) return null;
|
2021-06-11 14:02:28 +02:00
|
|
|
- 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
|
2021-11-23 15:03:50 +01:00
|
|
|
index 155c0dee5d3485310c60b4f4c3240d1ac07eb873..3ba1c033e00b56abcef005c04fa88cd24dae93ad 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
|
2021-10-02 19:21:49 +02:00
|
|
|
@@ -314,7 +314,20 @@ public class CraftBlock implements Block {
|
2021-06-11 14:02:28 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public BlockState getState() {
|
2021-10-02 19:21:49 +02:00
|
|
|
+ // Paper start
|
|
|
|
+ return this.getState(true);
|
2021-06-11 14:02:28 +02:00
|
|
|
+ }
|
2021-10-02 19:21:49 +02:00
|
|
|
+
|
|
|
|
+ @Override
|
2021-06-11 14:02:28 +02:00
|
|
|
+ public BlockState getState(boolean useSnapshot) {
|
|
|
|
+ boolean prev = CraftBlockEntityState.DISABLE_SNAPSHOT;
|
|
|
|
+ CraftBlockEntityState.DISABLE_SNAPSHOT = !useSnapshot;
|
|
|
|
+ try {
|
2021-10-02 19:21:49 +02:00
|
|
|
return CraftBlockStates.getBlockState(this);
|
2021-06-11 14:02:28 +02:00
|
|
|
+ } finally {
|
|
|
|
+ CraftBlockEntityState.DISABLE_SNAPSHOT = prev;
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
2021-10-02 19:21:49 +02:00
|
|
|
}
|
2021-06-11 14:02:28 +02:00
|
|
|
|
2021-10-02 19:21:49 +02:00
|
|
|
@Override
|
2021-06-11 14:02:28 +02:00
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockEntityState.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlockEntityState.java
|
2021-11-23 15:03:50 +01:00
|
|
|
index aa544f8be7d1db6fc6618d38efc40221afe85618..b98d442a8c749c59aff43189c3904ff4fb4cb353 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockEntityState.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlockEntityState.java
|
2021-10-02 19:21:49 +02:00
|
|
|
@@ -10,15 +10,26 @@ public abstract class CraftBlockEntityState<T extends BlockEntity> extends Craft
|
2021-06-11 14:02:28 +02:00
|
|
|
|
2021-10-02 19:21:49 +02:00
|
|
|
private final T tileEntity;
|
|
|
|
private final T snapshot;
|
2021-06-11 14:02:28 +02:00
|
|
|
+ public final boolean snapshotDisabled; // Paper
|
|
|
|
+ public static boolean DISABLE_SNAPSHOT = false; // Paper
|
|
|
|
|
2021-10-02 19:21:49 +02:00
|
|
|
public CraftBlockEntityState(World world, T tileEntity) {
|
|
|
|
super(world, tileEntity.getBlockPos(), tileEntity.getBlockState());
|
|
|
|
|
2021-06-11 14:02:28 +02:00
|
|
|
this.tileEntity = tileEntity;
|
2021-10-02 19:21:49 +02:00
|
|
|
|
2021-06-11 14:02:28 +02:00
|
|
|
+ // Paper start
|
|
|
|
+ this.snapshotDisabled = DISABLE_SNAPSHOT;
|
|
|
|
+ if (DISABLE_SNAPSHOT) {
|
|
|
|
+ this.snapshot = this.tileEntity;
|
|
|
|
+ } else {
|
2021-10-02 19:21:49 +02:00
|
|
|
+ this.snapshot = this.createSnapshot(tileEntity);
|
2021-06-11 14:02:28 +02:00
|
|
|
+ }
|
|
|
|
// copy tile entity data:
|
|
|
|
- this.snapshot = this.createSnapshot(tileEntity);
|
|
|
|
- this.load(snapshot);
|
2021-10-02 19:21:49 +02:00
|
|
|
+ if (this.snapshot != null) {
|
2021-06-11 14:02:28 +02:00
|
|
|
+ this.load(this.snapshot);
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
}
|
|
|
|
|
2021-08-25 09:59:26 +02:00
|
|
|
public void refreshSnapshot() {
|
2021-06-11 14:02:28 +02:00
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/persistence/CraftPersistentDataContainer.java b/src/main/java/org/bukkit/craftbukkit/persistence/CraftPersistentDataContainer.java
|
2021-06-12 17:06:20 +02:00
|
|
|
index ddd7b63f0452042baa3fca04bb9fbdb42fcecbfd..b638351581fa09c488425a2318b782a5812140ce 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/persistence/CraftPersistentDataContainer.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/persistence/CraftPersistentDataContainer.java
|
|
|
|
@@ -155,4 +155,10 @@ public final class CraftPersistentDataContainer implements PersistentDataContain
|
|
|
|
public Map<String, Object> serialize() {
|
2021-06-12 17:06:20 +02:00
|
|
|
return (Map<String, Object>) CraftNBTTagConfigSerializer.serialize(this.toTagCompound());
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
+
|
|
|
|
+ // Paper start
|
|
|
|
+ public void clear() {
|
|
|
|
+ this.customDataTags.clear();
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
}
|