Updated Upstream (Bukkit/CraftBukkit) (#11501)
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
This commit is contained in:
@@ -171,6 +171,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
|
||||
final Material material;
|
||||
- private CraftBlockEntityState<?> blockEntityTag;
|
||||
- private BlockVector position;
|
||||
+ // Paper start - store data separately
|
||||
+ DataComponentMap components;
|
||||
+ CustomData blockEntityTag;
|
||||
@@ -204,6 +205,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ // Paper start
|
||||
+ this.components = te.components;
|
||||
this.blockEntityTag = te.blockEntityTag;
|
||||
- this.position = te.position;
|
||||
+ // Paper end
|
||||
}
|
||||
|
||||
@@ -211,14 +213,19 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
super(tag, extraHandledDcts); // Paper
|
||||
this.material = material;
|
||||
|
||||
- getOrEmpty(tag, CraftMetaBlockState.BLOCK_ENTITY_TAG).ifPresent((blockTag) -> {
|
||||
- CompoundTag nbt = blockTag.copyTag();
|
||||
+ // Paper start - move to separate method to be re-called
|
||||
+ this.updateBlockState(tag);
|
||||
+ }
|
||||
+
|
||||
|
||||
- this.blockEntityTag = CraftMetaBlockState.getBlockState(material, nbt);
|
||||
- if (nbt.contains("x", CraftMagicNumbers.NBT.TAG_ANY_NUMBER) && nbt.contains("y", CraftMagicNumbers.NBT.TAG_ANY_NUMBER) && nbt.contains("z", CraftMagicNumbers.NBT.TAG_ANY_NUMBER)) {
|
||||
- this.position = new BlockVector(nbt.getInt("x"), nbt.getInt("y"), nbt.getInt("z"));
|
||||
- }
|
||||
+ private void updateBlockState(final DataComponentPatch tag) {
|
||||
+ // Paper end
|
||||
getOrEmpty(tag, CraftMetaBlockState.BLOCK_ENTITY_TAG).ifPresent((nbt) -> {
|
||||
- this.blockEntityTag = CraftMetaBlockState.getBlockState(material, nbt.copyTag());
|
||||
+ getOrEmpty(tag, CraftMetaBlockState.BLOCK_ENTITY_TAG).ifPresent((nbt) -> {
|
||||
+ this.blockEntityTag = nbt; // Paper
|
||||
});
|
||||
|
||||
@@ -271,13 +278,33 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ this.setBlockState(CraftMetaBlockState.getBlockState(this.material, this.internalTag)); // Paper - general item meta fixes - pass through setter
|
||||
this.internalTag = null;
|
||||
}
|
||||
- this.position = SerializableMeta.getObject(BlockVector.class, map, "blockPosition", true);
|
||||
+ // Paper start - general item meta fixes - parse spigot legacy position and merge into block entity tag
|
||||
+ final BlockVector legacyPosition = SerializableMeta.getObject(BlockVector.class, map, "blockPosition", true);
|
||||
+ if (legacyPosition != null) {
|
||||
+ this.blockEntityTag = this.blockEntityTag.update(t -> {
|
||||
+ if (t.isEmpty()) {
|
||||
+ BlockEntity.addEntityType(t, java.util.Objects.requireNonNull(CraftBlockStates.getBlockEntityType(this.materialForBlockEntityType())));
|
||||
+ }
|
||||
+ t.putInt("x", legacyPosition.getBlockX());
|
||||
+ t.putInt("y", legacyPosition.getBlockY());
|
||||
+ t.putInt("z", legacyPosition.getBlockZ());
|
||||
+ });
|
||||
+ }
|
||||
+ // Paper end - general item meta fixes - parse spigot legacy position and merge into block entity tag
|
||||
}
|
||||
@@ -0,0 +0,0 @@ public class CraftMetaBlockState extends CraftMetaItem implements BlockStateMeta
|
||||
|
||||
@Override
|
||||
void applyToItem(CraftMetaItem.Applicator tag) {
|
||||
super.applyToItem(tag);
|
||||
|
||||
- CompoundTag nbt = null;
|
||||
- if (this.blockEntityTag != null) {
|
||||
- tag.put(CraftMetaBlockState.BLOCK_ENTITY_TAG, CustomData.of(this.blockEntityTag.getSnapshotNBTWithoutComponents()));
|
||||
- nbt = this.blockEntityTag.getItemNBT();
|
||||
-
|
||||
- for (TypedDataComponent<?> component : this.blockEntityTag.collectComponents()) {
|
||||
- tag.putIfAbsent(component);
|
||||
- }
|
||||
+ // Paper start - accurately replicate logic for creating ItemStack from BlockEntity
|
||||
+ // taken from BlockEntity#saveToItem and BlockItem#setBlockEntityData
|
||||
+ final CompoundTag nbt = this.blockEntityTag.copyTag();
|
||||
@@ -286,11 +313,24 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ } else if (!nbt.isEmpty()) {
|
||||
+ BlockEntity.addEntityType(nbt, java.util.Objects.requireNonNull(CraftBlockStates.getBlockEntityType(this.materialForBlockEntityType())));
|
||||
+ tag.put(CraftMetaBlockState.BLOCK_ENTITY_TAG, CustomData.of(nbt));
|
||||
+ }
|
||||
}
|
||||
|
||||
- for (TypedDataComponent<?> component : this.blockEntityTag.collectComponents()) {
|
||||
- tag.putIfAbsent(component);
|
||||
- if (this.position != null) {
|
||||
- if (nbt == null) {
|
||||
- nbt = new CompoundTag();
|
||||
- }
|
||||
-
|
||||
- nbt.putInt("x", this.position.getBlockX());
|
||||
- nbt.putInt("y", this.position.getBlockY());
|
||||
- nbt.putInt("z", this.position.getBlockZ());
|
||||
- }
|
||||
-
|
||||
- if (nbt != null && !nbt.isEmpty()) {
|
||||
- CraftBlockEntityState<?> tile = (this.blockEntityTag != null) ? this.blockEntityTag : CraftMetaBlockState.getBlockState(this.material, null);
|
||||
- // See ItemBlock#setBlockEntityData
|
||||
- tile.addEntityType(nbt);
|
||||
-
|
||||
- tag.put(CraftMetaBlockState.BLOCK_ENTITY_TAG, CustomData.of(nbt));
|
||||
+ for (final TypedDataComponent<?> component : this.components) {
|
||||
+ if (CraftMetaItem.DEFAULT_HANDLED_DCTS.contains(component.type())) continue; // if the component type was already handled by CraftMetaItem, don't add it again
|
||||
+ tag.builder.set(component);
|
||||
@@ -308,10 +348,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ // Paper start - new serialization format
|
||||
+ if (tag.contains(CraftMetaBlockState.BLOCK_ENTITY_TAG_CUSTOM_DATA.NBT, CraftMagicNumbers.NBT.TAG_COMPOUND)) {
|
||||
+ this.blockEntityTag = CustomData.of(tag.getCompound(CraftMetaBlockState.BLOCK_ENTITY_TAG_CUSTOM_DATA.NBT));
|
||||
}
|
||||
+ }
|
||||
+ if (tag.contains(CraftMetaBlockState.BLOCK_ENTITY_COMPONENTS.NBT, CraftMagicNumbers.NBT.TAG_COMPOUND)) {
|
||||
+ this.components = DataComponentMap.CODEC.parse(org.bukkit.craftbukkit.CraftRegistry.getMinecraftRegistry().createSerializationContext(net.minecraft.nbt.NbtOps.INSTANCE), tag.getCompound(CraftMetaBlockState.BLOCK_ENTITY_COMPONENTS.NBT)).getOrThrow();
|
||||
+ }
|
||||
}
|
||||
+ // Paper end - new serialization format
|
||||
}
|
||||
|
||||
@@ -322,15 +362,24 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ // Paper start - new serialization format
|
||||
+ if (!this.blockEntityTag.isEmpty()) {
|
||||
+ internalTags.put(CraftMetaBlockState.BLOCK_ENTITY_TAG_CUSTOM_DATA.NBT, this.blockEntityTag.getUnsafe()); // unsafe because it's serialized right away
|
||||
+ }
|
||||
}
|
||||
+ if (!this.components.isEmpty()) {
|
||||
+ final Tag componentsTag = DataComponentMap.CODEC.encodeStart(org.bukkit.craftbukkit.CraftRegistry.getMinecraftRegistry().createSerializationContext(net.minecraft.nbt.NbtOps.INSTANCE), this.components).getOrThrow();
|
||||
+ internalTags.put(CraftMetaBlockState.BLOCK_ENTITY_COMPONENTS.NBT, componentsTag);
|
||||
}
|
||||
+ }
|
||||
+ // Paper end - new serialization format
|
||||
}
|
||||
|
||||
@Override
|
||||
ImmutableMap.Builder<String, Object> serialize(ImmutableMap.Builder<String, Object> builder) {
|
||||
super.serialize(builder);
|
||||
builder.put("blockMaterial", this.material.name());
|
||||
- if (this.position != null) {
|
||||
- builder.put("blockPosition", this.position);
|
||||
- }
|
||||
return builder;
|
||||
}
|
||||
|
||||
@@ -0,0 +0,0 @@ public class CraftMetaBlockState extends CraftMetaItem implements BlockStateMeta
|
||||
int applyHash() {
|
||||
final int original;
|
||||
@@ -338,6 +387,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
- if (this.blockEntityTag != null) {
|
||||
- hash = 61 * hash + this.blockEntityTag.hashCode();
|
||||
- }
|
||||
- if (this.position != null) {
|
||||
- hash = 61 * hash + this.position.hashCode();
|
||||
- }
|
||||
+ // Paper start
|
||||
+ hash = 61 * hash + this.blockEntityTag.hashCode();
|
||||
+ hash = 61 * hash + this.components.hashCode();
|
||||
@@ -349,21 +401,26 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
if (meta instanceof CraftMetaBlockState) {
|
||||
CraftMetaBlockState that = (CraftMetaBlockState) meta;
|
||||
|
||||
- return Objects.equal(this.blockEntityTag, that.blockEntityTag);
|
||||
- return Objects.equal(this.blockEntityTag, that.blockEntityTag) && Objects.equal(this.position, that.position);
|
||||
+ return Objects.equal(this.blockEntityTag, that.blockEntityTag) && Objects.equal(this.components, that.components); // Paper
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean isBlockStateEmpty() {
|
||||
- return !(this.blockEntityTag != null || this.position != null);
|
||||
+ return !(this.blockEntityTag != null);
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean notUncommon(CraftMetaItem meta) {
|
||||
- return super.notUncommon(meta) && (meta instanceof CraftMetaBlockState || this.blockEntityTag == null);
|
||||
- return super.notUncommon(meta) && (meta instanceof CraftMetaBlockState || this.isBlockStateEmpty());
|
||||
+ return super.notUncommon(meta) && (meta instanceof CraftMetaBlockState || (this.blockEntityTag.isEmpty() && this.components.isEmpty())); // Paper
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean isEmpty() {
|
||||
- return super.isEmpty() && this.blockEntityTag == null;
|
||||
- return super.isEmpty() && this.isBlockStateEmpty();
|
||||
+ return super.isEmpty() && this.blockEntityTag.isEmpty() && this.components.isEmpty(); // Paper
|
||||
}
|
||||
|
||||
@@ -373,6 +430,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
- if (this.blockEntityTag != null) {
|
||||
- meta.blockEntityTag = this.blockEntityTag.copy();
|
||||
- }
|
||||
- if (this.position != null) {
|
||||
- meta.position = this.position.clone();
|
||||
- }
|
||||
+ // Paper start - no need for "clone" because they are essentially immutables
|
||||
+ meta.blockEntityTag = this.blockEntityTag;
|
||||
+ meta.components = this.components;
|
||||
@@ -1053,6 +1113,15 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
itemTag.put(CraftMetaItem.DAMAGE, this.damage);
|
||||
}
|
||||
|
||||
@@ -0,0 +0,0 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
||||
}
|
||||
|
||||
void applyEnchantments(Map<Enchantment, Integer> enchantments, CraftMetaItem.Applicator tag, ItemMetaKeyType<ItemEnchantments> key, ItemFlag itemFlag) {
|
||||
- if (enchantments == null && !this.hasItemFlag(itemFlag)) {
|
||||
+ if (enchantments == null /*&& !this.hasItemFlag(itemFlag)*/) { // Paper - general item meta fixes - only emit enchantment component if enchantments are defined
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -0,0 +0,0 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
||||
}
|
||||
|
||||
@@ -1070,7 +1139,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
|
||||
@Overridden
|
||||
boolean isEmpty() {
|
||||
- return !(this.hasDisplayName() || this.hasItemName() || this.hasLocalizedName() || this.hasEnchants() || (this.lore != null) || this.hasCustomModelData() || this.hasBlockData() || this.hasRepairCost() || !this.unhandledTags.build().isEmpty() || !this.removedTags.isEmpty() || !this.persistentDataContainer.isEmpty() || this.hideFlag != 0 || this.isHideTooltip() || this.isUnbreakable() || this.hasEnchantmentGlintOverride() || this.isFireResistant() || this.hasMaxStackSize() || this.hasRarity() || this.hasFood() || this.hasTool() || this.hasDamage() || this.hasMaxDamage() || this.hasAttributeModifiers() || this.customTag != null || this.canPlaceOnPredicates != null || this.canBreakPredicates != null); // Paper
|
||||
- return !(this.hasDisplayName() || this.hasItemName() || this.hasLocalizedName() || this.hasEnchants() || (this.lore != null) || this.hasCustomModelData() || this.hasBlockData() || this.hasRepairCost() || !this.unhandledTags.build().isEmpty() || !this.removedTags.isEmpty() || !this.persistentDataContainer.isEmpty() || this.hideFlag != 0 || this.isHideTooltip() || this.isUnbreakable() || this.hasEnchantmentGlintOverride() || this.isFireResistant() || this.hasMaxStackSize() || this.hasRarity() || this.hasFood() || this.hasTool() || this.hasJukeboxPlayable() || this.hasDamage() || this.hasMaxDamage() || this.hasAttributeModifiers() || this.customTag != null || this.canPlaceOnPredicates != null || this.canBreakPredicates != null); // Paper
|
||||
+ return !(this.hasDisplayName() || this.hasItemName() || this.hasLocalizedName() || this.hasEnchants() || (this.lore != null) || this.hasCustomModelData() || this.hasBlockData() || this.hasRepairCost() || !this.unhandledTags.build().isEmpty() || !this.removedTags.isEmpty() || !this.persistentDataContainer.isEmpty() || this.hideFlag != 0 || this.isHideTooltip() || this.isUnbreakable() || this.hasEnchantmentGlintOverride() || this.isFireResistant() || this.hasMaxStackSize() || this.hasRarity() || this.hasFood() || this.hasTool() || this.hasJukeboxPlayable() || this.hasDamageValue() || this.hasMaxDamage() || this.hasAttributeModifiers() || this.customTag != null || this.canPlaceOnPredicates != null || this.canBreakPredicates != null); // Paper
|
||||
}
|
||||
|
||||
@@ -1551,7 +1620,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
// Invalid colour
|
||||
}
|
||||
@@ -0,0 +0,0 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta {
|
||||
super.applyToItem(tag);
|
||||
}
|
||||
|
||||
Optional<Holder<Potion>> defaultPotion = (this.hasBasePotionType()) ? Optional.of(CraftPotionType.bukkitToMinecraftHolder(this.type)) : Optional.empty();
|
||||
- Optional<Integer> potionColor = (this.hasColor()) ? Optional.of(this.color.asRGB()) : Optional.empty();
|
||||
@@ -2035,7 +2104,7 @@ diff --git a/src/test/java/org/bukkit/craftbukkit/inventory/DeprecatedItemMetaCu
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/test/java/org/bukkit/craftbukkit/inventory/DeprecatedItemMetaCustomValueTest.java
|
||||
+++ b/src/test/java/org/bukkit/craftbukkit/inventory/DeprecatedItemMetaCustomValueTest.java
|
||||
@@ -0,0 +0,0 @@ public class DeprecatedItemMetaCustomValueTest extends AbstractTestingBase {
|
||||
@@ -0,0 +0,0 @@ public class DeprecatedItemMetaCustomValueTest {
|
||||
public void testNBTTagStoring() {
|
||||
CraftMetaItem itemMeta = this.createComplexItemMeta();
|
||||
|
||||
@@ -2048,7 +2117,7 @@ diff --git a/src/test/java/org/bukkit/craftbukkit/inventory/PersistentDataContai
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/test/java/org/bukkit/craftbukkit/inventory/PersistentDataContainerTest.java
|
||||
+++ b/src/test/java/org/bukkit/craftbukkit/inventory/PersistentDataContainerTest.java
|
||||
@@ -0,0 +0,0 @@ public class PersistentDataContainerTest extends AbstractTestingBase {
|
||||
@@ -0,0 +0,0 @@ public class PersistentDataContainerTest {
|
||||
public void testNBTTagStoring() {
|
||||
CraftMetaItem itemMeta = this.createComplexItemMeta();
|
||||
|
||||
@@ -2057,7 +2126,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
itemMeta.applyToItem(compound);
|
||||
|
||||
assertEquals(itemMeta, new CraftMetaItem(compound.build(), null)); // Paper
|
||||
@@ -0,0 +0,0 @@ public class PersistentDataContainerTest extends AbstractTestingBase {
|
||||
@@ -0,0 +0,0 @@ public class PersistentDataContainerTest {
|
||||
assertEquals(List.of(), container.get(PersistentDataContainerTest.requestKey("list"), PersistentDataType.LIST.strings()));
|
||||
|
||||
// Write and read the entire container to NBT
|
||||
|
||||
Reference in New Issue
Block a user