Exemple #1
0
    public void OnHeldItemChange(IMinecraftUser user, IMinecraftPacket packet)
    {
        short slot = packet.ReadInt16();

        if (slot < 0 || slot > 8)
        {
            throw new IndexOutOfRangeException($"Slot was out of bounds: {slot}");
        }

        _logger.LogDebug($"Current slot: {slot}");

        user.Player.HotBar.SetSlotIndex(slot);

        _logger.LogDebug($"Selected Item: ItemId = {user.Player.HotBar.SelectedSlot.ItemId}");
    }
Exemple #2
0
    public void OnCreativeInventoryAction(IMinecraftUser user, IMinecraftPacket packet)
    {
        short slot = (short)(packet.ReadInt16() - RedstoneContants.PlayerInventoryHotbarOffset);
        // item slot structure
        bool present = packet.ReadBoolean();

        if (present)
        {
            int         itemId     = packet.ReadVarInt32();
            byte        itemCount  = packet.ReadByte();
            NbtCompound itemExtras = packet.ReadNbtCompound();

            _logger.LogInformation($"Item with id: {itemId} (x{itemCount}) set at slot {slot}");
            user.Player.HotBar.SetItem(slot, itemId, itemCount);
        }
        else
        {
            _logger.LogInformation($"Clearing item slot '{slot}'");
            user.Player.HotBar.ClearItem(slot);
        }
    }