Search in sources :

Example 1 with MetadataType

use of net.glowstone.entity.meta.MetadataType in project Glowstone by GlowstoneMC.

the class PlayParticleCodec method encode.

@Override
public ByteBuf encode(ByteBuf buf, PlayParticleMessage message) throws IOException {
    buf.writeInt(message.getParticle());
    buf.writeBoolean(message.isLongDistance());
    buf.writeDouble(message.getX());
    buf.writeDouble(message.getY());
    buf.writeDouble(message.getZ());
    buf.writeFloat(message.getOfsX());
    buf.writeFloat(message.getOfsY());
    buf.writeFloat(message.getOfsZ());
    buf.writeFloat(message.getData());
    buf.writeInt(message.getCount());
    for (Object extData : message.getExtData()) {
        MetadataType type = MetadataType.byClass(extData.getClass());
        if (type != null) {
            GlowBufUtils.writeValue(buf, extData, type);
        }
    }
    return buf;
}
Also used : MetadataType(net.glowstone.entity.meta.MetadataType)

Example 2 with MetadataType

use of net.glowstone.entity.meta.MetadataType in project Glowstone by GlowstoneMC.

the class GlowBufUtils method readMetadata.

/**
 * Read a list of mob metadata entries from the buffer.
 *
 * @param buf The buffer.
 * @return The metadata.
 * @throws IOException if the buffer could not be read
 */
public static List<Entry> readMetadata(ByteBuf buf) throws IOException {
    List<Entry> entries = new ArrayList<>();
    byte item;
    while ((item = buf.readByte()) != -1) {
        MetadataType type = MetadataType.byId(buf.readByte());
        MetadataIndex index = MetadataIndex.getIndex((int) item, type);
        switch(type) {
            case BYTE:
                entries.add(new Entry(index, buf.readByte()));
                break;
            case INT:
                entries.add(new Entry(index, ByteBufUtils.readVarInt(buf)));
                break;
            case FLOAT:
                entries.add(new Entry(index, buf.readFloat()));
                break;
            case STRING:
                entries.add(new Entry(index, ByteBufUtils.readUTF8(buf)));
                break;
            case ITEM:
                entries.add(new Entry(index, readSlot(buf)));
                break;
            case BOOLEAN:
                entries.add(new Entry(index, buf.readBoolean()));
                break;
            case VECTOR:
                float x = buf.readFloat();
                float y = buf.readFloat();
                float z = buf.readFloat();
                entries.add(new MetadataMap.Entry(index, new EulerAngle(x, y, z)));
                break;
            case POSITION:
            case OPTPOSITION:
                entries.add(new Entry(index, Position.getPosition(buf.readLong())));
                break;
            case DIRECTION:
                entries.add(new Entry(index, ByteBufUtils.readVarInt(buf)));
                break;
            case OPTUUID:
                if (buf.readBoolean()) {
                    entries.add(new Entry(index, readUuid(buf)));
                }
                break;
            case BLOCKID:
                entries.add(new Entry(index, ByteBufUtils.readVarInt(buf)));
                break;
            case NBTTAG:
                entries.add(new Entry(index, readCompound(buf)));
                break;
            default:
        }
    }
    return entries;
}
Also used : MetadataIndex(net.glowstone.entity.meta.MetadataIndex) MetadataMap(net.glowstone.entity.meta.MetadataMap) Entry(net.glowstone.entity.meta.MetadataMap.Entry) ArrayList(java.util.ArrayList) MetadataType(net.glowstone.entity.meta.MetadataType) Entry(net.glowstone.entity.meta.MetadataMap.Entry) EulerAngle(org.bukkit.util.EulerAngle)

Aggregations

MetadataType (net.glowstone.entity.meta.MetadataType)2 ArrayList (java.util.ArrayList)1 MetadataIndex (net.glowstone.entity.meta.MetadataIndex)1 MetadataMap (net.glowstone.entity.meta.MetadataMap)1 Entry (net.glowstone.entity.meta.MetadataMap.Entry)1 EulerAngle (org.bukkit.util.EulerAngle)1