Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-11-15 04:20:04 +01:00
3b9db2b194
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: bb4e97c6 Add support for Java 23 bc6874dd Bump asm to 9.7.1 50e8a00b PR-1064: Add specific getTopInventory methods for InventoryView derivatives 758b0a0f SPIGOT-7911: Fix Location#isWorldLoaded() for re-loaded worlds 133a64a7 Improve Registry#getOrThrow messages be0f5957 PR-1058: Add tests for Minecraft registry <-> Bukkit fields d1b31df2 PR-1062: Clarify BeaconView documentation 3fab4384 PR-1060: Cache Material to BlockType and ItemType conversion 967a7301 SPIGOT-7906: Increase YAML nesting limit to 100 6ecf033d SPIGOT-7899: Smithing recipes don't require inputs CraftBukkit Changes: 0a7bd6c81 PR-1493: Improve reroute performance and add some tests 54941524c Add support for Java 23 f4d957fff SPIGOT-7915: Fix World#getKeepSpawnInMemory() using Spawn Radius rather than Spawn Chunk Radius ded183674 Fix HIDE_ENCHANTS flag in items without enchantments 308785a0a Bump asm to 9.7.1 and re-add ClassReader to ClassWriter 72ce823cd PR-1487: Add specific getTopInventory methods for InventoryView derivatives 11a5e840c SPIGOT-7907, PR-1484: Improve merchant recipe item matching behavior to more closely align with older versions 45b66f7e4 SPIGOT-7909: Always set HIDE_ENCHANTS flag to item if flag is set 963459791 Increase outdated build delay fc5b2d75f SPIGOT-7910: Fix launching breeze wind charge from API and improve dispenser launch API c7d6428f2 SPIGOT-7856, PR-1483: End platform not dropping items after replacing blocks 2a5572b52 SPIGOT-7780, PR-1482: Cannot edit chunks during unload event 527041ab5 SPIGOT-7902, PR-1477: Fix CraftMetaPotion#hasCustomEffects() does not check if customEffects (List) is empty 5529a1769 Implement base methods for tags 30fbdbaaf Improve Registry#getOrThrow messages 6b71a7322 PR-1475: Add tests for Minecraft registry <-> Bukkit fields 5f24c255c SPIGOT-7908: Mark junit-platform-suite-engine as test scope e4c92ef65 PR-1473: Change tests to use suites, to run tests in different environments and feature flags d25e1e722 PR-1481: Fix BeaconView#set[X]Effect(null) d69a05362 PR-1480: Fix PerMaterialTest#isEdible test running for legacy materials bb3284a89 PR-1479: Use custom #isBlock method in legacy init instead of the one in Material, since it relies on legacy being init 98c57cbbe SPIGOT-7904: Fix NPE for PlayerItemBreakEvent f35bae9ec Fix missing hasJukeboxPlayable 8a6f8b6d8 SPIGOT-7881: CTRL+Pick Block saves position data into item 7913b3be7 SPIGOT-7899: Smithing recipes don't require inputs
166 Zeilen
7.6 KiB
Diff
166 Zeilen
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 d6ad310d3b472c40c128cfb459171d9f48e50915..48bee70ba4188a4a55beb6584224b0f23784dd88 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
|
|
@@ -59,6 +59,7 @@ public abstract class BlockEntity {
|
|
this.worldPosition = pos.immutable();
|
|
this.validateBlockState(state);
|
|
this.blockState = state;
|
|
+ this.persistentDataContainer = new CraftPersistentDataContainer(DATA_TYPE_REGISTRY); // Paper - always init
|
|
}
|
|
|
|
private void validateBlockState(BlockState state) {
|
|
@@ -92,7 +93,7 @@ public abstract class BlockEntity {
|
|
|
|
// CraftBukkit start - read container
|
|
protected void loadAdditional(CompoundTag nbt, HolderLookup.Provider registryLookup) {
|
|
- 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) {
|
|
@@ -379,8 +380,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 483a89ba477506ae108f680e586b37c142119696..80418a05d53516d2c539383aa9994099c634b905 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockEntityState.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlockEntityState.java
|
|
@@ -24,15 +24,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, Location location) {
|
|
@@ -184,4 +195,11 @@ public class CraftBlockEntityState<T extends BlockEntity> extends CraftBlockStat
|
|
public CraftBlockEntityState<T> copy(Location location) {
|
|
return new CraftBlockEntityState<>(this, location);
|
|
}
|
|
+
|
|
+ // 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 0173a8eac2153d889536e48970f967040490e4b7..83ac5fc6cbbd249b5865ab203b150f53f01c9f05 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockStates.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlockStates.java
|
|
@@ -387,15 +387,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
|
|
}
|
|
|
|
@Deprecated
|
|
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
|
|
}
|