Exemplo n.º 1
0
    public void OnPlayerDigging(IMinecraftUser user, IMinecraftPacket packet)
    {
        var status   = (DiggingType)packet.ReadVarInt32();
        var position = packet.ReadPosition();
        var face     = (BlockFaceType)packet.ReadByte();

        _logger.LogTrace($"Status={status};Position={position};Face={face}");

        if (user.Player.GameMode is ServerGameModeType.Creative)
        {
            IBlock previousBlock = user.Player.Map.GetBlock(position);

            if (previousBlock.IsAir)
            {
                throw new InvalidOperationException($"Cannot dig air blocks ({position})");
            }

            using var playerDiggingAck = new AcknowledgePlayerDiggingPacket(position, previousBlock, DiggingType.Started);
            user.Player.SendPacketToVisibleEntities(playerDiggingAck);

            using var blockChange = new BlockChangePacket(BlockType.Air, position);
            user.Player.SendPacketToVisibleEntities(blockChange);

            IBlock block = user.Player.Map.SetBlock(BlockType.Air, position);

            using var chunkPacket = new ChunkDataPacket(block.Chunk);
            user.Player.SendPacketToVisibleEntities(chunkPacket, includeEntity: true);
        }
        else
        {
            // TODO: other modes
        }
    }
Exemplo n.º 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);
        }
    }