Skip to content

Commit ff9ab9e

Browse files
committed
24w34a
1 parent c69a8c3 commit ff9ab9e

File tree

8 files changed

+136
-5
lines changed

8 files changed

+136
-5
lines changed

protocol/src/main/java/org/geysermc/mcprotocollib/protocol/codec/MinecraftCodec.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,9 @@
210210

211211
public class MinecraftCodec {
212212
public static final PacketCodec CODEC = PacketCodec.builder()
213-
.protocolVersion((1 << 30) | 205)
213+
.protocolVersion((1 << 30) | 206)
214214
.helper(MinecraftCodecHelper::new)
215-
.minecraftVersion("24w33a")
215+
.minecraftVersion("24w34a")
216216
.state(ProtocolState.HANDSHAKE, MinecraftPacketRegistry.builder()
217217
.registerServerboundPacket(ClientIntentionPacket.class, ClientIntentionPacket::new)
218218
)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package org.geysermc.mcprotocollib.protocol.data.game.item.component;
2+
3+
import org.geysermc.mcprotocollib.protocol.data.game.level.sound.Sound;
4+
5+
import java.util.List;
6+
7+
public record Consumable(float consumeSeconds, ItemUseAnimation animation, Sound sound, boolean hasConsumeParticles, List<ConsumeEffect> onConsumeEffects) {
8+
9+
public enum ItemUseAnimation {
10+
NONE,
11+
EAT,
12+
DRINK,
13+
BLOCK,
14+
BOW,
15+
SPEAR,
16+
CROSSBOW,
17+
SPYGLASS,
18+
TOOT_HORN,
19+
BRUSH;
20+
21+
private static final ItemUseAnimation[] VALUES = values();
22+
23+
public static ItemUseAnimation from(int id) {
24+
return VALUES[id];
25+
}
26+
}
27+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package org.geysermc.mcprotocollib.protocol.data.game.item.component;
2+
3+
import org.geysermc.mcprotocollib.protocol.data.game.level.sound.Sound;
4+
5+
import java.util.List;
6+
7+
public interface ConsumeEffect {
8+
9+
record ApplyEffects(List<MobEffectInstance> effects, float probability) implements ConsumeEffect {
10+
}
11+
12+
record RemoveEffects(HolderSet effects) implements ConsumeEffect {
13+
}
14+
15+
record ClearAllEffects() implements ConsumeEffect {
16+
}
17+
18+
record TeleportRandomly(float diameter) implements ConsumeEffect {
19+
}
20+
21+
record PlaySound(Sound sound) implements ConsumeEffect {
22+
}
23+
}

protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/item/component/DataComponentType.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ public class DataComponentType<T> {
4242
public static final BooleanComponentType ENCHANTMENT_GLINT_OVERRIDE = new BooleanComponentType(ByteBuf::readBoolean, ByteBuf::writeBoolean, BooleanDataComponent::new);
4343
public static final DataComponentType<NbtMap> INTANGIBLE_PROJECTILE = new DataComponentType<>(ItemCodecHelper::readCompoundTag, ItemCodecHelper::writeAnyTag, ObjectDataComponent::new);
4444
public static final DataComponentType<FoodProperties> FOOD = new DataComponentType<>(ItemCodecHelper::readFoodProperties, ItemCodecHelper::writeFoodProperties, ObjectDataComponent::new);
45+
public static final DataComponentType<Consumable> CONSUMABLE = new DataComponentType<>(ItemCodecHelper::readConsumable, ItemCodecHelper::writeConsumable, ObjectDataComponent::new);
46+
public static final DataComponentType<ItemStack> USE_REMAINDER = new DataComponentType<>(ItemCodecHelper::readItemStack, ItemCodecHelper::writeItemStack, ObjectDataComponent::new);
47+
public static final DataComponentType<UseCooldown> USE_COOLDOWN = new DataComponentType<>(ItemCodecHelper::readUseCooldown, ItemCodecHelper::writeUseCooldown, ObjectDataComponent::new);
4548
public static final DataComponentType<Unit> FIRE_RESISTANT = new DataComponentType<>(unitReader(), unitWriter(), ObjectDataComponent::new);
4649
public static final DataComponentType<ToolData> TOOL = new DataComponentType<>(ItemCodecHelper::readToolData, ItemCodecHelper::writeToolData, ObjectDataComponent::new);
4750
public static final IntComponentType ENCHANTABLE = new IntComponentType(ItemCodecHelper::readVarInt, ItemCodecHelper::writeVarInt, IntDataComponent::new);

protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/item/component/ItemCodecHelper.java

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,73 @@ public void writeFoodProperties(ByteBuf buf, FoodProperties properties) {
257257
});
258258
}
259259

260+
public Consumable readConsumable(ByteBuf buf) {
261+
float consumeSeconds = buf.readFloat();
262+
Consumable.ItemUseAnimation animation = Consumable.ItemUseAnimation.from(this.readVarInt(buf));
263+
Sound sound = this.readById(buf, BuiltinSound::from, this::readSoundEvent);
264+
boolean hasConsumeParticles = buf.readBoolean();
265+
List<ConsumeEffect> onConsumeEffects = this.readList(buf, this::readConsumeEffect);
266+
return new Consumable(consumeSeconds, animation, sound, hasConsumeParticles, onConsumeEffects);
267+
}
268+
269+
public void writeConsumable(ByteBuf buf, Consumable consumable) {
270+
buf.writeFloat(consumable.consumeSeconds());
271+
this.writeVarInt(buf, consumable.animation().ordinal());
272+
if (consumable.sound() instanceof CustomSound) {
273+
this.writeVarInt(buf, 0);
274+
this.writeSoundEvent(buf, consumable.sound());
275+
} else {
276+
this.writeVarInt(buf, ((BuiltinSound) consumable.sound()).ordinal() + 1);
277+
}
278+
279+
buf.writeBoolean(consumable.hasConsumeParticles());
280+
this.writeList(buf, consumable.onConsumeEffects(), this::writeConsumeEffect);
281+
}
282+
283+
public ConsumeEffect readConsumeEffect(ByteBuf buf) {
284+
return switch (this.readVarInt(buf)) {
285+
case 0 -> new ConsumeEffect.ApplyEffects(this.readList(buf, this::readEffectInstance), buf.readFloat());
286+
case 1 -> new ConsumeEffect.RemoveEffects(this.readHolderSet(buf));
287+
case 2 -> new ConsumeEffect.ClearAllEffects();
288+
case 3 -> new ConsumeEffect.TeleportRandomly(buf.readFloat());
289+
case 4 -> new ConsumeEffect.PlaySound(this.readById(buf, BuiltinSound::from, this::readSoundEvent));
290+
default -> throw new IllegalStateException("Unexpected value: " + this.readVarInt(buf));
291+
};
292+
}
293+
294+
public void writeConsumeEffect(ByteBuf buf, ConsumeEffect consumeEffect) {
295+
if (consumeEffect instanceof ConsumeEffect.ApplyEffects applyEffects) {
296+
this.writeVarInt(buf, 0);
297+
this.writeList(buf, applyEffects.effects(), this::writeEffectInstance);
298+
buf.writeFloat(applyEffects.probability());
299+
} else if (consumeEffect instanceof ConsumeEffect.RemoveEffects removeEffects) {
300+
this.writeVarInt(buf, 1);
301+
this.writeHolderSet(buf, removeEffects.effects());
302+
} else if (consumeEffect instanceof ConsumeEffect.ClearAllEffects) {
303+
this.writeVarInt(buf, 2);
304+
} else if (consumeEffect instanceof ConsumeEffect.TeleportRandomly teleportRandomly) {
305+
this.writeVarInt(buf, 3);
306+
buf.writeFloat(teleportRandomly.diameter());
307+
} else if (consumeEffect instanceof ConsumeEffect.PlaySound playSound) {
308+
this.writeVarInt(buf, 4);
309+
if (playSound.sound() instanceof CustomSound) {
310+
this.writeVarInt(buf, 0);
311+
this.writeSoundEvent(buf, playSound.sound());
312+
} else {
313+
this.writeVarInt(buf, ((BuiltinSound) playSound.sound()).ordinal() + 1);
314+
}
315+
}
316+
}
317+
318+
public UseCooldown readUseCooldown(ByteBuf buf) {
319+
return new UseCooldown(buf.readFloat(), this.readNullable(buf, this::readResourceLocation));
320+
}
321+
322+
public void writeUseCooldown(ByteBuf buf, UseCooldown useCooldown) {
323+
buf.writeFloat(useCooldown.seconds());
324+
this.writeNullable(buf, useCooldown.cooldownGroup(), this::writeResourceLocation);
325+
}
326+
260327
public MobEffectInstance readEffectInstance(ByteBuf buf) {
261328
Effect effect = this.readEffect(buf);
262329
return new MobEffectInstance(effect, this.readEffectDetails(buf));
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package org.geysermc.mcprotocollib.protocol.data.game.item.component;
2+
3+
import net.kyori.adventure.key.Key;
4+
import org.checkerframework.checker.nullness.qual.Nullable;
5+
6+
public record UseCooldown(float seconds, @Nullable Key cooldownGroup) {
7+
}

protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/ingame/clientbound/ClientboundCooldownPacket.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,25 @@
44
import lombok.AllArgsConstructor;
55
import lombok.Data;
66
import lombok.With;
7+
import net.kyori.adventure.key.Key;
78
import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper;
89
import org.geysermc.mcprotocollib.protocol.codec.MinecraftPacket;
910

1011
@Data
1112
@With
1213
@AllArgsConstructor
1314
public class ClientboundCooldownPacket implements MinecraftPacket {
14-
private final int itemId;
15+
private final Key cooldownGroup;
1516
private final int cooldownTicks;
1617

1718
public ClientboundCooldownPacket(ByteBuf in, MinecraftCodecHelper helper) {
18-
this.itemId = helper.readVarInt(in);
19+
this.cooldownGroup = helper.readResourceLocation(in);
1920
this.cooldownTicks = helper.readVarInt(in);
2021
}
2122

2223
@Override
2324
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
24-
helper.writeVarInt(out, this.itemId);
25+
helper.writeResourceLocation(out, this.cooldownGroup);
2526
helper.writeVarInt(out, this.cooldownTicks);
2627
}
2728
}

protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/ingame/serverbound/player/ServerboundUseItemOnPacket.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public class ServerboundUseItemOnPacket implements MinecraftPacket {
2222
private final float cursorY;
2323
private final float cursorZ;
2424
private final boolean insideBlock;
25+
private final boolean hitWorldBorder;
2526
private final int sequence;
2627

2728
public ServerboundUseItemOnPacket(ByteBuf in, MinecraftCodecHelper helper) {
@@ -32,6 +33,7 @@ public ServerboundUseItemOnPacket(ByteBuf in, MinecraftCodecHelper helper) {
3233
this.cursorY = in.readFloat();
3334
this.cursorZ = in.readFloat();
3435
this.insideBlock = in.readBoolean();
36+
this.hitWorldBorder = in.readBoolean();
3537
this.sequence = helper.readVarInt(in);
3638
}
3739

@@ -44,6 +46,7 @@ public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
4446
out.writeFloat(this.cursorY);
4547
out.writeFloat(this.cursorZ);
4648
out.writeBoolean(this.insideBlock);
49+
out.writeBoolean(this.hitWorldBorder);
4750
helper.writeVarInt(out, this.sequence);
4851
}
4952
}

0 commit comments

Comments
 (0)