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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations