コード例 #1
0
    public void OnDrop()
    {
        if (playerEvents.hotbar.GetSlot(PlayerEvents.hotbarSlot) == null)
        {
            return;
        }

        ItemID    id = playerEvents.hotbar.GetSlot(PlayerEvents.hotbarSlot).GetID();
        ItemStack its;
        byte      amount;

        if (!MainControllerManager.ctrl)
        {
            if (playerEvents.hotbar.GetSlot(PlayerEvents.hotbarSlot).Decrement())
            {
                playerEvents.hotbar.SetNull(PlayerEvents.hotbarSlot);
            }

            amount = 1;
            its    = new ItemStack(id, amount);
        }
        else
        {
            amount = playerEvents.hotbar.GetSlot(PlayerEvents.hotbarSlot).GetAmount();
            playerEvents.hotbar.SetNull(PlayerEvents.hotbarSlot);

            its = new ItemStack(id, amount);
        }


        Vector3 force = this.playerCamera.forward / 5f;

        NetMessage message = new NetMessage(NetCode.DROPITEM);

        message.DropItem(this.playerCamera.position.x, this.playerCamera.position.y, this.playerCamera.position.z, this.playerCamera.rotation.x, this.playerCamera.rotation.y, this.playerCamera.rotation.z, force.x, force.y, force.z, (ushort)id, amount);
        this.cl.client.Send(message.GetMessage(), message.size);

        playerEvents.DrawHotbarSlot(PlayerEvents.hotbarSlot);
        playerEvents.DrawItemEntity(playerEvents.hotbar.GetSlot(PlayerEvents.hotbarSlot));
        playerEvents.invUIPlayer.DrawSlot(1, PlayerEvents.hotbarSlot);
    }
コード例 #2
0
    // Uses item in hand
    public void UseItem()
    {
        // If ain't aiming at anything
        if (!current.active)
        {
            return;
        }

        ItemStack its = playerEvents.GetSlotStack();

        // If is holding no items
        if (its == null)
        {
            return;
        }

        Item it = its.GetItem();

        // If is a placeable item
        if (it is IPlaceable)
        {
            IPlaceable itPlaceable = it as IPlaceable;
            // If block placement was successful in client
            if (this.PlaceBlock(itPlaceable.placeableBlockID))
            {
                PlayerRaycast.lastBlockPlaced = it.id;
                if (its.Decrement())
                {
                    playerEvents.hotbar.SetNull(PlayerEvents.hotbarSlot);
                    playerEvents.DestroyItemEntity();
                }
                playerEvents.DrawHotbarSlot(PlayerEvents.hotbarSlot);
                playerEvents.invUIPlayer.DrawSlot(1, PlayerEvents.hotbarSlot);
            }
        }
    }