geforkt von Mirrors/Paper
Fix skipping custom block entity tag (#10812)
Dieser Commit ist enthalten in:
Ursprung
91b9b6b0de
Commit
532b3df1ee
@ -7,6 +7,7 @@ Subject: [PATCH] General ItemMeta fixes
|
||||
private-f net/minecraft/world/item/ItemStack components
|
||||
public net/minecraft/world/food/FoodProperties DEFAULT_EAT_SECONDS
|
||||
public org/bukkit/craftbukkit/block/CraftBlockStates getBlockState(Lorg/bukkit/World;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/block/entity/BlockEntity;)Lorg/bukkit/craftbukkit/block/CraftBlockState;
|
||||
public net/minecraft/world/level/block/entity/BlockEntity saveId(Lnet/minecraft/nbt/CompoundTag;)V
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/world/item/ItemStack.java b/src/main/java/net/minecraft/world/item/ItemStack.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
@ -62,6 +63,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ this.applyTo(this.snapshot);
|
||||
+ final CompoundTag nbt = this.snapshot.saveCustomOnly(this.getRegistryAccess());
|
||||
+ this.snapshot.removeComponentsFromTag(nbt);
|
||||
+ if (!nbt.isEmpty()) {
|
||||
+ // have to include the "id" if it's going to have block entity data
|
||||
+ this.snapshot.saveId(nbt);
|
||||
+ }
|
||||
+ return nbt;
|
||||
+ }
|
||||
+ // Paper end
|
||||
@ -268,8 +273,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ // Paper start - accurately replicate logic for creating ItemStack from BlockEntity
|
||||
+ // taken from BlockEntity#saveToItem and BlockItem#setBlockEntityData
|
||||
+ final CompoundTag nbt = this.blockEntityTag.copyTag();
|
||||
+ nbt.remove("id");
|
||||
+ if (!nbt.isEmpty()) {
|
||||
+ if (nbt.contains("id", CraftMagicNumbers.NBT.TAG_STRING)) {
|
||||
+ tag.put(CraftMetaBlockState.BLOCK_ENTITY_TAG, CustomData.of(nbt));
|
||||
+ } else if (!nbt.isEmpty()) {
|
||||
+ BlockEntity.addEntityType(nbt, java.util.Objects.requireNonNull(CraftBlockStates.getBlockEntityType(this.materialForBlockEntityType())));
|
||||
+ tag.put(CraftMetaBlockState.BLOCK_ENTITY_TAG, CustomData.of(nbt));
|
||||
+ }
|
||||
@ -294,10 +300,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
|
||||
}
|
||||
|
||||
@ -308,11 +314,11 @@ 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
|
||||
}
|
||||
|
||||
@ -424,11 +430,12 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ // have to be used to update the fields on CraftMetaItem
|
||||
+ final CraftBlockEntityState<?> craftBlockState = (CraftBlockEntityState<?>) blockState;
|
||||
+ final CompoundTag data = craftBlockState.getSnapshotCustomNbtOnly();
|
||||
+ BlockEntity.addEntityType(data, craftBlockState.getTileEntity().getType());
|
||||
+ this.blockEntityTag = CustomData.of(data);
|
||||
+ final PatchedDataComponentMap patchedMap = new net.minecraft.core.component.PatchedDataComponentMap(craftBlockState.getHandle().getBlock().asItem().components());
|
||||
+ final net.minecraft.core.component.DataComponentMap map = craftBlockState.collectComponents();
|
||||
+ patchedMap.setAll(map);
|
||||
+ if (!data.isEmpty()) {
|
||||
+ patchedMap.set(BLOCK_ENTITY_TAG.TYPE, CustomData.of(data));
|
||||
+ }
|
||||
+ final DataComponentPatch patch = patchedMap.asPatch();
|
||||
+ this.updateFromPatch(patch, null);
|
||||
+ // we have to reset the fields because this should be like a "new" block entity is being used
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren