|
7 | 7 | import cn.nukkit.block.BlockID;
|
8 | 8 | import cn.nukkit.entity.item.EntityItem;
|
9 | 9 | import cn.nukkit.event.block.ItemFrameDropItemEvent;
|
10 |
| -import cn.nukkit.item.Item; |
11 |
| -import cn.nukkit.item.ItemBlock; |
12 |
| -import cn.nukkit.item.MinecraftItemID; |
| 10 | +import cn.nukkit.item.*; |
13 | 11 | import cn.nukkit.level.Level;
|
14 | 12 | import cn.nukkit.level.format.FullChunk;
|
15 | 13 | import cn.nukkit.nbt.NBTIO;
|
@@ -102,16 +100,28 @@ public CompoundTag getSpawnCompound() {
|
102 | 100 | if (!this.namedTag.contains("Item")) {
|
103 | 101 | this.setItem(new ItemBlock(Block.get(BlockID.AIR)), false);
|
104 | 102 | }
|
105 |
| - CompoundTag item = namedTag.getCompound("Item").copy(); |
106 |
| - item.setName("Item"); |
| 103 | + Item item = getItem(); |
107 | 104 | CompoundTag tag = new CompoundTag()
|
108 | 105 | .putString("id", BlockEntity.ITEM_FRAME)
|
109 | 106 | .putInt("x", (int) this.x)
|
110 | 107 | .putInt("y", (int) this.y)
|
111 | 108 | .putInt("z", (int) this.z);
|
112 | 109 |
|
113 |
| - if (item.getShort("id") != Item.AIR) { |
114 |
| - tag.putCompound("Item", item) |
| 110 | + if (!item.isNull()) { |
| 111 | + CompoundTag itemTag = NBTIO.putItemHelper(item); |
| 112 | + int networkFullId = item.getNetworkFullId(); |
| 113 | + int networkDamage = RuntimeItems.hasData(networkFullId)? RuntimeItems.getData(networkFullId) |
| 114 | + : item.hasMeta() && ! (item instanceof ItemDurable) ? item.getDamage() |
| 115 | + : 0 ; |
| 116 | + String namespacedId = RuntimeItems.getRuntimeMapping().getNamespacedIdByNetworkId( |
| 117 | + RuntimeItems.getNetworkId(networkFullId) |
| 118 | + ); |
| 119 | + if (namespacedId != null) { |
| 120 | + itemTag.remove("id"); |
| 121 | + itemTag.putShort("Damage", networkDamage); |
| 122 | + itemTag.putString("Name", namespacedId); |
| 123 | + } |
| 124 | + tag.putCompound("Item", itemTag) |
115 | 125 | .putByte("ItemRotation", this.getItemRotation());
|
116 | 126 | }
|
117 | 127 | return tag;
|
|
0 commit comments