mirror of
https://github.com/GeyserMC/MCProtocolLib.git
synced 2024-11-14 19:34:58 -05:00
24w34a
This commit is contained in:
parent
c69a8c3537
commit
ff9ab9edf0
8 changed files with 136 additions and 5 deletions
|
@ -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) | 205)
|
.protocolVersion((1 << 30) | 206)
|
||||||
.helper(MinecraftCodecHelper::new)
|
.helper(MinecraftCodecHelper::new)
|
||||||
.minecraftVersion("24w33a")
|
.minecraftVersion("24w34a")
|
||||||
.state(ProtocolState.HANDSHAKE, MinecraftPacketRegistry.builder()
|
.state(ProtocolState.HANDSHAKE, MinecraftPacketRegistry.builder()
|
||||||
.registerServerboundPacket(ClientIntentionPacket.class, ClientIntentionPacket::new)
|
.registerServerboundPacket(ClientIntentionPacket.class, ClientIntentionPacket::new)
|
||||||
)
|
)
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
package org.geysermc.mcprotocollib.protocol.data.game.item.component;
|
||||||
|
|
||||||
|
import org.geysermc.mcprotocollib.protocol.data.game.level.sound.Sound;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public record Consumable(float consumeSeconds, ItemUseAnimation animation, Sound sound, boolean hasConsumeParticles, List<ConsumeEffect> onConsumeEffects) {
|
||||||
|
|
||||||
|
public enum ItemUseAnimation {
|
||||||
|
NONE,
|
||||||
|
EAT,
|
||||||
|
DRINK,
|
||||||
|
BLOCK,
|
||||||
|
BOW,
|
||||||
|
SPEAR,
|
||||||
|
CROSSBOW,
|
||||||
|
SPYGLASS,
|
||||||
|
TOOT_HORN,
|
||||||
|
BRUSH;
|
||||||
|
|
||||||
|
private static final ItemUseAnimation[] VALUES = values();
|
||||||
|
|
||||||
|
public static ItemUseAnimation from(int id) {
|
||||||
|
return VALUES[id];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
package org.geysermc.mcprotocollib.protocol.data.game.item.component;
|
||||||
|
|
||||||
|
import org.geysermc.mcprotocollib.protocol.data.game.level.sound.Sound;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface ConsumeEffect {
|
||||||
|
|
||||||
|
record ApplyEffects(List<MobEffectInstance> effects, float probability) implements ConsumeEffect {
|
||||||
|
}
|
||||||
|
|
||||||
|
record RemoveEffects(HolderSet effects) implements ConsumeEffect {
|
||||||
|
}
|
||||||
|
|
||||||
|
record ClearAllEffects() implements ConsumeEffect {
|
||||||
|
}
|
||||||
|
|
||||||
|
record TeleportRandomly(float diameter) implements ConsumeEffect {
|
||||||
|
}
|
||||||
|
|
||||||
|
record PlaySound(Sound sound) implements ConsumeEffect {
|
||||||
|
}
|
||||||
|
}
|
|
@ -42,6 +42,9 @@ public class DataComponentType<T> {
|
||||||
public static final BooleanComponentType ENCHANTMENT_GLINT_OVERRIDE = new BooleanComponentType(ByteBuf::readBoolean, ByteBuf::writeBoolean, BooleanDataComponent::new);
|
public static final BooleanComponentType ENCHANTMENT_GLINT_OVERRIDE = new BooleanComponentType(ByteBuf::readBoolean, ByteBuf::writeBoolean, BooleanDataComponent::new);
|
||||||
public static final DataComponentType<NbtMap> INTANGIBLE_PROJECTILE = new DataComponentType<>(ItemCodecHelper::readCompoundTag, ItemCodecHelper::writeAnyTag, ObjectDataComponent::new);
|
public static final DataComponentType<NbtMap> INTANGIBLE_PROJECTILE = new DataComponentType<>(ItemCodecHelper::readCompoundTag, ItemCodecHelper::writeAnyTag, ObjectDataComponent::new);
|
||||||
public static final DataComponentType<FoodProperties> FOOD = new DataComponentType<>(ItemCodecHelper::readFoodProperties, ItemCodecHelper::writeFoodProperties, ObjectDataComponent::new);
|
public static final DataComponentType<FoodProperties> FOOD = new DataComponentType<>(ItemCodecHelper::readFoodProperties, ItemCodecHelper::writeFoodProperties, 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<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<Unit> FIRE_RESISTANT = new DataComponentType<>(unitReader(), unitWriter(), 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);
|
||||||
|
|
|
@ -257,6 +257,73 @@ public class ItemCodecHelper extends MinecraftCodecHelper {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Consumable readConsumable(ByteBuf buf) {
|
||||||
|
float consumeSeconds = buf.readFloat();
|
||||||
|
Consumable.ItemUseAnimation animation = Consumable.ItemUseAnimation.from(this.readVarInt(buf));
|
||||||
|
Sound sound = this.readById(buf, BuiltinSound::from, this::readSoundEvent);
|
||||||
|
boolean hasConsumeParticles = buf.readBoolean();
|
||||||
|
List<ConsumeEffect> onConsumeEffects = this.readList(buf, this::readConsumeEffect);
|
||||||
|
return new Consumable(consumeSeconds, animation, sound, hasConsumeParticles, onConsumeEffects);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeConsumable(ByteBuf buf, Consumable consumable) {
|
||||||
|
buf.writeFloat(consumable.consumeSeconds());
|
||||||
|
this.writeVarInt(buf, consumable.animation().ordinal());
|
||||||
|
if (consumable.sound() instanceof CustomSound) {
|
||||||
|
this.writeVarInt(buf, 0);
|
||||||
|
this.writeSoundEvent(buf, consumable.sound());
|
||||||
|
} else {
|
||||||
|
this.writeVarInt(buf, ((BuiltinSound) consumable.sound()).ordinal() + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
buf.writeBoolean(consumable.hasConsumeParticles());
|
||||||
|
this.writeList(buf, consumable.onConsumeEffects(), this::writeConsumeEffect);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConsumeEffect readConsumeEffect(ByteBuf buf) {
|
||||||
|
return switch (this.readVarInt(buf)) {
|
||||||
|
case 0 -> new ConsumeEffect.ApplyEffects(this.readList(buf, this::readEffectInstance), buf.readFloat());
|
||||||
|
case 1 -> new ConsumeEffect.RemoveEffects(this.readHolderSet(buf));
|
||||||
|
case 2 -> new ConsumeEffect.ClearAllEffects();
|
||||||
|
case 3 -> new ConsumeEffect.TeleportRandomly(buf.readFloat());
|
||||||
|
case 4 -> new ConsumeEffect.PlaySound(this.readById(buf, BuiltinSound::from, this::readSoundEvent));
|
||||||
|
default -> throw new IllegalStateException("Unexpected value: " + this.readVarInt(buf));
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeConsumeEffect(ByteBuf buf, ConsumeEffect consumeEffect) {
|
||||||
|
if (consumeEffect instanceof ConsumeEffect.ApplyEffects applyEffects) {
|
||||||
|
this.writeVarInt(buf, 0);
|
||||||
|
this.writeList(buf, applyEffects.effects(), this::writeEffectInstance);
|
||||||
|
buf.writeFloat(applyEffects.probability());
|
||||||
|
} else if (consumeEffect instanceof ConsumeEffect.RemoveEffects removeEffects) {
|
||||||
|
this.writeVarInt(buf, 1);
|
||||||
|
this.writeHolderSet(buf, removeEffects.effects());
|
||||||
|
} else if (consumeEffect instanceof ConsumeEffect.ClearAllEffects) {
|
||||||
|
this.writeVarInt(buf, 2);
|
||||||
|
} else if (consumeEffect instanceof ConsumeEffect.TeleportRandomly teleportRandomly) {
|
||||||
|
this.writeVarInt(buf, 3);
|
||||||
|
buf.writeFloat(teleportRandomly.diameter());
|
||||||
|
} else if (consumeEffect instanceof ConsumeEffect.PlaySound playSound) {
|
||||||
|
this.writeVarInt(buf, 4);
|
||||||
|
if (playSound.sound() instanceof CustomSound) {
|
||||||
|
this.writeVarInt(buf, 0);
|
||||||
|
this.writeSoundEvent(buf, playSound.sound());
|
||||||
|
} else {
|
||||||
|
this.writeVarInt(buf, ((BuiltinSound) playSound.sound()).ordinal() + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public UseCooldown readUseCooldown(ByteBuf buf) {
|
||||||
|
return new UseCooldown(buf.readFloat(), this.readNullable(buf, this::readResourceLocation));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeUseCooldown(ByteBuf buf, UseCooldown useCooldown) {
|
||||||
|
buf.writeFloat(useCooldown.seconds());
|
||||||
|
this.writeNullable(buf, useCooldown.cooldownGroup(), this::writeResourceLocation);
|
||||||
|
}
|
||||||
|
|
||||||
public MobEffectInstance readEffectInstance(ByteBuf buf) {
|
public MobEffectInstance readEffectInstance(ByteBuf buf) {
|
||||||
Effect effect = this.readEffect(buf);
|
Effect effect = this.readEffect(buf);
|
||||||
return new MobEffectInstance(effect, this.readEffectDetails(buf));
|
return new MobEffectInstance(effect, this.readEffectDetails(buf));
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
package org.geysermc.mcprotocollib.protocol.data.game.item.component;
|
||||||
|
|
||||||
|
import net.kyori.adventure.key.Key;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
|
public record UseCooldown(float seconds, @Nullable Key cooldownGroup) {
|
||||||
|
}
|
|
@ -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 net.kyori.adventure.key.Key;
|
||||||
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,17 +12,17 @@ import org.geysermc.mcprotocollib.protocol.codec.MinecraftPacket;
|
||||||
@With
|
@With
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class ClientboundCooldownPacket implements MinecraftPacket {
|
public class ClientboundCooldownPacket implements MinecraftPacket {
|
||||||
private final int itemId;
|
private final Key cooldownGroup;
|
||||||
private final int cooldownTicks;
|
private final int cooldownTicks;
|
||||||
|
|
||||||
public ClientboundCooldownPacket(ByteBuf in, MinecraftCodecHelper helper) {
|
public ClientboundCooldownPacket(ByteBuf in, MinecraftCodecHelper helper) {
|
||||||
this.itemId = helper.readVarInt(in);
|
this.cooldownGroup = helper.readResourceLocation(in);
|
||||||
this.cooldownTicks = helper.readVarInt(in);
|
this.cooldownTicks = helper.readVarInt(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
|
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
|
||||||
helper.writeVarInt(out, this.itemId);
|
helper.writeResourceLocation(out, this.cooldownGroup);
|
||||||
helper.writeVarInt(out, this.cooldownTicks);
|
helper.writeVarInt(out, this.cooldownTicks);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ public class ServerboundUseItemOnPacket implements MinecraftPacket {
|
||||||
private final float cursorY;
|
private final float cursorY;
|
||||||
private final float cursorZ;
|
private final float cursorZ;
|
||||||
private final boolean insideBlock;
|
private final boolean insideBlock;
|
||||||
|
private final boolean hitWorldBorder;
|
||||||
private final int sequence;
|
private final int sequence;
|
||||||
|
|
||||||
public ServerboundUseItemOnPacket(ByteBuf in, MinecraftCodecHelper helper) {
|
public ServerboundUseItemOnPacket(ByteBuf in, MinecraftCodecHelper helper) {
|
||||||
|
@ -32,6 +33,7 @@ public class ServerboundUseItemOnPacket implements MinecraftPacket {
|
||||||
this.cursorY = in.readFloat();
|
this.cursorY = in.readFloat();
|
||||||
this.cursorZ = in.readFloat();
|
this.cursorZ = in.readFloat();
|
||||||
this.insideBlock = in.readBoolean();
|
this.insideBlock = in.readBoolean();
|
||||||
|
this.hitWorldBorder = in.readBoolean();
|
||||||
this.sequence = helper.readVarInt(in);
|
this.sequence = helper.readVarInt(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,6 +46,7 @@ public class ServerboundUseItemOnPacket implements MinecraftPacket {
|
||||||
out.writeFloat(this.cursorY);
|
out.writeFloat(this.cursorY);
|
||||||
out.writeFloat(this.cursorZ);
|
out.writeFloat(this.cursorZ);
|
||||||
out.writeBoolean(this.insideBlock);
|
out.writeBoolean(this.insideBlock);
|
||||||
|
out.writeBoolean(this.hitWorldBorder);
|
||||||
helper.writeVarInt(out, this.sequence);
|
helper.writeVarInt(out, this.sequence);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue