throw new UnsupportedOperationException("NestedPacket serialization unsupported (aka TODO)");
});
} else if (type == Vector2.class) {
writeActions.add((packet, buffer) -> {
try {
Vector2 vector = (Vector2) field.get(packet);
if (vector != null) {
buffer.writeFloat(vector.getX());
buffer.writeFloat(vector.getY());
} else {
buffer.writeFloat(0);
buffer.writeFloat(0);
}
} catch (IllegalArgumentException | IllegalAccessException e) {
// should never happen
LOGGER.error("Unexpected error: ", e);
throw new RuntimeException(e);
}
});
} else if (type == Vector3.class) {
writeActions.add((packet, buffer) -> {
try {
Vector3 vector = (Vector3) field.get(packet);
if (vector != null) {
buffer.writeFloat(vector.getX());
buffer.writeFloat(vector.getY());
buffer.writeFloat(vector.getZ());
} else {
buffer.writeFloat(0);
buffer.writeFloat(0);
buffer.writeFloat(0);
}
} catch (IllegalArgumentException | IllegalAccessException e) {
// should never happen
LOGGER.error("Unexpected error: ", e);
throw new RuntimeException(e);
}
});
} else if (type == Vector4.class) {
writeActions.add((packet, buffer) -> {
try {
Vector4 vector = (Vector4) field.get(packet);
if (vector != null) {
buffer.writeFloat(vector.getX());
buffer.writeFloat(vector.getY());
buffer.writeFloat(vector.getZ());
buffer.writeFloat(vector.getA());
} else {
buffer.writeFloat(0);
buffer.writeFloat(0);
buffer.writeFloat(0);
buffer.writeFloat(0);