From 0ea350e2f3f04065b1a08e382e56961acb84dc41 Mon Sep 17 00:00:00 2001 From: Alemiz Date: Thu, 15 Aug 2024 17:08:55 +0200 Subject: [PATCH] Add missing viewOffset to CameraPresetsPacket --- .../CameraInstructionSerializer_618.java | 52 ++++++++++--------- .../CameraInstructionSerializer_v712.java | 35 +++++++++++++ .../CameraPresetsSerializer_v712.java | 7 +-- .../data/camera/CameraSetInstruction.java | 4 ++ 4 files changed, 69 insertions(+), 29 deletions(-) diff --git a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v618/serializer/CameraInstructionSerializer_618.java b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v618/serializer/CameraInstructionSerializer_618.java index 9bd2b2d7d..134108cdc 100644 --- a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v618/serializer/CameraInstructionSerializer_618.java +++ b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v618/serializer/CameraInstructionSerializer_618.java @@ -20,18 +20,7 @@ public class CameraInstructionSerializer_618 implements BedrockPacketSerializer< @Override public void serialize(ByteBuf buffer, BedrockCodecHelper helper, CameraInstructionPacket packet) { - helper.writeOptionalNull(buffer, packet.getSetInstruction(), (buf, set) -> { - DefinitionUtils.checkDefinition(helper.getCameraPresetDefinitions(), set.getPreset()); - buffer.writeIntLE(set.getPreset().getRuntimeId()); - - helper.writeOptionalNull(buf, set.getEase(), this::writeEase); - helper.writeOptionalNull(buf, set.getPos(), helper::writeVector3f); - helper.writeOptionalNull(buf, set.getRot(), helper::writeVector2f); - helper.writeOptionalNull(buf, set.getFacing(), helper::writeVector3f); - helper.writeOptional(buf, OptionalBoolean::isPresent, set.getDefaultPreset(), - (b, optional) -> b.writeBoolean(optional.getAsBoolean())); - }); - + helper.writeOptionalNull(buffer, packet.getSetInstruction(), (buf, set) -> this.writeSetInstruction(helper, buf, set)); helper.writeOptional(buffer, OptionalBoolean::isPresent, packet.getClear(), (b, optional) -> b.writeBoolean(optional.getAsBoolean())); @@ -43,18 +32,7 @@ public void serialize(ByteBuf buffer, BedrockCodecHelper helper, CameraInstructi @Override public void deserialize(ByteBuf buffer, BedrockCodecHelper helper, CameraInstructionPacket packet) { - CameraSetInstruction set = helper.readOptional(buffer, null, buf -> { - int runtimeId = buf.readIntLE(); - NamedDefinition definition = helper.getCameraPresetDefinitions().getDefinition(runtimeId); - Preconditions.checkNotNull(definition, "Unknown camera preset " + runtimeId); - - CameraSetInstruction.EaseData ease = helper.readOptional(buf, null, this::readEase); - Vector3f pos = helper.readOptional(buf, null, helper::readVector3f); - Vector2f rot = helper.readOptional(buf, null, helper::readVector2f); - Vector3f facing = helper.readOptional(buf, null, helper::readVector3f); - OptionalBoolean defaultPreset = helper.readOptional(buffer, OptionalBoolean.empty(), b -> OptionalBoolean.of(b.readBoolean())); - return new CameraSetInstruction(definition, ease, pos, rot, facing, defaultPreset); - }); + CameraSetInstruction set = helper.readOptional(buffer, null, buf -> this.readSetInstruction(buf, helper)); packet.setSetInstruction(set); packet.setClear(helper.readOptional(buffer, OptionalBoolean.empty(), buf -> OptionalBoolean.of(buf.readBoolean()))); @@ -105,4 +83,30 @@ protected Color readColor(ByteBuf buffer) { (int) (buffer.readFloatLE() * 255) ); } + + protected void writeSetInstruction(BedrockCodecHelper helper, ByteBuf buf, CameraSetInstruction set) { + DefinitionUtils.checkDefinition(helper.getCameraPresetDefinitions(), set.getPreset()); + buf.writeIntLE(set.getPreset().getRuntimeId()); + + helper.writeOptionalNull(buf, set.getEase(), this::writeEase); + helper.writeOptionalNull(buf, set.getPos(), helper::writeVector3f); + helper.writeOptionalNull(buf, set.getRot(), helper::writeVector2f); + helper.writeOptionalNull(buf, set.getFacing(), helper::writeVector3f); + + helper.writeOptional(buf, OptionalBoolean::isPresent, set.getDefaultPreset(), + (b, optional) -> b.writeBoolean(optional.getAsBoolean())); + } + + protected CameraSetInstruction readSetInstruction(ByteBuf buf, BedrockCodecHelper helper) { + int runtimeId = buf.readIntLE(); + NamedDefinition definition = helper.getCameraPresetDefinitions().getDefinition(runtimeId); + Preconditions.checkNotNull(definition, "Unknown camera preset " + runtimeId); + + CameraSetInstruction.EaseData ease = helper.readOptional(buf, null, this::readEase); + Vector3f pos = helper.readOptional(buf, null, helper::readVector3f); + Vector2f rot = helper.readOptional(buf, null, helper::readVector2f); + Vector3f facing = helper.readOptional(buf, null, helper::readVector3f); + OptionalBoolean defaultPreset = helper.readOptional(buf, OptionalBoolean.empty(), b -> OptionalBoolean.of(b.readBoolean())); + return new CameraSetInstruction(definition, ease, pos, rot, facing, null, defaultPreset); + } } diff --git a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v712/serializer/CameraInstructionSerializer_v712.java b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v712/serializer/CameraInstructionSerializer_v712.java index 8811b8fe7..3170177cc 100644 --- a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v712/serializer/CameraInstructionSerializer_v712.java +++ b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v712/serializer/CameraInstructionSerializer_v712.java @@ -1,12 +1,17 @@ package org.cloudburstmc.protocol.bedrock.codec.v712.serializer; import io.netty.buffer.ByteBuf; +import org.cloudburstmc.math.vector.Vector2f; import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.codec.BedrockCodecHelper; import org.cloudburstmc.protocol.bedrock.codec.v618.serializer.CameraInstructionSerializer_618; +import org.cloudburstmc.protocol.bedrock.data.camera.CameraSetInstruction; import org.cloudburstmc.protocol.bedrock.data.camera.CameraTargetInstruction; import org.cloudburstmc.protocol.bedrock.packet.CameraInstructionPacket; +import org.cloudburstmc.protocol.common.NamedDefinition; +import org.cloudburstmc.protocol.common.util.DefinitionUtils; import org.cloudburstmc.protocol.common.util.OptionalBoolean; +import org.cloudburstmc.protocol.common.util.Preconditions; import org.cloudburstmc.protocol.common.util.VarInts; public class CameraInstructionSerializer_v712 extends CameraInstructionSerializer_618 { @@ -33,4 +38,34 @@ public void deserialize(ByteBuf buffer, BedrockCodecHelper helper, CameraInstruc })); packet.setRemoveTarget(helper.readOptional(buffer, OptionalBoolean.empty(), buf -> OptionalBoolean.of(buf.readBoolean()))); } + + @Override + protected void writeSetInstruction(BedrockCodecHelper helper, ByteBuf buf, CameraSetInstruction set) { + DefinitionUtils.checkDefinition(helper.getCameraPresetDefinitions(), set.getPreset()); + buf.writeIntLE(set.getPreset().getRuntimeId()); + + helper.writeOptionalNull(buf, set.getEase(), this::writeEase); + helper.writeOptionalNull(buf, set.getPos(), helper::writeVector3f); + helper.writeOptionalNull(buf, set.getRot(), helper::writeVector2f); + helper.writeOptionalNull(buf, set.getFacing(), helper::writeVector3f); + helper.writeOptionalNull(buf, set.getViewOffset(), helper::writeVector2f); + + helper.writeOptional(buf, OptionalBoolean::isPresent, set.getDefaultPreset(), + (b, optional) -> b.writeBoolean(optional.getAsBoolean())); + } + + @Override + protected CameraSetInstruction readSetInstruction(ByteBuf buf, BedrockCodecHelper helper) { + int runtimeId = buf.readIntLE(); + NamedDefinition definition = helper.getCameraPresetDefinitions().getDefinition(runtimeId); + Preconditions.checkNotNull(definition, "Unknown camera preset " + runtimeId); + + CameraSetInstruction.EaseData ease = helper.readOptional(buf, null, this::readEase); + Vector3f pos = helper.readOptional(buf, null, helper::readVector3f); + Vector2f rot = helper.readOptional(buf, null, helper::readVector2f); + Vector3f facing = helper.readOptional(buf, null, helper::readVector3f); + Vector2f viewOffset = helper.readOptional(buf, null, helper::readVector2f); + OptionalBoolean defaultPreset = helper.readOptional(buf, OptionalBoolean.empty(), b -> OptionalBoolean.of(b.readBoolean())); + return new CameraSetInstruction(definition, ease, pos, rot, facing, viewOffset, defaultPreset); + } } \ No newline at end of file diff --git a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v712/serializer/CameraPresetsSerializer_v712.java b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v712/serializer/CameraPresetsSerializer_v712.java index 7ecb792e1..aabdbe93d 100644 --- a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v712/serializer/CameraPresetsSerializer_v712.java +++ b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v712/serializer/CameraPresetsSerializer_v712.java @@ -21,10 +21,7 @@ public void writePreset(ByteBuf buffer, BedrockCodecHelper helper, CameraPreset helper.writeOptionalNull(buffer, preset.getPos(), (buf, pos) -> buf.writeFloatLE(pos.getZ())); helper.writeOptionalNull(buffer, preset.getPitch(), ByteBuf::writeFloatLE); helper.writeOptionalNull(buffer, preset.getYaw(), ByteBuf::writeFloatLE); - helper.writeOptionalNull(buffer, preset.getViewOffset(), (buf, viewOffset) -> { - buf.writeFloatLE(viewOffset.getX()); - buf.writeFloatLE(viewOffset.getY()); - }); + helper.writeOptionalNull(buffer, preset.getViewOffset(), helper::writeVector2f); helper.writeOptionalNull(buffer, preset.getRadius(), ByteBuf::writeFloatLE); helper.writeOptionalNull(buffer, preset.getListener(), (buf, listener) -> buf.writeByte(listener.ordinal())); helper.writeOptional(buffer, OptionalBoolean::isPresent, preset.getPlayEffect(), @@ -43,7 +40,7 @@ public CameraPreset readPreset(ByteBuf buffer, BedrockCodecHelper helper) { Float pitch = helper.readOptional(buffer, null, ByteBuf::readFloatLE); Float yaw = helper.readOptional(buffer, null, ByteBuf::readFloatLE); - Vector2f viewOffset = helper.readOptional(buffer, null, buf -> Vector2f.from(buf.readFloatLE(), buf.readFloatLE())); + Vector2f viewOffset = helper.readOptional(buffer, null, helper::readVector2f); Float radius = helper.readOptional(buffer, null, ByteBuf::readFloatLE); CameraAudioListener listener = helper.readOptional(buffer, null, buf -> CameraAudioListener.values()[buf.readUnsignedByte()]); diff --git a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/data/camera/CameraSetInstruction.java b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/data/camera/CameraSetInstruction.java index b90b25833..e78c2611a 100644 --- a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/data/camera/CameraSetInstruction.java +++ b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/data/camera/CameraSetInstruction.java @@ -17,6 +17,10 @@ public class CameraSetInstruction { private Vector3f pos; private Vector2f rot; private Vector3f facing; + /** + * @since v712 + */ + private Vector2f viewOffset; private OptionalBoolean defaultPreset = OptionalBoolean.empty(); @Data