@Override protected DataBuffer encodeBespoke() { int size = 3 * Short.BYTES; for (Model model : Arrays.asList(primary, secondary)) { size += model.getId().isPresent() ? Short.BYTES : Byte.BYTES; size += model.getAnimation().isPresent() ? Short.BYTES : Byte.BYTES; } DataBuffer buffer = DataBuffer.allocate(size); for (OptionalInt optional : Arrays.asList( primary.getId(), secondary.getId(), primary.getAnimation(), secondary.getAnimation())) { if (optional.isPresent()) { int id = optional.getAsInt(); buffer.putByte(id >> 8 + 1); buffer.putByte(id); } else { buffer.putBoolean(false); } } buffer.putShort(scale); buffer.putShort(pitch); buffer.putShort(roll); return buffer.flip().asReadOnlyBuffer(); }