df-mc / dragonfly

Minecraft Bedrock Edition server software written in Go
https://discord.gg/U4kFWHhTNR
MIT License
678 stars 139 forks source link

Item doesnt immediately update with drag and drop enchant system #654

Open HashimTheArab opened 2 years ago

HashimTheArab commented 2 years ago

https://user-images.githubusercontent.com/13991048/185820636-9d073a38-6a5d-4ac1-a507-8907c9006c4c.mp4

(flashes vid)

this is the code

func (h *InventoryHandler) HandlePlace(ctx *event.Context, slot int, it item.Stack) {
    enchant, ok := ce.FromBook(it)
    if !ok {
        return
    }

    targetItem, err := h.p.Inventory().Item(slot)
    if targetItem.Empty() || err != nil || !enchant.CompatibleWithItem(targetItem.Item()) {
        return
    }
    if err := h.p.Inventory().SetItem(slot, ce.ApplyEnchant(targetItem, enchant.Type(), enchant.Level())); err == nil {
        ctx.Cancel()
        time.AfterFunc(time.Millisecond*50, func() {
            h.p.Inventory().RemoveItem(it)
        })
    }
}

if it helps this is whats showing in the console

DEBU[0081] failed processing packet from (R53D): failed changing held slot: client-side item must be identical to server-side item, but got differences: client: Stack<item.Pickaxe{Tier:{HarvestLevel:4 BaseMiningEffic
iency:9 BaseAttackDamage:5 EnchantmentValue:15 Durability:2031 Name:netherite}}>(custom name='', lore='[]', damage=0, anvilCost=0) x1 vs server: Stack<item.Pickaxe{Tier:{HarvestLevel:4 BaseMiningEfficiency:9 BaseAttackDamage:5 Encha
ntmentValue:15 Durability:2031 Name:netherite}}>(custom name='', lore='[§r§6Speed 1§r]', damage=0, anvilCost=0) x1
DEBU[0081] failed processing packet from 127.0.0.1:59081 (R53D): InventoryTransaction: failed verifying actions in Normal transaction: different item thrown than held in slot: item.Stack{id:8367, item:item.Pickaxe{Tier:item.ToolTier
{HarvestLevel:4, BaseMiningEfficiency:9, BaseAttackDamage:5, EnchantmentValue:15, Durability:2031, Name:"netherite"}}, count:1, customName:"", lore:[]string(nil), damage:0, anvilCost:0, data:map[string]interface {}(nil), enchantment
s:map[item.EnchantmentType]item.Enchantment(nil)} was thrown but held item.Stack{id:8355, item:item.Pickaxe{Tier:item.ToolTier{HarvestLevel:4, BaseMiningEfficiency:9, BaseAttackDamage:5, EnchantmentValue:15, Durability:2031, Name:"n
etherite"}}, count:1, customName:"", lore:[]string{"§r§6Speed 1§r"}, damage:0, anvilCost:0, data:map[string]interface {}(nil), enchantments:map[item.EnchantmentType]item.Enchantment{ce.Speed{customEnchant:ce.customEnchant{}}:item.En
chantment{t:ce.Speed{customEnchant:ce.customEnchant{}}, lvl:1}}}
Theflashiscool2 commented 2 years ago

Directly after the book is placed on the item it sends this: DEBU[0047] failed processing packet from (R53D): ItemStackRequest: error resolving item stack request: *protocol.SwapStackRequestAction: action was cancelled The console thing shown above happens when you try and drop the item after using the book on it.

Sandertv commented 2 years ago

Probably a duplicate of https://github.com/df-mc/dragonfly/issues/646.