Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-11-15 04:20:04 +01:00
b31089a929
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: d264e972 #591: Add option for a consumer before spawning an item 1c537fce #590: Add spawn and transform reasons for piglin zombification. CraftBukkit Changes: ee5006d1 #810: Add option for a consumer before spawning an item f6a39d3c #809: Add spawn and transform reasons for piglin zombification. 0c24068a Organise imports Spigot Changes: bff52619 Organise imports
148 Zeilen
6.5 KiB
Diff
148 Zeilen
6.5 KiB
Diff
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/server/TileEntity.java b/src/main/java/net/minecraft/server/TileEntity.java
|
|
index 524f84ad2c50f8b837eefd0465901b1e22359410..c6ae3d3f9d7957d4bbe0b4e2613558e5cd9dd9ec 100644
|
|
--- a/src/main/java/net/minecraft/server/TileEntity.java
|
|
+++ b/src/main/java/net/minecraft/server/TileEntity.java
|
|
@@ -36,6 +36,7 @@ public abstract class TileEntity implements KeyedObject { // Paper
|
|
public TileEntity(TileEntityTypes<?> tileentitytypes) {
|
|
this.position = BlockPosition.ZERO;
|
|
this.tileType = tileentitytypes;
|
|
+ persistentDataContainer = new CraftPersistentDataContainer(DATA_TYPE_REGISTRY); // Paper - always init
|
|
}
|
|
|
|
// Paper start
|
|
@@ -84,7 +85,7 @@ public abstract class TileEntity implements KeyedObject { // Paper
|
|
public void load(IBlockData iblockdata, NBTTagCompound nbttagcompound) {
|
|
this.position = new BlockPosition(nbttagcompound.getInt("x"), nbttagcompound.getInt("y"), nbttagcompound.getInt("z"));
|
|
// CraftBukkit start - read container
|
|
- this.persistentDataContainer = new CraftPersistentDataContainer(DATA_TYPE_REGISTRY);
|
|
+ this.persistentDataContainer.clear(); // Paper - clear instead of reinit
|
|
|
|
NBTBase persistentDataTag = nbttagcompound.get("PublicBukkitValues");
|
|
if (persistentDataTag instanceof NBTTagCompound) {
|
|
@@ -234,7 +235,12 @@ public abstract class TileEntity implements KeyedObject { // Paper
|
|
}
|
|
|
|
// 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());
|
|
@@ -243,7 +249,7 @@ public abstract class TileEntity implements KeyedObject { // Paper
|
|
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
|
|
index 5de8463c94612edd11e02ac5d9757382c9598e7d..661bb54c27966c8050644b293d99dfe86e3c04ce 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
|
|
@@ -316,6 +316,20 @@ public class CraftBlock implements Block {
|
|
|
|
@Override
|
|
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
|
|
index 8a7e9302b4b6be086144add8df610b76b58e00d6..cca1c2ca5c1fe91fda30ace6f06a343b7850842e 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockEntityState.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlockEntityState.java
|
|
@@ -26,20 +26,40 @@ public class CraftBlockEntityState<T extends TileEntity> extends CraftBlockState
|
|
this.tileEntity = tileEntityClass.cast(world.getHandle().getTileEntity(this.getPosition()));
|
|
Preconditions.checkState(this.tileEntity != null, "Tile is null, asynchronous access? %s", block);
|
|
|
|
+ // Paper start
|
|
+ this.snapshotDisabled = DISABLE_SNAPSHOT;
|
|
+ if (DISABLE_SNAPSHOT) {
|
|
+ this.snapshot = this.tileEntity;
|
|
+ } else {
|
|
+ this.snapshot = this.createSnapshot(this.tileEntity);
|
|
+ }
|
|
// copy tile entity data:
|
|
- this.snapshot = this.createSnapshot(tileEntity);
|
|
- this.load(snapshot);
|
|
+ if(this.snapshot != null) {
|
|
+ this.load(this.snapshot);
|
|
+ }
|
|
+ // Paper end
|
|
}
|
|
|
|
+ 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;
|
|
-
|
|
+ // Paper start
|
|
+ this.snapshotDisabled = DISABLE_SNAPSHOT;
|
|
+ if (DISABLE_SNAPSHOT) {
|
|
+ this.snapshot = this.tileEntity;
|
|
+ } else {
|
|
+ this.snapshot = this.createSnapshot(this.tileEntity);
|
|
+ }
|
|
// copy tile entity data:
|
|
- this.snapshot = this.createSnapshot(tileEntity);
|
|
- this.load(snapshot);
|
|
+ if(this.snapshot != null) {
|
|
+ this.load(this.snapshot);
|
|
+ }
|
|
+ // Paper end
|
|
}
|
|
|
|
private T createSnapshot(T tileEntity) {
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/persistence/CraftPersistentDataContainer.java b/src/main/java/org/bukkit/craftbukkit/persistence/CraftPersistentDataContainer.java
|
|
index 58e2db5da178af6a8c30f563353fefe720ff9781..b704f550de290e0bc1235bf7e68c7eb347162c69 100644
|
|
--- 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() {
|
|
return (Map<String, Object>) CraftNBTTagConfigSerializer.serialize(toTagCompound());
|
|
}
|
|
+
|
|
+ // Paper start
|
|
+ public void clear() {
|
|
+ this.customDataTags.clear();
|
|
+ }
|
|
+ // Paper end
|
|
}
|