Search in sources :

Example 6 with BlockVector

use of org.bukkit.util.BlockVector in project Glowstone by GlowstoneMC.

the class GlowBufUtils method writeMetadata.

/**
     * Write a list of mob metadata entries to the buffer.
     *
     * @param buf     The buffer.
     * @param entries The metadata.
     * @throws IOException if the buffer could not be written to
     */
public static void writeMetadata(ByteBuf buf, List<Entry> entries) throws IOException {
    for (Entry entry : entries) {
        MetadataIndex index = entry.index;
        Object value = entry.value;
        int type = index.getType().getId();
        int id = index.getIndex();
        buf.writeByte(id);
        buf.writeByte(type);
        if (!index.getType().isOptional() && value == null) {
            continue;
        }
        if (index.getType().isOptional()) {
            buf.writeBoolean(value != null);
            if (value == null) {
                continue;
            }
        }
        switch(index.getType()) {
            case BYTE:
                buf.writeByte((Byte) value);
                break;
            case INT:
                ByteBufUtils.writeVarInt(buf, (Integer) value);
                break;
            case FLOAT:
                buf.writeFloat((Float) value);
                break;
            case STRING:
                ByteBufUtils.writeUTF8(buf, (String) value);
                break;
            case CHAT:
                writeChat(buf, (TextMessage) value);
                break;
            case ITEM:
                writeSlot(buf, (ItemStack) value);
                break;
            case BOOLEAN:
                buf.writeBoolean((Boolean) value);
                break;
            case VECTOR:
                EulerAngle angle = (EulerAngle) value;
                buf.writeFloat((float) Math.toDegrees(angle.getX()));
                buf.writeFloat((float) Math.toDegrees(angle.getY()));
                buf.writeFloat((float) Math.toDegrees(angle.getZ()));
                break;
            case POSITION:
            case OPTPOSITION:
                BlockVector vector = (BlockVector) value;
                buf.writeLong(Position.getPosition(vector));
                break;
            case DIRECTION:
                ByteBufUtils.writeVarInt(buf, (Integer) value);
                break;
            case OPTUUID:
                writeUuid(buf, (UUID) value);
                break;
            case BLOCKID:
                ByteBufUtils.writeVarInt(buf, (Integer) value);
                break;
        }
    }
    buf.writeByte(0xff);
}
Also used : MetadataIndex(net.glowstone.entity.meta.MetadataIndex) Entry(net.glowstone.entity.meta.MetadataMap.Entry) BlockVector(org.bukkit.util.BlockVector) EulerAngle(org.bukkit.util.EulerAngle)

Example 7 with BlockVector

use of org.bukkit.util.BlockVector in project Glowstone by GlowstoneMC.

the class SpawnPaintingCodec method decode.

@Override
public SpawnPaintingMessage decode(ByteBuf buf) throws IOException {
    int id = ByteBufUtils.readVarInt(buf);
    String title = ByteBufUtils.readUTF8(buf);
    BlockVector vector = GlowBufUtils.readBlockPosition(buf);
    int facing = buf.readByte();
    return new SpawnPaintingMessage(id, title, vector.getBlockX(), vector.getBlockY(), vector.getBlockZ(), facing);
}
Also used : SpawnPaintingMessage(net.glowstone.net.message.play.entity.SpawnPaintingMessage) BlockVector(org.bukkit.util.BlockVector)

Example 8 with BlockVector

use of org.bukkit.util.BlockVector in project Glowstone by GlowstoneMC.

the class BlockActionCodec method decode.

@Override
public BlockActionMessage decode(ByteBuf buf) throws IOException {
    BlockVector vector = GlowBufUtils.readBlockPosition(buf);
    int data1 = buf.readByte();
    int data2 = buf.readByte();
    int blockType = ByteBufUtils.readVarInt(buf);
    return new BlockActionMessage(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ(), data1, data2, blockType);
}
Also used : BlockVector(org.bukkit.util.BlockVector) BlockActionMessage(net.glowstone.net.message.play.game.BlockActionMessage)

Example 9 with BlockVector

use of org.bukkit.util.BlockVector in project Glowstone by GlowstoneMC.

the class BlockChangeCodec method decode.

@Override
public BlockChangeMessage decode(ByteBuf buffer) throws IOException {
    BlockVector pos = GlowBufUtils.readBlockPosition(buffer);
    int type = ByteBufUtils.readVarInt(buffer);
    return new BlockChangeMessage(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ(), type);
}
Also used : BlockVector(org.bukkit.util.BlockVector) BlockChangeMessage(net.glowstone.net.message.play.game.BlockChangeMessage)

Example 10 with BlockVector

use of org.bukkit.util.BlockVector in project Glowstone by GlowstoneMC.

the class BlockPlacementCodec method decode.

@Override
public BlockPlacementMessage decode(ByteBuf buf) throws IOException {
    BlockVector pos = GlowBufUtils.readBlockPosition(buf);
    int direction = buf.readByte();
    int hand = ByteBufUtils.readVarInt(buf);
    float cursorX = buf.readFloat();
    float cursorY = buf.readFloat();
    float cursorZ = buf.readFloat();
    return new BlockPlacementMessage(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ(), direction, hand, cursorX, cursorY, cursorZ);
}
Also used : BlockPlacementMessage(net.glowstone.net.message.play.player.BlockPlacementMessage) BlockVector(org.bukkit.util.BlockVector)

Aggregations

BlockVector (org.bukkit.util.BlockVector)19 Vector (org.bukkit.util.Vector)4 HashMap (java.util.HashMap)2 Map (java.util.Map)2 GlowBlock (net.glowstone.block.GlowBlock)2 UseBedMessage (net.glowstone.net.message.play.player.UseBedMessage)2 TextMessage (net.glowstone.util.TextMessage)2 Location (org.bukkit.Location)2 Block (org.bukkit.block.Block)2 Message (com.flowpowered.network.Message)1 ASkyBlock (com.wasteofplastic.acidisland.ASkyBlock)1 GameType (com.wasteofplastic.acidisland.Settings.GameType)1 GZIPInputStream (java.util.zip.GZIPInputStream)1 BlockData (net.aufdemrand.denizen.nms.interfaces.BlockData)1 Key (net.glowstone.chunk.GlowChunk.Key)1 GlowPlayer (net.glowstone.entity.GlowPlayer)1 MetadataIndex (net.glowstone.entity.meta.MetadataIndex)1 MetadataMap (net.glowstone.entity.meta.MetadataMap)1 Entry (net.glowstone.entity.meta.MetadataMap.Entry)1 SpawnPaintingMessage (net.glowstone.net.message.play.entity.SpawnPaintingMessage)1