mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-30 04:02:50 +01:00
31699ae9a8
* Updated Upstream (Bukkit/CraftBukkit) 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: a6a9d2a4 Remove some old ApiStatus.Experimental annotations be72314c SPIGOT-7300, PR-829: Add new DamageSource API providing enhanced information about entity damage b252cf05 SPIGOT-7576, PR-970: Add methods in MushroomCow to change stew effects b1c689bd PR-902: Add Server#isLoggingIPs to get log-ips configuration 08f86d1c PR-971: Add Player methods for client-side potion effects 2e3024a9 PR-963: Add API for in-world structures a23292a7 SPIGOT-7530, PR-948: Improve Resource Pack API with new 1.20.3 functionality 1851857b SPIGOT-3071, PR-969: Add entity spawn method with spawn reason cde4c52a SPIGOT-5553, PR-964: Add EntityKnockbackEvent CraftBukkit Changes: 38fd4bd50 Fix accidentally renamed internal damage method 80f0ce4be SPIGOT-7300, PR-1180: Add new DamageSource API providing enhanced information about entity damage 7e43f3b16 SPIGOT-7581: Fix typo in BlockMushroom ea14b7d90 SPIGOT-7576, PR-1347: Add methods in MushroomCow to change stew effects 4c687f243 PR-1259: Add Server#isLoggingIPs to get log-ips configuration 22a541a29 Improve support for per-world game rules cb7dccce2 PR-1348: Add Player methods for client-side potion effects b8d6109f0 PR-1335: Add API for in-world structures 4398a1b5b SPIGOT-7577: Make CraftWindCharge#explode discard the entity e74107678 Fix Crafter maximum stack size 0bb0f4f6a SPIGOT-7530, PR-1314: Improve Resource Pack API with new 1.20.3 functionality 4949f556d SPIGOT-3071, PR-1345: Add entity spawn method with spawn reason 20ac73ca2 PR-1353: Fix Structure#place not working as documented with 0 palette 3c1b77871 SPIGOT-6911, PR-1349: Change max book length in CraftMetaBook 333701839 SPIGOT-7572: Bee nests generated without bees f48f4174c SPIGOT-5553, PR-1336: Add EntityKnockbackEvent
165 lines
7.6 KiB
Diff
165 lines
7.6 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/world/level/block/entity/BlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/BlockEntity.java
|
|
index 66757716b401d4f5b690c895effbbaa46f169238..53443b472d21633f49c102b330c8406c92f09d8d 100644
|
|
--- a/src/main/java/net/minecraft/world/level/block/entity/BlockEntity.java
|
|
+++ b/src/main/java/net/minecraft/world/level/block/entity/BlockEntity.java
|
|
@@ -44,6 +44,7 @@ public abstract class BlockEntity {
|
|
this.type = type;
|
|
this.worldPosition = pos.immutable();
|
|
this.blockState = state;
|
|
+ this.persistentDataContainer = new CraftPersistentDataContainer(DATA_TYPE_REGISTRY); // Paper - always init
|
|
}
|
|
|
|
public static BlockPos getPosFromTag(CompoundTag nbt) {
|
|
@@ -65,7 +66,7 @@ public abstract class BlockEntity {
|
|
|
|
// CraftBukkit start - read container
|
|
public void load(CompoundTag nbt) {
|
|
- this.persistentDataContainer = new CraftPersistentDataContainer(BlockEntity.DATA_TYPE_REGISTRY);
|
|
+ this.persistentDataContainer.clear(); // Paper - clear instead of init
|
|
|
|
net.minecraft.nbt.Tag persistentDataTag = nbt.get("PublicBukkitValues");
|
|
if (persistentDataTag instanceof CompoundTag) {
|
|
@@ -239,8 +240,15 @@ public abstract class BlockEntity {
|
|
|
|
// CraftBukkit start - add method
|
|
public InventoryHolder getOwner() {
|
|
+ // Paper start
|
|
+ return getOwner(true);
|
|
+ }
|
|
+ public InventoryHolder getOwner(boolean useSnapshot) {
|
|
+ // Paper end
|
|
if (this.level == null) return null;
|
|
- org.bukkit.block.BlockState state = this.level.getWorld().getBlockAt(this.worldPosition.getX(), this.worldPosition.getY(), this.worldPosition.getZ()).getState();
|
|
+ org.bukkit.block.Block block = this.level.getWorld().getBlockAt(this.worldPosition.getX(), this.worldPosition.getY(), this.worldPosition.getZ());
|
|
+ if (block.getType() == org.bukkit.Material.AIR) return null;
|
|
+ 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 a1c1a101aa424e74309f6f4c0a53a6a8db5df441..013298c424025cd88f15d61e50d196f70fa4c58b 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
|
|
@@ -328,6 +328,13 @@ public class CraftBlock implements Block {
|
|
return CraftBlockStates.getBlockState(this);
|
|
}
|
|
|
|
+ // Paper start
|
|
+ @Override
|
|
+ public BlockState getState(boolean useSnapshot) {
|
|
+ return CraftBlockStates.getBlockState(this, useSnapshot);
|
|
+ }
|
|
+ // Paper end
|
|
+
|
|
@Override
|
|
public Biome getBiome() {
|
|
return this.getWorld().getBiome(this.getX(), this.getY(), this.getZ());
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockEntityState.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlockEntityState.java
|
|
index 22af1b41eec06d660dbe47c463014bcdd96fc5b6..f046f507a095e0cb8f839b9b4b06add3a671486b 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockEntityState.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlockEntityState.java
|
|
@@ -17,15 +17,26 @@ public class CraftBlockEntityState<T extends BlockEntity> extends CraftBlockStat
|
|
|
|
private final T tileEntity;
|
|
private final T snapshot;
|
|
+ public boolean snapshotDisabled; // Paper
|
|
+ public static boolean DISABLE_SNAPSHOT = false; // Paper
|
|
|
|
public CraftBlockEntityState(World world, T tileEntity) {
|
|
super(world, tileEntity.getBlockPos(), tileEntity.getBlockState());
|
|
|
|
this.tileEntity = tileEntity;
|
|
|
|
+ // Paper start
|
|
+ this.snapshotDisabled = DISABLE_SNAPSHOT;
|
|
+ if (DISABLE_SNAPSHOT) {
|
|
+ this.snapshot = this.tileEntity;
|
|
+ } else {
|
|
+ this.snapshot = this.createSnapshot(tileEntity);
|
|
+ }
|
|
// copy tile entity data:
|
|
- this.snapshot = this.createSnapshot(tileEntity);
|
|
- this.load(this.snapshot);
|
|
+ if (this.snapshot != null) {
|
|
+ this.load(this.snapshot);
|
|
+ }
|
|
+ // Paper end
|
|
}
|
|
|
|
protected CraftBlockEntityState(CraftBlockEntityState<T> state) {
|
|
@@ -136,4 +147,11 @@ public class CraftBlockEntityState<T extends BlockEntity> extends CraftBlockStat
|
|
public CraftBlockEntityState<T> copy() {
|
|
return new CraftBlockEntityState<>(this);
|
|
}
|
|
+
|
|
+ // Paper start
|
|
+ @Override
|
|
+ public boolean isSnapshot() {
|
|
+ return !this.snapshotDisabled;
|
|
+ }
|
|
+ // Paper end
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockStates.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlockStates.java
|
|
index 8b454bdb8a9a202ece4912320f3ac373e4fff65c..76a3f4ad26718f95f4cf64206efe16e598fa2285 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockStates.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlockStates.java
|
|
@@ -382,15 +382,30 @@ public final class CraftBlockStates {
|
|
}
|
|
|
|
public static BlockState getBlockState(Block block) {
|
|
+ // Paper start
|
|
+ return CraftBlockStates.getBlockState(block, true);
|
|
+ }
|
|
+ public static BlockState getBlockState(Block block, boolean useSnapshot) {
|
|
+ // Paper end
|
|
Preconditions.checkNotNull(block, "block is null");
|
|
CraftBlock craftBlock = (CraftBlock) block;
|
|
CraftWorld world = (CraftWorld) block.getWorld();
|
|
BlockPos blockPosition = craftBlock.getPosition();
|
|
net.minecraft.world.level.block.state.BlockState blockData = craftBlock.getNMS();
|
|
BlockEntity tileEntity = craftBlock.getHandle().getBlockEntity(blockPosition);
|
|
+ // Paper start - block state snapshots
|
|
+ boolean prev = CraftBlockEntityState.DISABLE_SNAPSHOT;
|
|
+ CraftBlockEntityState.DISABLE_SNAPSHOT = !useSnapshot;
|
|
+ try {
|
|
+ // Paper end
|
|
CraftBlockState blockState = CraftBlockStates.getBlockState(world, blockPosition, blockData, tileEntity);
|
|
blockState.setWorldHandle(craftBlock.getHandle()); // Inject the block's generator access
|
|
return blockState;
|
|
+ // Paper start
|
|
+ } finally {
|
|
+ CraftBlockEntityState.DISABLE_SNAPSHOT = prev;
|
|
+ }
|
|
+ // Paper end
|
|
}
|
|
|
|
public static BlockState getBlockState(Material material, @Nullable CompoundTag blockEntityTag) {
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/persistence/CraftPersistentDataContainer.java b/src/main/java/org/bukkit/craftbukkit/persistence/CraftPersistentDataContainer.java
|
|
index dbb9a5b2f8d3bc0b13e0f56f6e8a0d9a7b761327..3001bb0e3d4af9b16645a0136093db594b89ab01 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/persistence/CraftPersistentDataContainer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/persistence/CraftPersistentDataContainer.java
|
|
@@ -177,4 +177,10 @@ public class CraftPersistentDataContainer implements PersistentDataContainer {
|
|
public String serialize() {
|
|
return CraftNBTTagConfigSerializer.serialize(this.toTagCompound());
|
|
}
|
|
+
|
|
+ // Paper start
|
|
+ public void clear() {
|
|
+ this.customDataTags.clear();
|
|
+ }
|
|
+ // Paper end
|
|
}
|