Update to 1.19.3-rc1

This commit is contained in:
Camotoy 2022-12-02 14:12:06 -05:00
parent 685882b90a
commit bb9b7e8299
No known key found for this signature in database
GPG key ID: 7EEFB66FE798081F
8 changed files with 71 additions and 70 deletions

View file

@ -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)
)

View file

@ -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> T readById(ByteBuf buf, IntFunction<T> registry, Function<ByteBuf, T> 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));
}

View file

@ -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.
*/

View file

@ -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;
}

View file

@ -1,4 +1,9 @@
package com.github.steveice10.mc.protocol.data.game.level.sound;
public interface Sound {
String getName();
boolean isNewSystem();
float getRange();
}

View file

@ -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);

View file

@ -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);
}
}
}

View file

@ -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));