Skip to content

Commit 43376c6

Browse files
Merge pull request CloudburstMC#1081 from PowerNukkit/v1.4/item_frame/fix
Fix Prismarine Crystals rendering incorrectly in item frames and ink_sac in recipes
2 parents 773e24d + d8cb69c commit 43376c6

File tree

5 files changed

+45
-19
lines changed

5 files changed

+45
-19
lines changed

src/main/java/cn/nukkit/blockentity/BlockEntityItemFrame.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
import cn.nukkit.block.BlockID;
88
import cn.nukkit.entity.item.EntityItem;
99
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.*;
1311
import cn.nukkit.level.Level;
1412
import cn.nukkit.level.format.FullChunk;
1513
import cn.nukkit.nbt.NBTIO;
@@ -102,16 +100,26 @@ public CompoundTag getSpawnCompound() {
102100
if (!this.namedTag.contains("Item")) {
103101
this.setItem(new ItemBlock(Block.get(BlockID.AIR)), false);
104102
}
105-
CompoundTag item = namedTag.getCompound("Item").copy();
106-
item.setName("Item");
103+
Item item = getItem();
107104
CompoundTag tag = new CompoundTag()
108105
.putString("id", BlockEntity.ITEM_FRAME)
109106
.putInt("x", (int) this.x)
110107
.putInt("y", (int) this.y)
111108
.putInt("z", (int) this.z);
112109

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 = (networkFullId & 0x1) == 0x1? 0 : item.getDamage();
114+
String namespacedId = RuntimeItems.getRuntimeMapping().getNamespacedIdByNetworkId(
115+
RuntimeItems.getNetworkId(networkFullId)
116+
);
117+
if (namespacedId != null) {
118+
itemTag.remove("id");
119+
itemTag.putShort("Damage", networkDamage);
120+
itemTag.putString("Name", namespacedId);
121+
}
122+
tag.putCompound("Item", itemTag)
115123
.putByte("ItemRotation", this.getItemRotation());
116124
}
117125
return tag;

src/main/java/cn/nukkit/item/Item.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,8 +1216,9 @@ public final int getNetworkId() throws UnknownNetworkIdException {
12161216
@PowerNukkitOnly
12171217
@Since("1.3.2.0-PN")
12181218
public String getNamespaceId() {
1219-
return RuntimeItems.getRuntimeMapping().getNamespacedIdByNetworkId(
1220-
RuntimeItems.getRuntimeMapping().getNetworkFullId(this)
1219+
RuntimeItemMapping runtimeMapping = RuntimeItems.getRuntimeMapping();
1220+
return runtimeMapping.getNamespacedIdByNetworkId(
1221+
RuntimeItems.getNetworkId(runtimeMapping.getNetworkFullId(this))
12211222
);
12221223
}
12231224

src/main/java/cn/nukkit/item/RuntimeItems.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cn.nukkit.item;
22

33
import cn.nukkit.Server;
4+
import cn.nukkit.api.PowerNukkitOnly;
45
import cn.nukkit.api.Since;
56
import cn.nukkit.utils.BinaryStream;
67
import com.google.gson.Gson;
@@ -23,6 +24,8 @@
2324
import java.util.LinkedHashMap;
2425
import java.util.Map;
2526

27+
import static com.google.common.base.Verify.verify;
28+
2629
@Since("1.3.2.0-PN")
2730
@UtilityClass
2831
@Log4j2
@@ -59,8 +62,14 @@ public class RuntimeItems {
5962
if (entry.oldId != null) {
6063
boolean hasData = entry.oldData != null;
6164
int fullId = getFullId(entry.oldId, hasData ? entry.oldData : 0);
62-
legacyNetworkMap.put(fullId, (entry.id << 1) | (hasData ? 1 : 0));
63-
networkLegacyMap.put(entry.id, fullId | (hasData ? 1 : 0));
65+
if (entry.deprecated != Boolean.TRUE) {
66+
verify(legacyNetworkMap.put(fullId, (entry.id << 1) | (hasData ? 1 : 0)) == 0,
67+
"Conflict while registering an item runtime id!"
68+
);
69+
}
70+
verify(networkLegacyMap.put(entry.id, fullId | (hasData ? 1 : 0)) == 0,
71+
"Conflict while registering an item runtime id!"
72+
);
6473
}
6574
}
6675

@@ -106,5 +115,8 @@ static class Entry {
106115
int id;
107116
Integer oldId;
108117
Integer oldData;
118+
@PowerNukkitOnly
119+
@Since("1.4.0.0-PN")
120+
Boolean deprecated;
109121
}
110122
}

src/main/java/cn/nukkit/utils/BinaryStream.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
package cn.nukkit.utils;
22

3-
import cn.nukkit.block.Block;
43
import cn.nukkit.api.Since;
4+
import cn.nukkit.block.Block;
55
import cn.nukkit.entity.Attribute;
66
import cn.nukkit.entity.data.Skin;
7-
import cn.nukkit.item.*;
7+
import cn.nukkit.item.Item;
8+
import cn.nukkit.item.ItemDurable;
9+
import cn.nukkit.item.ItemID;
10+
import cn.nukkit.item.RuntimeItems;
811
import cn.nukkit.level.GameRule;
912
import cn.nukkit.level.GameRules;
10-
import cn.nukkit.level.GlobalBlockPalette;
1113
import cn.nukkit.math.BlockFace;
1214
import cn.nukkit.math.BlockVector3;
1315
import cn.nukkit.math.Vector3f;
@@ -24,7 +26,6 @@
2426
import io.netty.util.internal.EmptyArrays;
2527

2628
import java.io.IOException;
27-
import java.io.UncheckedIOException;
2829
import java.lang.reflect.Array;
2930
import java.nio.ByteOrder;
3031
import java.nio.charset.StandardCharsets;

src/main/resources/runtime_item_ids.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4654,22 +4654,26 @@
46544654
{
46554655
"name": "minecraft:boat",
46564656
"id": 611,
4657-
"oldId": 333
4657+
"oldId": 333,
4658+
"deprecated": true
46584659
},
46594660
{
46604661
"name": "minecraft:dye",
46614662
"id": 612,
4662-
"oldId": 351
4663+
"oldId": 351,
4664+
"deprecated": true
46634665
},
46644666
{
46654667
"name": "minecraft:banner_pattern",
46664668
"id": 613,
4667-
"oldId": 434
4669+
"oldId": 434,
4670+
"deprecated": true
46684671
},
46694672
{
46704673
"name": "minecraft:spawn_egg",
46714674
"id": 614,
4672-
"oldId": 383
4675+
"oldId": 383,
4676+
"deprecated": true
46734677
},
46744678
{
46754679
"name": "minecraft:end_crystal",

0 commit comments

Comments
 (0)