Skip to content

Commit

Permalink
Add missing viewOffset to CameraPresetsPacket
Browse files Browse the repository at this point in the history
  • Loading branch information
Alemiz112 committed Aug 15, 2024
1 parent d5511d2 commit 0ea350e
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()));

Expand All @@ -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())));
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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()]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0ea350e

Please sign in to comment.