Skip to content

Commit

Permalink
Add support for MCBE 1.21.40 (#263)
Browse files Browse the repository at this point in the history
Co-Authored-By: Kaooot <[email protected]>
  • Loading branch information
Alemiz112 and Kaooot committed Oct 20, 2024
1 parent 947e50f commit 43b1c87
Show file tree
Hide file tree
Showing 41 changed files with 756 additions and 51 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ Check out [EXAMPLES.md](EXAMPLES.md) for examples on how to use this library.
| Bedrock_v685 | 1.21.0 |
| Bedrock_v686 | 1.21.2 |
| Bedrock_v712 | 1.21.20 |
| Bedrock_v729 | 1.21.30 |
| Bedrock_v748 | 1.21.40 |

##### Repository:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected ResourcePacksInfoPacket.Entry readEntry(ByteBuf buffer, BedrockCodecHe
String contentKey = helper.readString(buffer);
String subPackName = helper.readString(buffer);
String contentId = helper.readString(buffer);
return new ResourcePacksInfoPacket.Entry(packId, packVersion, packSize, contentKey, subPackName, contentId, false, false, false);
return new ResourcePacksInfoPacket.Entry(packId, packVersion, packSize, contentKey, subPackName, contentId, false, false, false, null);
}

protected void writeEntry(ByteBuf buffer, BedrockCodecHelper helper, ResourcePacksInfoPacket.Entry entry, boolean resource) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ public ResourcePacksInfoPacket.Entry readEntry(ByteBuf buffer, BedrockCodecHelpe
String contentId = helper.readString(buffer);
boolean isScripting = buffer.readBoolean();
return new ResourcePacksInfoPacket.Entry(packId, packVersion, packSize, contentKey, subPackName, contentId,
isScripting, false, false);
isScripting, false, false, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ public void deserialize(ByteBuf buffer, BedrockCodecHelper helper, CorrectPlayer
packet.setPosition(helper.readVector3f(buffer));
packet.setDelta(helper.readVector3f(buffer));
packet.setOnGround(buffer.readBoolean());
packet.setTick(VarInts.readUnsignedInt(buffer));
packet.setTick(VarInts.readUnsignedLong(buffer));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ public ResourcePacksInfoPacket.Entry readEntry(ByteBuf buffer, BedrockCodecHelpe
boolean isScripting = buffer.readBoolean();
boolean raytracingCapable = resource && buffer.readBoolean();
return new ResourcePacksInfoPacket.Entry(packId, packVersion, packSize, contentKey, subPackName, contentId,
isScripting, raytracingCapable, false);
isScripting, raytracingCapable, false, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,6 @@ protected CameraSetInstruction readSetInstruction(ByteBuf buf, BedrockCodecHelpe
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);
return new CameraSetInstruction(definition, ease, pos, rot, facing, null, null, defaultPreset);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ public CameraPreset readPreset(ByteBuf buffer, BedrockCodecHelper helper) {

CameraAudioListener listener = helper.readOptional(buffer, null, buf -> CameraAudioListener.values()[buf.readUnsignedByte()]);
OptionalBoolean effects = helper.readOptional(buffer, OptionalBoolean.empty(), buf -> OptionalBoolean.of(buf.readBoolean()));
return new CameraPreset(identifier, parentPreset, pos, yaw, pitch, null, null, listener, effects, null, null, null);
return new CameraPreset(identifier, parentPreset, pos, yaw, pitch, null, null, listener, effects, null, null, null, null, null, null, null);
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
package org.cloudburstmc.protocol.bedrock.codec.v618.serializer;

import io.netty.buffer.ByteBuf;
import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import org.cloudburstmc.protocol.bedrock.codec.BedrockCodecHelper;
import org.cloudburstmc.protocol.bedrock.codec.v448.serializer.ResourcePacksInfoSerializer_v448;
import org.cloudburstmc.protocol.bedrock.packet.ResourcePacksInfoPacket;
import org.cloudburstmc.protocol.common.util.VarInts;

import java.util.HashMap;
import java.util.Map;

@RequiredArgsConstructor(access = AccessLevel.PROTECTED)
public class ResourcePacksInfoSerializer_v618 extends ResourcePacksInfoSerializer_v448 {
private static final InternalLogger log = InternalLoggerFactory.getInstance(ResourcePacksInfoSerializer_v618.class);

public static final ResourcePacksInfoSerializer_v618 INSTANCE = new ResourcePacksInfoSerializer_v618();

Expand All @@ -25,14 +32,52 @@ public void deserialize(ByteBuf buffer, BedrockCodecHelper helper, ResourcePacks
}

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());
});
ByteBuf byteBuf = buffer.alloc().ioBuffer();
try {
int size = 0;
for (ResourcePacksInfoPacket.Entry info : packet.getResourcePackInfos()) {
if (info.getCdnUrl() != null) {
helper.writeString(byteBuf, info.getPackId() + "_" + info.getPackVersion());
helper.writeString(byteBuf, info.getCdnUrl());
size++;
}
}

VarInts.writeUnsignedInt(buffer, size);
if (size > 0) {
buffer.writeBytes(byteBuf);
}
} finally {
byteBuf.release();
}
}

protected void readCDNEntries(ByteBuf buffer, ResourcePacksInfoPacket packet, BedrockCodecHelper helper) {
helper.readArray(buffer, packet.getCDNEntries(), buf ->
new ResourcePacksInfoPacket.CDNEntry(helper.readString(buf), helper.readString(buf)));
int size = VarInts.readUnsignedInt(buffer);
if (size > helper.getEncodingSettings().maxListSize()) {
throw new IllegalArgumentException("CDN entries size exceeds maximum size " + size);
}

if (size == 0 || packet.getResourcePackInfos().isEmpty()) {
return;
}

Map<String, String> cdnUrls = new HashMap<>();
for (int i = 0; i < size; i++) {
String idVersion = helper.readString(buffer);
String url = helper.readString(buffer);
cdnUrls.put(idVersion, url);
}

for (ResourcePacksInfoPacket.Entry info : packet.getResourcePackInfos()) {
String url = cdnUrls.remove(info.getPackId() + "_" + info.getPackVersion());
if (url != null) {
info.setCdnUrl(url);
}
}

if (log.isDebugEnabled() && !cdnUrls.isEmpty()) {
log.debug("Found {} CDN URLs that do not match any resource pack", cdnUrls.size());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void deserialize(ByteBuf buffer, BedrockCodecHelper helper, CorrectPlayer
this.readVehiclePrediction(buffer, helper, packet);
}
packet.setOnGround(buffer.readBoolean());
packet.setTick(VarInts.readUnsignedInt(buffer));
packet.setTick(VarInts.readUnsignedLong(buffer));
}

protected void writeVehiclePrediction(ByteBuf buffer, BedrockCodecHelper helper, CorrectPlayerMovePredictionPacket packet) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ public class UpdatePlayerGameTypeSerializer_v671 extends UpdatePlayerGameTypeSer
@Override
public void serialize(ByteBuf buffer, BedrockCodecHelper helper, UpdatePlayerGameTypePacket packet) {
super.serialize(buffer, helper, packet);
VarInts.writeUnsignedInt(buffer, packet.getTick());
VarInts.writeUnsignedLong(buffer, packet.getTick());
}

@Override
public void deserialize(ByteBuf buffer, BedrockCodecHelper helper, UpdatePlayerGameTypePacket packet) {
super.deserialize(buffer, helper, packet);
packet.setTick(VarInts.readUnsignedInt(buffer));
packet.setTick(VarInts.readUnsignedLong(buffer));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
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 {
public static final CameraInstructionSerializer_v712 INSTANCE = new CameraInstructionSerializer_v712();
Expand Down Expand Up @@ -66,6 +65,6 @@ protected CameraSetInstruction readSetInstruction(ByteBuf buf, BedrockCodecHelpe
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);
return new CameraSetInstruction(definition, ease, pos, rot, facing, viewOffset, null, defaultPreset);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ public CameraPreset readPreset(ByteBuf buffer, BedrockCodecHelper helper) {

CameraAudioListener listener = helper.readOptional(buffer, null, buf -> CameraAudioListener.values()[buf.readUnsignedByte()]);
OptionalBoolean effects = helper.readOptional(buffer, OptionalBoolean.empty(), buf -> OptionalBoolean.of(buf.readBoolean()));
return new CameraPreset(identifier, parentPreset, pos, yaw, pitch, viewOffset, radius, listener, effects, null, null, null);
return new CameraPreset(identifier, parentPreset, pos, yaw, pitch, viewOffset, radius, listener, effects, null, null, null, null, null, null, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ public ResourcePacksInfoPacket.Entry readEntry(ByteBuf buffer, BedrockCodecHelpe
boolean isAddonPack = buffer.readBoolean();
boolean raytracingCapable = resource && buffer.readBoolean();
return new ResourcePacksInfoPacket.Entry(packId, packVersion, packSize, contentKey, subPackName, contentId,
isScripting, raytracingCapable, isAddonPack);
isScripting, raytracingCapable, isAddonPack, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
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.CameraPresetsSerializer_v618;
import org.cloudburstmc.protocol.bedrock.codec.v712.serializer.CameraPresetsSerializer_v712;
import org.cloudburstmc.protocol.bedrock.data.camera.CameraAudioListener;
import org.cloudburstmc.protocol.bedrock.data.camera.CameraPreset;
Expand Down Expand Up @@ -57,6 +56,6 @@ public CameraPreset readPreset(ByteBuf buffer, BedrockCodecHelper helper) {

CameraAudioListener listener = helper.readOptional(buffer, null, buf -> CameraAudioListener.values()[buf.readUnsignedByte()]);
OptionalBoolean effects = helper.readOptional(buffer, OptionalBoolean.empty(), buf -> OptionalBoolean.of(buf.readBoolean()));
return new CameraPreset(identifier, parentPreset, pos, yaw, pitch, viewOffset, radius, listener, effects, rotationSpeed, snapToTarget, entityOffset);
return new CameraPreset(identifier, parentPreset, pos, yaw, pitch, viewOffset, radius, listener, effects, rotationSpeed, snapToTarget, entityOffset, null, null, null, null);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.cloudburstmc.protocol.bedrock.codec.v748;

import org.cloudburstmc.protocol.bedrock.codec.BedrockCodec;
import org.cloudburstmc.protocol.bedrock.codec.v729.BedrockCodecHelper_v729;
import org.cloudburstmc.protocol.bedrock.codec.v729.Bedrock_v729;
import org.cloudburstmc.protocol.bedrock.codec.v748.serializer.*;
import org.cloudburstmc.protocol.bedrock.data.PacketRecipient;
import org.cloudburstmc.protocol.bedrock.packet.*;

public class Bedrock_v748 extends Bedrock_v729 {

public static final BedrockCodec CODEC = Bedrock_v729.CODEC.toBuilder()
.raknetProtocolVersion(11)
.protocolVersion(748)
.minecraftVersion("1.21.40")
.helper(() -> new BedrockCodecHelper_v729(ENTITY_DATA, GAME_RULE_TYPES, ITEM_STACK_REQUEST_TYPES, CONTAINER_SLOT_TYPES, PLAYER_ABILITIES, TEXT_PROCESSING_ORIGINS))
.updateSerializer(CameraInstructionPacket.class, CameraInstructionSerializer_v748.INSTANCE)
.updateSerializer(CameraPresetsPacket.class, CameraPresetsSerializer_v748.INSTANCE)
.updateSerializer(CraftingDataPacket.class, CraftingDataSerializer_v748.INSTANCE)
.updateSerializer(InventoryContentPacket.class, InventoryContentSerializer_v748.INSTANCE)
.updateSerializer(InventorySlotPacket.class, InventorySlotSerializer_v748.INSTANCE)
.updateSerializer(MobEffectPacket.class, MobEffectSerializer_v748.INSTANCE)
.updateSerializer(PlayerAuthInputPacket.class, PlayerAuthInputSerializer_v748.INSTANCE)
.updateSerializer(ResourcePacksInfoPacket.class, ResourcePacksInfoSerializer_v748.INSTANCE)
.registerPacket(MovementEffectPacket::new, MovementEffectSerializer_v748.INSTANCE, 318, PacketRecipient.CLIENT)
.registerPacket(SetMovementAuthorityPacket::new, SetMovementAuthoritySerializer_v748.INSTANCE, 319, PacketRecipient.CLIENT)
.build();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package org.cloudburstmc.protocol.bedrock.codec.v748.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.v712.serializer.CameraInstructionSerializer_v712;
import org.cloudburstmc.protocol.bedrock.data.camera.CameraSetInstruction;
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;

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

@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.writeOptionalNull(buf, set.getEntityOffset(), helper::writeVector3f);

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);
Vector3f entityOffset = 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, viewOffset, entityOffset, defaultPreset);
}
}
Loading

0 comments on commit 43b1c87

Please sign in to comment.