This commit is contained in:
basaigh 2024-11-27 00:16:41 +00:00
parent 2e07e5b805
commit 38921fd992
9 changed files with 75 additions and 40 deletions

View file

@ -157,6 +157,7 @@ import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.Serverbound
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.ServerboundConfigurationAcknowledgedPacket; import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.ServerboundConfigurationAcknowledgedPacket;
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.ServerboundDebugSampleSubscriptionPacket; import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.ServerboundDebugSampleSubscriptionPacket;
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.ServerboundLockDifficultyPacket; import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.ServerboundLockDifficultyPacket;
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.ServerboundPlayerLoadedPacket;
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.inventory.ServerboundContainerButtonClickPacket; import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.inventory.ServerboundContainerButtonClickPacket;
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.inventory.ServerboundContainerClickPacket; import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.inventory.ServerboundContainerClickPacket;
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.inventory.ServerboundContainerClosePacket; import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.inventory.ServerboundContainerClosePacket;
@ -215,9 +216,9 @@ import org.geysermc.mcprotocollib.protocol.packet.status.serverbound.Serverbound
public class MinecraftCodec { public class MinecraftCodec {
public static final PacketCodec CODEC = PacketCodec.builder() public static final PacketCodec CODEC = PacketCodec.builder()
.protocolVersion((1 << 30) | 220) .protocolVersion((1 << 30) | 221)
.helper(MinecraftCodecHelper::new) .helper(MinecraftCodecHelper::new)
.minecraftVersion("24w44a") .minecraftVersion("24w45a")
.state(ProtocolState.HANDSHAKE, MinecraftPacketRegistry.builder() .state(ProtocolState.HANDSHAKE, MinecraftPacketRegistry.builder()
.registerServerboundPacket(ClientIntentionPacket.class, ClientIntentionPacket::new) .registerServerboundPacket(ClientIntentionPacket.class, ClientIntentionPacket::new)
) )
@ -438,6 +439,7 @@ public class MinecraftCodec {
.registerServerboundPacket(ServerboundPlayerActionPacket.class, ServerboundPlayerActionPacket::new) .registerServerboundPacket(ServerboundPlayerActionPacket.class, ServerboundPlayerActionPacket::new)
.registerServerboundPacket(ServerboundPlayerCommandPacket.class, ServerboundPlayerCommandPacket::new) .registerServerboundPacket(ServerboundPlayerCommandPacket.class, ServerboundPlayerCommandPacket::new)
.registerServerboundPacket(ServerboundPlayerInputPacket.class, ServerboundPlayerInputPacket::new) .registerServerboundPacket(ServerboundPlayerInputPacket.class, ServerboundPlayerInputPacket::new)
.registerServerboundPacket(ServerboundPlayerLoadedPacket.class, (buf, helper) -> ServerboundPlayerLoadedPacket.INSTANCE)
.registerServerboundPacket(ServerboundPongPacket.class, ServerboundPongPacket::new) .registerServerboundPacket(ServerboundPongPacket.class, ServerboundPongPacket::new)
.registerServerboundPacket(ServerboundRecipeBookChangeSettingsPacket.class, ServerboundRecipeBookChangeSettingsPacket::new) .registerServerboundPacket(ServerboundRecipeBookChangeSettingsPacket.class, ServerboundRecipeBookChangeSettingsPacket::new)
.registerServerboundPacket(ServerboundRecipeBookSeenRecipePacket.class, ServerboundRecipeBookSeenRecipePacket::new) .registerServerboundPacket(ServerboundRecipeBookSeenRecipePacket.class, ServerboundRecipeBookSeenRecipePacket::new)

View file

@ -7,8 +7,7 @@ import org.geysermc.mcprotocollib.protocol.data.game.Holder;
import java.util.Map; import java.util.Map;
public record ArmorTrim(Holder<TrimMaterial> material, Holder<TrimPattern> pattern, boolean showInTooltip) { public record ArmorTrim(Holder<TrimMaterial> material, Holder<TrimPattern> pattern, boolean showInTooltip) {
public record TrimMaterial(String assetName, int ingredientId, float itemModelIndex, public record TrimMaterial(String assetName, int ingredientId, Map<Key, String> overrideArmorAssets, Component description) {
Map<Key, String> overrideArmorMaterials, Component description) {
} }
public record TrimPattern(Key assetId, int templateItemId, Component description, boolean decal) { public record TrimPattern(Key assetId, int templateItemId, Component description, boolean decal) {

View file

@ -0,0 +1,6 @@
package org.geysermc.mcprotocollib.protocol.data.game.item.component;
import java.util.List;
public record CustomModelData(List<Float> floats, List<Boolean> flags, List<String> strings, List<Integer> colors) {
}

View file

@ -35,7 +35,7 @@ public class DataComponentType<T> {
public static final DataComponentType<AdventureModePredicate> CAN_PLACE_ON = new DataComponentType<>(ItemCodecHelper::readAdventureModePredicate, ItemCodecHelper::writeAdventureModePredicate, ObjectDataComponent::new); public static final DataComponentType<AdventureModePredicate> CAN_PLACE_ON = new DataComponentType<>(ItemCodecHelper::readAdventureModePredicate, ItemCodecHelper::writeAdventureModePredicate, ObjectDataComponent::new);
public static final DataComponentType<AdventureModePredicate> CAN_BREAK = new DataComponentType<>(ItemCodecHelper::readAdventureModePredicate, ItemCodecHelper::writeAdventureModePredicate, ObjectDataComponent::new); public static final DataComponentType<AdventureModePredicate> CAN_BREAK = new DataComponentType<>(ItemCodecHelper::readAdventureModePredicate, ItemCodecHelper::writeAdventureModePredicate, ObjectDataComponent::new);
public static final DataComponentType<ItemAttributeModifiers> ATTRIBUTE_MODIFIERS = new DataComponentType<>(ItemCodecHelper::readItemAttributeModifiers, ItemCodecHelper::writeItemAttributeModifiers, ObjectDataComponent::new); public static final DataComponentType<ItemAttributeModifiers> ATTRIBUTE_MODIFIERS = new DataComponentType<>(ItemCodecHelper::readItemAttributeModifiers, ItemCodecHelper::writeItemAttributeModifiers, ObjectDataComponent::new);
public static final IntComponentType CUSTOM_MODEL_DATA = new IntComponentType(ItemCodecHelper::readVarInt, ItemCodecHelper::writeVarInt, IntDataComponent::new); public static final DataComponentType<CustomModelData> CUSTOM_MODEL_DATA = new DataComponentType<>(ItemCodecHelper::readCustomModelData, ItemCodecHelper::writeCustomModelData, ObjectDataComponent::new);
public static final DataComponentType<Unit> HIDE_ADDITIONAL_TOOLTIP = new DataComponentType<>(unitReader(), unitWriter(), ObjectDataComponent::new); public static final DataComponentType<Unit> HIDE_ADDITIONAL_TOOLTIP = new DataComponentType<>(unitReader(), unitWriter(), ObjectDataComponent::new);
public static final DataComponentType<Unit> HIDE_TOOLTIP = new DataComponentType<>(unitReader(), unitWriter(), ObjectDataComponent::new); public static final DataComponentType<Unit> HIDE_TOOLTIP = new DataComponentType<>(unitReader(), unitWriter(), ObjectDataComponent::new);
public static final IntComponentType REPAIR_COST = new IntComponentType(ItemCodecHelper::readVarInt, ItemCodecHelper::writeVarInt, IntDataComponent::new); public static final IntComponentType REPAIR_COST = new IntComponentType(ItemCodecHelper::readVarInt, ItemCodecHelper::writeVarInt, IntDataComponent::new);

View file

@ -193,6 +193,21 @@ public class ItemCodecHelper extends MinecraftCodecHelper {
buf.writeBoolean(modifiers.isShowInTooltip()); buf.writeBoolean(modifiers.isShowInTooltip());
} }
public CustomModelData readCustomModelData(ByteBuf buf) {
List<Float> floats = this.readList(buf, ByteBuf::readFloat);
List<Boolean> flags = this.readList(buf, ByteBuf::readBoolean);
List<String> strings = this.readList(buf, this::readString);
List<Integer> colors = this.readList(buf, ByteBuf::readInt);
return new CustomModelData(floats, flags, strings, colors);
}
public void writeCustomModelData(ByteBuf buf, CustomModelData modelData) {
this.writeList(buf, modelData.floats(), ByteBuf::writeFloat);
this.writeList(buf, modelData.flags(), ByteBuf::writeBoolean);
this.writeList(buf, modelData.strings(), this::writeString);
this.writeList(buf, modelData.colors(), ByteBuf::writeInt);
}
public DyedItemColor readDyedItemColor(ByteBuf buf) { public DyedItemColor readDyedItemColor(ByteBuf buf) {
return new DyedItemColor(buf.readInt(), buf.readBoolean()); return new DyedItemColor(buf.readInt(), buf.readBoolean());
} }
@ -394,7 +409,6 @@ public class ItemCodecHelper extends MinecraftCodecHelper {
public ArmorTrim.TrimMaterial readTrimMaterial(ByteBuf buf) { public ArmorTrim.TrimMaterial readTrimMaterial(ByteBuf buf) {
String assetName = this.readString(buf); String assetName = this.readString(buf);
int ingredientId = this.readVarInt(buf); int ingredientId = this.readVarInt(buf);
float itemModelIndex = buf.readFloat();
Map<Key, String> overrideArmorMaterials = new HashMap<>(); Map<Key, String> overrideArmorMaterials = new HashMap<>();
int overrideCount = this.readVarInt(buf); int overrideCount = this.readVarInt(buf);
@ -403,16 +417,15 @@ public class ItemCodecHelper extends MinecraftCodecHelper {
} }
Component description = this.readComponent(buf); Component description = this.readComponent(buf);
return new ArmorTrim.TrimMaterial(assetName, ingredientId, itemModelIndex, overrideArmorMaterials, description); return new ArmorTrim.TrimMaterial(assetName, ingredientId, overrideArmorMaterials, description);
} }
public void writeTrimMaterial(ByteBuf buf, ArmorTrim.TrimMaterial material) { public void writeTrimMaterial(ByteBuf buf, ArmorTrim.TrimMaterial material) {
this.writeString(buf, material.assetName()); this.writeString(buf, material.assetName());
this.writeVarInt(buf, material.ingredientId()); this.writeVarInt(buf, material.ingredientId());
buf.writeFloat(material.itemModelIndex());
this.writeVarInt(buf, material.overrideArmorMaterials().size()); this.writeVarInt(buf, material.overrideArmorAssets().size());
for (Map.Entry<Key, String> entry : material.overrideArmorMaterials().entrySet()) { for (Map.Entry<Key, String> entry : material.overrideArmorAssets().entrySet()) {
this.writeResourceLocation(buf, entry.getKey()); this.writeResourceLocation(buf, entry.getKey());
this.writeString(buf, entry.getValue()); this.writeString(buf, entry.getValue());
} }

View file

@ -4,6 +4,7 @@ import io.netty.buffer.ByteBuf;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.With; import lombok.With;
import org.cloudburstmc.math.vector.Vector3d;
import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper; import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper;
import org.geysermc.mcprotocollib.protocol.codec.MinecraftPacket; import org.geysermc.mcprotocollib.protocol.codec.MinecraftPacket;
@ -11,26 +12,22 @@ import org.geysermc.mcprotocollib.protocol.codec.MinecraftPacket;
@With @With
@AllArgsConstructor @AllArgsConstructor
public class ClientboundMoveVehiclePacket implements MinecraftPacket { public class ClientboundMoveVehiclePacket implements MinecraftPacket {
private final double x; private final Vector3d position;
private final double y; private final float yRot;
private final double z; private final float xRot;
private final float yaw;
private final float pitch;
public ClientboundMoveVehiclePacket(ByteBuf in, MinecraftCodecHelper helper) { public ClientboundMoveVehiclePacket(ByteBuf in, MinecraftCodecHelper helper) {
this.x = in.readDouble(); this.position = Vector3d.from(in.readDouble(), in.readDouble(), in.readDouble());
this.y = in.readDouble(); this.yRot = in.readFloat();
this.z = in.readDouble(); this.xRot = in.readFloat();
this.yaw = in.readFloat();
this.pitch = in.readFloat();
} }
@Override @Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) { public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
out.writeDouble(this.x); out.writeDouble(this.position.getX());
out.writeDouble(this.y); out.writeDouble(this.position.getY());
out.writeDouble(this.z); out.writeDouble(this.position.getZ());
out.writeFloat(this.yaw); out.writeFloat(this.yRot);
out.writeFloat(this.pitch); out.writeFloat(this.xRot);
} }
} }

View file

@ -0,0 +1,18 @@
package org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound;
import io.netty.buffer.ByteBuf;
import lombok.AccessLevel;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper;
import org.geysermc.mcprotocollib.protocol.codec.MinecraftPacket;
@Data
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class ServerboundPlayerLoadedPacket implements MinecraftPacket {
public static final ServerboundPlayerLoadedPacket INSTANCE = new ServerboundPlayerLoadedPacket();
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
}
}

View file

@ -4,6 +4,7 @@ import io.netty.buffer.ByteBuf;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.With; import lombok.With;
import org.cloudburstmc.math.vector.Vector3d;
import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper; import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper;
import org.geysermc.mcprotocollib.protocol.codec.MinecraftPacket; import org.geysermc.mcprotocollib.protocol.codec.MinecraftPacket;
@ -11,26 +12,25 @@ import org.geysermc.mcprotocollib.protocol.codec.MinecraftPacket;
@With @With
@AllArgsConstructor @AllArgsConstructor
public class ServerboundMoveVehiclePacket implements MinecraftPacket { public class ServerboundMoveVehiclePacket implements MinecraftPacket {
private final double x; private final Vector3d position;
private final double y; private final float yRot;
private final double z; private final float xRot;
private final float yaw; private final boolean onGround;
private final float pitch;
public ServerboundMoveVehiclePacket(ByteBuf in, MinecraftCodecHelper helper) { public ServerboundMoveVehiclePacket(ByteBuf in, MinecraftCodecHelper helper) {
this.x = in.readDouble(); this.position = Vector3d.from(in.readDouble(), in.readDouble(), in.readDouble());
this.y = in.readDouble(); this.yRot = in.readFloat();
this.z = in.readDouble(); this.xRot = in.readFloat();
this.yaw = in.readFloat(); this.onGround = in.readBoolean();
this.pitch = in.readFloat();
} }
@Override @Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) { public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
out.writeDouble(this.x); out.writeDouble(this.position.getX());
out.writeDouble(this.y); out.writeDouble(this.position.getY());
out.writeDouble(this.z); out.writeDouble(this.position.getZ());
out.writeFloat(this.yaw); out.writeFloat(this.yRot);
out.writeFloat(this.pitch); out.writeFloat(this.xRot);
out.writeBoolean(this.onGround);
} }
} }