Skip to content

Commit

Permalink
Start working on 1.20.70 support
Browse files Browse the repository at this point in the history
  • Loading branch information
Alemiz112 committed Feb 26, 2024
1 parent 96ce455 commit 7d272ae
Show file tree
Hide file tree
Showing 18 changed files with 274 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,23 @@ public class ResourcePacksInfoSerializer_v618 extends ResourcePacksInfoSerialize
@Override
public void serialize(ByteBuf buffer, BedrockCodecHelper helper, ResourcePacksInfoPacket packet) {
super.serialize(buffer, helper, packet);
this.writeCDNEntries(buffer, packet, helper);
}

@Override
public void deserialize(ByteBuf buffer, BedrockCodecHelper helper, ResourcePacksInfoPacket packet) {
super.deserialize(buffer, helper, packet);
this.readCDNEntries(buffer, packet, helper);
}

protected void writeCDNEntries(ByteBuf buffer, ResourcePacksInfoPacket packet, BedrockCodecHelper helper) {
helper.writeArray(buffer, packet.getCDNEntries(), (buf, entry) -> {
helper.writeString(buf, entry.getPackId());
helper.writeString(buf, entry.getRemoteUrl());
});
}

@Override
public void deserialize(ByteBuf buffer, BedrockCodecHelper helper, ResourcePacksInfoPacket packet) {
super.deserialize(buffer, helper, packet);
protected void readCDNEntries(ByteBuf buffer, ResourcePacksInfoPacket packet, BedrockCodecHelper helper) {
helper.readArray(buffer, packet.getCDNEntries(), buf ->
new ResourcePacksInfoPacket.CDNEntry(helper.readString(buf), helper.readString(buf)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ public class Bedrock_v649 extends Bedrock_v630 {
.insert(500, SoundEvent.UNDEFINED)
.build();

// TODO: check for command params

public static final BedrockCodec CODEC = Bedrock_v630.CODEC.toBuilder()
.raknetProtocolVersion(11)
.protocolVersion(649)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package org.cloudburstmc.protocol.bedrock.codec.v662;

import org.cloudburstmc.protocol.bedrock.codec.BedrockCodec;
import org.cloudburstmc.protocol.bedrock.codec.v291.serializer.LevelEventSerializer_v291;
import org.cloudburstmc.protocol.bedrock.codec.v361.serializer.LevelEventGenericSerializer_v361;
import org.cloudburstmc.protocol.bedrock.codec.v575.BedrockCodecHelper_v575;
import org.cloudburstmc.protocol.bedrock.codec.v649.Bedrock_v649;
import org.cloudburstmc.protocol.bedrock.codec.v662.serializer.*;
import org.cloudburstmc.protocol.bedrock.data.LevelEvent;
import org.cloudburstmc.protocol.bedrock.data.LevelEventType;
import org.cloudburstmc.protocol.bedrock.data.ParticleType;
import org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.request.TextProcessingEventOrigin;
import org.cloudburstmc.protocol.bedrock.packet.*;
import org.cloudburstmc.protocol.common.util.TypeMap;

public class Bedrock_v662 extends Bedrock_v649 {

protected static final TypeMap<ParticleType> PARTICLE_TYPES = Bedrock_v649.PARTICLE_TYPES
.toBuilder()
.replace(18, ParticleType.BREEZE_WIND_EXPLOSION)
.insert(90, ParticleType.VAULT_CONNECTION)
.insert(91, ParticleType.WIND_EXPLOSION)
.build();

protected static final TypeMap<LevelEventType> LEVEL_EVENTS = Bedrock_v649.LEVEL_EVENTS.toBuilder()
.replace(LEVEL_EVENT_BLOCK + 110, LevelEvent.PARTICLE_BREEZE_WIND_EXPLOSION)
.replace(LEVEL_EVENT_BLOCK + 114, LevelEvent.PARTICLE_WIND_EXPLOSION)
.insert(LEVEL_EVENT_BLOCK + 115, LevelEvent.ALL_PLAYERS_SLEEPING)
.insert(9811, LevelEvent.ANIMATION_VAULT_ACTIVATE)
.insert(9812, LevelEvent.ANIMATION_VAULT_DEACTIVATE)
.insert(9813, LevelEvent.ANIMATION_VAULT_EJECT_ITEM)
.insert(LEVEL_EVENT_PARTICLE_TYPE, PARTICLE_TYPES)
.build();

protected static final TypeMap<TextProcessingEventOrigin> TEXT_PROCESSING_ORIGINS = Bedrock_v649.TEXT_PROCESSING_ORIGINS
.toBuilder()
.replace(14, TextProcessingEventOrigin.SERVER_FORM) // replaces PASS_THROUGH_WITHOUT_SIFT
.build();

// TODO: check for command params

public static final BedrockCodec CODEC = Bedrock_v649.CODEC.toBuilder()
.raknetProtocolVersion(11)
.protocolVersion(662)
.minecraftVersion("1.20.70")
.helper(() -> new BedrockCodecHelper_v575(ENTITY_DATA, GAME_RULE_TYPES, ITEM_STACK_REQUEST_TYPES, CONTAINER_SLOT_TYPES, PLAYER_ABILITIES, TEXT_PROCESSING_ORIGINS))
.updateSerializer(LevelEventPacket.class, new LevelEventSerializer_v291(LEVEL_EVENTS))
.updateSerializer(LevelEventGenericPacket.class, new LevelEventGenericSerializer_v361(LEVEL_EVENTS))
.updateSerializer(LecternUpdatePacket.class, LecternUpdateSerializer_v662.INSTANCE)
.updateSerializer(MobEffectPacket.class, MobEffectSerializer_v662.INSTANCE)
.updateSerializer(PlayerAuthInputPacket.class, new PlayerAuthInputSerializer_v662())
.updateSerializer(ResourcePacksInfoPacket.class, ResourcePacksInfoSerializer_v622.INSTANCE)
.updateSerializer(SetEntityMotionPacket.class, SetEntityMotionSerializer_v662.INSTANCE)
.deregisterPacket(ItemFrameDropItemPacket.class) // this packet is now deprecated
.build();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.cloudburstmc.protocol.bedrock.codec.v662.serializer;

import io.netty.buffer.ByteBuf;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.cloudburstmc.protocol.bedrock.codec.BedrockCodecHelper;
import org.cloudburstmc.protocol.bedrock.codec.v354.serializer.LecternUpdateSerializer_v354;
import org.cloudburstmc.protocol.bedrock.packet.LecternUpdatePacket;

@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class LecternUpdateSerializer_v662 extends LecternUpdateSerializer_v354 {
public static final LecternUpdateSerializer_v662 INSTANCE = new LecternUpdateSerializer_v662();

@Override
public void serialize(ByteBuf buffer, BedrockCodecHelper helper, LecternUpdatePacket packet) {
buffer.writeByte(packet.getPage());
buffer.writeByte(packet.getTotalPages());
helper.writeBlockPosition(buffer, packet.getBlockPosition());
}

@Override
public void deserialize(ByteBuf buffer, BedrockCodecHelper helper, LecternUpdatePacket packet) {
packet.setPage(buffer.readUnsignedByte());
packet.setTotalPages(buffer.readUnsignedByte());
packet.setBlockPosition(helper.readBlockPosition(buffer));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.cloudburstmc.protocol.bedrock.codec.v662.serializer;

import io.netty.buffer.ByteBuf;
import org.cloudburstmc.protocol.bedrock.codec.BedrockCodecHelper;
import org.cloudburstmc.protocol.bedrock.codec.v291.serializer.MobEffectSerializer_v291;
import org.cloudburstmc.protocol.bedrock.packet.MobEffectPacket;
import org.cloudburstmc.protocol.common.util.VarInts;

public class MobEffectSerializer_v662 extends MobEffectSerializer_v291 {
public static final MobEffectSerializer_v662 INSTANCE = new MobEffectSerializer_v662();

@Override
public void serialize(ByteBuf buffer, BedrockCodecHelper helper, MobEffectPacket packet) {
super.serialize(buffer, helper, packet);
VarInts.writeUnsignedLong(buffer, packet.getTick());
}

@Override
public void deserialize(ByteBuf buffer, BedrockCodecHelper helper, MobEffectPacket packet) {
super.deserialize(buffer, helper, packet);
packet.setTick(VarInts.readUnsignedLong(buffer));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.cloudburstmc.protocol.bedrock.codec.v662.serializer;

import io.netty.buffer.ByteBuf;
import lombok.NoArgsConstructor;
import org.cloudburstmc.protocol.bedrock.codec.BedrockCodecHelper;
import org.cloudburstmc.protocol.bedrock.codec.v527.serializer.PlayerAuthInputSerializer_v527;
import org.cloudburstmc.protocol.bedrock.data.PlayerAuthInputData;
import org.cloudburstmc.protocol.bedrock.packet.PlayerAuthInputPacket;
import org.cloudburstmc.protocol.common.util.VarInts;

/**
* Use PlayerAuthInputSerializer_v527 here because predictedVehicle was added before analogMoveVector
*/
@NoArgsConstructor
public class PlayerAuthInputSerializer_v662 extends PlayerAuthInputSerializer_v527 {

@Override
public void serialize(ByteBuf buffer, BedrockCodecHelper helper, PlayerAuthInputPacket packet) {
super.serialize(buffer, helper, packet);
if (packet.getInputData().contains(PlayerAuthInputData.IN_CLIENT_PREDICTED_IN_VEHICLE)) {
helper.writeVector2f(buffer, packet.getVehicleRotation());
VarInts.writeLong(buffer, packet.getPredictedVehicle());
}
helper.writeVector2f(buffer, packet.getAnalogMoveVector());
}

@Override
public void deserialize(ByteBuf buffer, BedrockCodecHelper helper, PlayerAuthInputPacket packet) {
super.deserialize(buffer, helper, packet);
if (packet.getInputData().contains(PlayerAuthInputData.IN_CLIENT_PREDICTED_IN_VEHICLE)) {
packet.setVehicleRotation(helper.readVector2f(buffer));
packet.setPredictedVehicle(VarInts.readLong(buffer));
}
packet.setAnalogMoveVector(helper.readVector2f(buffer));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.cloudburstmc.protocol.bedrock.codec.v662.serializer;

import io.netty.buffer.ByteBuf;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import org.cloudburstmc.protocol.bedrock.codec.BedrockCodecHelper;
import org.cloudburstmc.protocol.bedrock.codec.v618.serializer.ResourcePacksInfoSerializer_v618;
import org.cloudburstmc.protocol.bedrock.packet.ResourcePacksInfoPacket;

@RequiredArgsConstructor(access = AccessLevel.PROTECTED)
public class ResourcePacksInfoSerializer_v622 extends ResourcePacksInfoSerializer_v618 {
public static final ResourcePacksInfoSerializer_v622 INSTANCE = new ResourcePacksInfoSerializer_v622();

@Override
public void serialize(ByteBuf buffer, BedrockCodecHelper helper, ResourcePacksInfoPacket packet) {
buffer.writeBoolean(packet.isForcedToAccept());
buffer.writeBoolean(packet.isHasAddonPacks());
buffer.writeBoolean(packet.isScriptingEnabled());
buffer.writeBoolean(packet.isForcingServerPacksEnabled());
writePacks(buffer, packet.getBehaviorPackInfos(), helper, false);
writePacks(buffer, packet.getResourcePackInfos(), helper, true);
this.writeCDNEntries(buffer, packet, helper);
}

@Override
public void deserialize(ByteBuf buffer, BedrockCodecHelper helper, ResourcePacksInfoPacket packet) {
packet.setForcedToAccept(buffer.readBoolean());
packet.setHasAddonPacks(buffer.readBoolean());
packet.setScriptingEnabled(buffer.readBoolean());
packet.setForcingServerPacksEnabled(buffer.readBoolean());
readPacks(buffer, packet.getBehaviorPackInfos(), helper, false);
readPacks(buffer, packet.getResourcePackInfos(), helper, true);
this.readCDNEntries(buffer, packet, helper);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.cloudburstmc.protocol.bedrock.codec.v662.serializer;

import io.netty.buffer.ByteBuf;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.cloudburstmc.protocol.bedrock.codec.BedrockCodecHelper;
import org.cloudburstmc.protocol.bedrock.codec.v291.serializer.SetEntityMotionSerializer_v291;
import org.cloudburstmc.protocol.bedrock.packet.SetEntityMotionPacket;
import org.cloudburstmc.protocol.common.util.VarInts;

@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class SetEntityMotionSerializer_v662 extends SetEntityMotionSerializer_v291 {
public static final SetEntityMotionSerializer_v662 INSTANCE = new SetEntityMotionSerializer_v662();

@Override
public void serialize(ByteBuf buffer, BedrockCodecHelper helper, SetEntityMotionPacket packet) {
super.serialize(buffer, helper, packet);
VarInts.writeUnsignedLong(buffer, packet.getTick());
}

@Override
public void deserialize(ByteBuf buffer, BedrockCodecHelper helper, SetEntityMotionPacket packet) {
super.deserialize(buffer, helper, packet);
packet.setTick(VarInts.readUnsignedLong(buffer));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ public enum LevelEvent implements LevelEventType {
PARTICLE_TRAIL_SPAWNER_DETECTION,
PARTICLE_TRAIL_SPAWNER_SPAWNING,
PARTICLE_TRAIL_SPAWNER_EJECTING,
/**
* @since v662
*/
PARTICLE_BREEZE_WIND_EXPLOSION,

SCULK_CATALYST_BLOOM,
SCULK_CHARGE,
Expand Down Expand Up @@ -141,5 +145,11 @@ public enum LevelEvent implements LevelEventType {

ALL_PLAYERS_SLEEPING,
SLEEPING_PLAYERS,
JUMP_PREVENTED
JUMP_PREVENTED,
/**
* @since v662
*/
ANIMATION_VAULT_ACTIVATE,
ANIMATION_VAULT_DEACTIVATE,
ANIMATION_VAULT_EJECT_ITEM,
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,13 @@ public enum ParticleType implements LevelEventType {
/**
* @since v649
*/
WIND_EXPLOSION
WIND_EXPLOSION,
/**
* @since v662
*/
BREEZE_WIND_EXPLOSION,
/**
* @since v662
*/
VAULT_CONNECTION
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,13 @@ public enum PlayerAuthInputData {
/**
* @since v649
*/
IN_CLIENT_PREDICTED_IN_VEHICLE
IN_CLIENT_PREDICTED_IN_VEHICLE,
/**
* @since v662
*/
PADDLE_LEFT,
/**
* @since v662
*/
PADDLE_RIGHT
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@ public enum TextProcessingEventOrigin {
*/
SUMMON_COMMAND,
/**
* @deprecated since v662
* @since v618
*/
PASS_THROUGH_WITHOUT_SIFT
@Deprecated
PASS_THROUGH_WITHOUT_SIFT,
/**
* @since v662
*/
SERVER_FORM
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
import org.cloudburstmc.math.vector.Vector3i;
import org.cloudburstmc.protocol.common.PacketSignal;

/**
* Deprecated since v662
*/
@Deprecated
@Data
@EqualsAndHashCode(doNotUseGetters = true)
@ToString(doNotUseGetters = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ public class LecternUpdatePacket implements BedrockPacket {
private int page;
private int totalPages;
private Vector3i blockPosition;
/**
* @deprecated since v662
*/
@Deprecated
private boolean droppingBook;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ public class MobEffectPacket implements BedrockPacket {
private int amplifier;
private boolean particles;
private int duration;
/**
* @since v662
*/
private long tick;

@Override
public final PacketSignal handle(BedrockPacketHandler handler) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ public class PlayerAuthInputPacket implements BedrockPacket {
* @since 649
*/
private long predictedVehicle;
/**
* @since 662
*/
private Vector2f vehicleRotation;

@Override
public PacketSignal handle(BedrockPacketHandler handler) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ public class ResourcePacksInfoPacket implements BedrockPacket {
private final List<Entry> behaviorPackInfos = new ObjectArrayList<>();
private final List<Entry> resourcePackInfos = new ObjectArrayList<>();
private boolean forcedToAccept;
/**
* @since v662
*/
private boolean hasAddonPacks;
private boolean scriptingEnabled;
/**
* @since v448
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
public class SetEntityMotionPacket implements BedrockPacket {
private long runtimeEntityId;
private Vector3f motion;
/**
* @since v662
*/
private long tick;

@Override
public final PacketSignal handle(BedrockPacketHandler handler) {
Expand Down

0 comments on commit 7d272ae

Please sign in to comment.