fix copper items (and possibly others) causing issues with creative item grouping

This commit is contained in:
ethaniccc
2026-01-03 15:06:30 -05:00
parent e17d0a914d
commit f09c500713
2 changed files with 46 additions and 11 deletions

View File

@@ -59,11 +59,14 @@ type DefaultItemTranslator struct {
originalToCustom map[int32]int32
customToOriginal map[int32]int32
hasDebugStick bool
infoUpdateRID int32
}
func NewItemTranslator(mapping mapping.Item, latestMapping mapping.Item, blockMapping mapping.Block, blockMappingLatest mapping.Block) *DefaultItemTranslator {
infoUpdateRID, _ := mapping.ItemNameToRuntimeID("minecraft:info_update")
return &DefaultItemTranslator{mapping: mapping, latest: latestMapping, blockMapping: blockMapping, blockMappingLatest: blockMappingLatest,
ridToCustomItem: make(map[int32]world.CustomItem), originalToCustom: make(map[int32]int32), customToOriginal: make(map[int32]int32)}
ridToCustomItem: make(map[int32]world.CustomItem), originalToCustom: make(map[int32]int32), customToOriginal: make(map[int32]int32), infoUpdateRID: infoUpdateRID}
}
func (t *DefaultItemTranslator) DowngradeItemType(input protocol.ItemType) protocol.ItemType {
@@ -104,6 +107,36 @@ func (t *DefaultItemTranslator) DowngradeItemType(input protocol.ItemType) proto
}
}
func (t *DefaultItemTranslator) TryDowngradeItemStack(input protocol.ItemStack) (protocol.ItemStack, bool) {
if t.latest == t.mapping || input.NetworkID == 0 {
return input, true
}
input.ItemType = t.DowngradeItemType(input.ItemType)
if input.ItemType.NetworkID == t.infoUpdateRID {
return input, false
}
blockRuntimeId := uint32(0)
if input.NetworkID != t.mapping.Air() {
name, _ := t.mapping.ItemRuntimeIDToName(input.NetworkID)
if latestBlockState, ok := item.BlockStateFromItemName(name, input.MetadataValue); ok {
var found bool
if blockRuntimeId, found = t.blockMapping.StateToRuntimeID(latestBlockState); !found {
blockRuntimeId = t.blockMapping.Air()
}
}
}
return protocol.ItemStack{
ItemType: input.ItemType,
BlockRuntimeID: int32(blockRuntimeId),
Count: input.Count,
NBTData: input.NBTData,
CanBePlacedOn: input.CanBePlacedOn,
CanBreak: input.CanBreak,
HasNetworkID: input.HasNetworkID,
}, true
}
func (t *DefaultItemTranslator) DowngradeItemStack(input protocol.ItemStack) protocol.ItemStack {
if t.latest == t.mapping || input.NetworkID == 0 {
return input
@@ -458,10 +491,17 @@ func (t *DefaultItemTranslator) DowngradeItemPackets(pks []packet.Packet, _ *min
}
pk.ItemInteractionData.HeldItem = t.DowngradeItemInstance(pk.ItemInteractionData.HeldItem)
case *packet.CreativeContent:
for i, creativeItem := range pk.Items {
creativeItem.Item = t.DowngradeItemStack(creativeItem.Item)
pk.Items[i] = creativeItem
newItems := make([]protocol.CreativeItem, 0, len(pk.Items))
for _, creativeItem := range pk.Items {
if newItem, ok := t.TryDowngradeItemStack(creativeItem.Item); ok {
creativeItem.Item = newItem
newItems = append(newItems, creativeItem)
}
}
pk.Items = newItems
for i, group := range pk.Groups {
group.Icon = t.DowngradeItemStack(group.Icon)
pk.Groups[i] = group
}
case *packet.InventoryTransaction:
for i, action := range pk.Actions {