This commit is contained in:
basaigh 2024-10-03 16:20:10 +01:00
parent 7f7445f6f0
commit 25103382a3
6 changed files with 20 additions and 13 deletions

View file

@ -210,9 +210,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) | 208) .protocolVersion((1 << 30) | 209)
.helper(MinecraftCodecHelper::new) .helper(MinecraftCodecHelper::new)
.minecraftVersion("24w36a") .minecraftVersion("24w37a")
.state(ProtocolState.HANDSHAKE, MinecraftPacketRegistry.builder() .state(ProtocolState.HANDSHAKE, MinecraftPacketRegistry.builder()
.registerServerboundPacket(ClientIntentionPacket.class, ClientIntentionPacket::new) .registerServerboundPacket(ClientIntentionPacket.class, ClientIntentionPacket::new)
) )

View file

@ -46,13 +46,14 @@ public class DataComponentType<T> {
public static final DataComponentType<Consumable> CONSUMABLE = new DataComponentType<>(ItemCodecHelper::readConsumable, ItemCodecHelper::writeConsumable, ObjectDataComponent::new); public static final DataComponentType<Consumable> CONSUMABLE = new DataComponentType<>(ItemCodecHelper::readConsumable, ItemCodecHelper::writeConsumable, ObjectDataComponent::new);
public static final DataComponentType<ItemStack> USE_REMAINDER = new DataComponentType<>(ItemCodecHelper::readItemStack, ItemCodecHelper::writeItemStack, ObjectDataComponent::new); public static final DataComponentType<ItemStack> USE_REMAINDER = new DataComponentType<>(ItemCodecHelper::readItemStack, ItemCodecHelper::writeItemStack, ObjectDataComponent::new);
public static final DataComponentType<UseCooldown> USE_COOLDOWN = new DataComponentType<>(ItemCodecHelper::readUseCooldown, ItemCodecHelper::writeUseCooldown, ObjectDataComponent::new); public static final DataComponentType<UseCooldown> USE_COOLDOWN = new DataComponentType<>(ItemCodecHelper::readUseCooldown, ItemCodecHelper::writeUseCooldown, ObjectDataComponent::new);
public static final DataComponentType<Unit> FIRE_RESISTANT = new DataComponentType<>(unitReader(), unitWriter(), ObjectDataComponent::new); public static final DataComponentType<Key> DAMAGE_RESISTANT = new DataComponentType<>(ItemCodecHelper::readResourceLocation, ItemCodecHelper::writeResourceLocation, ObjectDataComponent::new);
public static final DataComponentType<ToolData> TOOL = new DataComponentType<>(ItemCodecHelper::readToolData, ItemCodecHelper::writeToolData, ObjectDataComponent::new); public static final DataComponentType<ToolData> TOOL = new DataComponentType<>(ItemCodecHelper::readToolData, ItemCodecHelper::writeToolData, ObjectDataComponent::new);
public static final IntComponentType ENCHANTABLE = new IntComponentType(ItemCodecHelper::readVarInt, ItemCodecHelper::writeVarInt, IntDataComponent::new); public static final IntComponentType ENCHANTABLE = new IntComponentType(ItemCodecHelper::readVarInt, ItemCodecHelper::writeVarInt, IntDataComponent::new);
public static final DataComponentType<Equippable> EQUIPPABLE = new DataComponentType<>(ItemCodecHelper::readEquippable, ItemCodecHelper::writeEquippable, ObjectDataComponent::new); public static final DataComponentType<Equippable> EQUIPPABLE = new DataComponentType<>(ItemCodecHelper::readEquippable, ItemCodecHelper::writeEquippable, ObjectDataComponent::new);
public static final DataComponentType<HolderSet> REPAIRABLE = new DataComponentType<>(ItemCodecHelper::readHolderSet, ItemCodecHelper::writeHolderSet, ObjectDataComponent::new); public static final DataComponentType<HolderSet> REPAIRABLE = new DataComponentType<>(ItemCodecHelper::readHolderSet, ItemCodecHelper::writeHolderSet, ObjectDataComponent::new);
public static final DataComponentType<Unit> GLIDER = new DataComponentType<>(unitReader(), unitWriter(), ObjectDataComponent::new); public static final DataComponentType<Unit> GLIDER = new DataComponentType<>(unitReader(), unitWriter(), ObjectDataComponent::new);
public static final DataComponentType<Key> TOOLTIP_STYLE = new DataComponentType<>(ItemCodecHelper::readResourceLocation, ItemCodecHelper::writeResourceLocation, ObjectDataComponent::new); public static final DataComponentType<Key> TOOLTIP_STYLE = new DataComponentType<>(ItemCodecHelper::readResourceLocation, ItemCodecHelper::writeResourceLocation, ObjectDataComponent::new);
public static final DataComponentType<List<ConsumeEffect>> DEATH_PROTECTION = new DataComponentType<>(listReader(ItemCodecHelper::readConsumeEffect), listWriter(ItemCodecHelper::writeConsumeEffect), ObjectDataComponent::new);
public static final DataComponentType<ItemEnchantments> STORED_ENCHANTMENTS = new DataComponentType<>(ItemCodecHelper::readItemEnchantments, ItemCodecHelper::writeItemEnchantments, ObjectDataComponent::new); public static final DataComponentType<ItemEnchantments> STORED_ENCHANTMENTS = new DataComponentType<>(ItemCodecHelper::readItemEnchantments, ItemCodecHelper::writeItemEnchantments, ObjectDataComponent::new);
public static final DataComponentType<DyedItemColor> DYED_COLOR = new DataComponentType<>(ItemCodecHelper::readDyedItemColor, ItemCodecHelper::writeDyedItemColor, ObjectDataComponent::new); public static final DataComponentType<DyedItemColor> DYED_COLOR = new DataComponentType<>(ItemCodecHelper::readDyedItemColor, ItemCodecHelper::writeDyedItemColor, ObjectDataComponent::new);
public static final IntComponentType MAP_COLOR = new IntComponentType((helper, input) -> input.readInt(), (helper, output, value) -> output.writeInt(value), IntDataComponent::new); public static final IntComponentType MAP_COLOR = new IntComponentType((helper, input) -> input.readInt(), (helper, output, value) -> output.writeInt(value), IntDataComponent::new);

View file

@ -5,5 +5,6 @@ import org.checkerframework.checker.nullness.qual.Nullable;
import org.geysermc.mcprotocollib.protocol.data.game.entity.EquipmentSlot; import org.geysermc.mcprotocollib.protocol.data.game.entity.EquipmentSlot;
import org.geysermc.mcprotocollib.protocol.data.game.level.sound.Sound; import org.geysermc.mcprotocollib.protocol.data.game.level.sound.Sound;
public record Equippable(EquipmentSlot slot, Sound equipSound, @Nullable Key model, @Nullable HolderSet allowedEntities, boolean dispensable) { public record Equippable(EquipmentSlot slot, Sound equipSound, @Nullable Key model, @Nullable HolderSet allowedEntities,
boolean dispensable, boolean swappable, boolean damageOnHurt) {
} }

View file

@ -172,7 +172,9 @@ public class ItemCodecHelper extends MinecraftCodecHelper {
Key model = this.readNullable(buf, this::readResourceLocation); Key model = this.readNullable(buf, this::readResourceLocation);
HolderSet allowedEntities = this.readNullable(buf, this::readHolderSet); HolderSet allowedEntities = this.readNullable(buf, this::readHolderSet);
boolean dispensable = buf.readBoolean(); boolean dispensable = buf.readBoolean();
return new Equippable(slot, equipSound, model, allowedEntities, dispensable); boolean swappable = buf.readBoolean();
boolean damageOnHurt = buf.readBoolean();
return new Equippable(slot, equipSound, model, allowedEntities, dispensable, swappable, damageOnHurt);
} }
public void writeEquippable(ByteBuf buf, Equippable equippable) { public void writeEquippable(ByteBuf buf, Equippable equippable) {
@ -187,6 +189,8 @@ public class ItemCodecHelper extends MinecraftCodecHelper {
this.writeNullable(buf, equippable.model(), this::writeResourceLocation); this.writeNullable(buf, equippable.model(), this::writeResourceLocation);
this.writeNullable(buf, equippable.allowedEntities(), this::writeHolderSet); this.writeNullable(buf, equippable.allowedEntities(), this::writeHolderSet);
buf.writeBoolean(equippable.dispensable()); buf.writeBoolean(equippable.dispensable());
buf.writeBoolean(equippable.swappable());
buf.writeBoolean(equippable.damageOnHurt());
} }
public ItemAttributeModifiers readItemAttributeModifiers(ByteBuf buf) { public ItemAttributeModifiers readItemAttributeModifiers(ByteBuf buf) {
@ -231,7 +235,8 @@ public class ItemCodecHelper extends MinecraftCodecHelper {
int customColor = buf.readBoolean() ? buf.readInt() : -1; int customColor = buf.readBoolean() ? buf.readInt() : -1;
List<MobEffectInstance> customEffects = this.readList(buf, this::readEffectInstance); List<MobEffectInstance> customEffects = this.readList(buf, this::readEffectInstance);
return new PotionContents(potionId, customColor, customEffects); String customName = this.readNullable(buf, this::readString);
return new PotionContents(potionId, customColor, customEffects, customName);
} }
public void writePotionContents(ByteBuf buf, PotionContents contents) { public void writePotionContents(ByteBuf buf, PotionContents contents) {
@ -250,6 +255,7 @@ public class ItemCodecHelper extends MinecraftCodecHelper {
} }
this.writeList(buf, contents.getCustomEffects(), this::writeEffectInstance); this.writeList(buf, contents.getCustomEffects(), this::writeEffectInstance);
this.writeNullable(buf, contents.getCustomName(), this::writeString);
} }
public FoodProperties readFoodProperties(ByteBuf buf) { public FoodProperties readFoodProperties(ByteBuf buf) {

View file

@ -2,6 +2,7 @@ package org.geysermc.mcprotocollib.protocol.data.game.item.component;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.List; import java.util.List;
@ -11,4 +12,5 @@ public class PotionContents {
private final int potionId; private final int potionId;
private final int customColor; private final int customColor;
private final List<MobEffectInstance> customEffects; private final List<MobEffectInstance> customEffects;
private final @Nullable String customName;
} }

View file

@ -33,8 +33,8 @@ public class ClientboundPlayerPositionPacket implements MinecraftPacket {
this.id = helper.readVarInt(in); this.id = helper.readVarInt(in);
this.position = Vector3d.from(in.readDouble(), in.readDouble(), in.readDouble()); this.position = Vector3d.from(in.readDouble(), in.readDouble(), in.readDouble());
this.deltaMovement = Vector3d.from(in.readDouble(), in.readDouble(), in.readDouble()); this.deltaMovement = Vector3d.from(in.readDouble(), in.readDouble(), in.readDouble());
this.yRot = in.readByte() * 360 / 256F; this.yRot = in.readFloat();
this.xRot = in.readByte() * 360 / 256F; this.xRot = in.readFloat();
this.relativeArguments = new ArrayList<>(); this.relativeArguments = new ArrayList<>();
int flags = in.readInt(); int flags = in.readInt();
@ -56,11 +56,8 @@ public class ClientboundPlayerPositionPacket implements MinecraftPacket {
out.writeDouble(this.deltaMovement.getX()); out.writeDouble(this.deltaMovement.getX());
out.writeDouble(this.deltaMovement.getY()); out.writeDouble(this.deltaMovement.getY());
out.writeDouble(this.deltaMovement.getZ()); out.writeDouble(this.deltaMovement.getZ());
out.writeFloat(this.yRot);
float yRot = this.yRot * 256F / 360F; out.writeFloat(this.xRot);
out.writeByte(yRot < (int)yRot ? (int)yRot - 1 : (int)yRot);
float xRot = this.xRot * 256F / 360F;
out.writeByte(xRot < (int)xRot ? (int)xRot - 1 : (int)xRot);
int flags = 0; int flags = 0;
for (PositionElement element : this.relativeArguments) { for (PositionElement element : this.relativeArguments) {