mirror of
https://github.com/GeyserMC/MCProtocolLib.git
synced 2025-03-14 07:00:03 -04:00
Remake IOException removal
This commit is contained in:
parent
4f2e7a5b55
commit
5bd76a0e83
58 changed files with 176 additions and 168 deletions
protocol/src
main/java/org/geysermc/mcprotocollib
network
protocol
CheckedBiConsumer.javaCheckedFunction.javaMinecraftProtocol.java
codec
MinecraftCodecHelper.javaMinecraftPacket.javaMinecraftPacketSerializer.javaNBTException.javaPacketFactory.java
data/game
packet
common/clientbound
configuration/clientbound
ingame
clientbound
ClientboundBossEventPacket.javaClientboundCommandSuggestionsPacket.javaClientboundDisguisedChatPacket.javaClientboundPlayerChatPacket.javaClientboundPlayerInfoUpdatePacket.javaClientboundServerDataPacket.javaClientboundSystemChatPacket.javaClientboundTabListPacket.javaClientboundUpdateAdvancementsPacket.javaClientboundUpdateRecipesPacket.java
entity
ClientboundSetEntityDataPacket.javaClientboundSetEquipmentPacket.javaClientboundUpdateMobEffectPacket.java
player
inventory
ClientboundContainerSetContentPacket.javaClientboundContainerSetSlotPacket.javaClientboundMerchantOffersPacket.javaClientboundOpenScreenPacket.java
level
ClientboundBlockEntityDataPacket.javaClientboundExplodePacket.javaClientboundLevelChunkWithLightPacket.javaClientboundLevelParticlesPacket.javaClientboundMapItemDataPacket.javaClientboundTagQueryPacket.java
scoreboard
title
serverbound
login/clientbound
test/java/org/geysermc/mc/protocol/data
|
@ -50,7 +50,7 @@ public class PacketDefinition<T extends Packet, H extends PacketCodecHelper> {
|
|||
return this.serializer;
|
||||
}
|
||||
|
||||
public T newInstance(ByteBuf buf, H helper) throws IOException {
|
||||
public T newInstance(ByteBuf buf, H helper) {
|
||||
return this.serializer.deserialize(buf, helper, this);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import java.io.IOException;
|
|||
|
||||
public interface PacketSerializer<T extends Packet, H extends PacketCodecHelper> {
|
||||
|
||||
void serialize(ByteBuf buf, H helper, T packet) throws IOException;
|
||||
void serialize(ByteBuf buf, H helper, T packet);
|
||||
|
||||
T deserialize(ByteBuf buf, H helper, PacketDefinition<T, H> definition) throws IOException;
|
||||
T deserialize(ByteBuf buf, H helper, PacketDefinition<T, H> definition);
|
||||
}
|
||||
|
|
|
@ -145,11 +145,10 @@ public abstract class PacketProtocol {
|
|||
* @param buf The buffer to read the packet from.
|
||||
* @param codecHelper The codec helper.
|
||||
* @return The created packet.
|
||||
* @throws IOException if there was an IO error whilst reading the packet.
|
||||
* @throws IllegalArgumentException If the packet ID is not registered.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <H extends PacketCodecHelper> Packet createClientboundPacket(int id, ByteBuf buf, H codecHelper) throws IOException {
|
||||
public <H extends PacketCodecHelper> Packet createClientboundPacket(int id, ByteBuf buf, H codecHelper) {
|
||||
PacketDefinition<?, H> definition = (PacketDefinition<?, H>) this.clientbound.get(id);
|
||||
if (definition == null) {
|
||||
throw new IllegalArgumentException("Invalid packet id: " + id);
|
||||
|
@ -211,11 +210,10 @@ public abstract class PacketProtocol {
|
|||
* @param buf The buffer to read the packet from.
|
||||
* @param codecHelper The codec helper.
|
||||
* @return The created packet.
|
||||
* @throws IOException if there was an IO error whilst reading the packet.
|
||||
* @throws IllegalArgumentException If the packet ID is not registered.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <H extends PacketCodecHelper> Packet createServerboundPacket(int id, ByteBuf buf, H codecHelper) throws IOException {
|
||||
public <H extends PacketCodecHelper> Packet createServerboundPacket(int id, ByteBuf buf, H codecHelper) {
|
||||
PacketDefinition<?, H> definition = (PacketDefinition<?, H>) this.serverbound.get(id);
|
||||
if (definition == null) {
|
||||
throw new IllegalArgumentException("Invalid packet id: " + id);
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
package org.geysermc.mcprotocollib.protocol;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface CheckedBiConsumer<T, U, E extends Throwable> {
|
||||
void accept(T t, U u) throws E;
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
package org.geysermc.mcprotocollib.protocol;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface CheckedFunction<T, R, E extends Throwable> {
|
||||
R apply(T t) throws E;
|
||||
}
|
|
@ -203,7 +203,7 @@ public class MinecraftProtocol extends PacketProtocol {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Packet createClientboundPacket(int id, ByteBuf buf, PacketCodecHelper codecHelper) throws IOException {
|
||||
public Packet createClientboundPacket(int id, ByteBuf buf, PacketCodecHelper codecHelper) {
|
||||
return this.stateCodec.createClientboundPacket(id, buf, codecHelper);
|
||||
}
|
||||
|
||||
|
@ -223,7 +223,7 @@ public class MinecraftProtocol extends PacketProtocol {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Packet createServerboundPacket(int id, ByteBuf buf, PacketCodecHelper codecHelper) throws IOException {
|
||||
public Packet createServerboundPacket(int id, ByteBuf buf, PacketCodecHelper codecHelper) {
|
||||
return this.stateCodec.createServerboundPacket(id, buf, codecHelper);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
package org.geysermc.mcprotocollib.protocol.codec;
|
||||
|
||||
import com.github.steveice10.mc.auth.data.GameProfile;
|
||||
import org.geysermc.mcprotocollib.protocol.CheckedBiConsumer;
|
||||
import org.geysermc.mcprotocollib.protocol.CheckedFunction;
|
||||
import org.geysermc.mcprotocollib.protocol.data.DefaultComponentSerializer;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.Identifier;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.chat.numbers.BlankFormat;
|
||||
|
@ -86,6 +84,7 @@ import java.util.EnumSet;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.IntFunction;
|
||||
import java.util.function.ObjIntConsumer;
|
||||
|
@ -105,7 +104,7 @@ public class MinecraftCodecHelper extends BasePacketCodecHelper {
|
|||
protected CompoundTag registry;
|
||||
|
||||
@Nullable
|
||||
public <T, E extends Throwable> T readNullable(ByteBuf buf, CheckedFunction<ByteBuf, T, E> ifPresent) throws E {
|
||||
public <T> T readNullable(ByteBuf buf, Function<ByteBuf, T> ifPresent) {
|
||||
if (buf.readBoolean()) {
|
||||
return ifPresent.apply(buf);
|
||||
} else {
|
||||
|
@ -113,7 +112,7 @@ public class MinecraftCodecHelper extends BasePacketCodecHelper {
|
|||
}
|
||||
}
|
||||
|
||||
public <T, E extends Throwable> void writeNullable(ByteBuf buf, @Nullable T value, CheckedBiConsumer<ByteBuf, T, E> ifPresent) throws E {
|
||||
public <T> void writeNullable(ByteBuf buf, @Nullable T value, BiConsumer<ByteBuf, T> ifPresent) {
|
||||
if (value != null) {
|
||||
buf.writeBoolean(true);
|
||||
ifPresent.accept(buf, value);
|
||||
|
@ -189,12 +188,12 @@ public class MinecraftCodecHelper extends BasePacketCodecHelper {
|
|||
}
|
||||
|
||||
@Nullable
|
||||
public CompoundTag readAnyTag(ByteBuf buf) throws IOException {
|
||||
public CompoundTag readAnyTag(ByteBuf buf) {
|
||||
return readAnyTag(buf, CompoundTag.class);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public CompoundTag readAnyTagOrThrow(ByteBuf buf) throws IOException {
|
||||
public CompoundTag readAnyTagOrThrow(ByteBuf buf) {
|
||||
CompoundTag tag = readAnyTag(buf);
|
||||
if (tag == null) {
|
||||
throw new IllegalArgumentException("Got end-tag when trying to read CompoundTag");
|
||||
|
@ -203,13 +202,18 @@ public class MinecraftCodecHelper extends BasePacketCodecHelper {
|
|||
}
|
||||
|
||||
@Nullable
|
||||
public <T extends Tag> T readAnyTag(ByteBuf buf, Class<T> expected) throws IOException {
|
||||
Tag tag = NBTIO.readAnyTag(new InputStream() {
|
||||
@Override
|
||||
public int read() {
|
||||
return buf.readUnsignedByte();
|
||||
}
|
||||
});
|
||||
public <T extends Tag> T readAnyTag(ByteBuf buf, Class<T> expected) {
|
||||
Tag tag = null;
|
||||
try {
|
||||
tag = NBTIO.readAnyTag(new InputStream() {
|
||||
@Override
|
||||
public int read() {
|
||||
return buf.readUnsignedByte();
|
||||
}
|
||||
});
|
||||
} catch (IOException e) {
|
||||
throw new NBTException(e);
|
||||
}
|
||||
|
||||
if (tag == null) {
|
||||
return null;
|
||||
|
@ -222,17 +226,21 @@ public class MinecraftCodecHelper extends BasePacketCodecHelper {
|
|||
return expected.cast(tag);
|
||||
}
|
||||
|
||||
public <T extends Tag> void writeAnyTag(ByteBuf buf, @Nullable T tag) throws IOException {
|
||||
NBTIO.writeAnyTag(new OutputStream() {
|
||||
@Override
|
||||
public void write(int b) {
|
||||
buf.writeByte(b);
|
||||
}
|
||||
}, tag);
|
||||
public <T extends Tag> void writeAnyTag(ByteBuf buf, @Nullable T tag) {
|
||||
try {
|
||||
NBTIO.writeAnyTag(new OutputStream() {
|
||||
@Override
|
||||
public void write(int b) {
|
||||
buf.writeByte(b);
|
||||
}
|
||||
}, tag);
|
||||
} catch (IOException e) {
|
||||
throw new NBTException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ItemStack readItemStack(ByteBuf buf) throws IOException {
|
||||
public ItemStack readItemStack(ByteBuf buf) {
|
||||
boolean present = buf.readBoolean();
|
||||
if (!present) {
|
||||
return null;
|
||||
|
@ -242,7 +250,7 @@ public class MinecraftCodecHelper extends BasePacketCodecHelper {
|
|||
return new ItemStack(item, buf.readByte(), this.readAnyTag(buf));
|
||||
}
|
||||
|
||||
public void writeItemStack(ByteBuf buf, @Nullable ItemStack item) throws IOException {
|
||||
public void writeItemStack(ByteBuf buf, @Nullable ItemStack item) {
|
||||
buf.writeBoolean(item != null);
|
||||
if (item != null) {
|
||||
this.writeVarInt(buf, item.getId());
|
||||
|
@ -335,7 +343,7 @@ public class MinecraftCodecHelper extends BasePacketCodecHelper {
|
|||
this.writeVarInt(buf, e.ordinal());
|
||||
}
|
||||
|
||||
public Component readComponent(ByteBuf buf) throws IOException {
|
||||
public Component readComponent(ByteBuf buf) {
|
||||
// do not use CompoundTag, as mojang serializes a plaintext component as just a single StringTag
|
||||
Tag tag = readAnyTag(buf, Tag.class);
|
||||
if (tag == null) {
|
||||
|
@ -345,13 +353,13 @@ public class MinecraftCodecHelper extends BasePacketCodecHelper {
|
|||
return DefaultComponentSerializer.get().deserializeFromTree(json);
|
||||
}
|
||||
|
||||
public void writeComponent(ByteBuf buf, Component component) throws IOException {
|
||||
public void writeComponent(ByteBuf buf, Component component) {
|
||||
JsonElement json = DefaultComponentSerializer.get().serializeToTree(component);
|
||||
Tag tag = NbtComponentSerializer.jsonComponentToTag(json);
|
||||
writeAnyTag(buf, tag);
|
||||
}
|
||||
|
||||
public EntityMetadata<?, ?>[] readEntityMetadata(ByteBuf buf) throws IOException {
|
||||
public EntityMetadata<?, ?>[] readEntityMetadata(ByteBuf buf) {
|
||||
List<EntityMetadata<?, ?>> ret = new ArrayList<>();
|
||||
int id;
|
||||
while ((id = buf.readUnsignedByte()) != 255) {
|
||||
|
@ -361,7 +369,7 @@ public class MinecraftCodecHelper extends BasePacketCodecHelper {
|
|||
return ret.toArray(new EntityMetadata<?, ?>[0]);
|
||||
}
|
||||
|
||||
public void writeEntityMetadata(ByteBuf buf, EntityMetadata<?, ?>[] metadata) throws IOException {
|
||||
public void writeEntityMetadata(ByteBuf buf, EntityMetadata<?, ?>[] metadata) {
|
||||
for (EntityMetadata<?, ?> meta : metadata) {
|
||||
this.writeMetadata(buf, meta);
|
||||
}
|
||||
|
@ -369,12 +377,12 @@ public class MinecraftCodecHelper extends BasePacketCodecHelper {
|
|||
buf.writeByte(255);
|
||||
}
|
||||
|
||||
public EntityMetadata<?, ?> readMetadata(ByteBuf buf, int id) throws IOException {
|
||||
public EntityMetadata<?, ?> readMetadata(ByteBuf buf, int id) {
|
||||
MetadataType<?> type = this.readMetadataType(buf);
|
||||
return type.readMetadata(this, buf, id);
|
||||
}
|
||||
|
||||
public void writeMetadata(ByteBuf buf, EntityMetadata<?, ?> metadata) throws IOException {
|
||||
public void writeMetadata(ByteBuf buf, EntityMetadata<?, ?> metadata) {
|
||||
buf.writeByte(metadata.getId());
|
||||
this.writeMetadataType(buf, metadata.getType());
|
||||
metadata.write(this, buf);
|
||||
|
@ -437,17 +445,17 @@ public class MinecraftCodecHelper extends BasePacketCodecHelper {
|
|||
this.writeEnum(buf, type);
|
||||
}
|
||||
|
||||
public Particle readParticle(ByteBuf buf) throws IOException {
|
||||
public Particle readParticle(ByteBuf buf) {
|
||||
ParticleType particleType = this.readParticleType(buf);
|
||||
return new Particle(particleType, this.readParticleData(buf, particleType));
|
||||
}
|
||||
|
||||
public void writeParticle(ByteBuf buf, Particle particle) throws IOException {
|
||||
public void writeParticle(ByteBuf buf, Particle particle) {
|
||||
this.writeEnum(buf, particle.getType());
|
||||
this.writeParticleData(buf, particle.getType(), particle.getData());
|
||||
}
|
||||
|
||||
public ParticleData readParticleData(ByteBuf buf, ParticleType type) throws IOException {
|
||||
public ParticleData readParticleData(ByteBuf buf, ParticleType type) {
|
||||
return switch (type) {
|
||||
case BLOCK, BLOCK_MARKER -> new BlockParticleData(this.readVarInt(buf));
|
||||
case DUST -> {
|
||||
|
@ -476,7 +484,7 @@ public class MinecraftCodecHelper extends BasePacketCodecHelper {
|
|||
};
|
||||
}
|
||||
|
||||
public void writeParticleData(ByteBuf buf, ParticleType type, ParticleData data) throws IOException {
|
||||
public void writeParticleData(ByteBuf buf, ParticleType type, ParticleData data) {
|
||||
switch (type) {
|
||||
case BLOCK, BLOCK_MARKER -> this.writeVarInt(buf, ((BlockParticleData) data).getBlockState());
|
||||
case DUST -> {
|
||||
|
@ -521,7 +529,7 @@ public class MinecraftCodecHelper extends BasePacketCodecHelper {
|
|||
}
|
||||
}
|
||||
|
||||
public NumberFormat readNumberFormat(ByteBuf buf) throws IOException {
|
||||
public NumberFormat readNumberFormat(ByteBuf buf) {
|
||||
int id = this.readVarInt(buf);
|
||||
return switch (id) {
|
||||
case 0 -> BlankFormat.INSTANCE;
|
||||
|
@ -531,7 +539,7 @@ public class MinecraftCodecHelper extends BasePacketCodecHelper {
|
|||
};
|
||||
}
|
||||
|
||||
public void writeNumberFormat(ByteBuf buf, NumberFormat numberFormat) throws IOException {
|
||||
public void writeNumberFormat(ByteBuf buf, NumberFormat numberFormat) {
|
||||
if (numberFormat instanceof BlankFormat) {
|
||||
this.writeVarInt(buf, 0);
|
||||
} else if (numberFormat instanceof StyledFormat styledFormat) {
|
||||
|
@ -708,7 +716,7 @@ public class MinecraftCodecHelper extends BasePacketCodecHelper {
|
|||
buf.writeByte(event.ordinal());
|
||||
}
|
||||
|
||||
public Ingredient readRecipeIngredient(ByteBuf buf) throws IOException {
|
||||
public Ingredient readRecipeIngredient(ByteBuf buf) {
|
||||
ItemStack[] options = new ItemStack[this.readVarInt(buf)];
|
||||
for (int i = 0; i < options.length; i++) {
|
||||
options[i] = this.readItemStack(buf);
|
||||
|
@ -717,14 +725,14 @@ public class MinecraftCodecHelper extends BasePacketCodecHelper {
|
|||
return new Ingredient(options);
|
||||
}
|
||||
|
||||
public void writeRecipeIngredient(ByteBuf buf, Ingredient ingredient) throws IOException {
|
||||
public void writeRecipeIngredient(ByteBuf buf, Ingredient ingredient) {
|
||||
this.writeVarInt(buf, ingredient.getOptions().length);
|
||||
for (ItemStack option : ingredient.getOptions()) {
|
||||
this.writeItemStack(buf, option);
|
||||
}
|
||||
}
|
||||
|
||||
public DataPalette readDataPalette(ByteBuf buf, PaletteType paletteType) throws IOException {
|
||||
public DataPalette readDataPalette(ByteBuf buf, PaletteType paletteType) {
|
||||
int bitsPerEntry = buf.readByte() & 0xFF;
|
||||
Palette palette = this.readPalette(buf, paletteType, bitsPerEntry);
|
||||
BitStorage storage;
|
||||
|
@ -746,7 +754,7 @@ public class MinecraftCodecHelper extends BasePacketCodecHelper {
|
|||
* @deprecated globalPaletteBits is no longer in use, use {@link #readDataPalette(ByteBuf, PaletteType)} instead.
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
public DataPalette readDataPalette(ByteBuf buf, PaletteType paletteType, int globalPaletteBits) throws IOException {
|
||||
public DataPalette readDataPalette(ByteBuf buf, PaletteType paletteType, int globalPaletteBits) {
|
||||
return this.readDataPalette(buf, paletteType);
|
||||
}
|
||||
|
||||
|
@ -785,7 +793,7 @@ public class MinecraftCodecHelper extends BasePacketCodecHelper {
|
|||
}
|
||||
}
|
||||
|
||||
public ChunkSection readChunkSection(ByteBuf buf) throws IOException {
|
||||
public ChunkSection readChunkSection(ByteBuf buf) {
|
||||
int blockCount = buf.readShort();
|
||||
|
||||
DataPalette chunkPalette = this.readDataPalette(buf, PaletteType.CHUNK);
|
||||
|
@ -797,7 +805,7 @@ public class MinecraftCodecHelper extends BasePacketCodecHelper {
|
|||
* @deprecated globalBiomePaletteBits is no longer in use, use {@link #readChunkSection(ByteBuf)} instead.
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
public ChunkSection readChunkSection(ByteBuf buf, int globalBiomePaletteBits) throws IOException {
|
||||
public ChunkSection readChunkSection(ByteBuf buf, int globalBiomePaletteBits) {
|
||||
return this.readChunkSection(buf);
|
||||
}
|
||||
|
||||
|
|
|
@ -7,5 +7,5 @@ import java.io.IOException;
|
|||
|
||||
public interface MinecraftPacket extends Packet {
|
||||
|
||||
void serialize(ByteBuf buf, MinecraftCodecHelper helper) throws IOException;
|
||||
void serialize(ByteBuf buf, MinecraftCodecHelper helper);
|
||||
}
|
||||
|
|
|
@ -12,12 +12,12 @@ public class MinecraftPacketSerializer<T extends MinecraftPacket> implements Pac
|
|||
private final PacketFactory<T, MinecraftCodecHelper> factory;
|
||||
|
||||
@Override
|
||||
public void serialize(ByteBuf buf, MinecraftCodecHelper helper, T packet) throws IOException {
|
||||
public void serialize(ByteBuf buf, MinecraftCodecHelper helper, T packet) {
|
||||
packet.serialize(buf, helper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T deserialize(ByteBuf buf, MinecraftCodecHelper helper, PacketDefinition<T, MinecraftCodecHelper> definition) throws IOException {
|
||||
public T deserialize(ByteBuf buf, MinecraftCodecHelper helper, PacketDefinition<T, MinecraftCodecHelper> definition) {
|
||||
return this.factory.construct(buf, helper);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
package org.geysermc.mcprotocollib.protocol.codec;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Serial;
|
||||
|
||||
public class NBTException extends RuntimeException {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public NBTException(IOException e) {
|
||||
super(e);
|
||||
}
|
||||
}
|
|
@ -21,5 +21,5 @@ public interface PacketFactory<T extends Packet, H extends PacketCodecHelper> {
|
|||
* @param codecHelper the codec helper
|
||||
* @return a new packet from the input
|
||||
*/
|
||||
T construct(ByteBuf buf, H codecHelper) throws IOException;
|
||||
T construct(ByteBuf buf, H codecHelper);
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ public abstract class EntityMetadata<V, T extends MetadataType<V>> {
|
|||
* Overridden for primitive classes. This write method still checks for these primitives in the event
|
||||
* they are manually created using {@link ObjectEntityMetadata}.
|
||||
*/
|
||||
public void write(MinecraftCodecHelper helper, ByteBuf out) throws IOException {
|
||||
public void write(MinecraftCodecHelper helper, ByteBuf out) {
|
||||
this.type.writeMetadata(helper, out, this.getValue());
|
||||
}
|
||||
|
||||
|
|
|
@ -71,38 +71,38 @@ public class MetadataType<T> {
|
|||
VALUES.add(this);
|
||||
}
|
||||
|
||||
public EntityMetadata<T, ? extends MetadataType<T>> readMetadata(MinecraftCodecHelper helper, ByteBuf input, int id) throws IOException {
|
||||
public EntityMetadata<T, ? extends MetadataType<T>> readMetadata(MinecraftCodecHelper helper, ByteBuf input, int id) {
|
||||
return this.metadataFactory.create(id, this, this.reader.read(helper, input));
|
||||
}
|
||||
|
||||
public void writeMetadata(MinecraftCodecHelper helper, ByteBuf output, T value) throws IOException {
|
||||
public void writeMetadata(MinecraftCodecHelper helper, ByteBuf output, T value) {
|
||||
this.writer.write(helper, output, value);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface Reader<V> {
|
||||
V read(MinecraftCodecHelper helper, ByteBuf input) throws IOException;
|
||||
V read(MinecraftCodecHelper helper, ByteBuf input);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface Writer<V> {
|
||||
void write(MinecraftCodecHelper helper, ByteBuf output, V value) throws IOException;
|
||||
void write(MinecraftCodecHelper helper, ByteBuf output, V value);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface BasicReader<V> extends Reader<V> {
|
||||
V read(ByteBuf input) throws IOException;
|
||||
V read(ByteBuf input);
|
||||
|
||||
default V read(MinecraftCodecHelper helper, ByteBuf input) throws IOException {
|
||||
default V read(MinecraftCodecHelper helper, ByteBuf input) {
|
||||
return this.read(input);
|
||||
}
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface BasicWriter<V> extends Writer<V> {
|
||||
void write(ByteBuf output, V value) throws IOException;
|
||||
void write(ByteBuf output, V value);
|
||||
|
||||
default void write(MinecraftCodecHelper helper, ByteBuf output, V value) throws IOException {
|
||||
default void write(MinecraftCodecHelper helper, ByteBuf output, V value) {
|
||||
this.write(output, value);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ public class BooleanEntityMetadata extends EntityMetadata<Boolean, BooleanMetada
|
|||
}
|
||||
|
||||
@Override
|
||||
public void write(MinecraftCodecHelper helper, ByteBuf out) throws IOException {
|
||||
public void write(MinecraftCodecHelper helper, ByteBuf out) {
|
||||
this.type.writeMetadataPrimitive(out, this.value);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ public class ByteEntityMetadata extends EntityMetadata<Byte, ByteMetadataType> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void write(MinecraftCodecHelper helper, ByteBuf out) throws IOException {
|
||||
public void write(MinecraftCodecHelper helper, ByteBuf out) {
|
||||
this.type.writeMetadataPrimitive(out, this.value);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ public class FloatEntityMetadata extends EntityMetadata<Float, FloatMetadataType
|
|||
}
|
||||
|
||||
@Override
|
||||
public void write(MinecraftCodecHelper helper, ByteBuf out) throws IOException {
|
||||
public void write(MinecraftCodecHelper helper, ByteBuf out) {
|
||||
this.type.writeMetadataPrimitive(out, this.value);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ public class IntEntityMetadata extends EntityMetadata<Integer, IntMetadataType>
|
|||
}
|
||||
|
||||
@Override
|
||||
public void write(MinecraftCodecHelper helper, ByteBuf out) throws IOException {
|
||||
public void write(MinecraftCodecHelper helper, ByteBuf out) {
|
||||
this.type.writeMetadataPrimitive(helper, out, value);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ public class LongEntityMetadata extends EntityMetadata<Long, LongMetadataType> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void write(MinecraftCodecHelper helper, ByteBuf out) throws IOException {
|
||||
public void write(MinecraftCodecHelper helper, ByteBuf out) {
|
||||
this.type.writeMetadataPrimitive(helper, out, value);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ public class LightUpdateData {
|
|||
}
|
||||
}
|
||||
|
||||
public static void write(ByteBuf out, MinecraftCodecHelper helper, LightUpdateData data) throws IOException {
|
||||
public static void write(ByteBuf out, MinecraftCodecHelper helper, LightUpdateData data) {
|
||||
data.write(out, helper);
|
||||
}
|
||||
|
||||
|
|
|
@ -22,12 +22,12 @@ public class ClientboundDisconnectPacket implements MinecraftPacket {
|
|||
this(DefaultComponentSerializer.get().deserialize(reason));
|
||||
}
|
||||
|
||||
public ClientboundDisconnectPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||
public ClientboundDisconnectPacket(ByteBuf in, MinecraftCodecHelper helper) {
|
||||
this.reason = helper.readComponent(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
|
||||
helper.writeComponent(out, this.reason);
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ public class ClientboundResourcePackPushPacket implements MinecraftPacket {
|
|||
private final boolean required;
|
||||
private final @Nullable Component prompt;
|
||||
|
||||
public ClientboundResourcePackPushPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||
public ClientboundResourcePackPushPacket(ByteBuf in, MinecraftCodecHelper helper) {
|
||||
this.id = helper.readUUID(in);
|
||||
this.url = helper.readString(in);
|
||||
this.hash = helper.readString(in);
|
||||
|
@ -32,7 +32,7 @@ public class ClientboundResourcePackPushPacket implements MinecraftPacket {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
|
||||
helper.writeUUID(out, this.id);
|
||||
helper.writeString(out, this.url);
|
||||
helper.writeString(out, this.hash);
|
||||
|
|
|
@ -16,12 +16,12 @@ import java.io.IOException;
|
|||
public class ClientboundRegistryDataPacket implements MinecraftPacket {
|
||||
private final CompoundTag registry;
|
||||
|
||||
public ClientboundRegistryDataPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||
public ClientboundRegistryDataPacket(ByteBuf in, MinecraftCodecHelper helper) {
|
||||
this.registry = helper.readAnyTag(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
|
||||
helper.writeAnyTag(out, this.registry);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ public class ClientboundBossEventPacket implements MinecraftPacket {
|
|||
this.showFog = showFog;
|
||||
}
|
||||
|
||||
public ClientboundBossEventPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||
public ClientboundBossEventPacket(ByteBuf in, MinecraftCodecHelper helper) {
|
||||
this.uuid = helper.readUUID(in);
|
||||
this.action = BossBarAction.from(helper.readVarInt(in));
|
||||
|
||||
|
@ -101,7 +101,7 @@ public class ClientboundBossEventPacket implements MinecraftPacket {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
|
||||
helper.writeUUID(out, this.uuid);
|
||||
helper.writeVarInt(out, this.action.ordinal());
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ public class ClientboundCommandSuggestionsPacket implements MinecraftPacket {
|
|||
this.tooltips = Arrays.copyOf(tooltips, tooltips.length);
|
||||
}
|
||||
|
||||
public ClientboundCommandSuggestionsPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||
public ClientboundCommandSuggestionsPacket(ByteBuf in, MinecraftCodecHelper helper) {
|
||||
this.transactionId = helper.readVarInt(in);
|
||||
this.start = helper.readVarInt(in);
|
||||
this.length = helper.readVarInt(in);
|
||||
|
@ -47,7 +47,7 @@ public class ClientboundCommandSuggestionsPacket implements MinecraftPacket {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
|
||||
helper.writeVarInt(out, this.transactionId);
|
||||
helper.writeVarInt(out, this.start);
|
||||
helper.writeVarInt(out, this.length);
|
||||
|
|
|
@ -25,7 +25,7 @@ public class ClientboundDisguisedChatPacket implements MinecraftPacket {
|
|||
private final @Nullable Component targetName;
|
||||
|
||||
|
||||
public ClientboundDisguisedChatPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||
public ClientboundDisguisedChatPacket(ByteBuf in, MinecraftCodecHelper helper) {
|
||||
this.message = helper.readComponent(in);
|
||||
this.chatType = helper.readVarInt(in);
|
||||
this.name = helper.readComponent(in);
|
||||
|
@ -33,7 +33,7 @@ public class ClientboundDisguisedChatPacket implements MinecraftPacket {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
|
||||
helper.writeComponent(out, this.message);
|
||||
helper.writeVarInt(out, this.chatType);
|
||||
helper.writeComponent(out, this.name);
|
||||
|
|
|
@ -37,7 +37,7 @@ public class ClientboundPlayerChatPacket implements MinecraftPacket {
|
|||
private final Component name;
|
||||
private final @Nullable Component targetName;
|
||||
|
||||
public ClientboundPlayerChatPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||
public ClientboundPlayerChatPacket(ByteBuf in, MinecraftCodecHelper helper) {
|
||||
this.sender = helper.readUUID(in);
|
||||
this.index = helper.readVarInt(in);
|
||||
if (in.readBoolean()) {
|
||||
|
@ -65,7 +65,7 @@ public class ClientboundPlayerChatPacket implements MinecraftPacket {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
|
||||
helper.writeUUID(out, this.sender);
|
||||
helper.writeVarInt(out, this.index);
|
||||
out.writeBoolean(this.messageSignature != null);
|
||||
|
|
|
@ -28,7 +28,7 @@ public class ClientboundPlayerInfoUpdatePacket implements MinecraftPacket {
|
|||
private final EnumSet<PlayerListEntryAction> actions;
|
||||
private final PlayerListEntry[] entries;
|
||||
|
||||
public ClientboundPlayerInfoUpdatePacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||
public ClientboundPlayerInfoUpdatePacket(ByteBuf in, MinecraftCodecHelper helper) {
|
||||
this.actions = helper.readEnumSet(in, PlayerListEntryAction.VALUES);
|
||||
this.entries = new PlayerListEntry[helper.readVarInt(in)];
|
||||
for (int count = 0; count < this.entries.length; count++) {
|
||||
|
@ -58,7 +58,7 @@ public class ClientboundPlayerInfoUpdatePacket implements MinecraftPacket {
|
|||
try {
|
||||
publicKey = KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(keyBytes));
|
||||
} catch (GeneralSecurityException e) {
|
||||
throw new IOException("Could not decode public key.", e);
|
||||
throw new RuntimeException("Could not decode public key.", e);
|
||||
}
|
||||
|
||||
entry.setPublicKey(publicKey);
|
||||
|
@ -91,7 +91,7 @@ public class ClientboundPlayerInfoUpdatePacket implements MinecraftPacket {
|
|||
}
|
||||
}
|
||||
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
|
||||
helper.writeEnumSet(out, this.actions, PlayerListEntryAction.VALUES);
|
||||
helper.writeVarInt(out, this.entries.length);
|
||||
for (PlayerListEntry entry : this.entries) {
|
||||
|
|
|
@ -19,14 +19,14 @@ public class ClientboundServerDataPacket implements MinecraftPacket {
|
|||
private final byte @Nullable[] iconBytes;
|
||||
private final boolean enforcesSecureChat;
|
||||
|
||||
public ClientboundServerDataPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||
public ClientboundServerDataPacket(ByteBuf in, MinecraftCodecHelper helper) {
|
||||
this.motd = helper.readComponent(in);
|
||||
this.iconBytes = helper.readNullable(in, helper::readByteArray);
|
||||
this.enforcesSecureChat = in.readBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
|
||||
helper.writeComponent(out, this.motd);
|
||||
helper.writeNullable(out, this.iconBytes, helper::writeByteArray);
|
||||
out.writeBoolean(this.enforcesSecureChat);
|
||||
|
|
|
@ -17,13 +17,13 @@ public class ClientboundSystemChatPacket implements MinecraftPacket {
|
|||
private final Component content;
|
||||
private final boolean overlay;
|
||||
|
||||
public ClientboundSystemChatPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||
public ClientboundSystemChatPacket(ByteBuf in, MinecraftCodecHelper helper) {
|
||||
this.content = helper.readComponent(in);
|
||||
this.overlay = in.readBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
|
||||
helper.writeComponent(out, this.content);
|
||||
out.writeBoolean(this.overlay);
|
||||
}
|
||||
|
|
|
@ -18,13 +18,13 @@ public class ClientboundTabListPacket implements MinecraftPacket {
|
|||
private final @NonNull Component header;
|
||||
private final @NonNull Component footer;
|
||||
|
||||
public ClientboundTabListPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||
public ClientboundTabListPacket(ByteBuf in, MinecraftCodecHelper helper) {
|
||||
this.header = helper.readComponent(in);
|
||||
this.footer = helper.readComponent(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
|
||||
helper.writeComponent(out, this.header);
|
||||
helper.writeComponent(out, this.footer);
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ public class ClientboundUpdateAdvancementsPacket implements MinecraftPacket {
|
|||
return progress.get(criterionId);
|
||||
}
|
||||
|
||||
public ClientboundUpdateAdvancementsPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||
public ClientboundUpdateAdvancementsPacket(ByteBuf in, MinecraftCodecHelper helper) {
|
||||
this.reset = in.readBoolean();
|
||||
|
||||
this.advancements = new Advancement[helper.readVarInt(in)];
|
||||
|
@ -111,7 +111,7 @@ public class ClientboundUpdateAdvancementsPacket implements MinecraftPacket {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
|
||||
out.writeBoolean(this.reset);
|
||||
|
||||
helper.writeVarInt(out, this.advancements.length);
|
||||
|
|
|
@ -22,7 +22,7 @@ import java.io.IOException;
|
|||
public class ClientboundUpdateRecipesPacket implements MinecraftPacket {
|
||||
private final @NonNull Recipe[] recipes;
|
||||
|
||||
public ClientboundUpdateRecipesPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||
public ClientboundUpdateRecipesPacket(ByteBuf in, MinecraftCodecHelper helper) {
|
||||
this.recipes = new Recipe[helper.readVarInt(in)];
|
||||
for (int i = 0; i < this.recipes.length; i++) {
|
||||
RecipeType type = RecipeType.from(helper.readResourceLocation(in));
|
||||
|
@ -102,7 +102,7 @@ public class ClientboundUpdateRecipesPacket implements MinecraftPacket {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
|
||||
helper.writeVarInt(out, this.recipes.length);
|
||||
for (Recipe recipe : this.recipes) {
|
||||
helper.writeResourceLocation(out, recipe.getType().getResourceLocation());
|
||||
|
|
|
@ -18,13 +18,13 @@ public class ClientboundSetEntityDataPacket implements MinecraftPacket {
|
|||
private final int entityId;
|
||||
private final @NonNull EntityMetadata<?, ?>[] metadata;
|
||||
|
||||
public ClientboundSetEntityDataPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||
public ClientboundSetEntityDataPacket(ByteBuf in, MinecraftCodecHelper helper) {
|
||||
this.entityId = helper.readVarInt(in);
|
||||
this.metadata = helper.readEntityMetadata(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
|
||||
helper.writeVarInt(out, this.entityId);
|
||||
helper.writeEntityMetadata(out, this.metadata);
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ public class ClientboundSetEquipmentPacket implements MinecraftPacket {
|
|||
private final int entityId;
|
||||
private final @NonNull Equipment[] equipment;
|
||||
|
||||
public ClientboundSetEquipmentPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||
public ClientboundSetEquipmentPacket(ByteBuf in, MinecraftCodecHelper helper) {
|
||||
this.entityId = helper.readVarInt(in);
|
||||
boolean hasNextEntry = true;
|
||||
List<Equipment> list = new ArrayList<>();
|
||||
|
@ -37,7 +37,7 @@ public class ClientboundSetEquipmentPacket implements MinecraftPacket {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
|
||||
helper.writeVarInt(out, this.entityId);
|
||||
for (int i = 0; i < this.equipment.length; i++) {
|
||||
int rawSlot = this.equipment[i].getSlot().ordinal();
|
||||
|
|
|
@ -30,7 +30,7 @@ public class ClientboundUpdateMobEffectPacket implements MinecraftPacket {
|
|||
private final boolean showIcon;
|
||||
private final @Nullable CompoundTag factorData;
|
||||
|
||||
public ClientboundUpdateMobEffectPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||
public ClientboundUpdateMobEffectPacket(ByteBuf in, MinecraftCodecHelper helper) {
|
||||
this.entityId = helper.readVarInt(in);
|
||||
this.effect = helper.readEffect(in);
|
||||
this.amplifier = in.readByte();
|
||||
|
@ -44,7 +44,7 @@ public class ClientboundUpdateMobEffectPacket implements MinecraftPacket {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
|
||||
helper.writeVarInt(out, this.entityId);
|
||||
helper.writeEffect(out, this.effect);
|
||||
out.writeByte(this.amplifier);
|
||||
|
|
|
@ -17,13 +17,13 @@ public class ClientboundPlayerCombatKillPacket implements MinecraftPacket {
|
|||
private final int playerId;
|
||||
private final Component message;
|
||||
|
||||
public ClientboundPlayerCombatKillPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||
public ClientboundPlayerCombatKillPacket(ByteBuf in, MinecraftCodecHelper helper) {
|
||||
this.playerId = helper.readVarInt(in);
|
||||
this.message = helper.readComponent(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
|
||||
helper.writeVarInt(out, this.playerId);
|
||||
helper.writeComponent(out, this.message);
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ public class ClientboundContainerSetContentPacket implements MinecraftPacket {
|
|||
private final @Nullable ItemStack @NonNull [] items;
|
||||
private final @Nullable ItemStack carriedItem;
|
||||
|
||||
public ClientboundContainerSetContentPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||
public ClientboundContainerSetContentPacket(ByteBuf in, MinecraftCodecHelper helper) {
|
||||
this.containerId = in.readUnsignedByte();
|
||||
this.stateId = helper.readVarInt(in);
|
||||
this.items = new ItemStack[helper.readVarInt(in)];
|
||||
|
@ -32,7 +32,7 @@ public class ClientboundContainerSetContentPacket implements MinecraftPacket {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
|
||||
out.writeByte(this.containerId);
|
||||
helper.writeVarInt(out, this.stateId);
|
||||
helper.writeVarInt(out, this.items.length);
|
||||
|
|
|
@ -20,7 +20,7 @@ public class ClientboundContainerSetSlotPacket implements MinecraftPacket {
|
|||
private final int slot;
|
||||
private final @Nullable ItemStack item;
|
||||
|
||||
public ClientboundContainerSetSlotPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||
public ClientboundContainerSetSlotPacket(ByteBuf in, MinecraftCodecHelper helper) {
|
||||
this.containerId = in.readUnsignedByte();
|
||||
this.stateId = helper.readVarInt(in);
|
||||
this.slot = in.readShort();
|
||||
|
@ -28,7 +28,7 @@ public class ClientboundContainerSetSlotPacket implements MinecraftPacket {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
|
||||
out.writeByte(this.containerId);
|
||||
helper.writeVarInt(out, this.stateId);
|
||||
out.writeShort(this.slot);
|
||||
|
|
|
@ -23,7 +23,7 @@ public class ClientboundMerchantOffersPacket implements MinecraftPacket {
|
|||
private final boolean regularVillager;
|
||||
private final boolean canRestock;
|
||||
|
||||
public ClientboundMerchantOffersPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||
public ClientboundMerchantOffersPacket(ByteBuf in, MinecraftCodecHelper helper) {
|
||||
this.containerId = helper.readVarInt(in);
|
||||
|
||||
int size = helper.readVarInt(in);
|
||||
|
@ -51,7 +51,7 @@ public class ClientboundMerchantOffersPacket implements MinecraftPacket {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
|
||||
helper.writeVarInt(out, this.containerId);
|
||||
|
||||
helper.writeVarInt(out, this.trades.length);
|
||||
|
|
|
@ -21,7 +21,7 @@ public class ClientboundOpenScreenPacket implements MinecraftPacket {
|
|||
private final @NonNull ContainerType type;
|
||||
private final @NonNull Component title;
|
||||
|
||||
public ClientboundOpenScreenPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||
public ClientboundOpenScreenPacket(ByteBuf in, MinecraftCodecHelper helper) {
|
||||
this.containerId = helper.readVarInt(in);
|
||||
this.type = ContainerType.from(helper.readVarInt(in));
|
||||
this.title = helper.readComponent(in);
|
||||
|
@ -35,7 +35,7 @@ public class ClientboundOpenScreenPacket implements MinecraftPacket {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
|
||||
helper.writeVarInt(out, this.containerId);
|
||||
helper.writeVarInt(out, this.type.ordinal());
|
||||
helper.writeComponent(out, this.title);
|
||||
|
|
|
@ -22,14 +22,14 @@ public class ClientboundBlockEntityDataPacket implements MinecraftPacket {
|
|||
private final @NonNull BlockEntityType type;
|
||||
private final @Nullable CompoundTag nbt;
|
||||
|
||||
public ClientboundBlockEntityDataPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||
public ClientboundBlockEntityDataPacket(ByteBuf in, MinecraftCodecHelper helper) {
|
||||
this.position = helper.readPosition(in);
|
||||
this.type = helper.readBlockEntityType(in);
|
||||
this.nbt = helper.readAnyTag(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
|
||||
helper.writePosition(out, this.position);
|
||||
helper.writeBlockEntityType(out, this.type);
|
||||
helper.writeAnyTag(out, this.nbt);
|
||||
|
|
|
@ -33,7 +33,7 @@ public class ClientboundExplodePacket implements MinecraftPacket {
|
|||
private final @NonNull ExplosionInteraction blockInteraction;
|
||||
private final @NonNull Sound explosionSound;
|
||||
|
||||
public ClientboundExplodePacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||
public ClientboundExplodePacket(ByteBuf in, MinecraftCodecHelper helper) {
|
||||
this.x = in.readDouble();
|
||||
this.y = in.readDouble();
|
||||
this.z = in.readDouble();
|
||||
|
@ -54,7 +54,7 @@ public class ClientboundExplodePacket implements MinecraftPacket {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
|
||||
out.writeDouble(this.x);
|
||||
out.writeDouble(this.y);
|
||||
out.writeDouble(this.z);
|
||||
|
|
|
@ -25,7 +25,7 @@ public class ClientboundLevelChunkWithLightPacket implements MinecraftPacket {
|
|||
private final @NonNull BlockEntityInfo @NonNull [] blockEntities;
|
||||
private final @NonNull LightUpdateData lightData;
|
||||
|
||||
public ClientboundLevelChunkWithLightPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||
public ClientboundLevelChunkWithLightPacket(ByteBuf in, MinecraftCodecHelper helper) {
|
||||
this.x = in.readInt();
|
||||
this.z = in.readInt();
|
||||
this.heightMaps = helper.readAnyTagOrThrow(in);
|
||||
|
@ -46,7 +46,7 @@ public class ClientboundLevelChunkWithLightPacket implements MinecraftPacket {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
|
||||
out.writeInt(this.x);
|
||||
out.writeInt(this.z);
|
||||
helper.writeAnyTag(out, this.heightMaps);
|
||||
|
|
|
@ -27,7 +27,7 @@ public class ClientboundLevelParticlesPacket implements MinecraftPacket {
|
|||
private final float velocityOffset;
|
||||
private final int amount;
|
||||
|
||||
public ClientboundLevelParticlesPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||
public ClientboundLevelParticlesPacket(ByteBuf in, MinecraftCodecHelper helper) {
|
||||
ParticleType type = helper.readParticleType(in);
|
||||
this.longDistance = in.readBoolean();
|
||||
this.x = in.readDouble();
|
||||
|
@ -42,7 +42,7 @@ public class ClientboundLevelParticlesPacket implements MinecraftPacket {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
|
||||
helper.writeParticleType(out, this.particle.getType());
|
||||
out.writeBoolean(this.longDistance);
|
||||
out.writeDouble(this.x);
|
||||
|
|
|
@ -29,7 +29,7 @@ public class ClientboundMapItemDataPacket implements MinecraftPacket {
|
|||
this(mapId, scale, locked, icons, null);
|
||||
}
|
||||
|
||||
public ClientboundMapItemDataPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||
public ClientboundMapItemDataPacket(ByteBuf in, MinecraftCodecHelper helper) {
|
||||
this.mapId = helper.readVarInt(in);
|
||||
this.scale = in.readByte();
|
||||
this.locked = in.readBoolean();
|
||||
|
@ -64,7 +64,7 @@ public class ClientboundMapItemDataPacket implements MinecraftPacket {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
|
||||
helper.writeVarInt(out, this.mapId);
|
||||
out.writeByte(this.scale);
|
||||
out.writeBoolean(this.locked);
|
||||
|
|
|
@ -18,13 +18,13 @@ public class ClientboundTagQueryPacket implements MinecraftPacket {
|
|||
private final int transactionId;
|
||||
private final @Nullable CompoundTag nbt;
|
||||
|
||||
public ClientboundTagQueryPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||
public ClientboundTagQueryPacket(ByteBuf in, MinecraftCodecHelper helper) {
|
||||
this.transactionId = helper.readVarInt(in);
|
||||
this.nbt = helper.readAnyTag(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
|
||||
helper.writeVarInt(out, this.transactionId);
|
||||
helper.writeAnyTag(out, this.nbt);
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ public class ClientboundSetObjectivePacket implements MinecraftPacket {
|
|||
this.numberFormat = numberFormat;
|
||||
}
|
||||
|
||||
public ClientboundSetObjectivePacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||
public ClientboundSetObjectivePacket(ByteBuf in, MinecraftCodecHelper helper) {
|
||||
this.name = helper.readString(in);
|
||||
this.action = ObjectiveAction.from(in.readByte());
|
||||
if (this.action == ObjectiveAction.ADD || this.action == ObjectiveAction.UPDATE) {
|
||||
|
@ -76,7 +76,7 @@ public class ClientboundSetObjectivePacket implements MinecraftPacket {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
|
||||
helper.writeString(out, this.name);
|
||||
out.writeByte(this.action.ordinal());
|
||||
if (this.action == ObjectiveAction.ADD || this.action == ObjectiveAction.UPDATE) {
|
||||
|
|
|
@ -104,7 +104,7 @@ public class ClientboundSetPlayerTeamPacket implements MinecraftPacket {
|
|||
this.players = Arrays.copyOf(players, players.length);
|
||||
}
|
||||
|
||||
public ClientboundSetPlayerTeamPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||
public ClientboundSetPlayerTeamPacket(ByteBuf in, MinecraftCodecHelper helper) {
|
||||
this.teamName = helper.readString(in);
|
||||
this.action = TeamAction.from(in.readByte());
|
||||
if (this.action == TeamAction.CREATE || this.action == TeamAction.UPDATE) {
|
||||
|
@ -141,7 +141,7 @@ public class ClientboundSetPlayerTeamPacket implements MinecraftPacket {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
|
||||
helper.writeString(out, this.teamName);
|
||||
out.writeByte(this.action.ordinal());
|
||||
if (this.action == TeamAction.CREATE || this.action == TeamAction.UPDATE) {
|
||||
|
|
|
@ -31,7 +31,7 @@ public class ClientboundSetScorePacket implements MinecraftPacket {
|
|||
this.numberFormat = null;
|
||||
}
|
||||
|
||||
public ClientboundSetScorePacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||
public ClientboundSetScorePacket(ByteBuf in, MinecraftCodecHelper helper) {
|
||||
this.owner = helper.readString(in);
|
||||
this.objective = helper.readString(in);
|
||||
this.value = helper.readVarInt(in);
|
||||
|
@ -40,7 +40,7 @@ public class ClientboundSetScorePacket implements MinecraftPacket {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
|
||||
helper.writeString(out, this.owner);
|
||||
helper.writeString(out, this.objective);
|
||||
helper.writeVarInt(out, this.value);
|
||||
|
|
|
@ -16,12 +16,12 @@ import java.io.IOException;
|
|||
public class ClientboundSetActionBarTextPacket implements MinecraftPacket {
|
||||
private final Component text;
|
||||
|
||||
public ClientboundSetActionBarTextPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||
public ClientboundSetActionBarTextPacket(ByteBuf in, MinecraftCodecHelper helper) {
|
||||
this.text = helper.readComponent(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
|
||||
helper.writeComponent(out, this.text);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,12 +16,12 @@ import java.io.IOException;
|
|||
public class ClientboundSetSubtitleTextPacket implements MinecraftPacket {
|
||||
private final Component text;
|
||||
|
||||
public ClientboundSetSubtitleTextPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||
public ClientboundSetSubtitleTextPacket(ByteBuf in, MinecraftCodecHelper helper) {
|
||||
this.text = helper.readComponent(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
|
||||
helper.writeComponent(out, this.text);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ import java.io.IOException;
|
|||
public class ClientboundSetTitleTextPacket implements MinecraftPacket {
|
||||
private final @Nullable Component text;
|
||||
|
||||
public ClientboundSetTitleTextPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||
public ClientboundSetTitleTextPacket(ByteBuf in, MinecraftCodecHelper helper) {
|
||||
this.text = helper.readComponent(in);
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ public class ServerboundChatSessionUpdatePacket implements MinecraftPacket {
|
|||
private final PublicKey publicKey;
|
||||
private final byte[] keySignature;
|
||||
|
||||
public ServerboundChatSessionUpdatePacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||
public ServerboundChatSessionUpdatePacket(ByteBuf in, MinecraftCodecHelper helper) {
|
||||
this.sessionId = helper.readUUID(in);
|
||||
this.expiresAt = in.readLong();
|
||||
byte[] keyBytes = helper.readByteArray(in);
|
||||
|
@ -33,7 +33,7 @@ public class ServerboundChatSessionUpdatePacket implements MinecraftPacket {
|
|||
try {
|
||||
publicKey = KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(keyBytes));
|
||||
} catch (GeneralSecurityException e) {
|
||||
throw new IOException("Could not decode public key.", e);
|
||||
throw new RuntimeException("Could not decode public key.", e);
|
||||
}
|
||||
|
||||
this.publicKey = publicKey;
|
||||
|
|
|
@ -60,7 +60,7 @@ public class ServerboundContainerClickPacket implements MinecraftPacket {
|
|||
this.changedSlots = changedSlots;
|
||||
}
|
||||
|
||||
public ServerboundContainerClickPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||
public ServerboundContainerClickPacket(ByteBuf in, MinecraftCodecHelper helper) {
|
||||
this.containerId = in.readByte();
|
||||
this.stateId = helper.readVarInt(in);
|
||||
this.slot = in.readShort();
|
||||
|
@ -96,7 +96,7 @@ public class ServerboundContainerClickPacket implements MinecraftPacket {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
|
||||
out.writeByte(this.containerId);
|
||||
helper.writeVarInt(out, this.stateId);
|
||||
out.writeShort(this.slot);
|
||||
|
|
|
@ -10,6 +10,8 @@ import lombok.NonNull;
|
|||
import lombok.ToString;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
@ToString
|
||||
@EqualsAndHashCode
|
||||
|
@ -40,23 +42,22 @@ public class ServerboundSeenAdvancementsPacket implements MinecraftPacket {
|
|||
return this.tabId;
|
||||
}
|
||||
|
||||
public ServerboundSeenAdvancementsPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||
public ServerboundSeenAdvancementsPacket(ByteBuf in, MinecraftCodecHelper helper) {
|
||||
this.action = AdvancementTabAction.from(helper.readVarInt(in));
|
||||
switch (this.action) {
|
||||
case CLOSED_SCREEN -> this.tabId = null;
|
||||
case OPENED_TAB -> this.tabId = helper.readString(in);
|
||||
default -> throw new IOException("Unknown advancement tab action: " + this.action);
|
||||
}
|
||||
this.tabId = switch (this.action) {
|
||||
case CLOSED_SCREEN -> null;
|
||||
case OPENED_TAB -> helper.readString(in);
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
|
||||
helper.writeVarInt(out, this.action.ordinal());
|
||||
switch (this.action) {
|
||||
case CLOSED_SCREEN -> {
|
||||
}
|
||||
case OPENED_TAB -> helper.writeString(out, this.tabId);
|
||||
default -> throw new IOException("Unknown advancement tab action: " + this.action);
|
||||
}
|
||||
Consumer<String> tabIdWriter = switch (this.action) {
|
||||
case CLOSED_SCREEN -> tabId -> {
|
||||
};
|
||||
case OPENED_TAB -> tabId -> helper.writeString(out, tabId);
|
||||
};
|
||||
tabIdWriter.accept(this.tabId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,13 +19,13 @@ public class ServerboundSetCreativeModeSlotPacket implements MinecraftPacket {
|
|||
private final int slot;
|
||||
private final @Nullable ItemStack clickedItem;
|
||||
|
||||
public ServerboundSetCreativeModeSlotPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||
public ServerboundSetCreativeModeSlotPacket(ByteBuf in, MinecraftCodecHelper helper) {
|
||||
this.slot = in.readShort();
|
||||
this.clickedItem = helper.readItemStack(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
|
||||
out.writeShort(this.slot);
|
||||
helper.writeItemStack(out, this.clickedItem);
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ public class ClientboundHelloPacket implements MinecraftPacket {
|
|||
private final @NonNull PublicKey publicKey;
|
||||
private final byte @NonNull [] challenge;
|
||||
|
||||
public ClientboundHelloPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||
public ClientboundHelloPacket(ByteBuf in, MinecraftCodecHelper helper) {
|
||||
this.serverId = helper.readString(in);
|
||||
byte[] publicKey = helper.readByteArray(in);
|
||||
this.challenge = helper.readByteArray(in);
|
||||
|
@ -30,7 +30,7 @@ public class ClientboundHelloPacket implements MinecraftPacket {
|
|||
try {
|
||||
this.publicKey = KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(publicKey));
|
||||
} catch (GeneralSecurityException e) {
|
||||
throw new IOException("Could not decode public key.", e);
|
||||
throw new RuntimeException("Could not decode public key.", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ public class ChunkTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testChunkSectionEncoding() throws IOException {
|
||||
public void testChunkSectionEncoding() {
|
||||
MinecraftCodecHelper helper = new MinecraftCodecHelper(Int2ObjectMaps.emptyMap(), Collections.emptyMap());
|
||||
for (ChunkSection section : chunkSectionsToTest) {
|
||||
ByteBuf buf = Unpooled.buffer();
|
||||
|
|
Loading…
Reference in a new issue