use of com.github.dirtpowered.dirtmv.data.protocol.objects.V1_6_2EntityAttributes 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.V1_6_2EntityAttributes in project DirtMultiversion by DirtPowered.
the class ProtocolRelease74To73 method registerTranslators.
@Override
public void registerTranslators() {
// handshake
addTranslator(0x02, PacketDirection.TO_SERVER, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
return PacketUtil.createPacket(0x02, new TypeHolder[] { set(Type.BYTE, (byte) 73), data.read(1), data.read(2), data.read(3) });
}
});
// entity attributes/properties
addTranslator(0x2C, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
V1_6_1EntityAttributes attrObj = data.read(Type.V1_6_1_ENTITY_ATTRIBUTES, 1);
List<EntityAttribute> entityAttributes = new ArrayList<>();
for (Map.Entry<String, Double> entry : attrObj.getAttributes().entrySet()) {
entityAttributes.add(new EntityAttribute(entry.getKey(), entry.getValue()));
}
V1_6_2EntityAttributes attrObjModern = new V1_6_2EntityAttributes(entityAttributes);
return PacketUtil.createPacket(0x2C, new TypeHolder[] { data.read(0), set(Type.V1_6_2_ENTITY_ATTRIBUTES, attrObjModern) });
}
});
// kick disconnect
addTranslator(0xFF, PacketDirection.TO_CLIENT, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
if (session.getUserData().getPreNettyProtocolState() != PreNettyProtocolState.STATUS)
return data;
String reason = data.read(Type.STRING, 0);
ServerMotd pingMessage = ServerMotd.deserialize(reason);
pingMessage.setVersionName("1.6.2");
pingMessage.setProtocol(session.getUserData().getClientVersion().getRegistryId());
return PacketUtil.createPacket(0xFF, new TypeHolder[] { set(Type.STRING, ServerMotd.serialize(pingMessage)) });
}
});
// creative item get
addTranslator(0x6B, ProtocolState.PLAY, PacketDirection.TO_SERVER, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
ItemStack item = data.read(Type.V1_3R_ITEM, 1);
boolean notNull = item != null;
if (notNull && !creativeTab.exists(item.getItemId())) {
// replace all unknown items to stone
item.setItemId(1);
item.setData(0);
}
return PacketUtil.createPacket(0x6B, new TypeHolder[] { data.read(0), set(Type.V1_3R_ITEM, item) });
}
});
// block place
addTranslator(0x0F, PacketDirection.TO_SERVER, new PacketTranslator() {
@Override
public PacketData translate(ServerSession session, PacketData data) {
int x = data.read(Type.INT, 0);
int y = data.read(Type.UNSIGNED_BYTE, 1);
int z = data.read(Type.INT, 2);
ItemStack item = data.read(Type.V1_3R_ITEM, 4);
if (item == null)
return data;
int itemId = item.getItemId();
int face = data.read(Type.BYTE, 3);
if (face == 1) {
++y;
} else if (face == 2) {
--z;
} else if (face == 3) {
++z;
} else if (face == 4) {
--x;
} else if (face == 5) {
++x;
}
if (itemId == 323 && data.read(Type.SHORT, 5) > 0) {
PacketData signEditor = PacketUtil.createPacket(0x85, new TypeHolder[] { // ignored
set(Type.BYTE, (byte) 0), // x
set(Type.INT, x), // y
set(Type.INT, y), // z
set(Type.INT, z) });
session.sendPacket(signEditor, PacketDirection.TO_CLIENT, getFrom());
}
return data;
}
});
}
use of com.github.dirtpowered.dirtmv.data.protocol.objects.V1_6_2EntityAttributes 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