Skip to content

Commit

Permalink
Fix item componets usage, fixes eating some items (#2213)
Browse files Browse the repository at this point in the history
  • Loading branch information
PetteriM1 authored Feb 12, 2025
1 parent d68de40 commit 23dca34
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 10 deletions.
5 changes: 1 addition & 4 deletions src/main/java/cn/nukkit/item/RuntimeItemMapping.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,7 @@ public RuntimeItemMapping(Map<String, MappingEntry> mappings) {

int version = entry.get("version").getAsInt();
boolean componentBased = entry.get("componentBased").getAsBoolean();
CompoundTag components = null;
if (componentBased) {
components = new CompoundTag().putCompound("components", (CompoundTag) itemComponents.get(identifier));
}
CompoundTag components = (CompoundTag) itemComponents.get(identifier);
this.vanillaItems.put(identifier, new ItemComponentPacket.ItemDefinition(identifier, runtimeId, componentBased, version, components));

boolean hasDamage = false;
Expand Down
8 changes: 3 additions & 5 deletions src/main/java/cn/nukkit/item/custom/CustomItemManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,10 @@ public boolean closeRegistry() {

this.closed = true;

boolean hasItems = this.hasCustomItems();
this.getCachedPacket(); // Cache compressed packet

if (hasItems) {
this.getCachedPacket();
}
RuntimeItems.getMapping().getVanillaItemDefinitions().clear(); // Free up memory

return hasItems;
return this.hasCustomItems();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void encode() {
this.putBoolean(definition.isComponentBased);
this.putVarInt(definition.getVersion);

if (definition.isComponentBased) {
if (definition.getNetworkData != null) {
try {
this.put(NBTIO.write(definition.getNetworkData, ByteOrder.LITTLE_ENDIAN, true));
} catch (IOException e) {
Expand Down
Binary file modified src/main/resources/item_components.nbt
Binary file not shown.

0 comments on commit 23dca34

Please sign in to comment.