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