Search in sources :

Example 1 with AttributeModifier

use of com.github.dirtpowered.dirtmv.data.protocol.objects.AttributeModifier in project DirtMultiversion by DirtPowered.

the class V1_6_2EntityAttributesDataType method write.

@Override
public void write(TypeHolder typeHolder, PacketOutput packetOutput) throws IOException {
    V1_6_2EntityAttributes entityAttributes = (V1_6_2EntityAttributes) typeHolder.getObject();
    packetOutput.writeInt(entityAttributes.getEntityAttributes().size());
    for (EntityAttribute key : entityAttributes.getEntityAttributes()) {
        if (getType() == Type.V1_7_ENTITY_ATTRIBUTES || getType() == Type.V1_8_ENTITY_ATTRIBUTES) {
            V1_7_2RProtocol.STRING.write(new TypeHolder(Type.V1_7_STRING, key.getName()), packetOutput);
        } else {
            BaseProtocol.STRING.write(new TypeHolder(Type.STRING, key.getName()), packetOutput);
        }
        packetOutput.writeDouble(key.getValue());
        if (getType() == Type.V1_8_ENTITY_ATTRIBUTES) {
            packetOutput.writeVarInt(key.getAttributeModifiers().size());
        } else {
            packetOutput.writeShort(key.getAttributeModifiers().size());
        }
        for (AttributeModifier attributeModifier : key.getAttributeModifiers()) {
            V1_8RProtocol.UUID.write(new TypeHolder(Type.UUID, attributeModifier.getUuid()), packetOutput);
            packetOutput.writeDouble(attributeModifier.getAmount());
            packetOutput.writeByte(attributeModifier.getOperation());
        }
    }
}
Also used : V1_6_2EntityAttributes(com.github.dirtpowered.dirtmv.data.protocol.objects.V1_6_2EntityAttributes) TypeHolder(com.github.dirtpowered.dirtmv.data.protocol.TypeHolder) EntityAttribute(com.github.dirtpowered.dirtmv.data.protocol.objects.EntityAttribute) AttributeModifier(com.github.dirtpowered.dirtmv.data.protocol.objects.AttributeModifier)

Example 2 with AttributeModifier

use of com.github.dirtpowered.dirtmv.data.protocol.objects.AttributeModifier in project DirtMultiversion by DirtPowered.

the class V1_6_2EntityAttributesDataType method read.

@Override
public V1_6_2EntityAttributes read(PacketInput packetInput) throws IOException {
    int attrCount = packetInput.readInt();
    List<EntityAttribute> entityAttributes = new ArrayList<>();
    for (int i = 0; i < attrCount; i++) {
        String name;
        if (getType() == Type.V1_7_ENTITY_ATTRIBUTES || getType() == Type.V1_8_ENTITY_ATTRIBUTES) {
            name = V1_7_2RProtocol.STRING.read(packetInput);
        } else {
            name = BaseProtocol.STRING.read(packetInput);
        }
        double value = packetInput.readDouble();
        EntityAttribute entityAttribute = new EntityAttribute(name, value);
        int additionalData;
        if (getType() == Type.V1_8_ENTITY_ATTRIBUTES) {
            additionalData = packetInput.readVarInt();
        } else {
            additionalData = packetInput.readShort();
        }
        for (int j = 0; j < additionalData; j++) {
            UUID uuid = V1_8RProtocol.UUID.read(packetInput);
            double amount = packetInput.readDouble();
            int operation = packetInput.readByte();
            entityAttribute.addAttribute(new AttributeModifier(uuid, amount, operation));
        }
        entityAttributes.add(entityAttribute);
    }
    return new V1_6_2EntityAttributes(entityAttributes);
}
Also used : V1_6_2EntityAttributes(com.github.dirtpowered.dirtmv.data.protocol.objects.V1_6_2EntityAttributes) EntityAttribute(com.github.dirtpowered.dirtmv.data.protocol.objects.EntityAttribute) ArrayList(java.util.ArrayList) UUID(java.util.UUID) AttributeModifier(com.github.dirtpowered.dirtmv.data.protocol.objects.AttributeModifier)

Aggregations

AttributeModifier (com.github.dirtpowered.dirtmv.data.protocol.objects.AttributeModifier)2 EntityAttribute (com.github.dirtpowered.dirtmv.data.protocol.objects.EntityAttribute)2 V1_6_2EntityAttributes (com.github.dirtpowered.dirtmv.data.protocol.objects.V1_6_2EntityAttributes)2 TypeHolder (com.github.dirtpowered.dirtmv.data.protocol.TypeHolder)1 ArrayList (java.util.ArrayList)1 UUID (java.util.UUID)1