diff --git a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/BaseBedrockCodecHelper.java b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/BaseBedrockCodecHelper.java index 37f073acb..f4479225c 100644 --- a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/BaseBedrockCodecHelper.java +++ b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/BaseBedrockCodecHelper.java @@ -6,6 +6,7 @@ import io.netty.buffer.ByteBufUtil; import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLoggerFactory; +import it.unimi.dsi.fastutil.ints.Int2ObjectFunction; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import lombok.AccessLevel; import lombok.Getter; @@ -47,6 +48,7 @@ import java.nio.charset.StandardCharsets; import java.util.Collection; import java.util.List; +import java.util.Set; import java.util.UUID; import java.util.function.*; @@ -605,4 +607,14 @@ public FullContainerName readFullContainerName(ByteBuf buffer) { public void writeFullContainerName(ByteBuf buffer, FullContainerName containerName) { throw new UnsupportedOperationException(); } + + @Override + public > void readLargeVarIntFlags(ByteBuf buffer, Set flags, Class clazz) { + throw new UnsupportedOperationException(); + } + + @Override + public > void writeLargeVarIntFlags(ByteBuf buffer, Set flags, Class clazz) { + throw new UnsupportedOperationException(); + } } diff --git a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/BedrockCodecHelper.java b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/BedrockCodecHelper.java index df0c38702..7fb2b59c2 100644 --- a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/BedrockCodecHelper.java +++ b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/BedrockCodecHelper.java @@ -1,6 +1,7 @@ package org.cloudburstmc.protocol.bedrock.codec; import io.netty.buffer.ByteBuf; +import it.unimi.dsi.fastutil.ints.Int2ObjectFunction; import org.cloudburstmc.math.vector.Vector2f; import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.math.vector.Vector3i; @@ -33,6 +34,7 @@ import java.util.Collection; import java.util.List; +import java.util.Set; import java.util.UUID; import java.util.function.*; @@ -243,4 +245,8 @@ default void writeArray(ByteBuf buffer, Collection array, TriConsumer> void writeLargeVarIntFlags(ByteBuf buffer, Set flags, Class clazz); + + > void readLargeVarIntFlags(ByteBuf buffer, Set flags, Class clazz); } diff --git a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v765/BedrockCodecHelper_v765.java b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v765/BedrockCodecHelper_v765.java new file mode 100644 index 000000000..819e307b0 --- /dev/null +++ b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v765/BedrockCodecHelper_v765.java @@ -0,0 +1,42 @@ +package org.cloudburstmc.protocol.bedrock.codec.v765; + +import io.netty.buffer.ByteBuf; +import org.cloudburstmc.protocol.bedrock.codec.EntityDataTypeMap; +import org.cloudburstmc.protocol.bedrock.codec.v729.BedrockCodecHelper_v729; +import org.cloudburstmc.protocol.bedrock.data.Ability; +import org.cloudburstmc.protocol.bedrock.data.inventory.ContainerSlotType; +import org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.request.TextProcessingEventOrigin; +import org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.request.action.ItemStackRequestActionType; +import org.cloudburstmc.protocol.common.util.TypeMap; +import org.cloudburstmc.protocol.common.util.VarInts; + +import java.math.BigInteger; +import java.util.Set; +import java.util.concurrent.ThreadLocalRandom; + +public class BedrockCodecHelper_v765 extends BedrockCodecHelper_v729 { + + public BedrockCodecHelper_v765(EntityDataTypeMap entityData, TypeMap> gameRulesTypes, TypeMap stackRequestActionTypes, + TypeMap containerSlotTypes, TypeMap abilities, TypeMap textProcessingEventOrigins) { + super(entityData, gameRulesTypes, stackRequestActionTypes, containerSlotTypes, abilities, textProcessingEventOrigins); + } + + @Override + public > void readLargeVarIntFlags(ByteBuf buffer, Set flags, Class clazz) { + BigInteger flagsInt = VarInts.readUnsignedBigVarInt(buffer); + for (T flag : clazz.getEnumConstants()) { + if (flagsInt.testBit(flag.ordinal())) { + flags.add(flag); + } + } + } + + @Override + public > void writeLargeVarIntFlags(ByteBuf buffer, Set flags, Class clazz) { + BigInteger flagsInt = new BigInteger(clazz.getEnumConstants().length, ThreadLocalRandom.current()); + for (T flag : flags) { + flagsInt = flagsInt.setBit(flag.ordinal()); + } + VarInts.writeUnsignedBigVarInt(buffer, flagsInt); + } +} diff --git a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v765/Bedrock_v765.java b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v765/Bedrock_v765.java new file mode 100644 index 000000000..2164e1d81 --- /dev/null +++ b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v765/Bedrock_v765.java @@ -0,0 +1,59 @@ +package org.cloudburstmc.protocol.bedrock.codec.v765; + +import org.cloudburstmc.protocol.bedrock.codec.BedrockCodec; +import org.cloudburstmc.protocol.bedrock.codec.v291.serializer.LevelEventSerializer_v291; +import org.cloudburstmc.protocol.bedrock.codec.v291.serializer.LevelSoundEvent1Serializer_v291; +import org.cloudburstmc.protocol.bedrock.codec.v313.serializer.LevelSoundEvent2Serializer_v313; +import org.cloudburstmc.protocol.bedrock.codec.v332.serializer.LevelSoundEventSerializer_v332; +import org.cloudburstmc.protocol.bedrock.codec.v361.serializer.LevelEventGenericSerializer_v361; +import org.cloudburstmc.protocol.bedrock.codec.v748.Bedrock_v748; +import org.cloudburstmc.protocol.bedrock.codec.v765.serializer.CameraAimAssistPresetsSerializer_v765; +import org.cloudburstmc.protocol.bedrock.codec.v765.serializer.CameraAimAssistSerializer_v765; +import org.cloudburstmc.protocol.bedrock.codec.v765.serializer.PlayerAuthInputSerializer_v765; +import org.cloudburstmc.protocol.bedrock.codec.v765.serializer.ResourcePacksInfoSerializer_v765; +import org.cloudburstmc.protocol.bedrock.data.LevelEvent; +import org.cloudburstmc.protocol.bedrock.data.LevelEventType; +import org.cloudburstmc.protocol.bedrock.data.PacketRecipient; +import org.cloudburstmc.protocol.bedrock.data.SoundEvent; +import org.cloudburstmc.protocol.bedrock.packet.*; +import org.cloudburstmc.protocol.common.util.TypeMap; + +public class Bedrock_v765 extends Bedrock_v748 { + + protected static final TypeMap SOUND_EVENTS = Bedrock_v748.SOUND_EVENTS + .toBuilder() + .insert(532, SoundEvent.IMITATE_CREAKING) + .replace(534, SoundEvent.SPONGE_ABSORB) + .insert(536, SoundEvent.BLOCK_CREAKING_HEART_TRAIL) + .insert(537, SoundEvent.CREAKING_HEART_SPAWN) + .insert(538, SoundEvent.ACTIVATE) + .insert(539, SoundEvent.DEACTIVATE) + .insert(540, SoundEvent.FREEZE) + .insert(541, SoundEvent.UNFREEZE) + .insert(542, SoundEvent.OPEN) + .insert(543, SoundEvent.OPEN_LONG) + .insert(544, SoundEvent.CLOSE) + .insert(545, SoundEvent.CLOSE_LONG) + .insert(546, SoundEvent.UNDEFINED) + .build(); + + protected static final TypeMap LEVEL_EVENTS = Bedrock_v748.LEVEL_EVENTS.toBuilder() + .insert(9816, LevelEvent.PARTICLE_CREAKING_HEART_TRIAL) + .build(); + + public static final BedrockCodec CODEC = Bedrock_v748.CODEC.toBuilder() + .raknetProtocolVersion(11) + .protocolVersion(765) + .minecraftVersion("1.21.50") + .helper(() -> new BedrockCodecHelper_v765(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(LevelSoundEvent1Packet.class, new LevelSoundEvent1Serializer_v291(SOUND_EVENTS)) + .updateSerializer(LevelSoundEvent2Packet.class, new LevelSoundEvent2Serializer_v313(SOUND_EVENTS)) + .updateSerializer(LevelSoundEventPacket.class, new LevelSoundEventSerializer_v332(SOUND_EVENTS)) + .updateSerializer(CameraAimAssistPacket.class, CameraAimAssistSerializer_v765.INSTANCE) + .updateSerializer(ResourcePacksInfoPacket.class, ResourcePacksInfoSerializer_v765.INSTANCE) + .updateSerializer(PlayerAuthInputPacket.class, PlayerAuthInputSerializer_v765.INSTANCE) + .registerPacket(CameraAimAssistPresetsPacket::new, CameraAimAssistPresetsSerializer_v765.INSTANCE, 320, PacketRecipient.CLIENT) + .build(); +} \ No newline at end of file diff --git a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v765/serializer/CameraAimAssistPresetsSerializer_v765.java b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v765/serializer/CameraAimAssistPresetsSerializer_v765.java new file mode 100644 index 000000000..3d81fe523 --- /dev/null +++ b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v765/serializer/CameraAimAssistPresetsSerializer_v765.java @@ -0,0 +1,97 @@ +package org.cloudburstmc.protocol.bedrock.codec.v765.serializer; + +import io.netty.buffer.ByteBuf; +import org.cloudburstmc.protocol.bedrock.codec.BedrockCodecHelper; +import org.cloudburstmc.protocol.bedrock.codec.BedrockPacketSerializer; +import org.cloudburstmc.protocol.bedrock.data.camera.*; +import org.cloudburstmc.protocol.bedrock.packet.CameraAimAssistPresetsPacket; + +public class CameraAimAssistPresetsSerializer_v765 implements BedrockPacketSerializer { + public static final CameraAimAssistPresetsSerializer_v765 INSTANCE = new CameraAimAssistPresetsSerializer_v765(); + + @Override + public void serialize(ByteBuf buffer, BedrockCodecHelper helper, CameraAimAssistPresetsPacket packet) { + helper.writeArray(buffer, packet.getCategories(), this::writeCategories); + helper.writeArray(buffer, packet.getPresets(), this::writePreset); + } + + @Override + public void deserialize(ByteBuf buffer, BedrockCodecHelper helper, CameraAimAssistPresetsPacket packet) { + helper.readArray(buffer, packet.getCategories(), this::readCategories); + helper.readArray(buffer, packet.getPresets(), this::readPreset); + } + + protected void writeCategories(ByteBuf buffer, BedrockCodecHelper helper, CameraAimAssistCategories categories) { + helper.writeString(buffer, categories.getIdentifier()); + helper.writeArray(buffer, categories.getCategories(), this::writeCategory); + } + + protected CameraAimAssistCategories readCategories(ByteBuf buffer, BedrockCodecHelper helper) { + final CameraAimAssistCategories categories = new CameraAimAssistCategories(); + categories.setIdentifier(helper.readString(buffer)); + helper.readArray(buffer, categories.getCategories(), this::readCategory); + return categories; + } + + protected void writeCategory(ByteBuf buffer, BedrockCodecHelper helper, CameraAimAssistCategory category) { + helper.writeString(buffer, category.getName()); + + helper.writeArray(buffer, category.getEntityPriorities(), this::writePriority); + helper.writeArray(buffer, category.getBlockPriorities(), this::writePriority); + + helper.writeOptionalNull(buffer, category.getEntityDefaultPriorities(), ByteBuf::writeIntLE); + helper.writeOptionalNull(buffer, category.getBlockDefaultPriorities(), ByteBuf::writeIntLE); + } + + protected CameraAimAssistCategory readCategory(ByteBuf buffer, BedrockCodecHelper helper) { + CameraAimAssistCategory category = new CameraAimAssistCategory(); + category.setName(helper.readString(buffer)); + + helper.readArray(buffer, category.getEntityPriorities(), this::readPriority); + helper.readArray(buffer, category.getBlockPriorities(), this::readPriority); + + category.setEntityDefaultPriorities(helper.readOptional(buffer, null, ByteBuf::readIntLE)); + category.setBlockDefaultPriorities(helper.readOptional(buffer, null, ByteBuf::readIntLE)); + return category; + } + + protected void writePreset(ByteBuf buffer, BedrockCodecHelper helper, CameraAimAssistPresetDefinition preset) { + helper.writeString(buffer, preset.getIdentifier()); + helper.writeString(buffer, preset.getCategories()); + helper.writeArray(buffer, preset.getExclusionList(), helper::writeString); + helper.writeArray(buffer, preset.getLiquidTargetingList(), helper::writeString); + helper.writeArray(buffer, preset.getItemSettings(), this::writeItemSetting); + helper.writeOptionalNull(buffer, preset.getDefaultItemSettings(), helper::writeString); + helper.writeOptionalNull(buffer, preset.getHandSettings(), helper::writeString); + } + + protected CameraAimAssistPresetDefinition readPreset(ByteBuf buffer, BedrockCodecHelper helper) { + final CameraAimAssistPresetDefinition preset = new CameraAimAssistPresetDefinition(); + preset.setIdentifier(helper.readString(buffer)); + preset.setCategories(helper.readString(buffer)); + helper.readArray(buffer, preset.getExclusionList(), helper::readString); + helper.readArray(buffer, preset.getLiquidTargetingList(), helper::readString); + helper.readArray(buffer, preset.getItemSettings(), this::readItemSetting); + preset.setDefaultItemSettings(helper.readOptional(buffer, null, helper::readString)); + preset.setHandSettings(helper.readOptional(buffer, null, helper::readString)); + return preset; + } + + private void writePriority(ByteBuf buffer, BedrockCodecHelper helper, CameraAimAssistPriority priority) { + helper.writeString(buffer, priority.getName()); + buffer.writeIntLE(priority.getPriority()); + } + + private CameraAimAssistPriority readPriority(ByteBuf buffer, BedrockCodecHelper helper) { + return new CameraAimAssistPriority(helper.readString(buffer), buffer.readIntLE()); + } + + private void writeItemSetting(ByteBuf buffer, BedrockCodecHelper helper, CameraAimAssistItemSettings settings) { + helper.writeString(buffer, settings.getItemId()); + helper.writeString(buffer, settings.getCategory()); + } + + private CameraAimAssistItemSettings readItemSetting(ByteBuf buffer, BedrockCodecHelper helper) { + return new CameraAimAssistItemSettings(helper.readString(buffer), helper.readString(buffer)); + } +} \ No newline at end of file diff --git a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v765/serializer/CameraAimAssistSerializer_v765.java b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v765/serializer/CameraAimAssistSerializer_v765.java new file mode 100644 index 000000000..81eda9323 --- /dev/null +++ b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v765/serializer/CameraAimAssistSerializer_v765.java @@ -0,0 +1,22 @@ +package org.cloudburstmc.protocol.bedrock.codec.v765.serializer; + +import io.netty.buffer.ByteBuf; +import org.cloudburstmc.protocol.bedrock.codec.BedrockCodecHelper; +import org.cloudburstmc.protocol.bedrock.codec.v729.serializer.CameraAimAssistSerializer_v729; +import org.cloudburstmc.protocol.bedrock.packet.CameraAimAssistPacket; + +public class CameraAimAssistSerializer_v765 extends CameraAimAssistSerializer_v729 { + public static final CameraAimAssistSerializer_v765 INSTANCE = new CameraAimAssistSerializer_v765(); + + @Override + public void serialize(ByteBuf buffer, BedrockCodecHelper helper, CameraAimAssistPacket packet) { + helper.writeString(buffer, packet.getPresetId()); + super.serialize(buffer, helper, packet); + } + + @Override + public void deserialize(ByteBuf buffer, BedrockCodecHelper helper, CameraAimAssistPacket packet) { + packet.setPresetId(helper.readString(buffer)); + super.deserialize(buffer, helper, packet); + } +} \ No newline at end of file diff --git a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v765/serializer/PlayerAuthInputSerializer_v765.java b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v765/serializer/PlayerAuthInputSerializer_v765.java new file mode 100644 index 000000000..5bfb81498 --- /dev/null +++ b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v765/serializer/PlayerAuthInputSerializer_v765.java @@ -0,0 +1,89 @@ +package org.cloudburstmc.protocol.bedrock.codec.v765.serializer; + +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.RequiredArgsConstructor; +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.v748.serializer.PlayerAuthInputSerializer_v748; +import org.cloudburstmc.protocol.bedrock.data.PlayerAuthInputData; +import org.cloudburstmc.protocol.bedrock.data.PlayerBlockActionData; +import org.cloudburstmc.protocol.bedrock.packet.PlayerAuthInputPacket; +import org.cloudburstmc.protocol.common.util.VarInts; + +@RequiredArgsConstructor(access = AccessLevel.PROTECTED) +public class PlayerAuthInputSerializer_v765 extends PlayerAuthInputSerializer_v748 { + + public static final PlayerAuthInputSerializer_v765 INSTANCE = new PlayerAuthInputSerializer_v765(); + + @Override + public void serialize(ByteBuf buffer, BedrockCodecHelper helper, PlayerAuthInputPacket packet) { + Vector3f rotation = packet.getRotation(); + buffer.writeFloatLE(rotation.getX()); + buffer.writeFloatLE(rotation.getY()); + helper.writeVector3f(buffer, packet.getPosition()); + buffer.writeFloatLE(packet.getMotion().getX()); + buffer.writeFloatLE(packet.getMotion().getY()); + buffer.writeFloatLE(rotation.getZ()); + helper.writeLargeVarIntFlags(buffer, packet.getInputData(), PlayerAuthInputData.class); + VarInts.writeUnsignedInt(buffer, packet.getInputMode().ordinal()); + VarInts.writeUnsignedInt(buffer, packet.getPlayMode().ordinal()); + writeInteractionModel(buffer, helper, packet); + helper.writeVector2f(buffer, packet.getInteractRotation()); + VarInts.writeUnsignedLong(buffer, packet.getTick()); + helper.writeVector3f(buffer, packet.getDelta()); + if (packet.getInputData().contains(PlayerAuthInputData.PERFORM_ITEM_INTERACTION)) { + this.writeItemUseTransaction(buffer, helper, packet.getItemUseTransaction()); + } + if (packet.getInputData().contains(PlayerAuthInputData.PERFORM_ITEM_STACK_REQUEST)) { + helper.writeItemStackRequest(buffer, packet.getItemStackRequest()); + } + if (packet.getInputData().contains(PlayerAuthInputData.PERFORM_BLOCK_ACTIONS)) { + VarInts.writeInt(buffer, packet.getPlayerActions().size()); + for (PlayerBlockActionData actionData : packet.getPlayerActions()) { + writePlayerBlockActionData(buffer, helper, actionData); + } + } + 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()); + helper.writeVector3f(buffer, packet.getCameraOrientation()); + helper.writeVector2f(buffer, packet.getRawMoveVector()); + } + + @Override + public void deserialize(ByteBuf buffer, BedrockCodecHelper helper, PlayerAuthInputPacket packet) { + float x = buffer.readFloatLE(); + float y = buffer.readFloatLE(); + packet.setPosition(helper.readVector3f(buffer)); + packet.setMotion(Vector2f.from(buffer.readFloatLE(), buffer.readFloatLE())); + float z = buffer.readFloatLE(); + packet.setRotation(Vector3f.from(x, y, z)); + helper.readLargeVarIntFlags(buffer, packet.getInputData(), PlayerAuthInputData.class); + packet.setInputMode(INPUT_MODES[VarInts.readUnsignedInt(buffer)]); + packet.setPlayMode(CLIENT_PLAY_MODES[VarInts.readUnsignedInt(buffer)]); + readInteractionModel(buffer, helper, packet); + packet.setInteractRotation(helper.readVector2f(buffer)); + packet.setTick(VarInts.readUnsignedLong(buffer)); + packet.setDelta(helper.readVector3f(buffer)); + if (packet.getInputData().contains(PlayerAuthInputData.PERFORM_ITEM_INTERACTION)) { + packet.setItemUseTransaction(this.readItemUseTransaction(buffer, helper)); + } + if (packet.getInputData().contains(PlayerAuthInputData.PERFORM_ITEM_STACK_REQUEST)) { + packet.setItemStackRequest(helper.readItemStackRequest(buffer)); + } + if (packet.getInputData().contains(PlayerAuthInputData.PERFORM_BLOCK_ACTIONS)) { + helper.readArray(buffer, packet.getPlayerActions(), VarInts::readInt, this::readPlayerBlockActionData, 32); // 32 is more than enough + } + 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)); + packet.setCameraOrientation(helper.readVector3f(buffer)); + packet.setRawMoveVector(helper.readVector2f(buffer)); + } +} diff --git a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v765/serializer/ResourcePacksInfoSerializer_v765.java b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v765/serializer/ResourcePacksInfoSerializer_v765.java new file mode 100644 index 000000000..b5279bdc5 --- /dev/null +++ b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/codec/v765/serializer/ResourcePacksInfoSerializer_v765.java @@ -0,0 +1,30 @@ +package org.cloudburstmc.protocol.bedrock.codec.v765.serializer; + +import io.netty.buffer.ByteBuf; +import org.cloudburstmc.protocol.bedrock.codec.BedrockCodecHelper; +import org.cloudburstmc.protocol.bedrock.codec.v748.serializer.ResourcePacksInfoSerializer_v748; +import org.cloudburstmc.protocol.bedrock.packet.ResourcePacksInfoPacket; + +public class ResourcePacksInfoSerializer_v765 extends ResourcePacksInfoSerializer_v748 { + public static final ResourcePacksInfoSerializer_v765 INSTANCE = new ResourcePacksInfoSerializer_v765(); + + @Override + public void serialize(ByteBuf buffer, BedrockCodecHelper helper, ResourcePacksInfoPacket packet) { + buffer.writeBoolean(packet.isForcedToAccept()); + buffer.writeBoolean(packet.isHasAddonPacks()); + buffer.writeBoolean(packet.isScriptingEnabled()); + helper.writeUuid(buffer, packet.getWorldTemplateId()); + helper.writeString(buffer, packet.getWorldTemplateVersion()); + writePacks(buffer, packet.getResourcePackInfos(), helper, true); + } + + @Override + public void deserialize(ByteBuf buffer, BedrockCodecHelper helper, ResourcePacksInfoPacket packet) { + packet.setForcedToAccept(buffer.readBoolean()); + packet.setHasAddonPacks(buffer.readBoolean()); + packet.setScriptingEnabled(buffer.readBoolean()); + packet.setWorldTemplateId(helper.readUuid(buffer)); + packet.setWorldTemplateVersion(helper.readString(buffer)); + readPacks(buffer, packet.getResourcePackInfos(), helper, true); + } +} \ No newline at end of file diff --git a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/data/LevelEvent.java b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/data/LevelEvent.java index c44aef10b..ad0cb702c 100644 --- a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/data/LevelEvent.java +++ b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/data/LevelEvent.java @@ -111,6 +111,10 @@ public enum LevelEvent implements LevelEventType { PARTICLE_TRIAL_SPAWNER_DETECTION_CHARGED, PARTICLE_TRIAL_SPAWNER_BECOME_CHARGED, PARTICLE_SMASH_ATTACK_GROUND_DUST, + /** + * @since v765 + */ + PARTICLE_CREAKING_HEART_TRIAL, SCULK_CATALYST_BLOOM, SCULK_CHARGE, diff --git a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/data/PlayerAuthInputData.java b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/data/PlayerAuthInputData.java index 9680b9041..6179e4fbe 100644 --- a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/data/PlayerAuthInputData.java +++ b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/data/PlayerAuthInputData.java @@ -124,5 +124,29 @@ public enum PlayerAuthInputData { /** * @since v748 */ - STOP_SPIN_ATTACK + STOP_SPIN_ATTACK, + /** + * @since v765 + */ + JUMP_RELEASED_RAW, + /** + * @since v765 + */ + JUMP_PRESSED_RAW, + /** + * @since v765 + */ + JUMP_CURRENT_RAW, + /** + * @since v765 + */ + SNEAK_RELEASED_RAW, + /** + * @since v765 + */ + SNEAK_PRESSED_RAW, + /** + * @since v765 + */ + SNEAK_CURRENT_RAW, } diff --git a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/data/SoundEvent.java b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/data/SoundEvent.java index 86fb4b6e3..68d8e6af7 100644 --- a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/data/SoundEvent.java +++ b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/data/SoundEvent.java @@ -750,6 +750,54 @@ public enum SoundEvent { * @since v729 */ BUNDLE_INSERT_FAILED, + /** + * @since v765 + */ + IMITATE_CREAKING, + /** + * @since v765 + */ + SPONGE_ABSORB, + /** + * @since v765 + */ + BLOCK_CREAKING_HEART_TRAIL, + /** + * @since v765 + */ + CREAKING_HEART_SPAWN, + /** + * @since v765 + */ + ACTIVATE, + /** + * @since v765 + */ + DEACTIVATE, + /** + * @since v765 + */ + FREEZE, + /** + * @since v765 + */ + UNFREEZE, + /** + * @since v765 + */ + OPEN, + /** + * @since v765 + */ + OPEN_LONG, + /** + * @since v765 + */ + CLOSE, + /** + * @since v765 + */ + CLOSE_LONG, UNDEFINED } diff --git a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/data/camera/CameraAimAssistCategories.java b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/data/camera/CameraAimAssistCategories.java new file mode 100644 index 000000000..a41e89e78 --- /dev/null +++ b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/data/camera/CameraAimAssistCategories.java @@ -0,0 +1,12 @@ +package org.cloudburstmc.protocol.bedrock.data.camera; + +import it.unimi.dsi.fastutil.objects.ObjectArrayList; +import lombok.Data; + +import java.util.List; + +@Data +public class CameraAimAssistCategories { + private String identifier; + private final List categories = new ObjectArrayList<>(); +} \ No newline at end of file diff --git a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/data/camera/CameraAimAssistCategory.java b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/data/camera/CameraAimAssistCategory.java new file mode 100644 index 000000000..2b52a3c33 --- /dev/null +++ b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/data/camera/CameraAimAssistCategory.java @@ -0,0 +1,16 @@ +package org.cloudburstmc.protocol.bedrock.data.camera; + +import it.unimi.dsi.fastutil.objects.ObjectArrayList; +import lombok.Data; + +import java.util.ArrayList; +import java.util.List; + +@Data +public class CameraAimAssistCategory { + private String name; + private List entityPriorities = new ObjectArrayList<>(); + private List blockPriorities = new ArrayList<>(); + private Integer entityDefaultPriorities; + private Integer blockDefaultPriorities; +} \ No newline at end of file diff --git a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/data/camera/CameraAimAssistItemSettings.java b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/data/camera/CameraAimAssistItemSettings.java new file mode 100644 index 000000000..fc216feb8 --- /dev/null +++ b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/data/camera/CameraAimAssistItemSettings.java @@ -0,0 +1,11 @@ +package org.cloudburstmc.protocol.bedrock.data.camera; + +import lombok.AllArgsConstructor; +import lombok.Data; + +@Data +@AllArgsConstructor +public class CameraAimAssistItemSettings { + private final String itemId; + private final String category; +} diff --git a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/data/camera/CameraAimAssistPresetDefinition.java b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/data/camera/CameraAimAssistPresetDefinition.java new file mode 100644 index 000000000..a542ceaa6 --- /dev/null +++ b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/data/camera/CameraAimAssistPresetDefinition.java @@ -0,0 +1,17 @@ +package org.cloudburstmc.protocol.bedrock.data.camera; + +import it.unimi.dsi.fastutil.objects.ObjectArrayList; +import lombok.Data; + +import java.util.List; + +@Data +public class CameraAimAssistPresetDefinition { + private String identifier; + private String categories; + private final List exclusionList = new ObjectArrayList<>(); + private final List liquidTargetingList = new ObjectArrayList<>(); + private final List itemSettings = new ObjectArrayList<>(); + private String defaultItemSettings; + private String handSettings; +} \ No newline at end of file diff --git a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/data/camera/CameraAimAssistPriority.java b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/data/camera/CameraAimAssistPriority.java new file mode 100644 index 000000000..4bb5687c0 --- /dev/null +++ b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/data/camera/CameraAimAssistPriority.java @@ -0,0 +1,11 @@ +package org.cloudburstmc.protocol.bedrock.data.camera; + +import lombok.Data; +import lombok.RequiredArgsConstructor; + +@Data +@RequiredArgsConstructor +public class CameraAimAssistPriority { + private final String name; + private final int priority; +} diff --git a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/packet/BedrockPacketHandler.java b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/packet/BedrockPacketHandler.java index 536fa7074..f4937e10a 100644 --- a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/packet/BedrockPacketHandler.java +++ b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/packet/BedrockPacketHandler.java @@ -875,4 +875,8 @@ default PacketSignal handle(MovementEffectPacket packet) { default PacketSignal handle(SetMovementAuthorityPacket packet) { return PacketSignal.UNHANDLED; } + + default PacketSignal handle(CameraAimAssistPresetsPacket packet) { + return PacketSignal.UNHANDLED; + } } diff --git a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/packet/BedrockPacketType.java b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/packet/BedrockPacketType.java index d6360a15d..9fc0d949b 100644 --- a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/packet/BedrockPacketType.java +++ b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/packet/BedrockPacketType.java @@ -217,5 +217,6 @@ public enum BedrockPacketType { CAMERA_AIM_ASSIST, CONTAINER_REGISTRY_CLEANUP, MOVEMENT_EFFECT, - SET_MOVEMENT_AUTHORITY + SET_MOVEMENT_AUTHORITY, + CAMERA_AIM_ASSIST_PRESETS } diff --git a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/packet/CameraAimAssistPacket.java b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/packet/CameraAimAssistPacket.java index dc0f013d4..9a323bcf9 100644 --- a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/packet/CameraAimAssistPacket.java +++ b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/packet/CameraAimAssistPacket.java @@ -14,6 +14,10 @@ public class CameraAimAssistPacket implements BedrockPacket { private float distance; private TargetMode targetMode; private Action action; + /** + * @since v765 + */ + private String presetId; @Override public PacketSignal handle(BedrockPacketHandler handler) { diff --git a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/packet/CameraAimAssistPresetsPacket.java b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/packet/CameraAimAssistPresetsPacket.java new file mode 100644 index 000000000..e1d894ad3 --- /dev/null +++ b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/packet/CameraAimAssistPresetsPacket.java @@ -0,0 +1,38 @@ +package org.cloudburstmc.protocol.bedrock.packet; + +import it.unimi.dsi.fastutil.objects.ObjectArrayList; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; +import org.cloudburstmc.protocol.bedrock.data.camera.CameraAimAssistCategories; +import org.cloudburstmc.protocol.bedrock.data.camera.CameraAimAssistPresetDefinition; +import org.cloudburstmc.protocol.common.PacketSignal; + +import java.util.List; + +@Data +@EqualsAndHashCode(doNotUseGetters = true) +@ToString(doNotUseGetters = true) +public class CameraAimAssistPresetsPacket implements BedrockPacket { + private final List categories = new ObjectArrayList<>(); + private final List presets = new ObjectArrayList<>(); + + @Override + public PacketSignal handle(BedrockPacketHandler handler) { + return handler.handle(this); + } + + @Override + public BedrockPacketType getPacketType() { + return BedrockPacketType.CAMERA_AIM_ASSIST_PRESETS; + } + + @Override + public CameraAimAssistPresetsPacket clone() { + try { + return (CameraAimAssistPresetsPacket) super.clone(); + } catch (CloneNotSupportedException e) { + throw new AssertionError(e); + } + } +} \ No newline at end of file diff --git a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/packet/PlayerAuthInputPacket.java b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/packet/PlayerAuthInputPacket.java index 0de94b0c9..ae7d5f5ed 100644 --- a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/packet/PlayerAuthInputPacket.java +++ b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/packet/PlayerAuthInputPacket.java @@ -73,6 +73,10 @@ public class PlayerAuthInputPacket implements BedrockPacket { * @since v748 */ private Vector3f cameraOrientation; + /** + * @since v765 + */ + private Vector2f rawMoveVector; @Override public PacketSignal handle(BedrockPacketHandler handler) { diff --git a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/packet/ResourcePacksInfoPacket.java b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/packet/ResourcePacksInfoPacket.java index 7fb67d2a6..510e9516c 100644 --- a/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/packet/ResourcePacksInfoPacket.java +++ b/bedrock-codec/src/main/java/org/cloudburstmc/protocol/bedrock/packet/ResourcePacksInfoPacket.java @@ -5,6 +5,7 @@ import org.cloudburstmc.protocol.common.PacketSignal; import java.util.List; +import java.util.UUID; @Data @EqualsAndHashCode(doNotUseGetters = true) @@ -26,6 +27,14 @@ public class ResourcePacksInfoPacket implements BedrockPacket { * @deprecated since v729 */ private boolean forcingServerPacksEnabled; + /** + * @since v765 + */ + private UUID worldTemplateId; + /** + * @since v765 + */ + private String worldTemplateVersion; @Override public final PacketSignal handle(BedrockPacketHandler handler) { diff --git a/common/src/main/java/org/cloudburstmc/protocol/common/util/VarInts.java b/common/src/main/java/org/cloudburstmc/protocol/common/util/VarInts.java index 3c2effebc..828191935 100644 --- a/common/src/main/java/org/cloudburstmc/protocol/common/util/VarInts.java +++ b/common/src/main/java/org/cloudburstmc/protocol/common/util/VarInts.java @@ -1,11 +1,18 @@ package org.cloudburstmc.protocol.common.util; import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBufAllocator; +import io.netty.buffer.ByteBufUtil; import lombok.experimental.UtilityClass; +import java.math.BigInteger; + @UtilityClass public class VarInts { + private static final BigInteger BIG_INTEGER_7F = BigInteger.valueOf(0x7f); + private static final BigInteger BIG_INTEGER_80 = BigInteger.valueOf(0x80); + public static void writeInt(ByteBuf buffer, int value) { encode(buffer, ((value << 1) ^ (value >> 31)) & 0xFFFFFFFFL); } @@ -149,4 +156,29 @@ private static long decode(ByteBuf buf, int maxBits) { } throw new ArithmeticException("VarInt was too large"); } + + public static void writeUnsignedBigVarInt(ByteBuf buffer, BigInteger value) { + while (true) { + BigInteger bits = value.and(BIG_INTEGER_7F); + value = value.shiftRight(7); + if (value.compareTo(BigInteger.ZERO) == 0) { + buffer.writeByte(bits.intValue()); + return; + } + buffer.writeByte(bits.or(BIG_INTEGER_80).intValue()); + } + } + + public static BigInteger readUnsignedBigVarInt(ByteBuf buffer) { + BigInteger value = BigInteger.ZERO; + int shift = 0; + while (true) { + byte b = buffer.readByte(); + value = value.or(BigInteger.valueOf(b & 0x7F).shiftLeft(shift)); + if ((b & 0x80) == 0) { + return value; + } + shift += 7; + } + } }