Skip to content

Commit

Permalink
Fix CorrectPlayerMovePredictionPacket (#258)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaooot authored Sep 15, 2024
1 parent fd2bca9 commit 8453cc6
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public void serialize(ByteBuf buffer, BedrockCodecHelper helper, CorrectPlayerMo
helper.writeVector3f(buffer, packet.getPosition());
helper.writeVector3f(buffer, packet.getDelta());
if (packet.getPredictionType() == PredictionType.VEHICLE) {
helper.writeVector2f(buffer, packet.getVehicleRotation());
this.writeVehiclePrediction(buffer, helper, packet);
}
buffer.writeBoolean(packet.isOnGround());
VarInts.writeUnsignedLong(buffer, packet.getTick());
Expand All @@ -30,9 +30,17 @@ public void deserialize(ByteBuf buffer, BedrockCodecHelper helper, CorrectPlayer
packet.setPosition(helper.readVector3f(buffer));
packet.setDelta(helper.readVector3f(buffer));
if (packet.getPredictionType() == PredictionType.VEHICLE) {
packet.setVehicleRotation(helper.readVector2f(buffer));
this.readVehiclePrediction(buffer, helper, packet);
}
packet.setOnGround(buffer.readBoolean());
packet.setTick(VarInts.readUnsignedInt(buffer));
}

protected void writeVehiclePrediction(ByteBuf buffer, BedrockCodecHelper helper, CorrectPlayerMovePredictionPacket packet) {
helper.writeVector2f(buffer, packet.getVehicleRotation());
}

protected void readVehiclePrediction(ByteBuf buffer, BedrockCodecHelper helper, CorrectPlayerMovePredictionPacket packet) {
packet.setVehicleRotation(helper.readVector2f(buffer));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class Bedrock_v712 extends Bedrock_v686 {
.updateSerializer(CameraInstructionPacket.class, CameraInstructionSerializer_v712.INSTANCE)
.updateSerializer(CameraPresetsPacket.class, CameraPresetsSerializer_v712.INSTANCE)
.updateSerializer(ChangeDimensionPacket.class, ChangeDimensionSerializer_v712.INSTANCE)
.updateSerializer(CorrectPlayerMovePredictionPacket.class, CorrectPlayerMovePredictionSerializer_v712.INSTANCE)
.updateSerializer(DisconnectPacket.class, DisconnectSerializer_v712.INSTANCE)
.updateSerializer(EditorNetworkPacket.class, EditorNetworkSerializer_v712.INSTANCE)
.updateSerializer(InventoryContentPacket.class, InventoryContentSerializer_v712.INSTANCE)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.cloudburstmc.protocol.bedrock.codec.v712.serializer;

import io.netty.buffer.ByteBuf;
import org.cloudburstmc.protocol.bedrock.codec.BedrockCodecHelper;
import org.cloudburstmc.protocol.bedrock.codec.v671.serializer.CorrectPlayerMovePredictionSerializer_v671;
import org.cloudburstmc.protocol.bedrock.packet.CorrectPlayerMovePredictionPacket;

public class CorrectPlayerMovePredictionSerializer_v712 extends CorrectPlayerMovePredictionSerializer_v671 {
public static final CorrectPlayerMovePredictionSerializer_v712 INSTANCE = new CorrectPlayerMovePredictionSerializer_v712();

@Override
protected void writeVehiclePrediction(ByteBuf buffer, BedrockCodecHelper helper, CorrectPlayerMovePredictionPacket packet) {
super.writeVehiclePrediction(buffer, helper, packet);
helper.writeOptionalNull(buffer, packet.getVehicleAngularVelocity(), ByteBuf::writeFloatLE);
}

@Override
protected void readVehiclePrediction(ByteBuf buffer, BedrockCodecHelper helper, CorrectPlayerMovePredictionPacket packet) {
super.readVehiclePrediction(buffer, helper, packet);
packet.setVehicleAngularVelocity(helper.readOptional(buffer, null, ByteBuf::readFloatLE));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.cloudburstmc.protocol.bedrock.data;

public enum PredictionType {
VEHICLE,
PLAYER
PLAYER,
VEHICLE
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ public class CorrectPlayerMovePredictionPacket implements BedrockPacket {
*/
private Vector2f vehicleRotation;

/**
* @since v712
*/
private Float vehicleAngularVelocity;

@Override
public PacketSignal handle(BedrockPacketHandler handler) {
return handler.handle(this);
Expand Down

0 comments on commit 8453cc6

Please sign in to comment.