mapping: fixed custom item conversion (#4)

This commit is contained in:
Doge
2025-02-06 07:24:49 +03:00
committed by GitHub
parent 199c1628b1
commit 2672b73e4a
2 changed files with 12 additions and 2 deletions

View File

@@ -498,7 +498,7 @@ func (t *DefaultItemTranslator) DowngradeItemPackets(pks []packet.Packet, _ *min
panic(itemType) panic(itemType)
} }
} else { } else {
t.latest.RegisterEntry(entry.Name) t.latest.RegisterEntryRID(entry.Name, int32(entry.RuntimeID))
entry.RuntimeID = int16(t.mapping.RegisterEntry(entry.Name)) entry.RuntimeID = int16(t.mapping.RegisterEntry(entry.Name))
} }
pk.Items[i] = entry pk.Items[i] = entry
@@ -717,7 +717,7 @@ func (t *DefaultItemTranslator) UpgradeItemPackets(pks []packet.Packet, _ *minec
panic(itemType) panic(itemType)
} }
} else { } else {
t.latest.RegisterEntry(entry.Name) t.latest.RegisterEntryRID(entry.Name, int32(entry.RuntimeID))
entry.RuntimeID = int16(t.mapping.RegisterEntry(entry.Name)) entry.RuntimeID = int16(t.mapping.RegisterEntry(entry.Name))
} }
pk.Items[i] = entry pk.Items[i] = entry

View File

@@ -12,6 +12,7 @@ type Item interface {
// ItemNameToRuntimeID converts a string ID to an item runtime ID. // ItemNameToRuntimeID converts a string ID to an item runtime ID.
ItemNameToRuntimeID(string) (int32, bool) ItemNameToRuntimeID(string) (int32, bool)
RegisterEntry(string) int32 RegisterEntry(string) int32
RegisterEntryRID(string, int32)
Air() int32 Air() int32
ItemVersion() uint16 ItemVersion() uint16
} }
@@ -96,6 +97,15 @@ func (m *DefaultItemMapping) RegisterEntry(name string) int32 {
return nextRID return nextRID
} }
func (m *DefaultItemMapping) RegisterEntryRID(name string, rid int32) {
defer m.mu.Unlock()
m.mu.Lock()
if _, ok := m.itemNamesToRuntimeIDs[name]; !ok {
m.itemNamesToRuntimeIDs[name] = rid
m.itemRuntimeIDsToNames[rid] = name
}
}
func (m *DefaultItemMapping) Air() int32 { func (m *DefaultItemMapping) Air() int32 {
defer m.mu.Unlock() defer m.mu.Unlock()
m.mu.Lock() m.mu.Lock()