From bb9b7e82994502eb0059cc17b5e7940603cfaab5 Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+Camotoy@users.noreply.github.com> Date: Fri, 2 Dec 2022 14:12:06 -0500 Subject: [PATCH] Update to 1.19.3-rc1 --- .../mc/protocol/codec/MinecraftCodec.java | 4 +- .../protocol/codec/MinecraftCodecHelper.java | 60 ++++++++++--------- .../data/game/level/sound/BuiltinSound.java | 10 ++++ .../data/game/level/sound/CustomSound.java | 6 +- .../protocol/data/game/level/sound/Sound.java | 5 ++ .../ClientboundSoundEntityPacket.java | 15 +++-- .../ClientboundStopSoundPacket.java | 19 +----- .../level/ClientboundSoundPacket.java | 22 ++----- 8 files changed, 71 insertions(+), 70 deletions(-) diff --git a/src/main/java/com/github/steveice10/mc/protocol/codec/MinecraftCodec.java b/src/main/java/com/github/steveice10/mc/protocol/codec/MinecraftCodec.java index 32d3f957..84f3b083 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/codec/MinecraftCodec.java +++ b/src/main/java/com/github/steveice10/mc/protocol/codec/MinecraftCodec.java @@ -195,9 +195,9 @@ public class MinecraftCodec { } public static final PacketCodec CODEC = PacketCodec.builder() - .protocolVersion((1 << 30) | 111) + .protocolVersion((1 << 30) | 112) .helper(() -> new MinecraftCodecHelper(LEVEL_EVENTS, SOUND_NAMES)) - .minecraftVersion("1.19.3-pre3") + .minecraftVersion("1.19.3-rc1") .state(ProtocolState.HANDSHAKE, PacketStateCodec.builder() .registerServerboundPacket(0x00, ClientIntentionPacket.class, ClientIntentionPacket::new) ) diff --git a/src/main/java/com/github/steveice10/mc/protocol/codec/MinecraftCodecHelper.java b/src/main/java/com/github/steveice10/mc/protocol/codec/MinecraftCodecHelper.java index 1c3372f7..fe092df7 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/codec/MinecraftCodecHelper.java +++ b/src/main/java/com/github/steveice10/mc/protocol/codec/MinecraftCodecHelper.java @@ -25,6 +25,8 @@ import com.github.steveice10.mc.protocol.data.game.level.particle.positionsource import com.github.steveice10.mc.protocol.data.game.level.particle.positionsource.PositionSource; import com.github.steveice10.mc.protocol.data.game.level.particle.positionsource.PositionSourceType; import com.github.steveice10.mc.protocol.data.game.level.sound.BuiltinSound; +import com.github.steveice10.mc.protocol.data.game.level.sound.CustomSound; +import com.github.steveice10.mc.protocol.data.game.level.sound.Sound; import com.github.steveice10.mc.protocol.data.game.level.sound.SoundCategory; import com.github.steveice10.mc.protocol.data.game.recipe.Ingredient; import com.github.steveice10.mc.protocol.data.game.statistic.StatisticCategory; @@ -84,6 +86,14 @@ public class MinecraftCodecHelper extends BasePacketCodecHelper { } } + public String readResourceLocation(ByteBuf buf) { + return Identifier.formalize(this.readString(buf)); + } + + public void writeResourceLocation(ByteBuf buf, String location) { + this.writeString(buf, location); + } + public UUID readUUID(ByteBuf buf) { return new UUID(buf.readLong(), buf.readLong()); } @@ -595,14 +605,6 @@ public class MinecraftCodecHelper extends BasePacketCodecHelper { this.writeEnum(buf, category); } - public BuiltinSound readBuiltinSound(ByteBuf buf) { - return BuiltinSound.from(this.readVarInt(buf)); - } - - public void writeBuiltinSound(ByteBuf buf, BuiltinSound sound) { - this.writeEnum(buf, sound); - } - @Nullable public BuiltinSound getBuiltinSound(String name) { return this.soundNames.get(name); @@ -737,26 +739,6 @@ public class MinecraftCodecHelper extends BasePacketCodecHelper { } } - public GameProfile readGameProfile(ByteBuf buf) { - UUID uuid = this.readUUID(buf); - String name = this.readString(buf); - GameProfile profile = new GameProfile(uuid, name); - int propertyCount = this.readVarInt(buf); - for (int i = 0; i < propertyCount; i++) { - profile.getProperties().add(this.readProperty(buf)); - } - return profile; - } - - public void writeGameProfile(ByteBuf buf, GameProfile profile) { - this.writeUUID(buf, profile.getId()); - this.writeString(buf, profile.getName()); - this.writeVarInt(buf, profile.getProperties().size()); - for (GameProfile.Property property : profile.getProperties()) { - this.writeProperty(buf, property); - } - } - public GameProfile.Property readProperty(ByteBuf buf) { String name = this.readString(buf); String value = this.readString(buf); @@ -776,6 +758,28 @@ public class MinecraftCodecHelper extends BasePacketCodecHelper { } } + public T readById(ByteBuf buf, IntFunction registry, Function custom) { + int id = this.readVarInt(buf); + if (id == 0) { + return custom.apply(buf); + } + return registry.apply(id - 1); + } + + public CustomSound readSoundEvent(ByteBuf buf) { + String name = this.readString(buf); + boolean isNewSystem = buf.readBoolean(); + return new CustomSound(name, isNewSystem, isNewSystem ? buf.readFloat() : 16.0F); + } + + public void writeSoundEvent(ByteBuf buf, Sound soundEvent) { + writeString(buf, soundEvent.getName()); + buf.writeBoolean(soundEvent.isNewSystem()); + if (soundEvent.isNewSystem()) { + buf.writeFloat(soundEvent.getRange()); + } + } + public NibbleArray3d readNibbleArray(ByteBuf buf, int size) { return new NibbleArray3d(this.readByteArray(buf, ignored -> size)); } diff --git a/src/main/java/com/github/steveice10/mc/protocol/data/game/level/sound/BuiltinSound.java b/src/main/java/com/github/steveice10/mc/protocol/data/game/level/sound/BuiltinSound.java index a14479c3..099fcefc 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/data/game/level/sound/BuiltinSound.java +++ b/src/main/java/com/github/steveice10/mc/protocol/data/game/level/sound/BuiltinSound.java @@ -1402,6 +1402,16 @@ public enum BuiltinSound implements Sound { private final @NonNull String name; + @Override + public boolean isNewSystem() { + return false; + } + + @Override + public float getRange() { + return 16F; + } + /** * For grabbing when the SoundPacket is sent. */ diff --git a/src/main/java/com/github/steveice10/mc/protocol/data/game/level/sound/CustomSound.java b/src/main/java/com/github/steveice10/mc/protocol/data/game/level/sound/CustomSound.java index 3d240274..e5cefe55 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/data/game/level/sound/CustomSound.java +++ b/src/main/java/com/github/steveice10/mc/protocol/data/game/level/sound/CustomSound.java @@ -2,10 +2,12 @@ package com.github.steveice10.mc.protocol.data.game.level.sound; import lombok.AllArgsConstructor; import lombok.Data; -import lombok.NonNull; +import org.jetbrains.annotations.NotNull; @Data @AllArgsConstructor public class CustomSound implements Sound { - private final @NonNull String name; + private final @NotNull String name; + private final boolean newSystem; + private final float range; } diff --git a/src/main/java/com/github/steveice10/mc/protocol/data/game/level/sound/Sound.java b/src/main/java/com/github/steveice10/mc/protocol/data/game/level/sound/Sound.java index 3500b834..f2c41cf9 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/data/game/level/sound/Sound.java +++ b/src/main/java/com/github/steveice10/mc/protocol/data/game/level/sound/Sound.java @@ -1,4 +1,9 @@ package com.github.steveice10.mc.protocol.data.game.level.sound; public interface Sound { + String getName(); + + boolean isNewSystem(); + + float getRange(); } diff --git a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/clientbound/ClientboundSoundEntityPacket.java b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/clientbound/ClientboundSoundEntityPacket.java index 5a959024..eca9d199 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/clientbound/ClientboundSoundEntityPacket.java +++ b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/clientbound/ClientboundSoundEntityPacket.java @@ -3,6 +3,8 @@ package com.github.steveice10.mc.protocol.packet.ingame.clientbound; import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper; import com.github.steveice10.mc.protocol.codec.MinecraftPacket; import com.github.steveice10.mc.protocol.data.game.level.sound.BuiltinSound; +import com.github.steveice10.mc.protocol.data.game.level.sound.CustomSound; +import com.github.steveice10.mc.protocol.data.game.level.sound.Sound; import com.github.steveice10.mc.protocol.data.game.level.sound.SoundCategory; import io.netty.buffer.ByteBuf; import lombok.AllArgsConstructor; @@ -16,15 +18,15 @@ import java.io.IOException; @With @AllArgsConstructor public class ClientboundSoundEntityPacket implements MinecraftPacket { - private final @NonNull BuiltinSound sound; + private final @NonNull Sound sound; private final @NonNull SoundCategory category; private final int entityId; private final float volume; private final float pitch; private final long seed; - public ClientboundSoundEntityPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException { - this.sound = helper.readBuiltinSound(in); + public ClientboundSoundEntityPacket(ByteBuf in, MinecraftCodecHelper helper) { + this.sound = helper.readById(in, BuiltinSound::from, helper::readSoundEvent); this.category = helper.readSoundCategory(in); this.entityId = helper.readVarInt(in); this.volume = in.readFloat(); @@ -34,7 +36,12 @@ public class ClientboundSoundEntityPacket implements MinecraftPacket { @Override public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException { - helper.writeBuiltinSound(out, this.sound); + if (this.sound instanceof CustomSound) { + helper.writeVarInt(out, 0); + helper.writeSoundEvent(out, this.sound); + } else { + helper.writeVarInt(out, ((BuiltinSound) this.sound).ordinal() + 1); + } helper.writeSoundCategory(out, this.category); helper.writeVarInt(out, this.entityId); out.writeFloat(this.volume); diff --git a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/clientbound/ClientboundStopSoundPacket.java b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/clientbound/ClientboundStopSoundPacket.java index 2260404e..2a0b9120 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/clientbound/ClientboundStopSoundPacket.java +++ b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/clientbound/ClientboundStopSoundPacket.java @@ -22,7 +22,7 @@ public class ClientboundStopSoundPacket implements MinecraftPacket { private static final int FLAG_SOUND = 0x02; private final @Nullable SoundCategory category; - private final @Nullable Sound sound; + private final @Nullable String sound; public ClientboundStopSoundPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException { int flags = in.readByte(); @@ -33,13 +33,7 @@ public class ClientboundStopSoundPacket implements MinecraftPacket { } if ((flags & FLAG_SOUND) != 0) { - String value = helper.readString(in); - Sound sound = helper.getBuiltinSound(value); - if (sound != null) { - this.sound = sound; - } else { - this.sound = new CustomSound(value); - } + this.sound = helper.readResourceLocation(in); } else { this.sound = null; } @@ -62,14 +56,7 @@ public class ClientboundStopSoundPacket implements MinecraftPacket { } if (this.sound != null) { - String value = ""; - if (this.sound instanceof CustomSound) { - value = ((CustomSound) this.sound).getName(); - } else if (this.sound instanceof BuiltinSound) { - value = ((BuiltinSound) this.sound).getName(); - } - - helper.writeString(out, value); + helper.writeResourceLocation(out, this.sound); } } } diff --git a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/clientbound/level/ClientboundSoundPacket.java b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/clientbound/level/ClientboundSoundPacket.java index 6a218ccc..d7934f06 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/clientbound/level/ClientboundSoundPacket.java +++ b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/clientbound/level/ClientboundSoundPacket.java @@ -19,8 +19,6 @@ import java.io.IOException; @AllArgsConstructor public class ClientboundSoundPacket implements MinecraftPacket { private final @NonNull Sound sound; - private final float range; - private final boolean isNewSystem; private final @NonNull SoundCategory category; private final double x; private final double y; @@ -29,17 +27,8 @@ public class ClientboundSoundPacket implements MinecraftPacket { private final float pitch; private final long seed; - public ClientboundSoundPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException { - int id = helper.readVarInt(in); - if (id == 0) { - this.sound = new CustomSound(helper.readString(in)); - this.isNewSystem = in.readBoolean(); - this.range = this.isNewSystem ? in.readFloat() : 16.0F; - } else { - this.sound = BuiltinSound.from(id - 1); - this.isNewSystem = false; - this.range = 16.0F; - } + public ClientboundSoundPacket(ByteBuf in, MinecraftCodecHelper helper) { + this.sound = helper.readById(in, BuiltinSound::from, helper::readSoundEvent); this.category = helper.readSoundCategory(in); this.x = in.readInt() / 8D; this.y = in.readInt() / 8D; @@ -53,12 +42,9 @@ public class ClientboundSoundPacket implements MinecraftPacket { public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException { if (this.sound instanceof CustomSound) { helper.writeVarInt(out, 0); - helper.writeString(out, ((CustomSound) this.sound).getName()); - if (this.isNewSystem) { - out.writeFloat(this.range); - } + helper.writeSoundEvent(out, this.sound); } else { - helper.writeVarInt(out, ((BuiltinSound)this.sound).ordinal() + 1); + helper.writeVarInt(out, ((BuiltinSound) this.sound).ordinal() + 1); } helper.writeSoundCategory(out, this.category); out.writeInt((int) (this.x * 8));