Search in sources :

Example 1 with PEEntityAttribute

use of org.dragonet.common.data.entity.PEEntityAttribute in project DragonProxy by DragonetMC.

the class BinaryStream method putAttributeList.

/**
 * Writes a list of Attributes to the packet buffer using the standard
 * format.
 */
public void putAttributeList(PEEntityAttribute[] attributes) {
    this.putUnsignedVarInt(attributes.length);
    for (PEEntityAttribute attribute : attributes) {
        this.putString(attribute.name);
        this.putLFloat(attribute.min);
        this.putLFloat(attribute.currentValue);
        this.putLFloat(attribute.max);
    }
}
Also used : PEEntityAttribute(org.dragonet.common.data.entity.PEEntityAttribute)

Example 2 with PEEntityAttribute

use of org.dragonet.common.data.entity.PEEntityAttribute in project DragonProxy by DragonetMC.

the class UpdateAttributesPacket method encodePayload.

@Override
public void encodePayload() {
    putUnsignedVarLong(rtid);
    // System.out.println("PEEntityAttribute entity " + rtid);
    if (entries != null && entries.size() > 0) {
        putUnsignedVarInt(entries.size());
        for (PEEntityAttribute attr : entries) {
            // System.out.println("PEEntityAttribute " + attr.name + " : " + attr.currentValue);
            putLFloat(attr.min);
            putLFloat(attr.max);
            putLFloat(attr.currentValue);
            putLFloat(attr.defaultValue);
            putString(attr.name);
        }
    } else {
        putUnsignedVarInt(0);
    }
}
Also used : PEEntityAttribute(org.dragonet.common.data.entity.PEEntityAttribute)

Example 3 with PEEntityAttribute

use of org.dragonet.common.data.entity.PEEntityAttribute in project DragonProxy by DragonetMC.

the class AddEntityPacket method encodePayload.

@Override
public void encodePayload() {
    putVarLong(eid);
    putUnsignedVarLong(rtid);
    putUnsignedVarInt(type);
    putVector3F(position);
    putVector3F(motion);
    putLFloat(pitch);
    putLFloat(yaw);
    if (attributes != null && attributes.size() > 0) {
        putUnsignedVarInt(attributes.size());
        for (PEEntityAttribute attr : attributes) {
            putString(attr.name);
            putLFloat(attr.min);
            putLFloat(attr.currentValue);
            putLFloat(attr.max);
        }
    } else {
        putUnsignedVarInt(0);
    }
    if (meta != null) {
        meta.encode();
        put(meta.getBuffer());
    } else {
        putUnsignedVarInt(0);
    }
    if (links != null && links.length > 0) {
        putUnsignedVarInt(links.length);
        for (PEEntityLink l : links) {
            putEntityLink(l);
        }
    } else {
        putUnsignedVarInt(0);
    }
}
Also used : PEEntityLink(org.dragonet.common.data.entity.PEEntityLink) PEEntityAttribute(org.dragonet.common.data.entity.PEEntityAttribute)

Example 4 with PEEntityAttribute

use of org.dragonet.common.data.entity.PEEntityAttribute in project DragonProxy by DragonetMC.

the class BinaryStream method getAttributeList.

/**
 * Reads a list of Attributes from the stream.
 *
 * @return Attribute[]
 */
public PEEntityAttribute[] getAttributeList() throws Exception {
    List<PEEntityAttribute> list = new ArrayList<>();
    long count = this.getUnsignedVarInt();
    for (int i = 0; i < count; ++i) {
        String name = this.getString();
        PEEntityAttribute attr = PEEntityAttribute.findAttribute(name);
        if (attr != null) {
            attr.min = getLFloat();
            attr.currentValue = getLFloat();
            attr.max = this.getLFloat();
            list.add(attr);
        } else {
            throw new Exception("Unknown attribute type \"" + name + "\"");
        }
    }
    return list.stream().toArray(PEEntityAttribute[]::new);
}
Also used : PEEntityAttribute(org.dragonet.common.data.entity.PEEntityAttribute) IOException(java.io.IOException)

Aggregations

PEEntityAttribute (org.dragonet.common.data.entity.PEEntityAttribute)4 IOException (java.io.IOException)1 PEEntityLink (org.dragonet.common.data.entity.PEEntityLink)1