mirror of
https://github.com/GeyserMC/MCProtocolLib.git
synced 2024-11-14 19:34:58 -05:00
Merge remote-tracking branch 'origin/feature/1.19-packetlib-refactor' into feature/1.19
This commit is contained in:
commit
849c540e96
228 changed files with 2923 additions and 2645 deletions
4
pom.xml
4
pom.xml
|
@ -88,9 +88,9 @@
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.GeyserMC</groupId>
|
<groupId>com.github.steveice10</groupId>
|
||||||
<artifactId>packetlib</artifactId>
|
<artifactId>packetlib</artifactId>
|
||||||
<version>2.1</version>
|
<version>3.0-SNAPSHOT</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
@ -2,17 +2,20 @@ package com.github.steveice10.mc.protocol;
|
||||||
|
|
||||||
import com.github.steveice10.mc.auth.data.GameProfile;
|
import com.github.steveice10.mc.auth.data.GameProfile;
|
||||||
import com.github.steveice10.mc.protocol.codec.MinecraftCodec;
|
import com.github.steveice10.mc.protocol.codec.MinecraftCodec;
|
||||||
|
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
|
||||||
import com.github.steveice10.mc.protocol.codec.PacketCodec;
|
import com.github.steveice10.mc.protocol.codec.PacketCodec;
|
||||||
import com.github.steveice10.mc.protocol.codec.PacketStateCodec;
|
import com.github.steveice10.mc.protocol.codec.PacketStateCodec;
|
||||||
import com.github.steveice10.mc.protocol.data.ProtocolState;
|
import com.github.steveice10.mc.protocol.data.ProtocolState;
|
||||||
import com.github.steveice10.packetlib.Server;
|
import com.github.steveice10.packetlib.Server;
|
||||||
import com.github.steveice10.packetlib.Session;
|
import com.github.steveice10.packetlib.Session;
|
||||||
|
import com.github.steveice10.packetlib.codec.PacketCodecHelper;
|
||||||
|
import com.github.steveice10.packetlib.codec.PacketDefinition;
|
||||||
import com.github.steveice10.packetlib.crypt.AESEncryption;
|
import com.github.steveice10.packetlib.crypt.AESEncryption;
|
||||||
import com.github.steveice10.packetlib.crypt.PacketEncryption;
|
import com.github.steveice10.packetlib.crypt.PacketEncryption;
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
|
||||||
import com.github.steveice10.packetlib.packet.Packet;
|
import com.github.steveice10.packetlib.packet.Packet;
|
||||||
import com.github.steveice10.packetlib.packet.PacketHeader;
|
import com.github.steveice10.packetlib.packet.PacketHeader;
|
||||||
import com.github.steveice10.packetlib.packet.PacketProtocol;
|
import com.github.steveice10.packetlib.packet.PacketProtocol;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
@ -131,6 +134,11 @@ public class MinecraftProtocol extends PacketProtocol {
|
||||||
return MinecraftConstants.PACKET_HEADER;
|
return MinecraftConstants.PACKET_HEADER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PacketCodecHelper createHelper() {
|
||||||
|
return this.codec.getHelperFactory().get();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void newClientSession(Session session) {
|
public void newClientSession(Session session) {
|
||||||
session.setFlag(MinecraftConstants.PROFILE_KEY, this.profile);
|
session.setFlag(MinecraftConstants.PROFILE_KEY, this.profile);
|
||||||
|
@ -175,8 +183,8 @@ public class MinecraftProtocol extends PacketProtocol {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Packet createClientboundPacket(int id, NetInput in) throws IOException {
|
public Packet createClientboundPacket(int id, ByteBuf buf, PacketCodecHelper codecHelper) throws IOException {
|
||||||
return this.stateCodec.createClientboundPacket(id, in);
|
return this.stateCodec.createClientboundPacket(id, buf, codecHelper);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -195,8 +203,8 @@ public class MinecraftProtocol extends PacketProtocol {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Packet createServerboundPacket(int id, NetInput in) throws IOException {
|
public Packet createServerboundPacket(int id, ByteBuf buf, PacketCodecHelper codecHelper) throws IOException {
|
||||||
return this.stateCodec.createServerboundPacket(id, in);
|
return this.stateCodec.createServerboundPacket(id, buf, codecHelper);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -213,4 +221,14 @@ public class MinecraftProtocol extends PacketProtocol {
|
||||||
public Class<? extends Packet> getServerboundClass(int id) {
|
public Class<? extends Packet> getServerboundClass(int id) {
|
||||||
return this.stateCodec.getServerboundClass(id);
|
return this.stateCodec.getServerboundClass(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PacketDefinition<?, ?> getServerboundDefinition(int id) {
|
||||||
|
return this.stateCodec.getServerboundDefinition(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PacketDefinition<?, ?> getClientboundDefinition(int id) {
|
||||||
|
return this.stateCodec.getClientboundDefinition(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package com.github.steveice10.mc.protocol.codec;
|
package com.github.steveice10.mc.protocol.codec;
|
||||||
|
|
||||||
import com.github.steveice10.mc.protocol.data.ProtocolState;
|
import com.github.steveice10.mc.protocol.data.ProtocolState;
|
||||||
|
import com.github.steveice10.mc.protocol.data.game.level.event.LevelEvent;
|
||||||
|
import com.github.steveice10.mc.protocol.data.game.level.sound.BuiltinSound;
|
||||||
import com.github.steveice10.mc.protocol.packet.handshake.serverbound.ClientIntentionPacket;
|
import com.github.steveice10.mc.protocol.packet.handshake.serverbound.ClientIntentionPacket;
|
||||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundAwardStatsPacket;
|
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundAwardStatsPacket;
|
||||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundBossEventPacket;
|
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundBossEventPacket;
|
||||||
|
@ -169,11 +171,30 @@ import com.github.steveice10.mc.protocol.packet.status.clientbound.ClientboundPo
|
||||||
import com.github.steveice10.mc.protocol.packet.status.clientbound.ClientboundStatusResponsePacket;
|
import com.github.steveice10.mc.protocol.packet.status.clientbound.ClientboundStatusResponsePacket;
|
||||||
import com.github.steveice10.mc.protocol.packet.status.serverbound.ServerboundPingRequestPacket;
|
import com.github.steveice10.mc.protocol.packet.status.serverbound.ServerboundPingRequestPacket;
|
||||||
import com.github.steveice10.mc.protocol.packet.status.serverbound.ServerboundStatusRequestPacket;
|
import com.github.steveice10.mc.protocol.packet.status.serverbound.ServerboundStatusRequestPacket;
|
||||||
|
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||||
|
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class MinecraftCodec {
|
public class MinecraftCodec {
|
||||||
|
private static final Int2ObjectMap<LevelEvent> LEVEL_EVENTS = new Int2ObjectOpenHashMap<>();
|
||||||
|
private static final Map<String, BuiltinSound> SOUND_NAMES = new HashMap<>();
|
||||||
|
|
||||||
|
static {
|
||||||
|
for (LevelEvent levelEvent : LevelEvent.values()) {
|
||||||
|
LEVEL_EVENTS.put(levelEvent.getId(), levelEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (BuiltinSound sound : BuiltinSound.values()) {
|
||||||
|
SOUND_NAMES.put(sound.getName(), sound);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static final PacketCodec CODEC = PacketCodec.builder()
|
public static final PacketCodec CODEC = PacketCodec.builder()
|
||||||
.protocolVersion((1 << 30) | 87)
|
.protocolVersion((1 << 30) | 91)
|
||||||
.minecraftVersion("1.19-pre3")
|
.helper(() -> new MinecraftCodecHelper(LEVEL_EVENTS, SOUND_NAMES))
|
||||||
|
.minecraftVersion("1.19-rc2")
|
||||||
.state(ProtocolState.HANDSHAKE, PacketStateCodec.builder()
|
.state(ProtocolState.HANDSHAKE, PacketStateCodec.builder()
|
||||||
.registerServerboundPacket(0x00, ClientIntentionPacket.class, ClientIntentionPacket::new)
|
.registerServerboundPacket(0x00, ClientIntentionPacket.class, ClientIntentionPacket::new)
|
||||||
)
|
)
|
||||||
|
|
|
@ -0,0 +1,694 @@
|
||||||
|
package com.github.steveice10.mc.protocol.codec;
|
||||||
|
|
||||||
|
import com.github.steveice10.mc.protocol.data.DefaultComponentSerializer;
|
||||||
|
import com.github.steveice10.mc.protocol.data.MagicValues;
|
||||||
|
import com.github.steveice10.mc.protocol.data.game.Identifier;
|
||||||
|
import com.github.steveice10.mc.protocol.data.game.MessageType;
|
||||||
|
import com.github.steveice10.mc.protocol.data.game.chunk.BitStorage;
|
||||||
|
import com.github.steveice10.mc.protocol.data.game.chunk.ChunkSection;
|
||||||
|
import com.github.steveice10.mc.protocol.data.game.chunk.DataPalette;
|
||||||
|
import com.github.steveice10.mc.protocol.data.game.chunk.NibbleArray3d;
|
||||||
|
import com.github.steveice10.mc.protocol.data.game.chunk.palette.*;
|
||||||
|
import com.github.steveice10.mc.protocol.data.game.entity.Effect;
|
||||||
|
import com.github.steveice10.mc.protocol.data.game.entity.EntityEvent;
|
||||||
|
import com.github.steveice10.mc.protocol.data.game.entity.attribute.ModifierOperation;
|
||||||
|
import com.github.steveice10.mc.protocol.data.game.entity.metadata.*;
|
||||||
|
import com.github.steveice10.mc.protocol.data.game.entity.object.Direction;
|
||||||
|
import com.github.steveice10.mc.protocol.data.game.entity.player.BlockBreakStage;
|
||||||
|
import com.github.steveice10.mc.protocol.data.game.entity.type.PaintingType;
|
||||||
|
import com.github.steveice10.mc.protocol.data.game.level.LightUpdateData;
|
||||||
|
import com.github.steveice10.mc.protocol.data.game.level.block.BlockEntityType;
|
||||||
|
import com.github.steveice10.mc.protocol.data.game.level.event.LevelEvent;
|
||||||
|
import com.github.steveice10.mc.protocol.data.game.level.particle.*;
|
||||||
|
import com.github.steveice10.mc.protocol.data.game.level.particle.positionsource.BlockPositionSource;
|
||||||
|
import com.github.steveice10.mc.protocol.data.game.level.particle.positionsource.EntityPositionSource;
|
||||||
|
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.SoundCategory;
|
||||||
|
import com.github.steveice10.mc.protocol.data.game.recipe.Ingredient;
|
||||||
|
import com.github.steveice10.mc.protocol.data.game.statistic.StatisticCategory;
|
||||||
|
import com.github.steveice10.opennbt.NBTIO;
|
||||||
|
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||||
|
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
||||||
|
import com.github.steveice10.packetlib.codec.BasePacketCodecHelper;
|
||||||
|
import com.nukkitx.math.vector.Vector3f;
|
||||||
|
import com.nukkitx.math.vector.Vector3i;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.BitSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.function.ObjIntConsumer;
|
||||||
|
import java.util.function.ToIntFunction;
|
||||||
|
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class MinecraftCodecHelper extends BasePacketCodecHelper {
|
||||||
|
private static final int POSITION_X_SIZE = 38;
|
||||||
|
private static final int POSITION_Y_SIZE = 12;
|
||||||
|
private static final int POSITION_Z_SIZE = 38;
|
||||||
|
private static final int POSITION_Y_SHIFT = 0xFFF;
|
||||||
|
private static final int POSITION_WRITE_SHIFT = 0x3FFFFFF;
|
||||||
|
|
||||||
|
private final Int2ObjectMap<LevelEvent> levelEvents;
|
||||||
|
private final Map<String, BuiltinSound> soundNames;
|
||||||
|
|
||||||
|
public UUID readUUID(ByteBuf buf) {
|
||||||
|
return new UUID(buf.readLong(), buf.readLong());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeUUID(ByteBuf buf, UUID uuid) {
|
||||||
|
buf.writeLong(uuid.getMostSignificantBits());
|
||||||
|
buf.writeLong(uuid.getLeastSignificantBits());
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] readByteArray(ByteBuf buf) {
|
||||||
|
return this.readByteArray(buf, this::readVarInt);
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] readByteArray(ByteBuf buf, ToIntFunction<ByteBuf> reader) {
|
||||||
|
int length = reader.applyAsInt(buf);
|
||||||
|
byte[] bytes = new byte[length];
|
||||||
|
buf.readBytes(bytes);
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeByteArray(ByteBuf buf, byte[] bytes) {
|
||||||
|
this.writeByteArray(buf, bytes, this::writeVarInt);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeByteArray(ByteBuf buf, byte[] bytes, ObjIntConsumer<ByteBuf> writer) {
|
||||||
|
writer.accept(buf, bytes.length);
|
||||||
|
buf.writeBytes(bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
public long[] readLongArray(ByteBuf buf) {
|
||||||
|
return this.readLongArray(buf, this::readVarInt);
|
||||||
|
}
|
||||||
|
|
||||||
|
public long[] readLongArray(ByteBuf buf, ToIntFunction<ByteBuf> reader) {
|
||||||
|
int length = reader.applyAsInt(buf);
|
||||||
|
if (length < 0) {
|
||||||
|
throw new IllegalArgumentException("Array cannot have length less than 0.");
|
||||||
|
}
|
||||||
|
|
||||||
|
long[] l = new long[length];
|
||||||
|
for (int index = 0; index < length; index++) {
|
||||||
|
l[index] = buf.readLong();
|
||||||
|
}
|
||||||
|
|
||||||
|
return l;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeLongArray(ByteBuf buf, long[] l) {
|
||||||
|
this.writeLongArray(buf, l, this::writeVarInt);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeLongArray(ByteBuf buf, long[] l, ObjIntConsumer<ByteBuf> writer) {
|
||||||
|
writer.accept(buf, l.length);
|
||||||
|
for (long value : l) {
|
||||||
|
buf.writeLong(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompoundTag readTag(ByteBuf buf) throws IOException {
|
||||||
|
return readTag(buf, CompoundTag.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public <T extends Tag> T readTag(ByteBuf buf, Class<T> expected) throws IOException {
|
||||||
|
Tag tag = NBTIO.readTag(new InputStream() {
|
||||||
|
@Override
|
||||||
|
public int read() {
|
||||||
|
return buf.readUnsignedByte();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (tag == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tag.getClass() != expected) {
|
||||||
|
throw new IllegalArgumentException("Expected tag of type " + expected.getName() + " but got " + tag.getClass().getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
return expected.cast(tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompoundTag readTagLE(ByteBuf buf) throws IOException {
|
||||||
|
return readTagLE(buf, CompoundTag.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public <T extends Tag> T readTagLE(ByteBuf buf, Class<T> expected) throws IOException {
|
||||||
|
Tag tag = NBTIO.readTag(new InputStream() {
|
||||||
|
@Override
|
||||||
|
public int read() {
|
||||||
|
return buf.readUnsignedByte();
|
||||||
|
}
|
||||||
|
}, true);
|
||||||
|
|
||||||
|
if (tag == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tag.getClass() != expected) {
|
||||||
|
throw new IllegalArgumentException("Expected tag of type " + expected.getName() + " but got " + tag.getClass().getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
return expected.cast(tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T extends Tag> void writeTag(ByteBuf buf, T tag) throws IOException {
|
||||||
|
NBTIO.writeTag(new OutputStream() {
|
||||||
|
@Override
|
||||||
|
public void write(int b) throws IOException {
|
||||||
|
buf.writeByte(b);
|
||||||
|
}
|
||||||
|
}, tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T extends Tag> void writeTagLE(ByteBuf buf, T tag) throws IOException {
|
||||||
|
NBTIO.writeTag(new OutputStream() {
|
||||||
|
@Override
|
||||||
|
public void write(int b) throws IOException {
|
||||||
|
buf.writeByte(b);
|
||||||
|
}
|
||||||
|
}, tag, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStack readItemStack(ByteBuf buf) throws IOException {
|
||||||
|
boolean present = buf.readBoolean();
|
||||||
|
if (!present) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
int item = this.readVarInt(buf);
|
||||||
|
return new ItemStack(item, buf.readByte(), this.readTag(buf));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeItemStack(ByteBuf buf, ItemStack item) throws IOException {
|
||||||
|
buf.writeBoolean(item != null);
|
||||||
|
if (item != null) {
|
||||||
|
this.writeVarInt(buf, item.getId());
|
||||||
|
buf.writeByte(item.getAmount());
|
||||||
|
this.writeTag(buf, item.getNbt());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vector3i readPosition(ByteBuf buf) {
|
||||||
|
long val = buf.readLong();
|
||||||
|
|
||||||
|
int x = (int) (val >> POSITION_X_SIZE);
|
||||||
|
int y = (int) (val << 52 >> 52);
|
||||||
|
int z = (int) (val << 26 >> POSITION_Z_SIZE);
|
||||||
|
|
||||||
|
return Vector3i.from(x, y, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writePosition(ByteBuf buf, Vector3i pos) {
|
||||||
|
long x = pos.getX() & POSITION_WRITE_SHIFT;
|
||||||
|
long y = pos.getY() & POSITION_Y_SHIFT;
|
||||||
|
long z = pos.getZ() & POSITION_WRITE_SHIFT;
|
||||||
|
|
||||||
|
buf.writeLong(x << POSITION_X_SIZE | z << POSITION_Y_SIZE | y);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vector3f readRotation(ByteBuf buf) {
|
||||||
|
float x = buf.readFloat();
|
||||||
|
float y = buf.readFloat();
|
||||||
|
float z = buf.readFloat();
|
||||||
|
|
||||||
|
return Vector3f.from(x, y, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeRotation(ByteBuf buf, Vector3f rot) {
|
||||||
|
buf.writeFloat(rot.getX());
|
||||||
|
buf.writeFloat(rot.getY());
|
||||||
|
buf.writeFloat(rot.getZ());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Direction readDirection(ByteBuf buf) {
|
||||||
|
return Direction.from(this.readVarInt(buf));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeDirection(ByteBuf buf, Direction dir) {
|
||||||
|
this.writeEnum(buf, dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Pose readPose(ByteBuf buf) {
|
||||||
|
return Pose.from(this.readVarInt(buf));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writePose(ByteBuf buf, Pose pose) {
|
||||||
|
this.writeEnum(buf, pose);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PaintingType readPaintingType(ByteBuf buf) {
|
||||||
|
return PaintingType.from(this.readVarInt(buf));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writePaintingType(ByteBuf buf, PaintingType type) {
|
||||||
|
this.writeEnum(buf, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void writeEnum(ByteBuf buf, Enum<?> e){
|
||||||
|
this.writeVarInt(buf, e.ordinal());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Component readComponent(ByteBuf buf) {
|
||||||
|
return DefaultComponentSerializer.get().deserialize(this.readString(buf));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeComponent(ByteBuf buf, Component component) {
|
||||||
|
this.writeString(buf, DefaultComponentSerializer.get().serialize(component));
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityMetadata<?, ?>[] readEntityMetadata(ByteBuf buf) throws IOException {
|
||||||
|
List<EntityMetadata<?, ?>> ret = new ArrayList<>();
|
||||||
|
int id;
|
||||||
|
while ((id = buf.readUnsignedByte()) != 255) {
|
||||||
|
ret.add(this.readMetadata(buf, id));
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret.toArray(new EntityMetadata[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeEntityMetadata(ByteBuf buf, EntityMetadata<?, ?>[] metadata) throws IOException {
|
||||||
|
for (EntityMetadata<?, ?> meta : metadata) {
|
||||||
|
this.writeMetadata(buf, meta);
|
||||||
|
}
|
||||||
|
|
||||||
|
buf.writeByte(255);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityMetadata<?, ?> readMetadata(ByteBuf buf, int id) throws IOException {
|
||||||
|
MetadataType<?> type = this.readMetadataType(buf);
|
||||||
|
return type.readMetadata(this, buf, id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeMetadata(ByteBuf buf, EntityMetadata<?, ?> metadata) throws IOException {
|
||||||
|
buf.writeByte(metadata.getId());
|
||||||
|
this.writeMetadataType(buf, metadata.getType());
|
||||||
|
metadata.write(this, buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MetadataType<?> readMetadataType(ByteBuf buf) {
|
||||||
|
int id = this.readVarInt(buf);
|
||||||
|
if (id >= MetadataType.size()) {
|
||||||
|
throw new IllegalArgumentException("Received id " + id + " for MetadataType when the maximum was " + MetadataType.size() + "!");
|
||||||
|
}
|
||||||
|
|
||||||
|
return MetadataType.from(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeMetadataType(ByteBuf buf, MetadataType<?> type) {
|
||||||
|
this.writeVarInt(buf, type.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
public GlobalPos readGlobalPos(ByteBuf buf) {
|
||||||
|
String dimension = Identifier.formalize(this.readString(buf));
|
||||||
|
Vector3i pos = this.readPosition(buf);
|
||||||
|
return new GlobalPos(dimension, pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeGlobalPos(ByteBuf buf, GlobalPos pos) {
|
||||||
|
this.writeString(buf, pos.getDimension());
|
||||||
|
this.writePosition(buf, pos.getPosition());
|
||||||
|
}
|
||||||
|
|
||||||
|
public ParticleType readParticleType(ByteBuf buf) {
|
||||||
|
return ParticleType.from(this.readVarInt(buf));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeParticleType(ByteBuf buf, ParticleType type) {
|
||||||
|
this.writeEnum(buf, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Particle readParticle(ByteBuf buf) throws IOException {
|
||||||
|
ParticleType particleType = this.readParticleType(buf);
|
||||||
|
return new Particle(particleType, this.readParticleData(buf, particleType));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeParticle(ByteBuf buf, Particle particle) throws IOException {
|
||||||
|
this.writeEnum(buf, particle.getType());
|
||||||
|
this.writeParticleData(buf, particle.getType(), particle.getData());
|
||||||
|
}
|
||||||
|
|
||||||
|
public ParticleData readParticleData(ByteBuf buf, ParticleType type) throws IOException {
|
||||||
|
switch (type) {
|
||||||
|
case BLOCK:
|
||||||
|
case BLOCK_MARKER:
|
||||||
|
return new BlockParticleData(this.readVarInt(buf));
|
||||||
|
case DUST:
|
||||||
|
float red = buf.readFloat();
|
||||||
|
float green = buf.readFloat();
|
||||||
|
float blue = buf.readFloat();
|
||||||
|
float scale = buf.readFloat();
|
||||||
|
return new DustParticleData(red, green, blue, scale);
|
||||||
|
case DUST_COLOR_TRANSITION:
|
||||||
|
red = buf.readFloat();
|
||||||
|
green = buf.readFloat();
|
||||||
|
blue = buf.readFloat();
|
||||||
|
scale = buf.readFloat();
|
||||||
|
float newRed = buf.readFloat();
|
||||||
|
float newGreen = buf.readFloat();
|
||||||
|
float newBlue = buf.readFloat();
|
||||||
|
return new DustColorTransitionParticleData(red, green, blue, scale, newRed, newGreen, newBlue);
|
||||||
|
case FALLING_DUST:
|
||||||
|
return new FallingDustParticleData(this.readVarInt(buf));
|
||||||
|
case ITEM:
|
||||||
|
return new ItemParticleData(this.readItemStack(buf));
|
||||||
|
case SCULK_CHARGE:
|
||||||
|
return new SculkChargeParticleData(buf.readFloat());
|
||||||
|
case SHRIEK:
|
||||||
|
return new ShriekParticleData(this.readVarInt(buf));
|
||||||
|
case VIBRATION:
|
||||||
|
return new VibrationParticleData(this.readPositionSource(buf), this.readVarInt(buf));
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeParticleData(ByteBuf buf, ParticleType type, ParticleData data) throws IOException {
|
||||||
|
switch (type) {
|
||||||
|
case BLOCK:
|
||||||
|
case BLOCK_MARKER:
|
||||||
|
this.writeVarInt(buf, ((BlockParticleData) data).getBlockState());
|
||||||
|
break;
|
||||||
|
case DUST:
|
||||||
|
buf.writeFloat(((DustParticleData) data).getRed());
|
||||||
|
buf.writeFloat(((DustParticleData) data).getGreen());
|
||||||
|
buf.writeFloat(((DustParticleData) data).getBlue());
|
||||||
|
buf.writeFloat(((DustParticleData) data).getScale());
|
||||||
|
break;
|
||||||
|
case DUST_COLOR_TRANSITION:
|
||||||
|
buf.writeFloat(((DustParticleData) data).getRed());
|
||||||
|
buf.writeFloat(((DustParticleData) data).getGreen());
|
||||||
|
buf.writeFloat(((DustParticleData) data).getBlue());
|
||||||
|
buf.writeFloat(((DustParticleData) data).getScale());
|
||||||
|
buf.writeFloat(((DustColorTransitionParticleData) data).getNewRed());
|
||||||
|
buf.writeFloat(((DustColorTransitionParticleData) data).getNewGreen());
|
||||||
|
buf.writeFloat(((DustColorTransitionParticleData) data).getNewBlue());
|
||||||
|
break;
|
||||||
|
case FALLING_DUST:
|
||||||
|
this.writeVarInt(buf, ((FallingDustParticleData) data).getBlockState());
|
||||||
|
break;
|
||||||
|
case ITEM:
|
||||||
|
this.writeItemStack(buf, ((ItemParticleData) data).getItemStack());
|
||||||
|
break;
|
||||||
|
case SCULK_CHARGE:
|
||||||
|
buf.writeFloat(((SculkChargeParticleData) data).getRoll());
|
||||||
|
break;
|
||||||
|
case SHRIEK:
|
||||||
|
this.writeVarInt(buf, ((ShriekParticleData) data).getDelay());
|
||||||
|
break;
|
||||||
|
case VIBRATION:
|
||||||
|
this.writePositionSource(buf, ((VibrationParticleData) data).getPositionSource());
|
||||||
|
this.writeVarInt(buf, ((VibrationParticleData) data).getArrivalTicks());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public PositionSource readPositionSource(ByteBuf buf) {
|
||||||
|
PositionSourceType type = this.readPositionSourceType(buf);
|
||||||
|
switch (type) {
|
||||||
|
case BLOCK:
|
||||||
|
return new BlockPositionSource(this.readPosition(buf));
|
||||||
|
case ENTITY:
|
||||||
|
return new EntityPositionSource(this.readVarInt(buf), buf.readFloat());
|
||||||
|
default:
|
||||||
|
throw new IllegalStateException("Unknown position source type!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writePositionSource(ByteBuf buf, PositionSource positionSource) {
|
||||||
|
this.writePositionSourceType(buf, positionSource.getType());
|
||||||
|
if (positionSource instanceof BlockPositionSource) {
|
||||||
|
this.writePosition(buf, ((BlockPositionSource) positionSource).getPosition());
|
||||||
|
} else if (positionSource instanceof EntityPositionSource) {
|
||||||
|
this.writeVarInt(buf, ((EntityPositionSource) positionSource).getEntityId());
|
||||||
|
buf.writeFloat(((EntityPositionSource) positionSource).getYOffset());
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new IllegalStateException("Unknown position source type!");
|
||||||
|
}
|
||||||
|
|
||||||
|
public PositionSourceType readPositionSourceType(ByteBuf buf) {
|
||||||
|
return MagicValues.key(PositionSourceType.class, Identifier.formalize(this.readString(buf)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writePositionSourceType(ByteBuf buf, PositionSourceType type) {
|
||||||
|
this.writeString(buf, MagicValues.value(String.class, type));
|
||||||
|
}
|
||||||
|
|
||||||
|
public VillagerData readVillagerData(ByteBuf buf) {
|
||||||
|
return new VillagerData(this.readVarInt(buf), this.readVarInt(buf), this.readVarInt(buf));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeVillagerData(ByteBuf buf, VillagerData villagerData) {
|
||||||
|
this.writeVarInt(buf, villagerData.getType());
|
||||||
|
this.writeVarInt(buf, villagerData.getProfession());
|
||||||
|
this.writeVarInt(buf, villagerData.getLevel());
|
||||||
|
}
|
||||||
|
|
||||||
|
public ModifierOperation readModifierOperation(ByteBuf buf) {
|
||||||
|
return ModifierOperation.from(buf.readByte());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeModifierOperation(ByteBuf buf, ModifierOperation operation) {
|
||||||
|
buf.writeByte(operation.ordinal());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Effect readEffect(ByteBuf buf) {
|
||||||
|
return Effect.from(this.readVarInt(buf) - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeEffect(ByteBuf buf, Effect effect) {
|
||||||
|
this.writeVarInt(buf, effect.ordinal() + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlockBreakStage readBlockBreakStage(ByteBuf buf) {
|
||||||
|
int stage = buf.readUnsignedByte();
|
||||||
|
if (stage >= 0 && stage < 10) {
|
||||||
|
return BlockBreakStage.STAGES[stage];
|
||||||
|
} else {
|
||||||
|
return BlockBreakStage.RESET;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeBlockBreakStage(ByteBuf buf, BlockBreakStage stage) {
|
||||||
|
if (stage == BlockBreakStage.RESET) {
|
||||||
|
buf.writeByte(255);
|
||||||
|
} else {
|
||||||
|
buf.writeByte(stage.ordinal());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlockEntityType readBlockEntityType(ByteBuf buf) {
|
||||||
|
return BlockEntityType.from(this.readVarInt(buf));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeBlockEntityType(ByteBuf buf, BlockEntityType type) {
|
||||||
|
this.writeEnum(buf, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public LightUpdateData readLightUpdateData(ByteBuf buf) {
|
||||||
|
boolean trustEdges = buf.readBoolean();
|
||||||
|
|
||||||
|
BitSet skyYMask = BitSet.valueOf(this.readLongArray(buf));
|
||||||
|
BitSet blockYMask = BitSet.valueOf(this.readLongArray(buf));
|
||||||
|
BitSet emptySkyYMask = BitSet.valueOf(this.readLongArray(buf));
|
||||||
|
BitSet emptyBlockYMask = BitSet.valueOf(this.readLongArray(buf));
|
||||||
|
|
||||||
|
int skyUpdateSize = this.readVarInt(buf);
|
||||||
|
List<byte[]> skyUpdates = new ArrayList<>(skyUpdateSize);
|
||||||
|
for (int i = 0; i < skyUpdateSize; i++) {
|
||||||
|
skyUpdates.add(this.readByteArray(buf));
|
||||||
|
}
|
||||||
|
|
||||||
|
int blockUpdateSize = this.readVarInt(buf);
|
||||||
|
List<byte[]> blockUpdates = new ArrayList<>(blockUpdateSize);
|
||||||
|
for (int i = 0; i < blockUpdateSize; i++) {
|
||||||
|
blockUpdates.add(this.readByteArray(buf));
|
||||||
|
}
|
||||||
|
|
||||||
|
return new LightUpdateData(skyYMask, blockYMask, emptySkyYMask, emptyBlockYMask, skyUpdates, blockUpdates, trustEdges);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeLightUpdateData(ByteBuf buf, LightUpdateData data) {
|
||||||
|
buf.writeBoolean(data.isTrustEdges());
|
||||||
|
|
||||||
|
writeBitSet(buf, data.getSkyYMask());
|
||||||
|
writeBitSet(buf, data.getBlockYMask());
|
||||||
|
writeBitSet(buf, data.getEmptySkyYMask());
|
||||||
|
writeBitSet(buf, data.getEmptyBlockYMask());
|
||||||
|
|
||||||
|
this.writeVarInt(buf, data.getSkyUpdates().size());
|
||||||
|
for (byte[] array : data.getSkyUpdates()) {
|
||||||
|
this.writeByteArray(buf, array);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.writeVarInt(buf, data.getBlockUpdates().size());
|
||||||
|
for (byte[] array : data.getBlockUpdates()) {
|
||||||
|
this.writeByteArray(buf, array);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void writeBitSet(ByteBuf buf, BitSet bitSet) {
|
||||||
|
long[] array = bitSet.toLongArray();
|
||||||
|
this.writeLongArray(buf, array);
|
||||||
|
}
|
||||||
|
|
||||||
|
public LevelEvent readLevelEvent(ByteBuf buf) {
|
||||||
|
return this.levelEvents.get(this.readVarInt(buf));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeLevelEvent(ByteBuf buf, LevelEvent event) {
|
||||||
|
this.writeVarInt(buf, event.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
public StatisticCategory readStatisticCategory(ByteBuf buf) {
|
||||||
|
return StatisticCategory.from(this.readVarInt(buf));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeStatisticCategory(ByteBuf buf, StatisticCategory category) {
|
||||||
|
this.writeEnum(buf, category);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MessageType readMessageType(ByteBuf buf) {
|
||||||
|
return MessageType.from(this.readVarInt(buf));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeMessageType(ByteBuf buf, MessageType type) {
|
||||||
|
this.writeEnum(buf, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SoundCategory readSoundCategory(ByteBuf buf) {
|
||||||
|
return SoundCategory.from(this.readVarInt(buf));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeSoundCategory(ByteBuf buf, SoundCategory category) {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EntityEvent readEntityEvent(ByteBuf buf) {
|
||||||
|
return EntityEvent.from(buf.readByte());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeEntityEvent(ByteBuf buf, EntityEvent event) {
|
||||||
|
buf.writeByte(event.ordinal());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Ingredient readRecipeIngredient(ByteBuf buf) throws IOException {
|
||||||
|
ItemStack[] options = new ItemStack[this.readVarInt(buf)];
|
||||||
|
for (int i = 0; i < options.length; i++) {
|
||||||
|
options[i] = this.readItemStack(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Ingredient(options);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeRecipeIngredient(ByteBuf buf, Ingredient ingredient) throws IOException {
|
||||||
|
this.writeVarInt(buf, ingredient.getOptions().length);
|
||||||
|
for (ItemStack option : ingredient.getOptions()) {
|
||||||
|
this.writeItemStack(buf, option);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public DataPalette readDataPalette(ByteBuf buf, PaletteType paletteType, int globalPaletteBits) throws IOException {
|
||||||
|
int bitsPerEntry = buf.readByte();
|
||||||
|
Palette palette = this.readPalette(buf, paletteType, bitsPerEntry);
|
||||||
|
BitStorage storage;
|
||||||
|
if (!(palette instanceof SingletonPalette)) {
|
||||||
|
storage = new BitStorage(bitsPerEntry, paletteType.getStorageSize(), this.readLongArray(buf));
|
||||||
|
} else {
|
||||||
|
this.readVarInt(buf);
|
||||||
|
storage = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new DataPalette(palette, storage, paletteType, globalPaletteBits);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeDataPalette(ByteBuf buf, DataPalette palette) {
|
||||||
|
if (palette.getPalette() instanceof SingletonPalette) {
|
||||||
|
buf.writeByte(0); // Bits per entry
|
||||||
|
this.writeVarInt(buf, palette.getPalette().idToState(0));
|
||||||
|
this.writeVarInt(buf, 0); // Data length
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
buf.writeByte(palette.getStorage().getBitsPerEntry());
|
||||||
|
|
||||||
|
if (!(palette.getPalette() instanceof GlobalPalette)) {
|
||||||
|
int paletteLength = palette.getPalette().size();
|
||||||
|
this.writeVarInt(buf, paletteLength);
|
||||||
|
for (int i = 0; i < paletteLength; i++) {
|
||||||
|
this.writeVarInt(buf, palette.getPalette().idToState(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
long[] data = palette.getStorage().getData();
|
||||||
|
this.writeLongArray(buf, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Palette readPalette(ByteBuf buf, PaletteType paletteType, int bitsPerEntry) throws IOException {
|
||||||
|
if (bitsPerEntry > paletteType.getMaxBitsPerEntry()) {
|
||||||
|
return new GlobalPalette();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bitsPerEntry == 0) {
|
||||||
|
return new SingletonPalette(this.readVarInt(buf));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bitsPerEntry <= paletteType.getMinBitsPerEntry()) {
|
||||||
|
return new ListPalette(bitsPerEntry, buf, this);
|
||||||
|
} else {
|
||||||
|
return new MapPalette(bitsPerEntry, buf, this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ChunkSection readChunkSection(ByteBuf buf, int globalBiomePaletteBits) throws IOException {
|
||||||
|
int blockCount = buf.readShort();
|
||||||
|
|
||||||
|
DataPalette chunkPalette = this.readDataPalette(buf, PaletteType.CHUNK, DataPalette.GLOBAL_PALETTE_BITS_PER_ENTRY);
|
||||||
|
DataPalette biomePalette = this.readDataPalette(buf, PaletteType.BIOME, globalBiomePaletteBits);
|
||||||
|
return new ChunkSection(blockCount, chunkPalette, biomePalette);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeChunkSection(ByteBuf buf, ChunkSection section) {
|
||||||
|
buf.writeShort(section.getBlockCount());
|
||||||
|
this.writeDataPalette(buf, section.getChunkData());
|
||||||
|
this.writeDataPalette(buf, section.getBiomeData());
|
||||||
|
}
|
||||||
|
|
||||||
|
public NibbleArray3d readNibbleArray(ByteBuf buf, int size) {
|
||||||
|
return new NibbleArray3d(this.readByteArray(buf, ignored -> size));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeNibbleArray(ByteBuf buf, NibbleArray3d nibbleArray) {
|
||||||
|
buf.writeBytes(nibbleArray.getData());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
package com.github.steveice10.mc.protocol.codec;
|
||||||
|
|
||||||
|
import com.github.steveice10.packetlib.packet.Packet;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public interface MinecraftPacket extends Packet {
|
||||||
|
|
||||||
|
void serialize(ByteBuf buf, MinecraftCodecHelper helper) throws IOException;
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
package com.github.steveice10.mc.protocol.codec;
|
||||||
|
|
||||||
|
import com.github.steveice10.packetlib.codec.PacketDefinition;
|
||||||
|
import com.github.steveice10.packetlib.codec.PacketSerializer;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class MinecraftPacketSerializer<T extends MinecraftPacket> implements PacketSerializer<T, MinecraftCodecHelper> {
|
||||||
|
private final PacketFactory<T, MinecraftCodecHelper> factory;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void serialize(ByteBuf buf, MinecraftCodecHelper helper, T packet) throws IOException {
|
||||||
|
packet.serialize(buf, helper);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T deserialize(ByteBuf buf, MinecraftCodecHelper helper, PacketDefinition<T, MinecraftCodecHelper> definition) throws IOException {
|
||||||
|
return this.factory.construct(buf, helper);
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,10 +5,9 @@ import lombok.AccessLevel;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
import javax.annotation.concurrent.Immutable;
|
|
||||||
import java.util.EnumMap;
|
import java.util.EnumMap;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
@Immutable
|
|
||||||
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
|
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
|
||||||
public class PacketCodec {
|
public class PacketCodec {
|
||||||
|
|
||||||
|
@ -20,6 +19,9 @@ public class PacketCodec {
|
||||||
|
|
||||||
private final EnumMap<ProtocolState, PacketStateCodec> stateProtocols;
|
private final EnumMap<ProtocolState, PacketStateCodec> stateProtocols;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private final Supplier<MinecraftCodecHelper> helperFactory;
|
||||||
|
|
||||||
public PacketStateCodec getCodec(ProtocolState protocolState) {
|
public PacketStateCodec getCodec(ProtocolState protocolState) {
|
||||||
return this.stateProtocols.get(protocolState);
|
return this.stateProtocols.get(protocolState);
|
||||||
}
|
}
|
||||||
|
@ -34,6 +36,7 @@ public class PacketCodec {
|
||||||
builder.protocolVersion = this.protocolVersion;
|
builder.protocolVersion = this.protocolVersion;
|
||||||
builder.stateProtocols = this.stateProtocols;
|
builder.stateProtocols = this.stateProtocols;
|
||||||
builder.minecraftVersion = this.minecraftVersion;
|
builder.minecraftVersion = this.minecraftVersion;
|
||||||
|
builder.helperFactory = this.helperFactory;
|
||||||
|
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
@ -42,6 +45,7 @@ public class PacketCodec {
|
||||||
private int protocolVersion = -1;
|
private int protocolVersion = -1;
|
||||||
private String minecraftVersion = null;
|
private String minecraftVersion = null;
|
||||||
private EnumMap<ProtocolState, PacketStateCodec> stateProtocols = new EnumMap<>(ProtocolState.class);
|
private EnumMap<ProtocolState, PacketStateCodec> stateProtocols = new EnumMap<>(ProtocolState.class);
|
||||||
|
private Supplier<MinecraftCodecHelper> helperFactory;
|
||||||
|
|
||||||
public Builder protocolVersion(int protocolVersion) {
|
public Builder protocolVersion(int protocolVersion) {
|
||||||
this.protocolVersion = protocolVersion;
|
this.protocolVersion = protocolVersion;
|
||||||
|
@ -58,8 +62,13 @@ public class PacketCodec {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Builder helper(Supplier<MinecraftCodecHelper> helperFactory) {
|
||||||
|
this.helperFactory = helperFactory;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public PacketCodec build() {
|
public PacketCodec build() {
|
||||||
return new PacketCodec(this.protocolVersion, this.minecraftVersion, this.stateProtocols);
|
return new PacketCodec(this.protocolVersion, this.minecraftVersion, this.stateProtocols, this.helperFactory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
package com.github.steveice10.mc.protocol.codec;
|
||||||
|
|
||||||
|
import com.github.steveice10.packetlib.codec.PacketCodecHelper;
|
||||||
|
import com.github.steveice10.packetlib.codec.PacketSerializer;
|
||||||
|
import com.github.steveice10.packetlib.packet.Packet;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Factory for constructing {@link Packet}s.
|
||||||
|
*
|
||||||
|
* @param <T> the packet type
|
||||||
|
*/
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface PacketFactory<T extends Packet, H extends PacketCodecHelper> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new {@link Packet}.
|
||||||
|
*
|
||||||
|
* @param buf the input buffer
|
||||||
|
* @param codecHelper the codec helper
|
||||||
|
* @return a new packet from the input
|
||||||
|
*/
|
||||||
|
T construct(ByteBuf buf, H codecHelper) throws IOException;
|
||||||
|
}
|
|
@ -3,9 +3,8 @@ package com.github.steveice10.mc.protocol.codec;
|
||||||
import com.github.steveice10.mc.protocol.MinecraftConstants;
|
import com.github.steveice10.mc.protocol.MinecraftConstants;
|
||||||
import com.github.steveice10.packetlib.Server;
|
import com.github.steveice10.packetlib.Server;
|
||||||
import com.github.steveice10.packetlib.Session;
|
import com.github.steveice10.packetlib.Session;
|
||||||
import com.github.steveice10.packetlib.packet.Packet;
|
import com.github.steveice10.packetlib.codec.PacketCodecHelper;
|
||||||
import com.github.steveice10.packetlib.packet.PacketDefinition;
|
import com.github.steveice10.packetlib.codec.PacketDefinition;
|
||||||
import com.github.steveice10.packetlib.packet.PacketFactory;
|
|
||||||
import com.github.steveice10.packetlib.packet.PacketHeader;
|
import com.github.steveice10.packetlib.packet.PacketHeader;
|
||||||
import com.github.steveice10.packetlib.packet.PacketProtocol;
|
import com.github.steveice10.packetlib.packet.PacketProtocol;
|
||||||
|
|
||||||
|
@ -28,6 +27,11 @@ public class PacketStateCodec extends PacketProtocol {
|
||||||
return MinecraftConstants.PACKET_HEADER;
|
return MinecraftConstants.PACKET_HEADER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PacketCodecHelper createHelper() {
|
||||||
|
throw new UnsupportedOperationException("Not supported!");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void newClientSession(Session session) {
|
public void newClientSession(Session session) {
|
||||||
throw new UnsupportedOperationException("Not supported!");
|
throw new UnsupportedOperationException("Not supported!");
|
||||||
|
@ -39,26 +43,26 @@ public class PacketStateCodec extends PacketProtocol {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Builder {
|
public static class Builder {
|
||||||
private final Map<Integer, PacketDefinition<? extends Packet>> clientboundPackets = new HashMap<>();
|
private final Map<Integer, PacketDefinition<? extends MinecraftPacket, MinecraftCodecHelper>> clientboundPackets = new HashMap<>();
|
||||||
private final Map<Integer, PacketDefinition<? extends Packet>> serverboundPackets = new HashMap<>();
|
private final Map<Integer, PacketDefinition<? extends MinecraftPacket, MinecraftCodecHelper>> serverboundPackets = new HashMap<>();
|
||||||
|
|
||||||
public <T extends Packet> Builder registerClientboundPacket(int id, Class<T> packetClass, PacketFactory<T> factory) {
|
public <T extends MinecraftPacket> Builder registerClientboundPacket(int id, Class<T> packetClass, PacketFactory<T, MinecraftCodecHelper> factory) {
|
||||||
this.clientboundPackets.put(id, new PacketDefinition<>(id, packetClass, factory));
|
this.clientboundPackets.put(id, new PacketDefinition<>(id, packetClass, new MinecraftPacketSerializer<>(factory)));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T extends Packet> Builder registerServerboundPacket(int id, Class<T> packetClass, PacketFactory<T> factory) {
|
public <T extends MinecraftPacket> Builder registerServerboundPacket(int id, Class<T> packetClass, PacketFactory<T, MinecraftCodecHelper> factory) {
|
||||||
this.serverboundPackets.put(id, new PacketDefinition<>(id, packetClass, factory));
|
this.serverboundPackets.put(id, new PacketDefinition<>(id, packetClass, new MinecraftPacketSerializer<>(factory)));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PacketStateCodec build() {
|
public PacketStateCodec build() {
|
||||||
PacketStateCodec codec = new PacketStateCodec();
|
PacketStateCodec codec = new PacketStateCodec();
|
||||||
for (Map.Entry<Integer, PacketDefinition<? extends Packet>> entry : this.clientboundPackets.entrySet()) {
|
for (Map.Entry<Integer, PacketDefinition<? extends MinecraftPacket, MinecraftCodecHelper>> entry : this.clientboundPackets.entrySet()) {
|
||||||
codec.registerClientbound(entry.getValue());
|
codec.registerClientbound(entry.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Map.Entry<Integer, PacketDefinition<? extends Packet>> entry : this.serverboundPackets.entrySet()) {
|
for (Map.Entry<Integer, PacketDefinition<? extends MinecraftPacket, MinecraftCodecHelper>> entry : this.serverboundPackets.entrySet()) {
|
||||||
codec.registerServerbound(entry.getValue());
|
codec.registerServerbound(entry.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,5 +10,9 @@ public enum MessageType {
|
||||||
EMOTE_COMMAND,
|
EMOTE_COMMAND,
|
||||||
TELLRAW_COMMAND;
|
TELLRAW_COMMAND;
|
||||||
|
|
||||||
public static final MessageType[] VALUES = values();
|
private static final MessageType[] VALUES = values();
|
||||||
|
|
||||||
|
public static MessageType from(int id) {
|
||||||
|
return VALUES[id];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,33 +0,0 @@
|
||||||
package com.github.steveice10.mc.protocol.data.game;
|
|
||||||
|
|
||||||
import com.github.steveice10.opennbt.NBTIO;
|
|
||||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
|
|
||||||
public class NBT {
|
|
||||||
private NBT() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public static CompoundTag read(NetInput in) throws IOException {
|
|
||||||
return (CompoundTag) NBTIO.readTag(new InputStream() {
|
|
||||||
@Override
|
|
||||||
public int read() throws IOException {
|
|
||||||
return in.readUnsignedByte();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void write(NetOutput out, CompoundTag tag) throws IOException {
|
|
||||||
NBTIO.writeTag(new OutputStream() {
|
|
||||||
@Override
|
|
||||||
public void write(int b) throws IOException {
|
|
||||||
out.writeByte(b);
|
|
||||||
}
|
|
||||||
}, tag);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,12 +1,7 @@
|
||||||
package com.github.steveice10.mc.protocol.data.game.chunk;
|
package com.github.steveice10.mc.protocol.data.game.chunk;
|
||||||
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.chunk.palette.PaletteType;
|
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
|
||||||
import lombok.*;
|
import lombok.*;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@Setter(AccessLevel.NONE)
|
@Setter(AccessLevel.NONE)
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
|
@ -24,20 +19,6 @@ public class ChunkSection {
|
||||||
this(0, DataPalette.createForChunk(), DataPalette.createForBiome(4));
|
this(0, DataPalette.createForChunk(), DataPalette.createForBiome(4));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ChunkSection read(NetInput in, int globalBiomePaletteBits) throws IOException {
|
|
||||||
int blockCount = in.readShort();
|
|
||||||
|
|
||||||
DataPalette chunkPalette = DataPalette.read(in, PaletteType.CHUNK, DataPalette.GLOBAL_PALETTE_BITS_PER_ENTRY);
|
|
||||||
DataPalette biomePalette = DataPalette.read(in, PaletteType.BIOME, globalBiomePaletteBits);
|
|
||||||
return new ChunkSection(blockCount, chunkPalette, biomePalette);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void write(NetOutput out, ChunkSection section, int globalBiomePaletteBits) throws IOException {
|
|
||||||
out.writeShort(section.blockCount);
|
|
||||||
DataPalette.write(out, section.chunkData);
|
|
||||||
DataPalette.write(out, section.biomeData);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getBlock(int x, int y, int z) {
|
public int getBlock(int x, int y, int z) {
|
||||||
return this.chunkData.get(x, y, z);
|
return this.chunkData.get(x, y, z);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,8 @@
|
||||||
package com.github.steveice10.mc.protocol.data.game.chunk;
|
package com.github.steveice10.mc.protocol.data.game.chunk;
|
||||||
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.chunk.palette.*;
|
import com.github.steveice10.mc.protocol.data.game.chunk.palette.*;
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
|
||||||
import lombok.*;
|
import lombok.*;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
|
@ -37,44 +33,6 @@ public class DataPalette {
|
||||||
new BitStorage(paletteType.getMinBitsPerEntry(), paletteType.getStorageSize()), paletteType, globalPaletteBits);
|
new BitStorage(paletteType.getMinBitsPerEntry(), paletteType.getStorageSize()), paletteType, globalPaletteBits);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DataPalette read(NetInput in, PaletteType paletteType, int globalPaletteBits) throws IOException {
|
|
||||||
int bitsPerEntry = in.readByte();
|
|
||||||
Palette palette = readPalette(paletteType, bitsPerEntry, in);
|
|
||||||
BitStorage storage;
|
|
||||||
if (!(palette instanceof SingletonPalette)) {
|
|
||||||
int length = in.readVarInt();
|
|
||||||
storage = new BitStorage(bitsPerEntry, paletteType.getStorageSize(), in.readLongs(length));
|
|
||||||
} else {
|
|
||||||
in.readVarInt();
|
|
||||||
storage = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new DataPalette(palette, storage, paletteType, globalPaletteBits);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void write(NetOutput out, DataPalette palette) throws IOException {
|
|
||||||
if (palette.palette instanceof SingletonPalette) {
|
|
||||||
out.writeByte(0); // Bits per entry
|
|
||||||
out.writeVarInt(palette.palette.idToState(0));
|
|
||||||
out.writeVarInt(0); // Data length
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
out.writeByte(palette.storage.getBitsPerEntry());
|
|
||||||
|
|
||||||
if (!(palette.palette instanceof GlobalPalette)) {
|
|
||||||
int paletteLength = palette.palette.size();
|
|
||||||
out.writeVarInt(paletteLength);
|
|
||||||
for (int i = 0; i < paletteLength; i++) {
|
|
||||||
out.writeVarInt(palette.palette.idToState(i));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
long[] data = palette.storage.getData();
|
|
||||||
out.writeVarInt(data.length);
|
|
||||||
out.writeLongs(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int get(int x, int y, int z) {
|
public int get(int x, int y, int z) {
|
||||||
if (storage != null) {
|
if (storage != null) {
|
||||||
int id = this.storage.get(index(x, y, z));
|
int id = this.storage.get(index(x, y, z));
|
||||||
|
@ -106,20 +64,6 @@ public class DataPalette {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Palette readPalette(PaletteType paletteType, int bitsPerEntry, NetInput in) throws IOException {
|
|
||||||
if (bitsPerEntry > paletteType.getMaxBitsPerEntry()) {
|
|
||||||
return new GlobalPalette();
|
|
||||||
}
|
|
||||||
if (bitsPerEntry == 0) {
|
|
||||||
return new SingletonPalette(in);
|
|
||||||
}
|
|
||||||
if (bitsPerEntry <= paletteType.getMinBitsPerEntry()) {
|
|
||||||
return new ListPalette(bitsPerEntry, in);
|
|
||||||
} else {
|
|
||||||
return new MapPalette(bitsPerEntry, in);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private int sanitizeBitsPerEntry(int bitsPerEntry) {
|
private int sanitizeBitsPerEntry(int bitsPerEntry) {
|
||||||
if (bitsPerEntry <= this.paletteType.getMaxBitsPerEntry()) {
|
if (bitsPerEntry <= this.paletteType.getMaxBitsPerEntry()) {
|
||||||
return Math.max(this.paletteType.getMinBitsPerEntry(), bitsPerEntry);
|
return Math.max(this.paletteType.getMinBitsPerEntry(), bitsPerEntry);
|
||||||
|
|
|
@ -1,13 +1,9 @@
|
||||||
package com.github.steveice10.mc.protocol.data.game.chunk;
|
package com.github.steveice10.mc.protocol.data.game.chunk;
|
||||||
|
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class NibbleArray3d {
|
public class NibbleArray3d {
|
||||||
|
@ -17,14 +13,6 @@ public class NibbleArray3d {
|
||||||
this(new byte[size >> 1]);
|
this(new byte[size >> 1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public NibbleArray3d(@NonNull NetInput in, int size) throws IOException {
|
|
||||||
this(in.readBytes(size));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void write(@NonNull NetOutput out) throws IOException {
|
|
||||||
out.writeBytes(this.data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int get(int x, int y, int z) {
|
public int get(int x, int y, int z) {
|
||||||
int key = y << 8 | z << 4 | x;
|
int key = y << 8 | z << 4 | x;
|
||||||
int index = key >> 1;
|
int index = key >> 1;
|
||||||
|
|
|
@ -1,13 +1,16 @@
|
||||||
package com.github.steveice10.mc.protocol.data.game.chunk.palette;
|
package com.github.steveice10.mc.protocol.data.game.chunk.palette;
|
||||||
|
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A palette backed by a List.
|
* A palette backed by a List.
|
||||||
*/
|
*/
|
||||||
|
@Getter
|
||||||
@EqualsAndHashCode
|
@EqualsAndHashCode
|
||||||
public class ListPalette implements Palette {
|
public class ListPalette implements Palette {
|
||||||
private final int maxId;
|
private final int maxId;
|
||||||
|
@ -21,13 +24,14 @@ public class ListPalette implements Palette {
|
||||||
this.data = new int[this.maxId + 1];
|
this.data = new int[this.maxId + 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
public ListPalette(int bitsPerEntry, NetInput in) throws IOException {
|
public ListPalette(int bitsPerEntry, ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||||
this(bitsPerEntry);
|
this(bitsPerEntry);
|
||||||
|
|
||||||
int paletteLength = in.readVarInt();
|
int paletteLength = helper.readVarInt(in);
|
||||||
for (int i = 0; i < paletteLength; i++) {
|
for (int i = 0; i < paletteLength; i++) {
|
||||||
this.data[i] = in.readVarInt();
|
this.data[i] = helper.readVarInt(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.nextId = paletteLength;
|
this.nextId = paletteLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.github.steveice10.mc.protocol.data.game.chunk.palette;
|
package com.github.steveice10.mc.protocol.data.game.chunk.palette;
|
||||||
|
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.util.collection.IntObjectHashMap;
|
import io.netty.util.collection.IntObjectHashMap;
|
||||||
import io.netty.util.collection.IntObjectMap;
|
import io.netty.util.collection.IntObjectMap;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
@ -24,12 +25,12 @@ public class MapPalette implements Palette {
|
||||||
this.idToState = new int[this.maxId + 1];
|
this.idToState = new int[this.maxId + 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
public MapPalette(int bitsPerEntry, NetInput in) throws IOException {
|
public MapPalette(int bitsPerEntry, ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||||
this(bitsPerEntry);
|
this(bitsPerEntry);
|
||||||
|
|
||||||
int paletteLength = in.readVarInt();
|
int paletteLength = helper.readVarInt(in);
|
||||||
for (int i = 0; i < paletteLength; i++) {
|
for (int i = 0; i < paletteLength; i++) {
|
||||||
int state = in.readVarInt();
|
int state = helper.readVarInt(in);
|
||||||
this.idToState[i] = state;
|
this.idToState[i] = state;
|
||||||
this.stateToId.putIfAbsent(state, i);
|
this.stateToId.putIfAbsent(state, i);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
package com.github.steveice10.mc.protocol.data.game.chunk.palette;
|
package com.github.steveice10.mc.protocol.data.game.chunk.palette;
|
||||||
|
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A palette containing one state.
|
* A palette containing one state.
|
||||||
*/
|
*/
|
||||||
|
@ -16,10 +13,6 @@ public class SingletonPalette implements Palette {
|
||||||
this.state = state;
|
this.state = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SingletonPalette(NetInput in) throws IOException {
|
|
||||||
this.state = in.readVarInt();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int size() {
|
public int size() {
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
@ -37,11 +37,7 @@ public enum Effect {
|
||||||
|
|
||||||
public static final Effect[] VALUES = values();
|
public static final Effect[] VALUES = values();
|
||||||
|
|
||||||
public static Effect fromNetworkId(int id) {
|
public static Effect from(int id) {
|
||||||
return VALUES[id - 1];
|
return VALUES[id];
|
||||||
}
|
|
||||||
|
|
||||||
public static int toNetworkId(Effect effect) {
|
|
||||||
return effect.ordinal() + 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
package com.github.steveice10.mc.protocol.data.game.entity;
|
package com.github.steveice10.mc.protocol.data.game.entity;
|
||||||
|
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public enum EntityEvent {
|
public enum EntityEvent {
|
||||||
TIPPED_ARROW_EMIT_PARTICLES,
|
TIPPED_ARROW_EMIT_PARTICLES,
|
||||||
RABBIT_JUMP_OR_MINECART_SPAWNER_DELAY_RESET,
|
RABBIT_JUMP_OR_MINECART_SPAWNER_DELAY_RESET,
|
||||||
|
@ -71,11 +67,7 @@ public enum EntityEvent {
|
||||||
|
|
||||||
private static final EntityEvent[] VALUES = values();
|
private static final EntityEvent[] VALUES = values();
|
||||||
|
|
||||||
public static EntityEvent read(NetInput in) throws IOException {
|
public static EntityEvent from(int id) {
|
||||||
return VALUES[in.readByte()];
|
|
||||||
}
|
|
||||||
|
|
||||||
public static EntityEvent fromId(int id) {
|
|
||||||
return VALUES[id];
|
return VALUES[id];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
package com.github.steveice10.mc.protocol.data.game.entity.attribute;
|
package com.github.steveice10.mc.protocol.data.game.entity.attribute;
|
||||||
|
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public enum ModifierOperation {
|
public enum ModifierOperation {
|
||||||
ADD,
|
ADD,
|
||||||
ADD_MULTIPLIED,
|
ADD_MULTIPLIED,
|
||||||
|
@ -11,7 +7,7 @@ public enum ModifierOperation {
|
||||||
|
|
||||||
private static final ModifierOperation[] VALUES = values();
|
private static final ModifierOperation[] VALUES = values();
|
||||||
|
|
||||||
public static ModifierOperation read(NetInput in) throws IOException {
|
public static ModifierOperation from(int id) {
|
||||||
return VALUES[in.readByte()];
|
return VALUES[id];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package com.github.steveice10.mc.protocol.data.game.entity.metadata;
|
package com.github.steveice10.mc.protocol.data.game.entity.metadata;
|
||||||
|
|
||||||
|
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata;
|
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata;
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
import io.netty.buffer.ByteBuf;
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@ -20,32 +20,32 @@ public class BooleanMetadataType extends MetadataType<Boolean> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EntityMetadata<Boolean, BooleanMetadataType> readMetadata(NetInput input, int id) throws IOException {
|
public EntityMetadata<Boolean, BooleanMetadataType> readMetadata(MinecraftCodecHelper helper, ByteBuf input, int id) throws IOException {
|
||||||
return this.primitiveFactory.createPrimitive(id, this, this.primitiveReader.readPrimitive(input));
|
return this.primitiveFactory.createPrimitive(id, this, this.primitiveReader.readPrimitive(input));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeMetadataPrimitive(NetOutput output, boolean value) throws IOException {
|
public void writeMetadataPrimitive(ByteBuf output, boolean value) throws IOException {
|
||||||
this.primitiveWriter.writePrimitive(output, value);
|
this.primitiveWriter.writePrimitive(output, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface BooleanReader extends Reader<Boolean> {
|
public interface BooleanReader extends BasicReader<Boolean> {
|
||||||
boolean readPrimitive(NetInput input) throws IOException;
|
boolean readPrimitive(ByteBuf input) throws IOException;
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
@Override
|
@Override
|
||||||
default Boolean read(NetInput input) throws IOException {
|
default Boolean read(ByteBuf input) throws IOException {
|
||||||
return this.readPrimitive(input);
|
return this.readPrimitive(input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface BooleanWriter extends Writer<Boolean> {
|
public interface BooleanWriter extends BasicWriter<Boolean> {
|
||||||
void writePrimitive(NetOutput output, boolean value) throws IOException;
|
void writePrimitive(ByteBuf output, boolean value) throws IOException;
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
@Override
|
@Override
|
||||||
default void write(NetOutput output, Boolean value) throws IOException {
|
default void write(ByteBuf output, Boolean value) throws IOException {
|
||||||
this.writePrimitive(output, value);
|
this.writePrimitive(output, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package com.github.steveice10.mc.protocol.data.game.entity.metadata;
|
package com.github.steveice10.mc.protocol.data.game.entity.metadata;
|
||||||
|
|
||||||
|
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata;
|
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata;
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
import io.netty.buffer.ByteBuf;
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@ -20,32 +20,32 @@ public class ByteMetadataType extends MetadataType<Byte> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EntityMetadata<Byte, ByteMetadataType> readMetadata(NetInput input, int id) throws IOException {
|
public EntityMetadata<Byte, ByteMetadataType> readMetadata(MinecraftCodecHelper helper, ByteBuf input, int id) throws IOException {
|
||||||
return this.primitiveFactory.createPrimitive(id, this, this.primitiveReader.readPrimitive(input));
|
return this.primitiveFactory.createPrimitive(id, this, this.primitiveReader.readPrimitive(input));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeMetadataPrimitive(NetOutput output, byte value) throws IOException {
|
public void writeMetadataPrimitive(ByteBuf output, byte value) throws IOException {
|
||||||
this.primitiveWriter.writePrimitive(output, value);
|
this.primitiveWriter.writePrimitive(output, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface ByteReader extends Reader<Byte> {
|
public interface ByteReader extends BasicReader<Byte> {
|
||||||
byte readPrimitive(NetInput input) throws IOException;
|
byte readPrimitive(ByteBuf input) throws IOException;
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
@Override
|
@Override
|
||||||
default Byte read(NetInput input) throws IOException {
|
default Byte read(ByteBuf input) throws IOException {
|
||||||
return this.readPrimitive(input);
|
return this.readPrimitive(input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface ByteWriter extends Writer<Byte> {
|
public interface ByteWriter extends BasicWriter<Byte> {
|
||||||
void writePrimitive(NetOutput output, byte value) throws IOException;
|
void writePrimitive(ByteBuf output, byte value) throws IOException;
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
@Override
|
@Override
|
||||||
default void write(NetOutput output, Byte value) throws IOException {
|
default void write(ByteBuf output, Byte value) throws IOException {
|
||||||
this.writePrimitive(output, value);
|
this.writePrimitive(output, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
package com.github.steveice10.mc.protocol.data.game.entity.metadata;
|
package com.github.steveice10.mc.protocol.data.game.entity.metadata;
|
||||||
|
|
||||||
|
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ObjectEntityMetadata;
|
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ObjectEntityMetadata;
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
import io.netty.buffer.ByteBuf;
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.Objects;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
|
@ -21,33 +21,12 @@ public abstract class EntityMetadata<V, T extends MetadataType<V>> {
|
||||||
*/
|
*/
|
||||||
public abstract V getValue();
|
public abstract V getValue();
|
||||||
|
|
||||||
public static EntityMetadata<?, ?>[] read(NetInput in) throws IOException {
|
|
||||||
List<EntityMetadata<?, ?>> ret = new ArrayList<>();
|
|
||||||
int id;
|
|
||||||
while ((id = in.readUnsignedByte()) != 255) {
|
|
||||||
MetadataType<?> type = MetadataType.read(in);
|
|
||||||
ret.add(type.readMetadata(in, id));
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret.toArray(new EntityMetadata[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Overridden for primitive classes. This write method still checks for these primitives in the event
|
* Overridden for primitive classes. This write method still checks for these primitives in the event
|
||||||
* they are manually created using {@link ObjectEntityMetadata}.
|
* they are manually created using {@link ObjectEntityMetadata}.
|
||||||
*/
|
*/
|
||||||
protected void write(NetOutput out) throws IOException {
|
public void write(MinecraftCodecHelper helper, ByteBuf out) throws IOException {
|
||||||
this.type.writeMetadata(out, this.getValue());
|
this.type.writeMetadata(helper, out, this.getValue());
|
||||||
}
|
|
||||||
|
|
||||||
public static void write(NetOutput out, EntityMetadata<?, ?>[] metadata) throws IOException {
|
|
||||||
for (EntityMetadata<?, ?> meta : metadata) {
|
|
||||||
out.writeByte(meta.getId());
|
|
||||||
MetadataType.write(out, meta.getType());
|
|
||||||
meta.write(out);
|
|
||||||
}
|
|
||||||
|
|
||||||
out.writeByte(255);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package com.github.steveice10.mc.protocol.data.game.entity.metadata;
|
package com.github.steveice10.mc.protocol.data.game.entity.metadata;
|
||||||
|
|
||||||
|
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.FloatEntityMetadata;
|
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.FloatEntityMetadata;
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
import io.netty.buffer.ByteBuf;
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@ -20,32 +20,32 @@ public class FloatMetadataType extends MetadataType<Float> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EntityMetadata<Float, FloatMetadataType> readMetadata(NetInput input, int id) throws IOException {
|
public EntityMetadata<Float, FloatMetadataType> readMetadata(MinecraftCodecHelper helper, ByteBuf input, int id) throws IOException {
|
||||||
return this.primitiveFactory.createPrimitive(id, this, this.primitiveReader.readPrimitive(input));
|
return this.primitiveFactory.createPrimitive(id, this, this.primitiveReader.readPrimitive(input));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeMetadataPrimitive(NetOutput output, float value) throws IOException {
|
public void writeMetadataPrimitive(ByteBuf output, float value) throws IOException {
|
||||||
this.primitiveWriter.writePrimitive(output, value);
|
this.primitiveWriter.writePrimitive(output, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface FloatReader extends Reader<Float> {
|
public interface FloatReader extends BasicReader<Float> {
|
||||||
float readPrimitive(NetInput input) throws IOException;
|
float readPrimitive(ByteBuf input) throws IOException;
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
@Override
|
@Override
|
||||||
default Float read(NetInput input) throws IOException {
|
default Float read(ByteBuf input) throws IOException {
|
||||||
return this.readPrimitive(input);
|
return this.readPrimitive(input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface FloatWriter extends Writer<Float> {
|
public interface FloatWriter extends BasicWriter<Float> {
|
||||||
void writePrimitive(NetOutput output, float value) throws IOException;
|
void writePrimitive(ByteBuf output, float value) throws IOException;
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
@Override
|
@Override
|
||||||
default void write(NetOutput output, Float value) throws IOException {
|
default void write(ByteBuf output, Float value) throws IOException {
|
||||||
this.writePrimitive(output, value);
|
this.writePrimitive(output, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,7 @@
|
||||||
package com.github.steveice10.mc.protocol.data.game.entity.metadata;
|
package com.github.steveice10.mc.protocol.data.game.entity.metadata;
|
||||||
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.Identifier;
|
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
|
||||||
import com.nukkitx.math.vector.Vector3i;
|
import com.nukkitx.math.vector.Vector3i;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public class GlobalPos {
|
public class GlobalPos {
|
||||||
private final String dimension;
|
private final String dimension;
|
||||||
private final Vector3i position;
|
private final Vector3i position;
|
||||||
|
@ -35,15 +30,4 @@ public class GlobalPos {
|
||||||
public int getZ() {
|
public int getZ() {
|
||||||
return position.getZ();
|
return position.getZ();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static GlobalPos read(NetInput in) throws IOException {
|
|
||||||
String dimension = Identifier.formalize(in.readString());
|
|
||||||
Vector3i pos = Position.read(in);
|
|
||||||
return new GlobalPos(dimension, pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void write(NetOutput out, GlobalPos pos) throws IOException {
|
|
||||||
out.writeString(pos.getDimension());
|
|
||||||
Position.write(out, pos.getPosition());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package com.github.steveice10.mc.protocol.data.game.entity.metadata;
|
package com.github.steveice10.mc.protocol.data.game.entity.metadata;
|
||||||
|
|
||||||
|
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata;
|
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata;
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
import io.netty.buffer.ByteBuf;
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@ -20,33 +20,33 @@ public class IntMetadataType extends MetadataType<Integer> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EntityMetadata<Integer, IntMetadataType> readMetadata(NetInput input, int id) throws IOException {
|
public EntityMetadata<Integer, IntMetadataType> readMetadata(MinecraftCodecHelper helper, ByteBuf input, int id) throws IOException {
|
||||||
return this.primitiveFactory.createPrimitive(id, this, this.primitiveReader.readPrimitive(input));
|
return this.primitiveFactory.createPrimitive(id, this, this.primitiveReader.readPrimitive(helper, input));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeMetadataPrimitive(NetOutput output, int value) throws IOException {
|
public void writeMetadataPrimitive(MinecraftCodecHelper helper, ByteBuf output, int value) throws IOException {
|
||||||
this.primitiveWriter.writePrimitive(output, value);
|
this.primitiveWriter.writePrimitive(helper, output, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface IntReader extends Reader<Integer> {
|
public interface IntReader extends HelperReader<Integer> {
|
||||||
int readPrimitive(NetInput input) throws IOException;
|
int readPrimitive(MinecraftCodecHelper helper, ByteBuf input) throws IOException;
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
@Override
|
@Override
|
||||||
default Integer read(NetInput input) throws IOException {
|
default Integer read(MinecraftCodecHelper helper, ByteBuf input) throws IOException {
|
||||||
return this.readPrimitive(input);
|
return this.readPrimitive(helper, input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface IntWriter extends Writer<Integer> {
|
public interface IntWriter extends HelperWriter<Integer> {
|
||||||
void writePrimitive(NetOutput output, int value) throws IOException;
|
void writePrimitive(MinecraftCodecHelper helper, ByteBuf output, int value) throws IOException;
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
@Override
|
@Override
|
||||||
default void write(NetOutput output, Integer value) throws IOException {
|
default void write(MinecraftCodecHelper helper, ByteBuf output, Integer value) throws IOException {
|
||||||
this.writePrimitive(output, value);
|
this.writePrimitive(helper, output, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,9 @@
|
||||||
package com.github.steveice10.mc.protocol.data.game.entity.metadata;
|
package com.github.steveice10.mc.protocol.data.game.entity.metadata;
|
||||||
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.NBT;
|
|
||||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class ItemStack {
|
public class ItemStack {
|
||||||
|
@ -23,23 +18,4 @@ public class ItemStack {
|
||||||
public ItemStack(int id, int amount) {
|
public ItemStack(int id, int amount) {
|
||||||
this(id, amount, null);
|
this(id, amount, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ItemStack read(NetInput in) throws IOException {
|
|
||||||
boolean present = in.readBoolean();
|
|
||||||
if (!present) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
int item = in.readVarInt();
|
|
||||||
return new ItemStack(item, in.readByte(), NBT.read(in));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void write(NetOutput out, ItemStack item) throws IOException {
|
|
||||||
out.writeBoolean(item != null);
|
|
||||||
if (item != null) {
|
|
||||||
out.writeVarInt(item.getId());
|
|
||||||
out.writeByte(item.getAmount());
|
|
||||||
NBT.write(out, item.getNbt());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +1,15 @@
|
||||||
package com.github.steveice10.mc.protocol.data.game.entity.metadata;
|
package com.github.steveice10.mc.protocol.data.game.entity.metadata;
|
||||||
|
|
||||||
import com.github.steveice10.mc.protocol.data.DefaultComponentSerializer;
|
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
|
||||||
import com.github.steveice10.mc.protocol.data.game.NBT;
|
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.*;
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata;
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata;
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.FloatEntityMetadata;
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata;
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ObjectEntityMetadata;
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.object.Direction;
|
import com.github.steveice10.mc.protocol.data.game.entity.object.Direction;
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.type.PaintingType;
|
import com.github.steveice10.mc.protocol.data.game.entity.type.PaintingType;
|
||||||
import com.github.steveice10.mc.protocol.data.game.level.particle.Particle;
|
import com.github.steveice10.mc.protocol.data.game.level.particle.Particle;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
import com.nukkitx.math.vector.Vector3f;
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
|
||||||
import com.nukkitx.math.vector.Vector3i;
|
import com.nukkitx.math.vector.Vector3i;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import lombok.Getter;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -22,43 +18,40 @@ import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@Getter
|
||||||
public class MetadataType<T> {
|
public class MetadataType<T> {
|
||||||
private static final List<MetadataType<?>> VALUES = new ArrayList<>();
|
private static final List<MetadataType<?>> VALUES = new ArrayList<>();
|
||||||
|
|
||||||
public static final ByteMetadataType BYTE = new ByteMetadataType(NetInput::readByte, NetOutput::writeByte, ByteEntityMetadata::new);
|
public static final ByteMetadataType BYTE = new ByteMetadataType(ByteBuf::readByte, ByteBuf::writeByte, ByteEntityMetadata::new);
|
||||||
public static final IntMetadataType INT = new IntMetadataType(NetInput::readVarInt, NetOutput::writeVarInt, IntEntityMetadata::new);
|
public static final IntMetadataType INT = new IntMetadataType(MinecraftCodecHelper::readVarInt, MinecraftCodecHelper::writeVarInt, IntEntityMetadata::new);
|
||||||
public static final FloatMetadataType FLOAT = new FloatMetadataType(NetInput::readFloat, NetOutput::writeFloat, FloatEntityMetadata::new);
|
public static final FloatMetadataType FLOAT = new FloatMetadataType(ByteBuf::readFloat, ByteBuf::writeFloat, FloatEntityMetadata::new);
|
||||||
public static final MetadataType<String> STRING = new MetadataType<>(NetInput::readString, NetOutput::writeString, ObjectEntityMetadata::new);
|
public static final MetadataType<String> STRING = new MetadataType<>(MinecraftCodecHelper::readString, MinecraftCodecHelper::writeString, ObjectEntityMetadata::new);
|
||||||
public static final MetadataType<Component> CHAT = new MetadataType<>(in -> DefaultComponentSerializer.get().deserialize(in.readString()),
|
public static final MetadataType<Component> CHAT = new MetadataType<>(MinecraftCodecHelper::readComponent, MinecraftCodecHelper::writeComponent, ObjectEntityMetadata::new);
|
||||||
(out, value) -> out.writeString(DefaultComponentSerializer.get().serialize(value)),
|
public static final MetadataType<Optional<Component>> OPTIONAL_CHAT = new MetadataType<>(optionalReader(MinecraftCodecHelper::readComponent), optionalWriter(MinecraftCodecHelper::writeComponent), ObjectEntityMetadata::new);
|
||||||
ObjectEntityMetadata::new);
|
public static final MetadataType<ItemStack> ITEM = new MetadataType<>(MinecraftCodecHelper::readItemStack, MinecraftCodecHelper::writeItemStack, ObjectEntityMetadata::new);
|
||||||
public static final MetadataType<Optional<Component>> OPTIONAL_CHAT = new MetadataType<>(optionalReader(in -> DefaultComponentSerializer.get().deserialize(in.readString())),
|
public static final BooleanMetadataType BOOLEAN = new BooleanMetadataType(ByteBuf::readBoolean, ByteBuf::writeBoolean, BooleanEntityMetadata::new);
|
||||||
optionalWriter((out, value) -> out.writeString(DefaultComponentSerializer.get().serialize(value))),
|
public static final MetadataType<Vector3f> ROTATION = new MetadataType<>(MinecraftCodecHelper::readRotation, MinecraftCodecHelper::writeRotation, ObjectEntityMetadata::new);
|
||||||
ObjectEntityMetadata::new);
|
public static final MetadataType<Vector3i> POSITION = new MetadataType<>(MinecraftCodecHelper::readPosition, MinecraftCodecHelper::writePosition, ObjectEntityMetadata::new);
|
||||||
public static final MetadataType<ItemStack> ITEM = new MetadataType<>(ItemStack::read, ItemStack::write, ObjectEntityMetadata::new);
|
public static final MetadataType<Optional<Vector3i>> OPTIONAL_POSITION = new MetadataType<>(optionalReader(MinecraftCodecHelper::readPosition), optionalWriter(MinecraftCodecHelper::writePosition), ObjectEntityMetadata::new);
|
||||||
public static final BooleanMetadataType BOOLEAN = new BooleanMetadataType(NetInput::readBoolean, NetOutput::writeBoolean, BooleanEntityMetadata::new);
|
public static final MetadataType<Direction> DIRECTION = new MetadataType<>(MinecraftCodecHelper::readDirection, MinecraftCodecHelper::writeDirection, ObjectEntityMetadata::new);
|
||||||
public static final MetadataType<Rotation> ROTATION = new MetadataType<>(Rotation::read, Rotation::write, ObjectEntityMetadata::new);
|
public static final MetadataType<Optional<UUID>> OPTIONAL_UUID = new MetadataType<>(optionalReader(MinecraftCodecHelper::readUUID), optionalWriter(MinecraftCodecHelper::writeUUID), ObjectEntityMetadata::new);
|
||||||
public static final MetadataType<Vector3i> POSITION = new MetadataType<>(Position::read, Position::write, ObjectEntityMetadata::new);
|
public static final IntMetadataType BLOCK_STATE = new IntMetadataType(MinecraftCodecHelper::readVarInt, MinecraftCodecHelper::writeVarInt, IntEntityMetadata::new);
|
||||||
public static final MetadataType<Optional<Vector3i>> OPTIONAL_POSITION = new MetadataType<>(optionalReader(Position::read), optionalWriter(Position::write), ObjectEntityMetadata::new);
|
public static final MetadataType<CompoundTag> NBT_TAG = new MetadataType<>(MinecraftCodecHelper::readTag, MinecraftCodecHelper::writeTag, ObjectEntityMetadata::new);
|
||||||
public static final MetadataType<Direction> DIRECTION = new MetadataType<>(in -> in.readEnum(Direction.VALUES), NetOutput::writeEnum, ObjectEntityMetadata::new);
|
public static final MetadataType<Particle> PARTICLE = new MetadataType<>(MinecraftCodecHelper::readParticle, MinecraftCodecHelper::writeParticle, ObjectEntityMetadata::new);
|
||||||
public static final MetadataType<Optional<UUID>> OPTIONAL_UUID = new MetadataType<>(optionalReader(NetInput::readUUID), optionalWriter(NetOutput::writeUUID), ObjectEntityMetadata::new);
|
public static final MetadataType<VillagerData> VILLAGER_DATA = new MetadataType<>(MinecraftCodecHelper::readVillagerData, MinecraftCodecHelper::writeVillagerData, ObjectEntityMetadata::new);
|
||||||
public static final IntMetadataType BLOCK_STATE = new IntMetadataType(NetInput::readVarInt, NetOutput::writeVarInt, IntEntityMetadata::new);
|
|
||||||
public static final MetadataType<CompoundTag> NBT_TAG = new MetadataType<>(NBT::read, NBT::write, ObjectEntityMetadata::new);
|
|
||||||
public static final MetadataType<Particle> PARTICLE = new MetadataType<>(Particle::read, Particle::write, ObjectEntityMetadata::new);
|
|
||||||
public static final MetadataType<VillagerData> VILLAGER_DATA = new MetadataType<>(VillagerData::read, VillagerData::write, ObjectEntityMetadata::new);
|
|
||||||
public static final OptionalIntMetadataType OPTIONAL_VARINT = new OptionalIntMetadataType(ObjectEntityMetadata::new);
|
public static final OptionalIntMetadataType OPTIONAL_VARINT = new OptionalIntMetadataType(ObjectEntityMetadata::new);
|
||||||
public static final MetadataType<Pose> POSE = new MetadataType<>(in -> in.readEnum(Pose.VALUES), NetOutput::writeEnum, ObjectEntityMetadata::new);
|
public static final MetadataType<Pose> POSE = new MetadataType<>(MinecraftCodecHelper::readPose, MinecraftCodecHelper::writePose, ObjectEntityMetadata::new);
|
||||||
public static final IntMetadataType CAT_VARIANT = new IntMetadataType(NetInput::readVarInt, NetOutput::writeVarInt, IntEntityMetadata::new);
|
public static final IntMetadataType CAT_VARIANT = new IntMetadataType(MinecraftCodecHelper::readVarInt, MinecraftCodecHelper::writeVarInt, IntEntityMetadata::new);
|
||||||
public static final IntMetadataType FROG_VARIANT = new IntMetadataType(NetInput::readVarInt, NetOutput::writeVarInt, IntEntityMetadata::new);
|
public static final IntMetadataType FROG_VARIANT = new IntMetadataType(MinecraftCodecHelper::readVarInt, MinecraftCodecHelper::writeVarInt, IntEntityMetadata::new);
|
||||||
public static final MetadataType<Optional<GlobalPos>> OPTIONAL_GLOBAL_POS = new MetadataType<>(optionalReader(GlobalPos::read), optionalWriter(GlobalPos::write), ObjectEntityMetadata::new);
|
public static final MetadataType<Optional<GlobalPos>> OPTIONAL_GLOBAL_POS = new MetadataType<>(optionalReader(MinecraftCodecHelper::readGlobalPos), optionalWriter(MinecraftCodecHelper::writeGlobalPos), ObjectEntityMetadata::new);
|
||||||
public static final MetadataType<PaintingType> PAINTING_VARIANT = new MetadataType<>(PaintingType::read, NetOutput::writeEnum, ObjectEntityMetadata::new);
|
public static final MetadataType<PaintingType> PAINTING_VARIANT = new MetadataType<>(MinecraftCodecHelper::readPaintingType, MinecraftCodecHelper::writePaintingType, ObjectEntityMetadata::new);
|
||||||
|
|
||||||
protected final int id;
|
protected final int id;
|
||||||
protected final Reader<T> reader;
|
protected final Reader<T> reader;
|
||||||
protected final Writer<T> writer;
|
protected final Writer<T> writer;
|
||||||
protected final EntityMetadataFactory<T> metadataFactory;
|
protected final EntityMetadataFactory<T> metadataFactory;
|
||||||
|
|
||||||
protected MetadataType(Reader<T> reader, Writer<T> writer, EntityMetadataFactory<T> metadataFactory) {
|
protected MetadataType(BasicReader<T> reader, BasicWriter<T> writer, EntityMetadataFactory<T> metadataFactory) {
|
||||||
this.id = VALUES.size();
|
this.id = VALUES.size();
|
||||||
this.reader = reader;
|
this.reader = reader;
|
||||||
this.writer = writer;
|
this.writer = writer;
|
||||||
|
@ -67,22 +60,69 @@ public class MetadataType<T> {
|
||||||
VALUES.add(this);
|
VALUES.add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public EntityMetadata<T, ? extends MetadataType<T>> readMetadata(NetInput input, int id) throws IOException {
|
protected MetadataType(HelperReader<T> reader, HelperWriter<T> writer, EntityMetadataFactory<T> metadataFactory) {
|
||||||
return this.metadataFactory.create(id, this, this.reader.read(input));
|
this.id = VALUES.size();
|
||||||
|
this.reader = reader;
|
||||||
|
this.writer = writer;
|
||||||
|
this.metadataFactory = metadataFactory;
|
||||||
|
|
||||||
|
VALUES.add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeMetadata(NetOutput output, T value) throws IOException {
|
public EntityMetadata<T, ? extends MetadataType<T>> readMetadata(MinecraftCodecHelper helper, ByteBuf input, int id) throws IOException {
|
||||||
this.writer.write(output, value);
|
return this.metadataFactory.create(id, this, this.reader.read(helper, input));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeMetadata(MinecraftCodecHelper helper, ByteBuf output, T value) throws IOException {
|
||||||
|
this.writer.write(helper, output, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@FunctionalInterface
|
|
||||||
public interface Reader<V> {
|
public interface Reader<V> {
|
||||||
V read(NetInput input) throws IOException;
|
V read(ByteBuf input) throws IOException;
|
||||||
|
|
||||||
|
V read(MinecraftCodecHelper helper, ByteBuf input) throws IOException;
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface Writer<V> {
|
||||||
|
void write(ByteBuf output, V value) throws IOException;
|
||||||
|
|
||||||
|
void write(MinecraftCodecHelper helper, ByteBuf output, V value) throws IOException;
|
||||||
}
|
}
|
||||||
|
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface Writer<V> {
|
public interface BasicReader<V> extends Reader<V> {
|
||||||
void write(NetOutput output, V value) throws IOException;
|
V read(ByteBuf input) throws IOException;
|
||||||
|
|
||||||
|
default V read(MinecraftCodecHelper helper, ByteBuf input) throws IOException {
|
||||||
|
return this.read(input);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface BasicWriter<V> extends Writer<V> {
|
||||||
|
void write(ByteBuf output, V value) throws IOException;
|
||||||
|
|
||||||
|
default void write(MinecraftCodecHelper helper, ByteBuf output, V value) throws IOException {
|
||||||
|
this.write(output, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface HelperReader<V> extends Reader<V> {
|
||||||
|
default V read(ByteBuf input) throws IOException {
|
||||||
|
throw new UnsupportedOperationException("This reader needs a codec helper!");
|
||||||
|
}
|
||||||
|
|
||||||
|
V read(MinecraftCodecHelper helper, ByteBuf input) throws IOException;
|
||||||
|
}
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface HelperWriter<V> extends Writer<V> {
|
||||||
|
default void write(ByteBuf output, V value) throws IOException {
|
||||||
|
throw new UnsupportedOperationException("This writer needs a codec helper!");
|
||||||
|
}
|
||||||
|
|
||||||
|
void write(MinecraftCodecHelper helper, ByteBuf output, V value) throws IOException;
|
||||||
}
|
}
|
||||||
|
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
|
@ -90,7 +130,7 @@ public class MetadataType<T> {
|
||||||
EntityMetadata<V, ? extends MetadataType<V>> create(int id, MetadataType<V> type, V value);
|
EntityMetadata<V, ? extends MetadataType<V>> create(int id, MetadataType<V> type, V value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <T> Reader<Optional<T>> optionalReader(Reader<T> reader) {
|
private static <T> BasicReader<Optional<T>> optionalReader(BasicReader<T> reader) {
|
||||||
return input -> {
|
return input -> {
|
||||||
if (!input.readBoolean()) {
|
if (!input.readBoolean()) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
|
@ -100,7 +140,17 @@ public class MetadataType<T> {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <T> Writer<Optional<T>> optionalWriter(Writer<T> writer) {
|
private static <T> HelperReader<Optional<T>> optionalReader(HelperReader<T> reader) {
|
||||||
|
return (helper, input) -> {
|
||||||
|
if (!input.readBoolean()) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Optional.of(reader.read(helper, input));
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private static <T> BasicWriter<Optional<T>> optionalWriter(BasicWriter<T> writer) {
|
||||||
return (ouput, value) -> {
|
return (ouput, value) -> {
|
||||||
ouput.writeBoolean(value.isPresent());
|
ouput.writeBoolean(value.isPresent());
|
||||||
if (value.isPresent()) {
|
if (value.isPresent()) {
|
||||||
|
@ -109,16 +159,29 @@ public class MetadataType<T> {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MetadataType<?> read(NetInput in) throws IOException {
|
private static <T> HelperWriter<Optional<T>> optionalWriter(HelperWriter<T> writer) {
|
||||||
int id = in.readVarInt();
|
return (helper, ouput, value) -> {
|
||||||
|
ouput.writeBoolean(value.isPresent());
|
||||||
|
if (value.isPresent()) {
|
||||||
|
writer.write(helper, ouput, value.get());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MetadataType<?> read(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||||
|
int id = helper.readVarInt(in);
|
||||||
if (id >= VALUES.size()) {
|
if (id >= VALUES.size()) {
|
||||||
throw new IllegalArgumentException("Received id " + id + " for MetadataType when the maximum was " + VALUES.size() + "!");
|
throw new IllegalArgumentException("Received id " + id + " for MetadataType when the maximum was " + VALUES.size() + "!");
|
||||||
}
|
}
|
||||||
|
|
||||||
return VALUES.get(id);
|
return VALUES.get(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void write(NetOutput out, MetadataType<?> type) throws IOException {
|
public static MetadataType<?> from(int id) {
|
||||||
out.writeVarInt(type.id);
|
return VALUES.get(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int size() {
|
||||||
|
return VALUES.size();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package com.github.steveice10.mc.protocol.data.game.entity.metadata;
|
package com.github.steveice10.mc.protocol.data.game.entity.metadata;
|
||||||
|
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
import io.netty.buffer.ByteBuf;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.OptionalInt;
|
import java.util.OptionalInt;
|
||||||
|
@ -11,12 +11,12 @@ public class OptionalIntMetadataType extends MetadataType<OptionalInt> {
|
||||||
super(OptionalIntReader.INSTANCE, OptionalIntWriter.INSTANCE, metadataFactory);
|
super(OptionalIntReader.INSTANCE, OptionalIntWriter.INSTANCE, metadataFactory);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class OptionalIntReader implements Reader<OptionalInt> {
|
public static class OptionalIntReader implements HelperReader<OptionalInt> {
|
||||||
protected static final OptionalIntReader INSTANCE = new OptionalIntReader();
|
protected static final OptionalIntReader INSTANCE = new OptionalIntReader();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OptionalInt read(NetInput input) throws IOException {
|
public OptionalInt read(MinecraftCodecHelper helper, ByteBuf input) throws IOException {
|
||||||
int value = input.readVarInt();
|
int value = helper.readVarInt(input);
|
||||||
if (value == 0) {
|
if (value == 0) {
|
||||||
return OptionalInt.empty();
|
return OptionalInt.empty();
|
||||||
}
|
}
|
||||||
|
@ -25,15 +25,15 @@ public class OptionalIntMetadataType extends MetadataType<OptionalInt> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class OptionalIntWriter implements Writer<OptionalInt> {
|
public static class OptionalIntWriter implements HelperWriter<OptionalInt> {
|
||||||
protected static final OptionalIntWriter INSTANCE = new OptionalIntWriter();
|
protected static final OptionalIntWriter INSTANCE = new OptionalIntWriter();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(NetOutput output, OptionalInt value) throws IOException {
|
public void write(MinecraftCodecHelper helper, ByteBuf output, OptionalInt value) throws IOException {
|
||||||
if (value.isPresent()) {
|
if (value.isPresent()) {
|
||||||
output.writeVarInt(value.getAsInt() + 1);
|
helper.writeVarInt(output, value.getAsInt() + 1);
|
||||||
} else {
|
} else {
|
||||||
output.writeVarInt(0);
|
helper.writeVarInt(output, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,5 +16,9 @@ public enum Pose {
|
||||||
EMERGING,
|
EMERGING,
|
||||||
DIGGING;
|
DIGGING;
|
||||||
|
|
||||||
public static final Pose[] VALUES = values();
|
private static final Pose[] VALUES = values();
|
||||||
|
|
||||||
|
public static Pose from(int id) {
|
||||||
|
return VALUES[id];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,36 +0,0 @@
|
||||||
package com.github.steveice10.mc.protocol.data.game.entity.metadata;
|
|
||||||
|
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
|
||||||
import com.nukkitx.math.vector.Vector3i;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public final class Position {
|
|
||||||
private static final int POSITION_X_SIZE = 38;
|
|
||||||
private static final int POSITION_Y_SIZE = 12;
|
|
||||||
private static final int POSITION_Z_SIZE = 38;
|
|
||||||
private static final int POSITION_Y_SHIFT = 0xFFF;
|
|
||||||
private static final int POSITION_WRITE_SHIFT = 0x3FFFFFF;
|
|
||||||
|
|
||||||
public static Vector3i read(NetInput in) throws IOException {
|
|
||||||
long val = in.readLong();
|
|
||||||
|
|
||||||
int x = (int) (val >> POSITION_X_SIZE);
|
|
||||||
int y = (int) (val << 52 >> 52);
|
|
||||||
int z = (int) (val << 26 >> POSITION_Z_SIZE);
|
|
||||||
|
|
||||||
return Vector3i.from(x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void write(NetOutput out, Vector3i pos) throws IOException {
|
|
||||||
long x = pos.getX() & POSITION_WRITE_SHIFT;
|
|
||||||
long y = pos.getY() & POSITION_Y_SHIFT;
|
|
||||||
long z = pos.getZ() & POSITION_WRITE_SHIFT;
|
|
||||||
|
|
||||||
out.writeLong(x << POSITION_X_SIZE | z << POSITION_Y_SIZE | y);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Position() {
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,26 +0,0 @@
|
||||||
package com.github.steveice10.mc.protocol.data.game.entity.metadata;
|
|
||||||
|
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class Rotation {
|
|
||||||
private final float pitch;
|
|
||||||
private final float yaw;
|
|
||||||
private final float roll;
|
|
||||||
|
|
||||||
public static Rotation read(NetInput in) throws IOException {
|
|
||||||
return new Rotation(in.readFloat(), in.readFloat(), in.readFloat());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void write(NetOutput out, Rotation rot) throws IOException {
|
|
||||||
out.writeFloat(rot.getPitch());
|
|
||||||
out.writeFloat(rot.getYaw());
|
|
||||||
out.writeFloat(rot.getRoll());
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,26 +1,12 @@
|
||||||
package com.github.steveice10.mc.protocol.data.game.entity.metadata;
|
package com.github.steveice10.mc.protocol.data.game.entity.metadata;
|
||||||
|
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class VillagerData {
|
public class VillagerData {
|
||||||
private final int type;
|
private final int type;
|
||||||
private final int profession;
|
private final int profession;
|
||||||
private final int level;
|
private final int level;
|
||||||
|
|
||||||
public static VillagerData read(NetInput in) throws IOException {
|
|
||||||
return new VillagerData(in.readVarInt(), in.readVarInt(), in.readVarInt());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void write(NetOutput out, VillagerData villagerData) throws IOException {
|
|
||||||
out.writeVarInt(villagerData.getType());
|
|
||||||
out.writeVarInt(villagerData.getProfession());
|
|
||||||
out.writeVarInt(villagerData.getLevel());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
package com.github.steveice10.mc.protocol.data.game.entity.metadata.type;
|
package com.github.steveice10.mc.protocol.data.game.entity.metadata.type;
|
||||||
|
|
||||||
|
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.BooleanMetadataType;
|
import com.github.steveice10.mc.protocol.data.game.entity.metadata.BooleanMetadataType;
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
|
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
import io.netty.buffer.ByteBuf;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -26,7 +27,7 @@ public class BooleanEntityMetadata extends EntityMetadata<Boolean, BooleanMetada
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void write(NetOutput out) throws IOException {
|
public void write(MinecraftCodecHelper helper, ByteBuf out) throws IOException {
|
||||||
this.type.writeMetadataPrimitive(out, this.value);
|
this.type.writeMetadataPrimitive(out, this.value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
package com.github.steveice10.mc.protocol.data.game.entity.metadata.type;
|
package com.github.steveice10.mc.protocol.data.game.entity.metadata.type;
|
||||||
|
|
||||||
|
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.ByteMetadataType;
|
import com.github.steveice10.mc.protocol.data.game.entity.metadata.ByteMetadataType;
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
|
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
import io.netty.buffer.ByteBuf;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -26,7 +27,7 @@ public class ByteEntityMetadata extends EntityMetadata<Byte, ByteMetadataType> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void write(NetOutput out) throws IOException {
|
public void write(MinecraftCodecHelper helper, ByteBuf out) throws IOException {
|
||||||
this.type.writeMetadataPrimitive(out, this.value);
|
this.type.writeMetadataPrimitive(out, this.value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
package com.github.steveice10.mc.protocol.data.game.entity.metadata.type;
|
package com.github.steveice10.mc.protocol.data.game.entity.metadata.type;
|
||||||
|
|
||||||
|
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
|
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.FloatMetadataType;
|
import com.github.steveice10.mc.protocol.data.game.entity.metadata.FloatMetadataType;
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
import io.netty.buffer.ByteBuf;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -26,7 +27,7 @@ public class FloatEntityMetadata extends EntityMetadata<Float, FloatMetadataType
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void write(NetOutput out) throws IOException {
|
public void write(MinecraftCodecHelper helper, ByteBuf out) throws IOException {
|
||||||
this.type.writeMetadataPrimitive(out, this.value);
|
this.type.writeMetadataPrimitive(out, this.value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
package com.github.steveice10.mc.protocol.data.game.entity.metadata.type;
|
package com.github.steveice10.mc.protocol.data.game.entity.metadata.type;
|
||||||
|
|
||||||
|
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
|
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.IntMetadataType;
|
import com.github.steveice10.mc.protocol.data.game.entity.metadata.IntMetadataType;
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.MetadataType;
|
import com.github.steveice10.mc.protocol.data.game.entity.metadata.MetadataType;
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
import io.netty.buffer.ByteBuf;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -30,7 +31,7 @@ public class IntEntityMetadata extends EntityMetadata<Integer, IntMetadataType>
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void write(NetOutput out) throws IOException {
|
public void write(MinecraftCodecHelper helper, ByteBuf out) throws IOException {
|
||||||
this.type.writeMetadataPrimitive(out, value);
|
this.type.writeMetadataPrimitive(helper, out, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,4 +23,8 @@ public enum Direction implements ObjectData {
|
||||||
public static Direction getByHorizontalIndex(int index) {
|
public static Direction getByHorizontalIndex(int index) {
|
||||||
return HORIZONTAL_VALUES[index % HORIZONTAL_VALUES.length];
|
return HORIZONTAL_VALUES[index % HORIZONTAL_VALUES.length];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Direction from(int id) {
|
||||||
|
return VALUES[id];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
package com.github.steveice10.mc.protocol.data.game.entity.player;
|
package com.github.steveice10.mc.protocol.data.game.entity.player;
|
||||||
|
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public enum BlockBreakStage {
|
public enum BlockBreakStage {
|
||||||
STAGE_1,
|
STAGE_1,
|
||||||
STAGE_2,
|
STAGE_2,
|
||||||
|
@ -27,12 +23,4 @@ public enum BlockBreakStage {
|
||||||
STAGES = new BlockBreakStage[allValues.length - 1];
|
STAGES = new BlockBreakStage[allValues.length - 1];
|
||||||
System.arraycopy(allValues, 0, STAGES, 0, 10);
|
System.arraycopy(allValues, 0, STAGES, 0, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void write(NetOutput out) throws IOException {
|
|
||||||
if (this == RESET) {
|
|
||||||
out.writeByte(255);
|
|
||||||
} else {
|
|
||||||
out.writeByte(ordinal());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
package com.github.steveice10.mc.protocol.data.game.entity.type;
|
package com.github.steveice10.mc.protocol.data.game.entity.type;
|
||||||
|
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public enum EntityType {
|
public enum EntityType {
|
||||||
ALLAY,
|
ALLAY,
|
||||||
AREA_EFFECT_CLOUD,
|
AREA_EFFECT_CLOUD,
|
||||||
|
@ -126,11 +122,7 @@ public enum EntityType {
|
||||||
|
|
||||||
private static final EntityType[] VALUES = values();
|
private static final EntityType[] VALUES = values();
|
||||||
|
|
||||||
public static EntityType read(NetInput in) throws IOException {
|
public static EntityType from(int id) {
|
||||||
return in.readEnum(VALUES);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static EntityType fromId(int id) {
|
|
||||||
return VALUES[id];
|
return VALUES[id];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
package com.github.steveice10.mc.protocol.data.game.entity.type;
|
package com.github.steveice10.mc.protocol.data.game.entity.type;
|
||||||
|
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public enum PaintingType {
|
public enum PaintingType {
|
||||||
KEBAB,
|
KEBAB,
|
||||||
AZTEC,
|
AZTEC,
|
||||||
|
@ -38,11 +34,7 @@ public enum PaintingType {
|
||||||
|
|
||||||
private static final PaintingType[] VALUES = values();
|
private static final PaintingType[] VALUES = values();
|
||||||
|
|
||||||
public static PaintingType read(NetInput in) throws IOException {
|
public static PaintingType from(int id) {
|
||||||
return in.readEnum(VALUES);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static PaintingType fromId(int id) {
|
|
||||||
return VALUES[id];
|
return VALUES[id];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package com.github.steveice10.mc.protocol.data.game.level;
|
package com.github.steveice10.mc.protocol.data.game.level;
|
||||||
|
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
import io.netty.buffer.ByteBuf;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
|
@ -22,61 +22,56 @@ public class LightUpdateData {
|
||||||
private final @NonNull List<byte[]> blockUpdates;
|
private final @NonNull List<byte[]> blockUpdates;
|
||||||
private final boolean trustEdges;
|
private final boolean trustEdges;
|
||||||
|
|
||||||
public static LightUpdateData read(NetInput in) throws IOException {
|
public static LightUpdateData read(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||||
return new LightUpdateData(in);
|
return new LightUpdateData(in, helper);
|
||||||
}
|
}
|
||||||
|
|
||||||
private LightUpdateData(NetInput in) throws IOException {
|
private LightUpdateData(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||||
this.trustEdges = in.readBoolean();
|
this.trustEdges = in.readBoolean();
|
||||||
|
|
||||||
this.skyYMask = BitSet.valueOf(in.readLongs(in.readVarInt()));
|
this.skyYMask = BitSet.valueOf(helper.readLongArray(in));
|
||||||
this.blockYMask = BitSet.valueOf(in.readLongs(in.readVarInt()));
|
this.blockYMask = BitSet.valueOf(helper.readLongArray(in));
|
||||||
this.emptySkyYMask = BitSet.valueOf(in.readLongs(in.readVarInt()));
|
this.emptySkyYMask = BitSet.valueOf(helper.readLongArray(in));
|
||||||
this.emptyBlockYMask = BitSet.valueOf(in.readLongs(in.readVarInt()));
|
this.emptyBlockYMask = BitSet.valueOf(helper.readLongArray(in));
|
||||||
|
|
||||||
int skyUpdateSize = in.readVarInt();
|
int skyUpdateSize = helper.readVarInt(in);
|
||||||
skyUpdates = new ArrayList<>(skyUpdateSize);
|
skyUpdates = new ArrayList<>(skyUpdateSize);
|
||||||
for (int i = 0; i < skyUpdateSize; i++) {
|
for (int i = 0; i < skyUpdateSize; i++) {
|
||||||
skyUpdates.add(in.readBytes(in.readVarInt()));
|
skyUpdates.add(helper.readByteArray(in));
|
||||||
}
|
}
|
||||||
|
|
||||||
int blockUpdateSize = in.readVarInt();
|
int blockUpdateSize = helper.readVarInt(in);
|
||||||
blockUpdates = new ArrayList<>(blockUpdateSize);
|
blockUpdates = new ArrayList<>(blockUpdateSize);
|
||||||
for (int i = 0; i < blockUpdateSize; i++) {
|
for (int i = 0; i < blockUpdateSize; i++) {
|
||||||
blockUpdates.add(in.readBytes(in.readVarInt()));
|
blockUpdates.add(helper.readByteArray(in));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void write(NetOutput out, LightUpdateData data) throws IOException {
|
public static void write(ByteBuf out, MinecraftCodecHelper helper, LightUpdateData data) throws IOException {
|
||||||
data.write(out);
|
data.write(out, helper);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void write(NetOutput out) throws IOException {
|
private void write(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||||
out.writeBoolean(this.trustEdges);
|
out.writeBoolean(this.trustEdges);
|
||||||
|
|
||||||
writeBitSet(out, this.skyYMask);
|
writeBitSet(out, helper, this.skyYMask);
|
||||||
writeBitSet(out, this.blockYMask);
|
writeBitSet(out, helper, this.blockYMask);
|
||||||
writeBitSet(out, this.emptySkyYMask);
|
writeBitSet(out, helper, this.emptySkyYMask);
|
||||||
writeBitSet(out, this.emptyBlockYMask);
|
writeBitSet(out, helper, this.emptyBlockYMask);
|
||||||
|
|
||||||
out.writeVarInt(this.skyUpdates.size());
|
helper.writeVarInt(out, this.skyUpdates.size());
|
||||||
for (byte[] array : this.skyUpdates) {
|
for (byte[] array : this.skyUpdates) {
|
||||||
out.writeVarInt(array.length);
|
helper.writeByteArray(out, array);
|
||||||
out.writeBytes(array);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
out.writeVarInt(this.blockUpdates.size());
|
helper.writeVarInt(out, this.blockUpdates.size());
|
||||||
for (byte[] array : this.blockUpdates) {
|
for (byte[] array : this.blockUpdates) {
|
||||||
out.writeVarInt(array.length);
|
helper.writeByteArray(out, array);
|
||||||
out.writeBytes(array);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeBitSet(NetOutput out, BitSet bitSet) throws IOException {
|
private void writeBitSet(ByteBuf out, MinecraftCodecHelper helper, BitSet bitSet) throws IOException {
|
||||||
long[] array = bitSet.toLongArray();
|
long[] array = bitSet.toLongArray();
|
||||||
out.writeVarInt(array.length);
|
helper.writeLongArray(out, array);
|
||||||
for (long content : array) {
|
|
||||||
out.writeLong(content);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,7 @@ package com.github.steveice10.mc.protocol.data.game.level.block;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
|
|
|
@ -1,10 +1,5 @@
|
||||||
package com.github.steveice10.mc.protocol.data.game.level.block;
|
package com.github.steveice10.mc.protocol.data.game.level.block;
|
||||||
|
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public enum BlockEntityType {
|
public enum BlockEntityType {
|
||||||
FURNACE,
|
FURNACE,
|
||||||
CHEST,
|
CHEST,
|
||||||
|
@ -45,20 +40,11 @@ public enum BlockEntityType {
|
||||||
|
|
||||||
private static final BlockEntityType[] VALUES = values();
|
private static final BlockEntityType[] VALUES = values();
|
||||||
|
|
||||||
public static BlockEntityType read(NetInput in) throws IOException {
|
public static BlockEntityType from(int id) {
|
||||||
int id = in.readVarInt();
|
|
||||||
if (id >= 0 && id < VALUES.length) {
|
if (id >= 0 && id < VALUES.length) {
|
||||||
return VALUES[id];
|
return VALUES[id];
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void write(NetOutput out, BlockEntityType type) throws IOException {
|
|
||||||
if (type == null) {
|
|
||||||
out.writeVarInt(-1);
|
|
||||||
} else {
|
|
||||||
out.writeVarInt(type.ordinal());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,8 @@
|
||||||
package com.github.steveice10.mc.protocol.data.game.level.event;
|
package com.github.steveice10.mc.protocol.data.game.level.event;
|
||||||
|
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public enum LevelEvent {
|
public enum LevelEvent {
|
||||||
BLOCK_DISPENSER_DISPENSE(1000),
|
BLOCK_DISPENSER_DISPENSE(1000),
|
||||||
|
@ -89,22 +84,4 @@ public enum LevelEvent {
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private final int id;
|
private final int id;
|
||||||
|
|
||||||
private static final LevelEvent[] VALUES = values();
|
|
||||||
private static final Map<Integer, LevelEvent> LEVEL_EVENT_MAP = new HashMap<>();
|
|
||||||
|
|
||||||
public static LevelEvent read(NetInput in) throws IOException {
|
|
||||||
int levelEventId = in.readInt();
|
|
||||||
LevelEvent levelEvent = LEVEL_EVENT_MAP.get(levelEventId);
|
|
||||||
if (levelEvent == null) {
|
|
||||||
throw new IllegalStateException("Unknown level event with id: " + levelEventId);
|
|
||||||
}
|
|
||||||
return levelEvent;
|
|
||||||
}
|
|
||||||
|
|
||||||
static {
|
|
||||||
for (LevelEvent levelEvent : VALUES) {
|
|
||||||
LEVEL_EVENT_MAP.put(levelEvent.id, levelEvent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,26 +1,12 @@
|
||||||
package com.github.steveice10.mc.protocol.data.game.level.particle;
|
package com.github.steveice10.mc.protocol.data.game.level.particle;
|
||||||
|
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class Particle {
|
public class Particle {
|
||||||
private final @NonNull ParticleType type;
|
private final @NonNull ParticleType type;
|
||||||
private final ParticleData data;
|
private final ParticleData data;
|
||||||
|
|
||||||
public static Particle read(NetInput in) throws IOException {
|
|
||||||
ParticleType particleType = ParticleType.read(in);
|
|
||||||
return new Particle(particleType, ParticleData.read(in, particleType));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void write(NetOutput out, Particle particle) throws IOException {
|
|
||||||
out.writeEnum(particle.getType());
|
|
||||||
ParticleData.write(out, particle.getType(), particle.getData());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,85 +1,4 @@
|
||||||
package com.github.steveice10.mc.protocol.data.game.level.particle;
|
package com.github.steveice10.mc.protocol.data.game.level.particle;
|
||||||
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.level.particle.positionsource.PositionSource;
|
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public interface ParticleData {
|
public interface ParticleData {
|
||||||
static ParticleData read(NetInput in, ParticleType type) throws IOException {
|
|
||||||
switch (type) {
|
|
||||||
case BLOCK:
|
|
||||||
case BLOCK_MARKER:
|
|
||||||
return new BlockParticleData(in.readVarInt());
|
|
||||||
case DUST:
|
|
||||||
float red = in.readFloat();
|
|
||||||
float green = in.readFloat();
|
|
||||||
float blue = in.readFloat();
|
|
||||||
float scale = in.readFloat();
|
|
||||||
return new DustParticleData(red, green, blue, scale);
|
|
||||||
case DUST_COLOR_TRANSITION:
|
|
||||||
red = in.readFloat();
|
|
||||||
green = in.readFloat();
|
|
||||||
blue = in.readFloat();
|
|
||||||
scale = in.readFloat();
|
|
||||||
float newRed = in.readFloat();
|
|
||||||
float newGreen = in.readFloat();
|
|
||||||
float newBlue = in.readFloat();
|
|
||||||
return new DustColorTransitionParticleData(red, green, blue, scale, newRed, newGreen, newBlue);
|
|
||||||
case FALLING_DUST:
|
|
||||||
return new FallingDustParticleData(in.readVarInt());
|
|
||||||
case ITEM:
|
|
||||||
return new ItemParticleData(ItemStack.read(in));
|
|
||||||
case SCULK_CHARGE:
|
|
||||||
return new SculkChargeParticleData(in.readFloat());
|
|
||||||
case SHRIEK:
|
|
||||||
return new ShriekParticleData(in.readVarInt());
|
|
||||||
case VIBRATION:
|
|
||||||
return new VibrationParticleData(PositionSource.read(in), in.readVarInt());
|
|
||||||
default:
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void write(NetOutput out, ParticleType type, ParticleData data) throws IOException {
|
|
||||||
switch (type) {
|
|
||||||
case BLOCK:
|
|
||||||
case BLOCK_MARKER:
|
|
||||||
out.writeVarInt(((BlockParticleData) data).getBlockState());
|
|
||||||
break;
|
|
||||||
case DUST:
|
|
||||||
out.writeFloat(((DustParticleData) data).getRed());
|
|
||||||
out.writeFloat(((DustParticleData) data).getGreen());
|
|
||||||
out.writeFloat(((DustParticleData) data).getBlue());
|
|
||||||
out.writeFloat(((DustParticleData) data).getScale());
|
|
||||||
break;
|
|
||||||
case DUST_COLOR_TRANSITION:
|
|
||||||
out.writeFloat(((DustParticleData) data).getRed());
|
|
||||||
out.writeFloat(((DustParticleData) data).getGreen());
|
|
||||||
out.writeFloat(((DustParticleData) data).getBlue());
|
|
||||||
out.writeFloat(((DustParticleData) data).getScale());
|
|
||||||
out.writeFloat(((DustColorTransitionParticleData) data).getNewRed());
|
|
||||||
out.writeFloat(((DustColorTransitionParticleData) data).getNewGreen());
|
|
||||||
out.writeFloat(((DustColorTransitionParticleData) data).getNewBlue());
|
|
||||||
break;
|
|
||||||
case FALLING_DUST:
|
|
||||||
out.writeVarInt(((FallingDustParticleData) data).getBlockState());
|
|
||||||
break;
|
|
||||||
case ITEM:
|
|
||||||
ItemStack.write(out, ((ItemParticleData) data).getItemStack());
|
|
||||||
break;
|
|
||||||
case SCULK_CHARGE:
|
|
||||||
out.writeFloat(((SculkChargeParticleData) data).getRoll());
|
|
||||||
break;
|
|
||||||
case SHRIEK:
|
|
||||||
out.writeVarInt(((ShriekParticleData) data).getDelay());
|
|
||||||
break;
|
|
||||||
case VIBRATION:
|
|
||||||
PositionSource.write(out, ((VibrationParticleData) data).getPositionSource());
|
|
||||||
out.writeVarInt(((VibrationParticleData) data).getArrivalTicks());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
package com.github.steveice10.mc.protocol.data.game.level.particle;
|
package com.github.steveice10.mc.protocol.data.game.level.particle;
|
||||||
|
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public enum ParticleType {
|
public enum ParticleType {
|
||||||
AMBIENT_ENTITY_EFFECT,
|
AMBIENT_ENTITY_EFFECT,
|
||||||
ANGRY_VILLAGER,
|
ANGRY_VILLAGER,
|
||||||
|
@ -101,11 +97,7 @@ public enum ParticleType {
|
||||||
|
|
||||||
private static final ParticleType[] VALUES = values();
|
private static final ParticleType[] VALUES = values();
|
||||||
|
|
||||||
public static ParticleType read(NetInput in) throws IOException {
|
public static ParticleType from(int id) {
|
||||||
return in.readEnum(VALUES);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ParticleType fromId(int id) {
|
|
||||||
return VALUES[id];
|
return VALUES[id];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,35 +1,6 @@
|
||||||
package com.github.steveice10.mc.protocol.data.game.level.particle.positionsource;
|
package com.github.steveice10.mc.protocol.data.game.level.particle.positionsource;
|
||||||
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position;
|
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public interface PositionSource {
|
public interface PositionSource {
|
||||||
|
|
||||||
static PositionSource read(NetInput in) throws IOException {
|
|
||||||
PositionSourceType type = PositionSourceType.read(in);
|
|
||||||
switch (type) {
|
|
||||||
case BLOCK:
|
|
||||||
return new BlockPositionSource(Position.read(in));
|
|
||||||
case ENTITY:
|
|
||||||
return new EntityPositionSource(in.readVarInt(), in.readFloat());
|
|
||||||
default:
|
|
||||||
throw new IllegalStateException("Unknown position source type!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void write(NetOutput out, PositionSource positionSource) throws IOException {
|
|
||||||
positionSource.getType().write(out);
|
|
||||||
if (positionSource instanceof BlockPositionSource) {
|
|
||||||
Position.write(out, ((BlockPositionSource) positionSource).getPosition());
|
|
||||||
} else if (positionSource instanceof EntityPositionSource) {
|
|
||||||
out.writeVarInt(((EntityPositionSource) positionSource).getEntityId());
|
|
||||||
out.writeFloat(((EntityPositionSource) positionSource).getYOffset());
|
|
||||||
}
|
|
||||||
throw new IllegalStateException("Unknown position source type!");
|
|
||||||
}
|
|
||||||
|
|
||||||
PositionSourceType getType();
|
PositionSourceType getType();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,21 +1,6 @@
|
||||||
package com.github.steveice10.mc.protocol.data.game.level.particle.positionsource;
|
package com.github.steveice10.mc.protocol.data.game.level.particle.positionsource;
|
||||||
|
|
||||||
import com.github.steveice10.mc.protocol.data.MagicValues;
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.Identifier;
|
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public enum PositionSourceType {
|
public enum PositionSourceType {
|
||||||
BLOCK,
|
BLOCK,
|
||||||
ENTITY;
|
ENTITY;
|
||||||
|
|
||||||
public static PositionSourceType read(NetInput in) throws IOException {
|
|
||||||
return MagicValues.key(PositionSourceType.class, Identifier.formalize(in.readString()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void write(NetOutput out) throws IOException {
|
|
||||||
out.writeString(MagicValues.value(String.class, this));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1334,18 +1334,12 @@ public enum BuiltinSound implements Sound {
|
||||||
|
|
||||||
private final @NonNull String name;
|
private final @NonNull String name;
|
||||||
|
|
||||||
/**
|
|
||||||
* For grabbing when the CustomSoundPacket is sent.
|
|
||||||
*/
|
|
||||||
public static final Map<String, BuiltinSound> NAME_TO_SOUND = new HashMap<>();
|
|
||||||
/**
|
/**
|
||||||
* For grabbing when the SoundPacket is sent.
|
* For grabbing when the SoundPacket is sent.
|
||||||
*/
|
*/
|
||||||
public static final BuiltinSound[] VALUES = values();
|
private static final BuiltinSound[] VALUES = values();
|
||||||
|
|
||||||
static {
|
public static BuiltinSound from(int id) {
|
||||||
for (BuiltinSound sound : VALUES) {
|
return VALUES[id];
|
||||||
NAME_TO_SOUND.put(sound.name, sound);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
package com.github.steveice10.mc.protocol.data.game.level.sound;
|
package com.github.steveice10.mc.protocol.data.game.level.sound;
|
||||||
|
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public enum SoundCategory {
|
public enum SoundCategory {
|
||||||
MASTER,
|
MASTER,
|
||||||
MUSIC,
|
MUSIC,
|
||||||
|
@ -18,11 +14,8 @@ public enum SoundCategory {
|
||||||
|
|
||||||
private static final SoundCategory[] VALUES = values();
|
private static final SoundCategory[] VALUES = values();
|
||||||
|
|
||||||
public static SoundCategory read(NetInput in) throws IOException {
|
|
||||||
return in.readEnum(VALUES);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SoundCategory fromId(int id) {
|
public static SoundCategory from(int id) {
|
||||||
return VALUES[id];
|
return VALUES[id];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
package com.github.steveice10.mc.protocol.data.game.statistic;
|
package com.github.steveice10.mc.protocol.data.game.statistic;
|
||||||
|
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* "Custom" statistics in Minecraft that don't belong to any
|
* "Custom" statistics in Minecraft that don't belong to any
|
||||||
* specific category.
|
* specific category.
|
||||||
|
@ -99,11 +96,7 @@ public enum CustomStatistic implements Statistic {
|
||||||
this.format = format;
|
this.format = format;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CustomStatistic read(NetInput in) throws IOException {
|
public static CustomStatistic from(int id) {
|
||||||
return in.readEnum(VALUES);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static CustomStatistic fromId(int id) {
|
|
||||||
return VALUES[id];
|
return VALUES[id];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
package com.github.steveice10.mc.protocol.data.game.statistic;
|
package com.github.steveice10.mc.protocol.data.game.statistic;
|
||||||
|
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public enum StatisticCategory {
|
public enum StatisticCategory {
|
||||||
BREAK_BLOCK,
|
BREAK_BLOCK,
|
||||||
CRAFT_ITEM,
|
CRAFT_ITEM,
|
||||||
|
@ -17,11 +13,7 @@ public enum StatisticCategory {
|
||||||
|
|
||||||
private static final StatisticCategory[] VALUES = values();
|
private static final StatisticCategory[] VALUES = values();
|
||||||
|
|
||||||
public static StatisticCategory read(NetInput in) throws IOException {
|
public static StatisticCategory from(int id) {
|
||||||
return in.readEnum(VALUES);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static StatisticCategory fromId(int id) {
|
|
||||||
return VALUES[id];
|
return VALUES[id];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
package com.github.steveice10.mc.protocol.packet.handshake.serverbound;
|
package com.github.steveice10.mc.protocol.packet.handshake.serverbound;
|
||||||
|
|
||||||
|
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
|
||||||
|
import com.github.steveice10.mc.protocol.codec.MinecraftPacket;
|
||||||
import com.github.steveice10.mc.protocol.data.MagicValues;
|
import com.github.steveice10.mc.protocol.data.MagicValues;
|
||||||
import com.github.steveice10.mc.protocol.data.handshake.HandshakeIntent;
|
import com.github.steveice10.mc.protocol.data.handshake.HandshakeIntent;
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
import io.netty.buffer.ByteBuf;
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
|
||||||
import com.github.steveice10.packetlib.packet.Packet;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
|
@ -15,25 +15,25 @@ import java.io.IOException;
|
||||||
@Data
|
@Data
|
||||||
@With
|
@With
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class ClientIntentionPacket implements Packet {
|
public class ClientIntentionPacket implements MinecraftPacket {
|
||||||
private final int protocolVersion;
|
private final int protocolVersion;
|
||||||
private final @NonNull String hostname;
|
private final @NonNull String hostname;
|
||||||
private final int port;
|
private final int port;
|
||||||
private final @NonNull HandshakeIntent intent;
|
private final @NonNull HandshakeIntent intent;
|
||||||
|
|
||||||
public ClientIntentionPacket(NetInput in) throws IOException {
|
public ClientIntentionPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||||
this.protocolVersion = in.readVarInt();
|
this.protocolVersion = helper.readVarInt(in);
|
||||||
this.hostname = in.readString();
|
this.hostname = helper.readString(in);
|
||||||
this.port = in.readUnsignedShort();
|
this.port = in.readUnsignedShort();
|
||||||
this.intent = MagicValues.key(HandshakeIntent.class, in.readVarInt());
|
this.intent = MagicValues.key(HandshakeIntent.class, helper.readVarInt(in));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(NetOutput out) throws IOException {
|
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||||
out.writeVarInt(this.protocolVersion);
|
helper.writeVarInt(out, this.protocolVersion);
|
||||||
out.writeString(this.hostname);
|
helper.writeString(out, this.hostname);
|
||||||
out.writeShort(this.port);
|
out.writeShort(this.port);
|
||||||
out.writeVarInt(MagicValues.value(Integer.class, this.intent));
|
helper.writeVarInt(out, MagicValues.value(Integer.class, this.intent));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,20 +1,10 @@
|
||||||
package com.github.steveice10.mc.protocol.packet.ingame.clientbound;
|
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.entity.type.EntityType;
|
import com.github.steveice10.mc.protocol.data.game.entity.type.EntityType;
|
||||||
import com.github.steveice10.mc.protocol.data.game.statistic.BreakBlockStatistic;
|
import com.github.steveice10.mc.protocol.data.game.statistic.*;
|
||||||
import com.github.steveice10.mc.protocol.data.game.statistic.BreakItemStatistic;
|
import io.netty.buffer.ByteBuf;
|
||||||
import com.github.steveice10.mc.protocol.data.game.statistic.CraftItemStatistic;
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.statistic.CustomStatistic;
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.statistic.DropItemStatistic;
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.statistic.KillEntityStatistic;
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.statistic.KilledByEntityStatistic;
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.statistic.PickupItemStatistic;
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.statistic.Statistic;
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.statistic.StatisticCategory;
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.statistic.UseItemStatistic;
|
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
|
||||||
import com.github.steveice10.packetlib.packet.Packet;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
|
@ -27,14 +17,14 @@ import java.util.Map;
|
||||||
@Data
|
@Data
|
||||||
@With
|
@With
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class ClientboundAwardStatsPacket implements Packet {
|
public class ClientboundAwardStatsPacket implements MinecraftPacket {
|
||||||
private final @NonNull Map<Statistic, Integer> statistics = new HashMap<>(); //TODO Fastutil
|
private final @NonNull Map<Statistic, Integer> statistics = new HashMap<>(); //TODO Fastutil
|
||||||
|
|
||||||
public ClientboundAwardStatsPacket(NetInput in) throws IOException {
|
public ClientboundAwardStatsPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||||
int length = in.readVarInt();
|
int length = helper.readVarInt(in);
|
||||||
for (int index = 0; index < length; index++) {
|
for (int index = 0; index < length; index++) {
|
||||||
StatisticCategory category = StatisticCategory.read(in);
|
StatisticCategory category = helper.readStatisticCategory(in);
|
||||||
int statisticId = in.readVarInt();
|
int statisticId = helper.readVarInt(in);
|
||||||
Statistic statistic;
|
Statistic statistic;
|
||||||
switch (category) {
|
switch (category) {
|
||||||
case BREAK_BLOCK:
|
case BREAK_BLOCK:
|
||||||
|
@ -56,24 +46,24 @@ public class ClientboundAwardStatsPacket implements Packet {
|
||||||
statistic = new DropItemStatistic(statisticId);
|
statistic = new DropItemStatistic(statisticId);
|
||||||
break;
|
break;
|
||||||
case KILL_ENTITY:
|
case KILL_ENTITY:
|
||||||
statistic = new KillEntityStatistic(EntityType.fromId(statisticId));
|
statistic = new KillEntityStatistic(EntityType.from(statisticId));
|
||||||
break;
|
break;
|
||||||
case KILLED_BY_ENTITY:
|
case KILLED_BY_ENTITY:
|
||||||
statistic = new KilledByEntityStatistic(EntityType.fromId(statisticId));
|
statistic = new KilledByEntityStatistic(EntityType.from(statisticId));
|
||||||
break;
|
break;
|
||||||
case CUSTOM:
|
case CUSTOM:
|
||||||
statistic = CustomStatistic.fromId(statisticId);
|
statistic = CustomStatistic.from(statisticId);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
}
|
}
|
||||||
this.statistics.put(statistic, in.readVarInt());
|
this.statistics.put(statistic, helper.readVarInt(in));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(NetOutput out) throws IOException {
|
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||||
out.writeVarInt(this.statistics.size());
|
helper.writeVarInt(out, this.statistics.size());
|
||||||
for (Map.Entry<Statistic, Integer> entry : statistics.entrySet()) {
|
for (Map.Entry<Statistic, Integer> entry : statistics.entrySet()) {
|
||||||
Statistic statistic = entry.getKey();
|
Statistic statistic = entry.getKey();
|
||||||
|
|
||||||
|
@ -109,9 +99,9 @@ public class ClientboundAwardStatsPacket implements Packet {
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
}
|
}
|
||||||
out.writeVarInt(category.ordinal());
|
helper.writeStatisticCategory(out, category);
|
||||||
out.writeVarInt(statisticId);
|
helper.writeVarInt(out, statisticId);
|
||||||
out.writeVarInt(entry.getValue());
|
helper.writeVarInt(out, entry.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
package com.github.steveice10.mc.protocol.packet.ingame.clientbound;
|
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.DefaultComponentSerializer;
|
import com.github.steveice10.mc.protocol.data.DefaultComponentSerializer;
|
||||||
import com.github.steveice10.mc.protocol.data.MagicValues;
|
import com.github.steveice10.mc.protocol.data.MagicValues;
|
||||||
import com.github.steveice10.mc.protocol.data.game.BossBarAction;
|
import com.github.steveice10.mc.protocol.data.game.BossBarAction;
|
||||||
import com.github.steveice10.mc.protocol.data.game.BossBarColor;
|
import com.github.steveice10.mc.protocol.data.game.BossBarColor;
|
||||||
import com.github.steveice10.mc.protocol.data.game.BossBarDivision;
|
import com.github.steveice10.mc.protocol.data.game.BossBarDivision;
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
import io.netty.buffer.ByteBuf;
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
|
||||||
import com.github.steveice10.packetlib.packet.Packet;
|
|
||||||
import lombok.*;
|
import lombok.*;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ import java.util.UUID;
|
||||||
@Data
|
@Data
|
||||||
@With
|
@With
|
||||||
@AllArgsConstructor(access = AccessLevel.PRIVATE)
|
@AllArgsConstructor(access = AccessLevel.PRIVATE)
|
||||||
public class ClientboundBossEventPacket implements Packet {
|
public class ClientboundBossEventPacket implements MinecraftPacket {
|
||||||
private final @NonNull UUID uuid;
|
private final @NonNull UUID uuid;
|
||||||
private final @NonNull BossBarAction action;
|
private final @NonNull BossBarAction action;
|
||||||
|
|
||||||
|
@ -66,12 +66,12 @@ public class ClientboundBossEventPacket implements Packet {
|
||||||
this.showFog = showFog;
|
this.showFog = showFog;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ClientboundBossEventPacket(NetInput in) throws IOException {
|
public ClientboundBossEventPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||||
this.uuid = in.readUUID();
|
this.uuid = helper.readUUID(in);
|
||||||
this.action = MagicValues.key(BossBarAction.class, in.readVarInt());
|
this.action = MagicValues.key(BossBarAction.class, helper.readVarInt(in));
|
||||||
|
|
||||||
if (this.action == BossBarAction.ADD || this.action == BossBarAction.UPDATE_TITLE) {
|
if (this.action == BossBarAction.ADD || this.action == BossBarAction.UPDATE_TITLE) {
|
||||||
this.title = DefaultComponentSerializer.get().deserialize(in.readString());
|
this.title = helper.readComponent(in);
|
||||||
} else {
|
} else {
|
||||||
this.title = null;
|
this.title = null;
|
||||||
}
|
}
|
||||||
|
@ -83,8 +83,8 @@ public class ClientboundBossEventPacket implements Packet {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.action == BossBarAction.ADD || this.action == BossBarAction.UPDATE_STYLE) {
|
if (this.action == BossBarAction.ADD || this.action == BossBarAction.UPDATE_STYLE) {
|
||||||
this.color = MagicValues.key(BossBarColor.class, in.readVarInt());
|
this.color = MagicValues.key(BossBarColor.class, helper.readVarInt(in));
|
||||||
this.division = MagicValues.key(BossBarDivision.class, in.readVarInt());
|
this.division = MagicValues.key(BossBarDivision.class, helper.readVarInt(in));
|
||||||
} else {
|
} else {
|
||||||
this.color = null;
|
this.color = null;
|
||||||
this.division = null;
|
this.division = null;
|
||||||
|
@ -103,12 +103,12 @@ public class ClientboundBossEventPacket implements Packet {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(NetOutput out) throws IOException {
|
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||||
out.writeUUID(this.uuid);
|
helper.writeUUID(out, this.uuid);
|
||||||
out.writeVarInt(MagicValues.value(Integer.class, this.action));
|
helper.writeVarInt(out, MagicValues.value(Integer.class, this.action));
|
||||||
|
|
||||||
if (this.action == BossBarAction.ADD || this.action == BossBarAction.UPDATE_TITLE) {
|
if (this.action == BossBarAction.ADD || this.action == BossBarAction.UPDATE_TITLE) {
|
||||||
out.writeString(DefaultComponentSerializer.get().serialize(this.title));
|
helper.writeString(out, DefaultComponentSerializer.get().serialize(this.title));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.action == BossBarAction.ADD || this.action == BossBarAction.UPDATE_HEALTH) {
|
if (this.action == BossBarAction.ADD || this.action == BossBarAction.UPDATE_HEALTH) {
|
||||||
|
@ -116,8 +116,8 @@ public class ClientboundBossEventPacket implements Packet {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.action == BossBarAction.ADD || this.action == BossBarAction.UPDATE_STYLE) {
|
if (this.action == BossBarAction.ADD || this.action == BossBarAction.UPDATE_STYLE) {
|
||||||
out.writeVarInt(MagicValues.value(Integer.class, this.color));
|
helper.writeVarInt(out, MagicValues.value(Integer.class, this.color));
|
||||||
out.writeVarInt(MagicValues.value(Integer.class, this.division));
|
helper.writeVarInt(out, MagicValues.value(Integer.class, this.division));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.action == BossBarAction.ADD || this.action == BossBarAction.UPDATE_FLAGS) {
|
if (this.action == BossBarAction.ADD || this.action == BossBarAction.UPDATE_FLAGS) {
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
package com.github.steveice10.mc.protocol.packet.ingame.clientbound;
|
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.MagicValues;
|
import com.github.steveice10.mc.protocol.data.MagicValues;
|
||||||
import com.github.steveice10.mc.protocol.data.game.setting.Difficulty;
|
import com.github.steveice10.mc.protocol.data.game.setting.Difficulty;
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
import io.netty.buffer.ByteBuf;
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
|
||||||
import com.github.steveice10.packetlib.packet.Packet;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
|
@ -15,17 +15,17 @@ import java.io.IOException;
|
||||||
@Data
|
@Data
|
||||||
@With
|
@With
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class ClientboundChangeDifficultyPacket implements Packet {
|
public class ClientboundChangeDifficultyPacket implements MinecraftPacket {
|
||||||
private final @NonNull Difficulty difficulty;
|
private final @NonNull Difficulty difficulty;
|
||||||
private final boolean difficultyLocked;
|
private final boolean difficultyLocked;
|
||||||
|
|
||||||
public ClientboundChangeDifficultyPacket(NetInput in) throws IOException {
|
public ClientboundChangeDifficultyPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||||
this.difficulty = MagicValues.key(Difficulty.class, in.readUnsignedByte());
|
this.difficulty = MagicValues.key(Difficulty.class, in.readUnsignedByte());
|
||||||
this.difficultyLocked = in.readBoolean();
|
this.difficultyLocked = in.readBoolean();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(NetOutput out) throws IOException {
|
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||||
out.writeByte(MagicValues.value(Integer.class, this.difficulty));
|
out.writeByte(MagicValues.value(Integer.class, this.difficulty));
|
||||||
out.writeBoolean(this.difficultyLocked);
|
out.writeBoolean(this.difficultyLocked);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,38 +1,38 @@
|
||||||
package com.github.steveice10.mc.protocol.packet.ingame.clientbound;
|
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.DefaultComponentSerializer;
|
import com.github.steveice10.mc.protocol.data.DefaultComponentSerializer;
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
import io.netty.buffer.ByteBuf;
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
|
||||||
import com.github.steveice10.packetlib.packet.Packet;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.With;
|
import lombok.With;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@With
|
@With
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class ClientboundChatPreviewPacket implements Packet {
|
public class ClientboundChatPreviewPacket implements MinecraftPacket {
|
||||||
private final int queryId;
|
private final int queryId;
|
||||||
private final @Nullable Component preview;
|
private final @Nullable Component preview;
|
||||||
|
|
||||||
public ClientboundChatPreviewPacket(NetInput in) throws IOException {
|
public ClientboundChatPreviewPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||||
this.queryId = in.readInt();
|
this.queryId = in.readInt();
|
||||||
if (in.readBoolean()) {
|
if (in.readBoolean()) {
|
||||||
this.preview = DefaultComponentSerializer.get().deserialize(in.readString());
|
this.preview = helper.readComponent(in);
|
||||||
} else {
|
} else {
|
||||||
this.preview = null;
|
this.preview = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(NetOutput out) throws IOException {
|
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||||
out.writeInt(this.queryId);
|
out.writeInt(this.queryId);
|
||||||
if (this.preview != null) {
|
if (this.preview != null) {
|
||||||
out.writeString(DefaultComponentSerializer.get().serialize(this.preview));
|
helper.writeString(out, DefaultComponentSerializer.get().serialize(this.preview));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package com.github.steveice10.mc.protocol.packet.ingame.clientbound;
|
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.DefaultComponentSerializer;
|
import com.github.steveice10.mc.protocol.data.DefaultComponentSerializer;
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
import io.netty.buffer.ByteBuf;
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
|
||||||
import com.github.steveice10.packetlib.packet.Packet;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import lombok.With;
|
import lombok.With;
|
||||||
|
@ -14,7 +14,7 @@ import java.util.Arrays;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@With
|
@With
|
||||||
public class ClientboundCommandSuggestionsPacket implements Packet {
|
public class ClientboundCommandSuggestionsPacket implements MinecraftPacket {
|
||||||
private final int transactionId;
|
private final int transactionId;
|
||||||
private final int start;
|
private final int start;
|
||||||
private final int length;
|
private final int length;
|
||||||
|
@ -33,32 +33,32 @@ public class ClientboundCommandSuggestionsPacket implements Packet {
|
||||||
this.tooltips = Arrays.copyOf(tooltips, tooltips.length);
|
this.tooltips = Arrays.copyOf(tooltips, tooltips.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ClientboundCommandSuggestionsPacket(NetInput in) throws IOException {
|
public ClientboundCommandSuggestionsPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||||
this.transactionId = in.readVarInt();
|
this.transactionId = helper.readVarInt(in);
|
||||||
this.start = in.readVarInt();
|
this.start = helper.readVarInt(in);
|
||||||
this.length = in.readVarInt();
|
this.length = helper.readVarInt(in);
|
||||||
this.matches = new String[in.readVarInt()];
|
this.matches = new String[helper.readVarInt(in)];
|
||||||
this.tooltips = new Component[this.matches.length];
|
this.tooltips = new Component[this.matches.length];
|
||||||
for (int index = 0; index < this.matches.length; index++) {
|
for (int index = 0; index < this.matches.length; index++) {
|
||||||
this.matches[index] = in.readString();
|
this.matches[index] = helper.readString(in);
|
||||||
if (in.readBoolean()) {
|
if (in.readBoolean()) {
|
||||||
this.tooltips[index] = DefaultComponentSerializer.get().deserialize(in.readString());
|
this.tooltips[index] = helper.readComponent(in);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(NetOutput out) throws IOException {
|
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||||
out.writeVarInt(this.transactionId);
|
helper.writeVarInt(out, this.transactionId);
|
||||||
out.writeVarInt(this.start);
|
helper.writeVarInt(out, this.start);
|
||||||
out.writeVarInt(this.length);
|
helper.writeVarInt(out, this.length);
|
||||||
out.writeVarInt(this.matches.length);
|
helper.writeVarInt(out, this.matches.length);
|
||||||
for (int index = 0; index < this.matches.length; index++) {
|
for (int index = 0; index < this.matches.length; index++) {
|
||||||
out.writeString(this.matches[index]);
|
helper.writeString(out, this.matches[index]);
|
||||||
Component tooltip = this.tooltips[index];
|
Component tooltip = this.tooltips[index];
|
||||||
if (tooltip != null) {
|
if (tooltip != null) {
|
||||||
out.writeBoolean(true);
|
out.writeBoolean(true);
|
||||||
out.writeString(DefaultComponentSerializer.get().serialize(tooltip));
|
helper.writeString(out, DefaultComponentSerializer.get().serialize(tooltip));
|
||||||
} else {
|
} else {
|
||||||
out.writeBoolean(false);
|
out.writeBoolean(false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,24 +1,15 @@
|
||||||
package com.github.steveice10.mc.protocol.packet.ingame.clientbound;
|
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.MagicValues;
|
import com.github.steveice10.mc.protocol.data.MagicValues;
|
||||||
import com.github.steveice10.mc.protocol.data.game.Identifier;
|
import com.github.steveice10.mc.protocol.data.game.Identifier;
|
||||||
import com.github.steveice10.mc.protocol.data.game.command.CommandNode;
|
import com.github.steveice10.mc.protocol.data.game.command.CommandNode;
|
||||||
import com.github.steveice10.mc.protocol.data.game.command.CommandParser;
|
import com.github.steveice10.mc.protocol.data.game.command.CommandParser;
|
||||||
import com.github.steveice10.mc.protocol.data.game.command.CommandType;
|
import com.github.steveice10.mc.protocol.data.game.command.CommandType;
|
||||||
import com.github.steveice10.mc.protocol.data.game.command.SuggestionType;
|
import com.github.steveice10.mc.protocol.data.game.command.SuggestionType;
|
||||||
import com.github.steveice10.mc.protocol.data.game.command.properties.CommandProperties;
|
import com.github.steveice10.mc.protocol.data.game.command.properties.*;
|
||||||
import com.github.steveice10.mc.protocol.data.game.command.properties.DoubleProperties;
|
import io.netty.buffer.ByteBuf;
|
||||||
import com.github.steveice10.mc.protocol.data.game.command.properties.EntityProperties;
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.command.properties.FloatProperties;
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.command.properties.IntegerProperties;
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.command.properties.LongProperties;
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.command.properties.RangeProperties;
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.command.properties.ScoreHolderProperties;
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.command.properties.StringProperties;
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.command.properties.ResourceProperties;
|
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
|
||||||
import com.github.steveice10.packetlib.packet.Packet;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
|
@ -29,7 +20,7 @@ import java.io.IOException;
|
||||||
@Data
|
@Data
|
||||||
@With
|
@With
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class ClientboundCommandsPacket implements Packet {
|
public class ClientboundCommandsPacket implements MinecraftPacket {
|
||||||
private static final int FLAG_TYPE_MASK = 0x03;
|
private static final int FLAG_TYPE_MASK = 0x03;
|
||||||
private static final int FLAG_EXECUTABLE = 0x04;
|
private static final int FLAG_EXECUTABLE = 0x04;
|
||||||
private static final int FLAG_REDIRECT = 0x08;
|
private static final int FLAG_REDIRECT = 0x08;
|
||||||
|
@ -44,32 +35,32 @@ public class ClientboundCommandsPacket implements Packet {
|
||||||
private final @NonNull CommandNode[] nodes;
|
private final @NonNull CommandNode[] nodes;
|
||||||
private final int firstNodeIndex;
|
private final int firstNodeIndex;
|
||||||
|
|
||||||
public ClientboundCommandsPacket(NetInput in) throws IOException {
|
public ClientboundCommandsPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||||
this.nodes = new CommandNode[in.readVarInt()];
|
this.nodes = new CommandNode[helper.readVarInt(in)];
|
||||||
for (int i = 0; i < this.nodes.length; i++) {
|
for (int i = 0; i < this.nodes.length; i++) {
|
||||||
byte flags = in.readByte();
|
byte flags = in.readByte();
|
||||||
CommandType type = MagicValues.key(CommandType.class, flags & FLAG_TYPE_MASK);
|
CommandType type = MagicValues.key(CommandType.class, flags & FLAG_TYPE_MASK);
|
||||||
boolean executable = (flags & FLAG_EXECUTABLE) != 0;
|
boolean executable = (flags & FLAG_EXECUTABLE) != 0;
|
||||||
|
|
||||||
int[] children = new int[in.readVarInt()];
|
int[] children = new int[helper.readVarInt(in)];
|
||||||
for (int j = 0; j < children.length; j++) {
|
for (int j = 0; j < children.length; j++) {
|
||||||
children[j] = in.readVarInt();
|
children[j] = helper.readVarInt(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
int redirectIndex = -1;
|
int redirectIndex = -1;
|
||||||
if ((flags & FLAG_REDIRECT) != 0) {
|
if ((flags & FLAG_REDIRECT) != 0) {
|
||||||
redirectIndex = in.readVarInt();
|
redirectIndex = helper.readVarInt(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
String name = null;
|
String name = null;
|
||||||
if (type == CommandType.LITERAL || type == CommandType.ARGUMENT) {
|
if (type == CommandType.LITERAL || type == CommandType.ARGUMENT) {
|
||||||
name = in.readString();
|
name = helper.readString(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
CommandParser parser = null;
|
CommandParser parser = null;
|
||||||
CommandProperties properties = null;
|
CommandProperties properties = null;
|
||||||
if (type == CommandType.ARGUMENT) {
|
if (type == CommandType.ARGUMENT) {
|
||||||
parser = MagicValues.key(CommandParser.class, in.readVarInt());
|
parser = MagicValues.key(CommandParser.class, helper.readVarInt(in));
|
||||||
switch (parser) {
|
switch (parser) {
|
||||||
case DOUBLE: {
|
case DOUBLE: {
|
||||||
byte numberFlags = in.readByte();
|
byte numberFlags = in.readByte();
|
||||||
|
@ -132,7 +123,7 @@ public class ClientboundCommandsPacket implements Packet {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case STRING:
|
case STRING:
|
||||||
properties = MagicValues.key(StringProperties.class, in.readVarInt());
|
properties = MagicValues.key(StringProperties.class, helper.readVarInt(in));
|
||||||
break;
|
break;
|
||||||
case ENTITY: {
|
case ENTITY: {
|
||||||
byte entityFlags = in.readByte();
|
byte entityFlags = in.readByte();
|
||||||
|
@ -145,7 +136,7 @@ public class ClientboundCommandsPacket implements Packet {
|
||||||
break;
|
break;
|
||||||
case RESOURCE:
|
case RESOURCE:
|
||||||
case RESOURCE_OR_TAG:
|
case RESOURCE_OR_TAG:
|
||||||
properties = new ResourceProperties(in.readString());
|
properties = new ResourceProperties(helper.readString(in));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -154,18 +145,18 @@ public class ClientboundCommandsPacket implements Packet {
|
||||||
|
|
||||||
SuggestionType suggestionType = null;
|
SuggestionType suggestionType = null;
|
||||||
if ((flags & FLAG_SUGGESTION_TYPE) != 0) {
|
if ((flags & FLAG_SUGGESTION_TYPE) != 0) {
|
||||||
suggestionType = MagicValues.key(SuggestionType.class, Identifier.formalize(in.readString()));
|
suggestionType = MagicValues.key(SuggestionType.class, Identifier.formalize(helper.readString(in)));
|
||||||
}
|
}
|
||||||
|
|
||||||
this.nodes[i] = new CommandNode(type, executable, children, redirectIndex, name, parser, properties, suggestionType);
|
this.nodes[i] = new CommandNode(type, executable, children, redirectIndex, name, parser, properties, suggestionType);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.firstNodeIndex = in.readVarInt();
|
this.firstNodeIndex = helper.readVarInt(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(NetOutput out) throws IOException {
|
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||||
out.writeVarInt(this.nodes.length);
|
helper.writeVarInt(out, this.nodes.length);
|
||||||
for (CommandNode node : this.nodes) {
|
for (CommandNode node : this.nodes) {
|
||||||
int flags = MagicValues.value(Integer.class, node.getType()) & FLAG_TYPE_MASK;
|
int flags = MagicValues.value(Integer.class, node.getType()) & FLAG_TYPE_MASK;
|
||||||
if (node.isExecutable()) {
|
if (node.isExecutable()) {
|
||||||
|
@ -182,21 +173,21 @@ public class ClientboundCommandsPacket implements Packet {
|
||||||
|
|
||||||
out.writeByte(flags);
|
out.writeByte(flags);
|
||||||
|
|
||||||
out.writeVarInt(node.getChildIndices().length);
|
helper.writeVarInt(out, node.getChildIndices().length);
|
||||||
for (int childIndex : node.getChildIndices()) {
|
for (int childIndex : node.getChildIndices()) {
|
||||||
out.writeVarInt(childIndex);
|
helper.writeVarInt(out, childIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node.getRedirectIndex() != -1) {
|
if (node.getRedirectIndex() != -1) {
|
||||||
out.writeVarInt(node.getRedirectIndex());
|
helper.writeVarInt(out, node.getRedirectIndex());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node.getType() == CommandType.LITERAL || node.getType() == CommandType.ARGUMENT) {
|
if (node.getType() == CommandType.LITERAL || node.getType() == CommandType.ARGUMENT) {
|
||||||
out.writeString(node.getName());
|
helper.writeString(out, node.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node.getType() == CommandType.ARGUMENT) {
|
if (node.getType() == CommandType.ARGUMENT) {
|
||||||
out.writeVarInt(MagicValues.value(Integer.class, node.getParser()));
|
helper.writeVarInt(out, MagicValues.value(Integer.class, node.getParser()));
|
||||||
switch (node.getParser()) {
|
switch (node.getParser()) {
|
||||||
case DOUBLE: {
|
case DOUBLE: {
|
||||||
DoubleProperties properties = (DoubleProperties) node.getProperties();
|
DoubleProperties properties = (DoubleProperties) node.getProperties();
|
||||||
|
@ -291,7 +282,7 @@ public class ClientboundCommandsPacket implements Packet {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case STRING:
|
case STRING:
|
||||||
out.writeVarInt(MagicValues.value(Integer.class, node.getProperties()));
|
helper.writeVarInt(out, MagicValues.value(Integer.class, node.getProperties()));
|
||||||
break;
|
break;
|
||||||
case ENTITY: {
|
case ENTITY: {
|
||||||
EntityProperties properties = (EntityProperties) node.getProperties();
|
EntityProperties properties = (EntityProperties) node.getProperties();
|
||||||
|
@ -312,7 +303,7 @@ public class ClientboundCommandsPacket implements Packet {
|
||||||
break;
|
break;
|
||||||
case RESOURCE:
|
case RESOURCE:
|
||||||
case RESOURCE_OR_TAG:
|
case RESOURCE_OR_TAG:
|
||||||
out.writeString(((ResourceProperties) node.getProperties()).getRegistryKey());
|
helper.writeString(out, ((ResourceProperties) node.getProperties()).getRegistryKey());
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -320,10 +311,10 @@ public class ClientboundCommandsPacket implements Packet {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node.getSuggestionType() != null) {
|
if (node.getSuggestionType() != null) {
|
||||||
out.writeString(MagicValues.value(String.class, node.getSuggestionType()));
|
helper.writeString(out, MagicValues.value(String.class, node.getSuggestionType()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
out.writeVarInt(this.firstNodeIndex);
|
helper.writeVarInt(out, this.firstNodeIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package com.github.steveice10.mc.protocol.packet.ingame.clientbound;
|
package com.github.steveice10.mc.protocol.packet.ingame.clientbound;
|
||||||
|
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
import com.github.steveice10.mc.protocol.codec.MinecraftPacket;
|
||||||
import com.github.steveice10.packetlib.packet.Packet;
|
import io.netty.buffer.ByteBuf;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.With;
|
import lombok.With;
|
||||||
|
@ -12,18 +12,18 @@ import java.io.IOException;
|
||||||
@Data
|
@Data
|
||||||
@With
|
@With
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class ClientboundCooldownPacket implements Packet {
|
public class ClientboundCooldownPacket implements MinecraftPacket {
|
||||||
private final int itemId;
|
private final int itemId;
|
||||||
private final int cooldownTicks;
|
private final int cooldownTicks;
|
||||||
|
|
||||||
public ClientboundCooldownPacket(NetInput in) throws IOException {
|
public ClientboundCooldownPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||||
this.itemId = in.readVarInt();
|
this.itemId = helper.readVarInt(in);
|
||||||
this.cooldownTicks = in.readVarInt();
|
this.cooldownTicks = helper.readVarInt(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(NetOutput out) throws IOException {
|
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||||
out.writeVarInt(this.itemId);
|
helper.writeVarInt(out, this.itemId);
|
||||||
out.writeVarInt(this.cooldownTicks);
|
helper.writeVarInt(out, this.cooldownTicks);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package com.github.steveice10.mc.protocol.packet.ingame.clientbound;
|
package com.github.steveice10.mc.protocol.packet.ingame.clientbound;
|
||||||
|
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
import com.github.steveice10.mc.protocol.codec.MinecraftPacket;
|
||||||
import com.github.steveice10.packetlib.packet.Packet;
|
import io.netty.buffer.ByteBuf;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
|
@ -13,18 +13,18 @@ import java.io.IOException;
|
||||||
@Data
|
@Data
|
||||||
@With
|
@With
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class ClientboundCustomPayloadPacket implements Packet {
|
public class ClientboundCustomPayloadPacket implements MinecraftPacket {
|
||||||
private final @NonNull String channel;
|
private final @NonNull String channel;
|
||||||
private final @NonNull byte[] data;
|
private final @NonNull byte[] data;
|
||||||
|
|
||||||
public ClientboundCustomPayloadPacket(NetInput in) throws IOException {
|
public ClientboundCustomPayloadPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||||
this.channel = in.readString();
|
this.channel = helper.readString(in);
|
||||||
this.data = in.readBytes(in.available());
|
this.data = helper.readByteArray(in, ByteBuf::readableBytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(NetOutput out) throws IOException {
|
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||||
out.writeString(this.channel);
|
helper.writeString(out, this.channel);
|
||||||
out.writeBytes(this.data);
|
out.writeBytes(this.data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package com.github.steveice10.mc.protocol.packet.ingame.clientbound;
|
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.DefaultComponentSerializer;
|
import com.github.steveice10.mc.protocol.data.DefaultComponentSerializer;
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
import io.netty.buffer.ByteBuf;
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
|
||||||
import com.github.steveice10.packetlib.packet.Packet;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
|
@ -15,20 +15,20 @@ import java.io.IOException;
|
||||||
@Data
|
@Data
|
||||||
@With
|
@With
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class ClientboundDisconnectPacket implements Packet {
|
public class ClientboundDisconnectPacket implements MinecraftPacket {
|
||||||
private final @NonNull Component reason;
|
private final @NonNull Component reason;
|
||||||
|
|
||||||
public ClientboundDisconnectPacket(@NonNull String reason) {
|
public ClientboundDisconnectPacket(@NonNull String reason) {
|
||||||
this(DefaultComponentSerializer.get().deserialize(reason));
|
this(DefaultComponentSerializer.get().deserialize(reason));
|
||||||
}
|
}
|
||||||
|
|
||||||
public ClientboundDisconnectPacket(NetInput in) throws IOException {
|
public ClientboundDisconnectPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||||
this.reason = DefaultComponentSerializer.get().deserialize(in.readString());
|
this.reason = helper.readComponent(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(NetOutput out) throws IOException {
|
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||||
out.writeString(DefaultComponentSerializer.get().serialize(this.reason));
|
helper.writeComponent(out, this.reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package com.github.steveice10.mc.protocol.packet.ingame.clientbound;
|
package com.github.steveice10.mc.protocol.packet.ingame.clientbound;
|
||||||
|
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
import com.github.steveice10.mc.protocol.codec.MinecraftPacket;
|
||||||
import com.github.steveice10.packetlib.packet.Packet;
|
import io.netty.buffer.ByteBuf;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.With;
|
import lombok.With;
|
||||||
|
@ -12,15 +12,15 @@ import java.io.IOException;
|
||||||
@Data
|
@Data
|
||||||
@With
|
@With
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class ClientboundKeepAlivePacket implements Packet {
|
public class ClientboundKeepAlivePacket implements MinecraftPacket {
|
||||||
private final long pingId;
|
private final long pingId;
|
||||||
|
|
||||||
public ClientboundKeepAlivePacket(NetInput in) throws IOException {
|
public ClientboundKeepAlivePacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||||
this.pingId = in.readLong();
|
this.pingId = in.readLong();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(NetOutput out) throws IOException {
|
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||||
out.writeLong(this.pingId);
|
out.writeLong(this.pingId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,25 +1,24 @@
|
||||||
package com.github.steveice10.mc.protocol.packet.ingame.clientbound;
|
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.MagicValues;
|
import com.github.steveice10.mc.protocol.data.MagicValues;
|
||||||
import com.github.steveice10.mc.protocol.data.game.NBT;
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.GlobalPos;
|
import com.github.steveice10.mc.protocol.data.game.entity.metadata.GlobalPos;
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode;
|
import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
import io.netty.buffer.ByteBuf;
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
|
||||||
import com.github.steveice10.packetlib.packet.Packet;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import lombok.With;
|
import lombok.With;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@With
|
@With
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class ClientboundLoginPacket implements Packet {
|
public class ClientboundLoginPacket implements MinecraftPacket {
|
||||||
private static final int GAMEMODE_MASK = 0x07;
|
private static final int GAMEMODE_MASK = 0x07;
|
||||||
|
|
||||||
private final int entityId;
|
private final int entityId;
|
||||||
|
@ -41,38 +40,38 @@ public class ClientboundLoginPacket implements Packet {
|
||||||
private final boolean flat;
|
private final boolean flat;
|
||||||
private final @Nullable GlobalPos lastDeathPos;
|
private final @Nullable GlobalPos lastDeathPos;
|
||||||
|
|
||||||
public ClientboundLoginPacket(NetInput in) throws IOException {
|
public ClientboundLoginPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||||
this.entityId = in.readInt();
|
this.entityId = in.readInt();
|
||||||
|
|
||||||
this.hardcore = in.readBoolean();
|
this.hardcore = in.readBoolean();
|
||||||
int gameMode = in.readUnsignedByte();
|
int gameMode = in.readUnsignedByte();
|
||||||
this.gameMode = MagicValues.key(GameMode.class, gameMode & GAMEMODE_MASK);
|
this.gameMode = MagicValues.key(GameMode.class, gameMode & GAMEMODE_MASK);
|
||||||
this.previousGamemode = MagicValues.key(GameMode.class, in.readUnsignedByte());
|
this.previousGamemode = MagicValues.key(GameMode.class, in.readUnsignedByte());
|
||||||
this.worldCount = in.readVarInt();
|
this.worldCount = helper.readVarInt(in);
|
||||||
this.worldNames = new String[this.worldCount];
|
this.worldNames = new String[this.worldCount];
|
||||||
for (int i = 0; i < this.worldCount; i++) {
|
for (int i = 0; i < this.worldCount; i++) {
|
||||||
this.worldNames[i] = in.readString();
|
this.worldNames[i] = helper.readString(in);
|
||||||
}
|
}
|
||||||
this.dimensionCodec = NBT.read(in);
|
this.dimensionCodec = helper.readTag(in);
|
||||||
this.dimension = in.readString();
|
this.dimension = helper.readString(in);
|
||||||
this.worldName = in.readString();
|
this.worldName = helper.readString(in);
|
||||||
this.hashedSeed = in.readLong();
|
this.hashedSeed = in.readLong();
|
||||||
this.maxPlayers = in.readVarInt();
|
this.maxPlayers = helper.readVarInt(in);
|
||||||
this.viewDistance = in.readVarInt();
|
this.viewDistance = helper.readVarInt(in);
|
||||||
this.simulationDistance = in.readVarInt();
|
this.simulationDistance = helper.readVarInt(in);
|
||||||
this.reducedDebugInfo = in.readBoolean();
|
this.reducedDebugInfo = in.readBoolean();
|
||||||
this.enableRespawnScreen = in.readBoolean();
|
this.enableRespawnScreen = in.readBoolean();
|
||||||
this.debug = in.readBoolean();
|
this.debug = in.readBoolean();
|
||||||
this.flat = in.readBoolean();
|
this.flat = in.readBoolean();
|
||||||
if (in.readBoolean()) {
|
if (in.readBoolean()) {
|
||||||
this.lastDeathPos = GlobalPos.read(in);
|
this.lastDeathPos = helper.readGlobalPos(in);
|
||||||
} else {
|
} else {
|
||||||
this.lastDeathPos = null;
|
this.lastDeathPos = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(NetOutput out) throws IOException {
|
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||||
out.writeInt(this.entityId);
|
out.writeInt(this.entityId);
|
||||||
|
|
||||||
out.writeBoolean(this.hardcore);
|
out.writeBoolean(this.hardcore);
|
||||||
|
@ -80,24 +79,24 @@ public class ClientboundLoginPacket implements Packet {
|
||||||
|
|
||||||
out.writeByte(gameMode);
|
out.writeByte(gameMode);
|
||||||
out.writeByte(MagicValues.value(Integer.class, this.previousGamemode));
|
out.writeByte(MagicValues.value(Integer.class, this.previousGamemode));
|
||||||
out.writeVarInt(this.worldCount);
|
helper.writeVarInt(out, this.worldCount);
|
||||||
for (String worldName : this.worldNames) {
|
for (String worldName : this.worldNames) {
|
||||||
out.writeString(worldName);
|
helper.writeString(out, worldName);
|
||||||
}
|
}
|
||||||
NBT.write(out, this.dimensionCodec);
|
helper.writeTag(out, this.dimensionCodec);
|
||||||
out.writeString(this.dimension);
|
helper.writeString(out, this.dimension);
|
||||||
out.writeString(this.worldName);
|
helper.writeString(out, this.worldName);
|
||||||
out.writeLong(this.hashedSeed);
|
out.writeLong(this.hashedSeed);
|
||||||
out.writeVarInt(this.maxPlayers);
|
helper.writeVarInt(out, this.maxPlayers);
|
||||||
out.writeVarInt(this.viewDistance);
|
helper.writeVarInt(out, this.viewDistance);
|
||||||
out.writeVarInt(this.simulationDistance);
|
helper.writeVarInt(out, this.simulationDistance);
|
||||||
out.writeBoolean(this.reducedDebugInfo);
|
out.writeBoolean(this.reducedDebugInfo);
|
||||||
out.writeBoolean(this.enableRespawnScreen);
|
out.writeBoolean(this.enableRespawnScreen);
|
||||||
out.writeBoolean(this.debug);
|
out.writeBoolean(this.debug);
|
||||||
out.writeBoolean(this.flat);
|
out.writeBoolean(this.flat);
|
||||||
out.writeBoolean(this.lastDeathPos != null);
|
out.writeBoolean(this.lastDeathPos != null);
|
||||||
if (this.lastDeathPos != null) {
|
if (this.lastDeathPos != null) {
|
||||||
GlobalPos.write(out, this.lastDeathPos);
|
helper.writeGlobalPos(out, this.lastDeathPos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package com.github.steveice10.mc.protocol.packet.ingame.clientbound;
|
package com.github.steveice10.mc.protocol.packet.ingame.clientbound;
|
||||||
|
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
import com.github.steveice10.mc.protocol.codec.MinecraftPacket;
|
||||||
import com.github.steveice10.packetlib.packet.Packet;
|
import io.netty.buffer.ByteBuf;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.With;
|
import lombok.With;
|
||||||
|
@ -12,15 +12,15 @@ import java.io.IOException;
|
||||||
@Data
|
@Data
|
||||||
@With
|
@With
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class ClientboundPingPacket implements Packet {
|
public class ClientboundPingPacket implements MinecraftPacket {
|
||||||
private final int id;
|
private final int id;
|
||||||
|
|
||||||
public ClientboundPingPacket(NetInput in) throws IOException {
|
public ClientboundPingPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||||
this.id = in.readInt();
|
this.id = in.readInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(NetOutput out) throws IOException {
|
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||||
out.writeInt(this.id);
|
out.writeInt(this.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,24 +1,24 @@
|
||||||
package com.github.steveice10.mc.protocol.packet.ingame.clientbound;
|
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.DefaultComponentSerializer;
|
import com.github.steveice10.mc.protocol.data.DefaultComponentSerializer;
|
||||||
import com.github.steveice10.mc.protocol.data.game.MessageType;
|
import com.github.steveice10.mc.protocol.data.game.MessageType;
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
import io.netty.buffer.ByteBuf;
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
|
||||||
import com.github.steveice10.packetlib.packet.Packet;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
import lombok.With;
|
import lombok.With;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@With
|
@With
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class ClientboundPlayerChatPacket implements Packet {
|
public class ClientboundPlayerChatPacket implements MinecraftPacket {
|
||||||
private final Component signedContent;
|
private final Component signedContent;
|
||||||
private final @Nullable Component unsignedContent;
|
private final @Nullable Component unsignedContent;
|
||||||
private final MessageType type;
|
private final MessageType type;
|
||||||
|
@ -30,37 +30,37 @@ public class ClientboundPlayerChatPacket implements Packet {
|
||||||
private final byte[] signature;
|
private final byte[] signature;
|
||||||
private final long timeStamp;
|
private final long timeStamp;
|
||||||
|
|
||||||
public ClientboundPlayerChatPacket(NetInput in) throws IOException {
|
public ClientboundPlayerChatPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||||
this.signedContent = DefaultComponentSerializer.get().deserialize(in.readString());
|
this.signedContent = helper.readComponent(in);
|
||||||
if (in.readBoolean()) {
|
if (in.readBoolean()) {
|
||||||
this.unsignedContent = DefaultComponentSerializer.get().deserialize(in.readString());
|
this.unsignedContent = helper.readComponent(in);
|
||||||
} else {
|
} else {
|
||||||
this.unsignedContent = null;
|
this.unsignedContent = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.type = in.readEnum(MessageType.VALUES);
|
this.type = helper.readMessageType(in);
|
||||||
this.senderUUID = in.readUUID();
|
this.senderUUID = helper.readUUID(in);
|
||||||
this.senderName = DefaultComponentSerializer.get().deserialize(in.readString());
|
this.senderName = helper.readComponent(in);
|
||||||
if (in.readBoolean()) {
|
if (in.readBoolean()) {
|
||||||
this.senderTeamName = DefaultComponentSerializer.get().deserialize(in.readString());
|
this.senderTeamName = helper.readComponent(in);
|
||||||
} else {
|
} else {
|
||||||
this.senderTeamName = null;
|
this.senderTeamName = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.timeStamp = in.readLong();
|
this.timeStamp = in.readLong();
|
||||||
this.salt = in.readLong();
|
this.salt = in.readLong();
|
||||||
this.signature = in.readBytes(in.readVarInt());
|
this.signature = helper.readByteArray(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(NetOutput out) throws IOException {
|
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||||
DefaultComponentSerializer.get().serialize(this.signedContent);
|
helper.writeComponent(out, this.signedContent);
|
||||||
if (this.unsignedContent != null) {
|
if (this.unsignedContent != null) {
|
||||||
DefaultComponentSerializer.get().serialize(this.unsignedContent);
|
helper.writeComponent(out, this.unsignedContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
out.writeEnum(this.type);
|
helper.writeMessageType(out, this.type);
|
||||||
out.writeUUID(this.senderUUID);
|
helper.writeUUID(out, this.senderUUID);
|
||||||
DefaultComponentSerializer.get().serialize(this.senderName);
|
DefaultComponentSerializer.get().serialize(this.senderName);
|
||||||
if (this.senderTeamName != null) {
|
if (this.senderTeamName != null) {
|
||||||
DefaultComponentSerializer.get().serialize(this.senderTeamName);
|
DefaultComponentSerializer.get().serialize(this.senderTeamName);
|
||||||
|
@ -68,7 +68,7 @@ public class ClientboundPlayerChatPacket implements Packet {
|
||||||
|
|
||||||
out.writeLong(this.timeStamp);
|
out.writeLong(this.timeStamp);
|
||||||
out.writeLong(this.salt);
|
out.writeLong(this.salt);
|
||||||
out.writeVarInt(this.signature.length);
|
helper.writeVarInt(out, this.signature.length);
|
||||||
out.writeBytes(this.signature);
|
out.writeBytes(this.signature);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
package com.github.steveice10.mc.protocol.packet.ingame.clientbound;
|
package com.github.steveice10.mc.protocol.packet.ingame.clientbound;
|
||||||
|
|
||||||
import com.github.steveice10.mc.auth.data.GameProfile;
|
import com.github.steveice10.mc.auth.data.GameProfile;
|
||||||
|
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
|
||||||
|
import com.github.steveice10.mc.protocol.codec.MinecraftPacket;
|
||||||
import com.github.steveice10.mc.protocol.data.DefaultComponentSerializer;
|
import com.github.steveice10.mc.protocol.data.DefaultComponentSerializer;
|
||||||
import com.github.steveice10.mc.protocol.data.MagicValues;
|
import com.github.steveice10.mc.protocol.data.MagicValues;
|
||||||
import com.github.steveice10.mc.protocol.data.game.PlayerListEntry;
|
import com.github.steveice10.mc.protocol.data.game.PlayerListEntry;
|
||||||
import com.github.steveice10.mc.protocol.data.game.PlayerListEntryAction;
|
import com.github.steveice10.mc.protocol.data.game.PlayerListEntryAction;
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode;
|
import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode;
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
import io.netty.buffer.ByteBuf;
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
|
||||||
import com.github.steveice10.packetlib.packet.Packet;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
|
@ -27,18 +27,18 @@ import java.util.UUID;
|
||||||
@Data
|
@Data
|
||||||
@With
|
@With
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class ClientboundPlayerInfoPacket implements Packet {
|
public class ClientboundPlayerInfoPacket implements MinecraftPacket {
|
||||||
private final @NonNull PlayerListEntryAction action;
|
private final @NonNull PlayerListEntryAction action;
|
||||||
private final @NonNull PlayerListEntry[] entries;
|
private final @NonNull PlayerListEntry[] entries;
|
||||||
|
|
||||||
public ClientboundPlayerInfoPacket(NetInput in) throws IOException {
|
public ClientboundPlayerInfoPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||||
this.action = MagicValues.key(PlayerListEntryAction.class, in.readVarInt());
|
this.action = MagicValues.key(PlayerListEntryAction.class, helper.readVarInt(in));
|
||||||
this.entries = new PlayerListEntry[in.readVarInt()];
|
this.entries = new PlayerListEntry[helper.readVarInt(in)];
|
||||||
for (int count = 0; count < this.entries.length; count++) {
|
for (int count = 0; count < this.entries.length; count++) {
|
||||||
UUID uuid = in.readUUID();
|
UUID uuid = helper.readUUID(in);
|
||||||
GameProfile profile;
|
GameProfile profile;
|
||||||
if (this.action == PlayerListEntryAction.ADD_PLAYER) {
|
if (this.action == PlayerListEntryAction.ADD_PLAYER) {
|
||||||
profile = new GameProfile(uuid, in.readString());
|
profile = new GameProfile(uuid, helper.readString(in));
|
||||||
} else {
|
} else {
|
||||||
profile = new GameProfile(uuid, null);
|
profile = new GameProfile(uuid, null);
|
||||||
}
|
}
|
||||||
|
@ -46,14 +46,14 @@ public class ClientboundPlayerInfoPacket implements Packet {
|
||||||
PlayerListEntry entry = null;
|
PlayerListEntry entry = null;
|
||||||
switch (this.action) {
|
switch (this.action) {
|
||||||
case ADD_PLAYER: {
|
case ADD_PLAYER: {
|
||||||
int properties = in.readVarInt();
|
int properties = helper.readVarInt(in);
|
||||||
List<GameProfile.Property> propertyList = new ArrayList<>();
|
List<GameProfile.Property> propertyList = new ArrayList<>();
|
||||||
for (int index = 0; index < properties; index++) {
|
for (int index = 0; index < properties; index++) {
|
||||||
String propertyName = in.readString();
|
String propertyName = helper.readString(in);
|
||||||
String value = in.readString();
|
String value = helper.readString(in);
|
||||||
String signature = null;
|
String signature = null;
|
||||||
if (in.readBoolean()) {
|
if (in.readBoolean()) {
|
||||||
signature = in.readString();
|
signature = helper.readString(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
propertyList.add(new GameProfile.Property(propertyName, value, signature));
|
propertyList.add(new GameProfile.Property(propertyName, value, signature));
|
||||||
|
@ -61,12 +61,12 @@ public class ClientboundPlayerInfoPacket implements Packet {
|
||||||
|
|
||||||
profile.setProperties(propertyList);
|
profile.setProperties(propertyList);
|
||||||
|
|
||||||
int rawGameMode = in.readVarInt();
|
int rawGameMode = helper.readVarInt(in);
|
||||||
GameMode gameMode = MagicValues.key(GameMode.class, Math.max(rawGameMode, 0));
|
GameMode gameMode = MagicValues.key(GameMode.class, Math.max(rawGameMode, 0));
|
||||||
int ping = in.readVarInt();
|
int ping = helper.readVarInt(in);
|
||||||
Component displayName = null;
|
Component displayName = null;
|
||||||
if (in.readBoolean()) {
|
if (in.readBoolean()) {
|
||||||
displayName = DefaultComponentSerializer.get().deserialize(in.readString());
|
displayName = helper.readComponent(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
long expiresAt;
|
long expiresAt;
|
||||||
|
@ -74,8 +74,8 @@ public class ClientboundPlayerInfoPacket implements Packet {
|
||||||
byte[] keySignature = null;
|
byte[] keySignature = null;
|
||||||
if (in.readBoolean()) {
|
if (in.readBoolean()) {
|
||||||
expiresAt = in.readLong();
|
expiresAt = in.readLong();
|
||||||
byte[] keyBytes = in.readBytes(in.readVarInt());
|
byte[] keyBytes = helper.readByteArray(in);
|
||||||
keySignature = in.readBytes(in.readVarInt());
|
keySignature = helper.readByteArray(in);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
publicKey = KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(keyBytes));
|
publicKey = KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(keyBytes));
|
||||||
|
@ -90,14 +90,14 @@ public class ClientboundPlayerInfoPacket implements Packet {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case UPDATE_GAMEMODE: {
|
case UPDATE_GAMEMODE: {
|
||||||
int rawGameMode = in.readVarInt();
|
int rawGameMode = helper.readVarInt(in);
|
||||||
GameMode mode = MagicValues.key(GameMode.class, Math.max(rawGameMode, 0));
|
GameMode mode = MagicValues.key(GameMode.class, Math.max(rawGameMode, 0));
|
||||||
|
|
||||||
entry = new PlayerListEntry(profile, mode);
|
entry = new PlayerListEntry(profile, mode);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case UPDATE_LATENCY: {
|
case UPDATE_LATENCY: {
|
||||||
int ping = in.readVarInt();
|
int ping = helper.readVarInt(in);
|
||||||
|
|
||||||
entry = new PlayerListEntry(profile, ping);
|
entry = new PlayerListEntry(profile, ping);
|
||||||
break;
|
break;
|
||||||
|
@ -105,7 +105,7 @@ public class ClientboundPlayerInfoPacket implements Packet {
|
||||||
case UPDATE_DISPLAY_NAME: {
|
case UPDATE_DISPLAY_NAME: {
|
||||||
Component displayName = null;
|
Component displayName = null;
|
||||||
if (in.readBoolean()) {
|
if (in.readBoolean()) {
|
||||||
displayName = DefaultComponentSerializer.get().deserialize(in.readString());
|
displayName = helper.readComponent(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
entry = new PlayerListEntry(profile, displayName);
|
entry = new PlayerListEntry(profile, displayName);
|
||||||
|
@ -121,51 +121,51 @@ public class ClientboundPlayerInfoPacket implements Packet {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(NetOutput out) throws IOException {
|
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||||
out.writeVarInt(MagicValues.value(Integer.class, this.action));
|
helper.writeVarInt(out, MagicValues.value(Integer.class, this.action));
|
||||||
out.writeVarInt(this.entries.length);
|
helper.writeVarInt(out, this.entries.length);
|
||||||
for (PlayerListEntry entry : this.entries) {
|
for (PlayerListEntry entry : this.entries) {
|
||||||
out.writeUUID(entry.getProfile().getId());
|
helper.writeUUID(out, entry.getProfile().getId());
|
||||||
switch (this.action) {
|
switch (this.action) {
|
||||||
case ADD_PLAYER:
|
case ADD_PLAYER:
|
||||||
out.writeString(entry.getProfile().getName());
|
helper.writeString(out, entry.getProfile().getName());
|
||||||
out.writeVarInt(entry.getProfile().getProperties().size());
|
helper.writeVarInt(out, entry.getProfile().getProperties().size());
|
||||||
for (GameProfile.Property property : entry.getProfile().getProperties()) {
|
for (GameProfile.Property property : entry.getProfile().getProperties()) {
|
||||||
out.writeString(property.getName());
|
helper.writeString(out, property.getName());
|
||||||
out.writeString(property.getValue());
|
helper.writeString(out, property.getValue());
|
||||||
out.writeBoolean(property.hasSignature());
|
out.writeBoolean(property.hasSignature());
|
||||||
if (property.hasSignature()) {
|
if (property.hasSignature()) {
|
||||||
out.writeString(property.getSignature());
|
helper.writeString(out, property.getSignature());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
out.writeVarInt(MagicValues.value(Integer.class, entry.getGameMode()));
|
helper.writeVarInt(out, MagicValues.value(Integer.class, entry.getGameMode()));
|
||||||
out.writeVarInt(entry.getPing());
|
helper.writeVarInt(out, entry.getPing());
|
||||||
out.writeBoolean(entry.getDisplayName() != null);
|
out.writeBoolean(entry.getDisplayName() != null);
|
||||||
if (entry.getDisplayName() != null) {
|
if (entry.getDisplayName() != null) {
|
||||||
out.writeString(DefaultComponentSerializer.get().serialize(entry.getDisplayName()));
|
helper.writeString(out, DefaultComponentSerializer.get().serialize(entry.getDisplayName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (entry.getPublicKey() != null) {
|
if (entry.getPublicKey() != null) {
|
||||||
out.writeLong(entry.getExpiresAt());
|
out.writeLong(entry.getExpiresAt());
|
||||||
byte[] encoded = entry.getPublicKey().getEncoded();
|
byte[] encoded = entry.getPublicKey().getEncoded();
|
||||||
out.writeVarInt(encoded.length);
|
helper.writeVarInt(out, encoded.length);
|
||||||
out.writeBytes(encoded);
|
out.writeBytes(encoded);
|
||||||
out.writeVarInt(entry.getKeySignature().length);
|
helper.writeVarInt(out, entry.getKeySignature().length);
|
||||||
out.writeBytes(entry.getKeySignature());
|
out.writeBytes(entry.getKeySignature());
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case UPDATE_GAMEMODE:
|
case UPDATE_GAMEMODE:
|
||||||
out.writeVarInt(MagicValues.value(Integer.class, entry.getGameMode()));
|
helper.writeVarInt(out, MagicValues.value(Integer.class, entry.getGameMode()));
|
||||||
break;
|
break;
|
||||||
case UPDATE_LATENCY:
|
case UPDATE_LATENCY:
|
||||||
out.writeVarInt(entry.getPing());
|
helper.writeVarInt(out, entry.getPing());
|
||||||
break;
|
break;
|
||||||
case UPDATE_DISPLAY_NAME:
|
case UPDATE_DISPLAY_NAME:
|
||||||
out.writeBoolean(entry.getDisplayName() != null);
|
out.writeBoolean(entry.getDisplayName() != null);
|
||||||
if (entry.getDisplayName() != null) {
|
if (entry.getDisplayName() != null) {
|
||||||
out.writeString(DefaultComponentSerializer.get().serialize(entry.getDisplayName()));
|
helper.writeString(out, DefaultComponentSerializer.get().serialize(entry.getDisplayName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
package com.github.steveice10.mc.protocol.packet.ingame.clientbound;
|
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.MagicValues;
|
import com.github.steveice10.mc.protocol.data.MagicValues;
|
||||||
import com.github.steveice10.mc.protocol.data.game.UnlockRecipesAction;
|
import com.github.steveice10.mc.protocol.data.game.UnlockRecipesAction;
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
import io.netty.buffer.ByteBuf;
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
|
||||||
import com.github.steveice10.packetlib.packet.Packet;
|
|
||||||
import lombok.*;
|
import lombok.*;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -13,7 +13,7 @@ import java.util.Arrays;
|
||||||
@Data
|
@Data
|
||||||
@With
|
@With
|
||||||
@AllArgsConstructor(access = AccessLevel.PRIVATE)
|
@AllArgsConstructor(access = AccessLevel.PRIVATE)
|
||||||
public class ClientboundRecipePacket implements Packet {
|
public class ClientboundRecipePacket implements MinecraftPacket {
|
||||||
private final @NonNull UnlockRecipesAction action;
|
private final @NonNull UnlockRecipesAction action;
|
||||||
|
|
||||||
private final @NonNull String[] recipes;
|
private final @NonNull String[] recipes;
|
||||||
|
@ -72,8 +72,8 @@ public class ClientboundRecipePacket implements Packet {
|
||||||
this.alreadyKnownRecipes = Arrays.copyOf(alreadyKnownRecipes, alreadyKnownRecipes.length);
|
this.alreadyKnownRecipes = Arrays.copyOf(alreadyKnownRecipes, alreadyKnownRecipes.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ClientboundRecipePacket(NetInput in) throws IOException {
|
public ClientboundRecipePacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||||
this.action = MagicValues.key(UnlockRecipesAction.class, in.readVarInt());
|
this.action = MagicValues.key(UnlockRecipesAction.class, helper.readVarInt(in));
|
||||||
|
|
||||||
this.openCraftingBook = in.readBoolean();
|
this.openCraftingBook = in.readBoolean();
|
||||||
this.activateCraftingFiltering = in.readBoolean();
|
this.activateCraftingFiltering = in.readBoolean();
|
||||||
|
@ -85,23 +85,23 @@ public class ClientboundRecipePacket implements Packet {
|
||||||
this.activateSmokingFiltering = in.readBoolean();
|
this.activateSmokingFiltering = in.readBoolean();
|
||||||
|
|
||||||
if (this.action == UnlockRecipesAction.INIT) {
|
if (this.action == UnlockRecipesAction.INIT) {
|
||||||
this.alreadyKnownRecipes = new String[in.readVarInt()];
|
this.alreadyKnownRecipes = new String[helper.readVarInt(in)];
|
||||||
for (int i = 0; i < this.alreadyKnownRecipes.length; i++) {
|
for (int i = 0; i < this.alreadyKnownRecipes.length; i++) {
|
||||||
this.alreadyKnownRecipes[i] = in.readString();
|
this.alreadyKnownRecipes[i] = helper.readString(in);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.alreadyKnownRecipes = null;
|
this.alreadyKnownRecipes = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.recipes = new String[in.readVarInt()];
|
this.recipes = new String[helper.readVarInt(in)];
|
||||||
for (int i = 0; i < this.recipes.length; i++) {
|
for (int i = 0; i < this.recipes.length; i++) {
|
||||||
this.recipes[i] = in.readString();
|
this.recipes[i] = helper.readString(in);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(NetOutput out) throws IOException {
|
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||||
out.writeVarInt(MagicValues.value(Integer.class, this.action));
|
helper.writeVarInt(out, MagicValues.value(Integer.class, this.action));
|
||||||
|
|
||||||
out.writeBoolean(this.openCraftingBook);
|
out.writeBoolean(this.openCraftingBook);
|
||||||
out.writeBoolean(this.activateCraftingFiltering);
|
out.writeBoolean(this.activateCraftingFiltering);
|
||||||
|
@ -113,15 +113,15 @@ public class ClientboundRecipePacket implements Packet {
|
||||||
out.writeBoolean(this.activateSmokingFiltering);
|
out.writeBoolean(this.activateSmokingFiltering);
|
||||||
|
|
||||||
if (this.action == UnlockRecipesAction.INIT) {
|
if (this.action == UnlockRecipesAction.INIT) {
|
||||||
out.writeVarInt(this.alreadyKnownRecipes.length);
|
helper.writeVarInt(out, this.alreadyKnownRecipes.length);
|
||||||
for (String recipeId : this.alreadyKnownRecipes) {
|
for (String recipeId : this.alreadyKnownRecipes) {
|
||||||
out.writeString(recipeId);
|
helper.writeString(out, recipeId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
out.writeVarInt(this.recipes.length);
|
helper.writeVarInt(out, this.recipes.length);
|
||||||
for (String recipeId : this.recipes) {
|
for (String recipeId : this.recipes) {
|
||||||
out.writeString(recipeId);
|
helper.writeString(out, recipeId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,46 +1,45 @@
|
||||||
package com.github.steveice10.mc.protocol.packet.ingame.clientbound;
|
package com.github.steveice10.mc.protocol.packet.ingame.clientbound;
|
||||||
|
|
||||||
import com.github.steveice10.mc.protocol.data.DefaultComponentSerializer;
|
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
import com.github.steveice10.mc.protocol.codec.MinecraftPacket;
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
import io.netty.buffer.ByteBuf;
|
||||||
import com.github.steveice10.packetlib.packet.Packet;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import lombok.With;
|
import lombok.With;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@With
|
@With
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class ClientboundResourcePackPacket implements Packet {
|
public class ClientboundResourcePackPacket implements MinecraftPacket {
|
||||||
private final @NonNull String url;
|
private final @NonNull String url;
|
||||||
private final @NonNull String hash;
|
private final @NonNull String hash;
|
||||||
private final boolean required;
|
private final boolean required;
|
||||||
private final @Nullable Component prompt;
|
private final @Nullable Component prompt;
|
||||||
|
|
||||||
public ClientboundResourcePackPacket(NetInput in) throws IOException {
|
public ClientboundResourcePackPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||||
this.url = in.readString();
|
this.url = helper.readString(in);
|
||||||
this.hash = in.readString();
|
this.hash = helper.readString(in);
|
||||||
this.required = in.readBoolean();
|
this.required = in.readBoolean();
|
||||||
if (in.readBoolean()) {
|
if (in.readBoolean()) {
|
||||||
this.prompt = DefaultComponentSerializer.get().deserialize(in.readString());
|
this.prompt = helper.readComponent(in);
|
||||||
} else {
|
} else {
|
||||||
this.prompt = null;
|
this.prompt = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(NetOutput out) throws IOException {
|
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||||
out.writeString(this.url);
|
helper.writeString(out, this.url);
|
||||||
out.writeString(this.hash);
|
helper.writeString(out, this.hash);
|
||||||
out.writeBoolean(this.required);
|
out.writeBoolean(this.required);
|
||||||
out.writeBoolean(this.prompt != null);
|
out.writeBoolean(this.prompt != null);
|
||||||
if (this.prompt != null) {
|
if (this.prompt != null) {
|
||||||
out.writeString(DefaultComponentSerializer.get().serialize(this.prompt));
|
helper.writeComponent(out, this.prompt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,26 +1,23 @@
|
||||||
package com.github.steveice10.mc.protocol.packet.ingame.clientbound;
|
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.MagicValues;
|
import com.github.steveice10.mc.protocol.data.MagicValues;
|
||||||
import com.github.steveice10.mc.protocol.data.game.NBT;
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.GlobalPos;
|
import com.github.steveice10.mc.protocol.data.game.entity.metadata.GlobalPos;
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position;
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode;
|
import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
import io.netty.buffer.ByteBuf;
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
|
||||||
import com.github.steveice10.packetlib.packet.Packet;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import lombok.With;
|
import lombok.With;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@With
|
@With
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class ClientboundRespawnPacket implements Packet {
|
public class ClientboundRespawnPacket implements MinecraftPacket {
|
||||||
private final @NonNull String dimension;
|
private final @NonNull String dimension;
|
||||||
private final @NonNull String worldName;
|
private final @NonNull String worldName;
|
||||||
private final long hashedSeed;
|
private final long hashedSeed;
|
||||||
|
@ -31,9 +28,9 @@ public class ClientboundRespawnPacket implements Packet {
|
||||||
private final boolean copyMetadata;
|
private final boolean copyMetadata;
|
||||||
private final @Nullable GlobalPos lastDeathPos;
|
private final @Nullable GlobalPos lastDeathPos;
|
||||||
|
|
||||||
public ClientboundRespawnPacket(NetInput in) throws IOException {
|
public ClientboundRespawnPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||||
this.dimension = in.readString();
|
this.dimension = helper.readString(in);
|
||||||
this.worldName = in.readString();
|
this.worldName = helper.readString(in);
|
||||||
this.hashedSeed = in.readLong();
|
this.hashedSeed = in.readLong();
|
||||||
this.gamemode = MagicValues.key(GameMode.class, in.readUnsignedByte());
|
this.gamemode = MagicValues.key(GameMode.class, in.readUnsignedByte());
|
||||||
this.previousGamemode = MagicValues.key(GameMode.class, in.readUnsignedByte());
|
this.previousGamemode = MagicValues.key(GameMode.class, in.readUnsignedByte());
|
||||||
|
@ -41,16 +38,16 @@ public class ClientboundRespawnPacket implements Packet {
|
||||||
this.flat = in.readBoolean();
|
this.flat = in.readBoolean();
|
||||||
this.copyMetadata = in.readBoolean();
|
this.copyMetadata = in.readBoolean();
|
||||||
if (in.readBoolean()) {
|
if (in.readBoolean()) {
|
||||||
this.lastDeathPos = GlobalPos.read(in);
|
this.lastDeathPos = helper.readGlobalPos(in);
|
||||||
} else {
|
} else {
|
||||||
this.lastDeathPos = null;
|
this.lastDeathPos = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(NetOutput out) throws IOException {
|
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||||
out.writeString(this.dimension);
|
helper.writeString(out, this.dimension);
|
||||||
out.writeString(this.worldName);
|
helper.writeString(out, this.worldName);
|
||||||
out.writeLong(this.hashedSeed);
|
out.writeLong(this.hashedSeed);
|
||||||
out.writeByte(MagicValues.value(Integer.class, this.gamemode));
|
out.writeByte(MagicValues.value(Integer.class, this.gamemode));
|
||||||
out.writeByte(MagicValues.value(Integer.class, this.previousGamemode));
|
out.writeByte(MagicValues.value(Integer.class, this.previousGamemode));
|
||||||
|
@ -59,7 +56,7 @@ public class ClientboundRespawnPacket implements Packet {
|
||||||
out.writeBoolean(this.copyMetadata);
|
out.writeBoolean(this.copyMetadata);
|
||||||
out.writeBoolean(this.lastDeathPos != null);
|
out.writeBoolean(this.lastDeathPos != null);
|
||||||
if (this.lastDeathPos != null) {
|
if (this.lastDeathPos != null) {
|
||||||
GlobalPos.write(out, this.lastDeathPos);
|
helper.writeGlobalPos(out, this.lastDeathPos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package com.github.steveice10.mc.protocol.packet.ingame.clientbound;
|
package com.github.steveice10.mc.protocol.packet.ingame.clientbound;
|
||||||
|
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
import com.github.steveice10.mc.protocol.codec.MinecraftPacket;
|
||||||
import com.github.steveice10.packetlib.packet.Packet;
|
import io.netty.buffer.ByteBuf;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.With;
|
import lombok.With;
|
||||||
|
@ -12,22 +12,22 @@ import java.io.IOException;
|
||||||
@Data
|
@Data
|
||||||
@With
|
@With
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class ClientboundSelectAdvancementsTabPacket implements Packet {
|
public class ClientboundSelectAdvancementsTabPacket implements MinecraftPacket {
|
||||||
private final String tabId;
|
private final String tabId;
|
||||||
|
|
||||||
public ClientboundSelectAdvancementsTabPacket(NetInput in) throws IOException {
|
public ClientboundSelectAdvancementsTabPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||||
if (in.readBoolean()) {
|
if (in.readBoolean()) {
|
||||||
this.tabId = in.readString();
|
this.tabId = helper.readString(in);
|
||||||
} else {
|
} else {
|
||||||
this.tabId = null;
|
this.tabId = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(NetOutput out) throws IOException {
|
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||||
if (this.tabId != null) {
|
if (this.tabId != null) {
|
||||||
out.writeBoolean(true);
|
out.writeBoolean(true);
|
||||||
out.writeString(this.tabId);
|
helper.writeString(out, this.tabId);
|
||||||
} else {
|
} else {
|
||||||
out.writeBoolean(false);
|
out.writeBoolean(false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,34 +1,34 @@
|
||||||
package com.github.steveice10.mc.protocol.packet.ingame.clientbound;
|
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.DefaultComponentSerializer;
|
import com.github.steveice10.mc.protocol.data.DefaultComponentSerializer;
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
import io.netty.buffer.ByteBuf;
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
|
||||||
import com.github.steveice10.packetlib.packet.Packet;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.With;
|
import lombok.With;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@With
|
@With
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class ClientboundServerDataPacket implements Packet {
|
public class ClientboundServerDataPacket implements MinecraftPacket {
|
||||||
private final @Nullable Component motd;
|
private final @Nullable Component motd;
|
||||||
private final @Nullable String iconBase64;
|
private final @Nullable String iconBase64;
|
||||||
private final boolean previewsChat;
|
private final boolean previewsChat;
|
||||||
|
|
||||||
public ClientboundServerDataPacket(NetInput in) throws IOException {
|
public ClientboundServerDataPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||||
if (in.readBoolean()) {
|
if (in.readBoolean()) {
|
||||||
this.motd = DefaultComponentSerializer.get().deserialize(in.readString());
|
this.motd = helper.readComponent(in);
|
||||||
} else {
|
} else {
|
||||||
this.motd = null;
|
this.motd = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in.readBoolean()) {
|
if (in.readBoolean()) {
|
||||||
this.iconBase64 = in.readString();
|
this.iconBase64 = helper.readString(in);
|
||||||
} else {
|
} else {
|
||||||
this.iconBase64 = null;
|
this.iconBase64 = null;
|
||||||
}
|
}
|
||||||
|
@ -37,15 +37,15 @@ public class ClientboundServerDataPacket implements Packet {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(NetOutput out) throws IOException {
|
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||||
out.writeBoolean(this.motd != null);
|
out.writeBoolean(this.motd != null);
|
||||||
if (this.motd != null) {
|
if (this.motd != null) {
|
||||||
out.writeString(DefaultComponentSerializer.get().serialize(this.motd));
|
helper.writeString(out, DefaultComponentSerializer.get().serialize(this.motd));
|
||||||
}
|
}
|
||||||
|
|
||||||
out.writeBoolean(this.iconBase64 != null);
|
out.writeBoolean(this.iconBase64 != null);
|
||||||
if (this.iconBase64 != null) {
|
if (this.iconBase64 != null) {
|
||||||
out.writeString(this.iconBase64);
|
helper.writeString(out, this.iconBase64);
|
||||||
}
|
}
|
||||||
|
|
||||||
out.writeBoolean(this.previewsChat);
|
out.writeBoolean(this.previewsChat);
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package com.github.steveice10.mc.protocol.packet.ingame.clientbound;
|
package com.github.steveice10.mc.protocol.packet.ingame.clientbound;
|
||||||
|
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
import com.github.steveice10.mc.protocol.codec.MinecraftPacket;
|
||||||
import com.github.steveice10.packetlib.packet.Packet;
|
import io.netty.buffer.ByteBuf;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.With;
|
import lombok.With;
|
||||||
|
@ -12,15 +12,15 @@ import java.io.IOException;
|
||||||
@Data
|
@Data
|
||||||
@With
|
@With
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class ClientboundSetCameraPacket implements Packet {
|
public class ClientboundSetCameraPacket implements MinecraftPacket {
|
||||||
private final int cameraEntityId;
|
private final int cameraEntityId;
|
||||||
|
|
||||||
public ClientboundSetCameraPacket(NetInput in) throws IOException {
|
public ClientboundSetCameraPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||||
this.cameraEntityId = in.readVarInt();
|
this.cameraEntityId = helper.readVarInt(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(NetOutput out) throws IOException {
|
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||||
out.writeVarInt(this.cameraEntityId);
|
helper.writeVarInt(out, this.cameraEntityId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package com.github.steveice10.mc.protocol.packet.ingame.clientbound;
|
package com.github.steveice10.mc.protocol.packet.ingame.clientbound;
|
||||||
|
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
import com.github.steveice10.mc.protocol.codec.MinecraftPacket;
|
||||||
import com.github.steveice10.packetlib.packet.Packet;
|
import io.netty.buffer.ByteBuf;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.With;
|
import lombok.With;
|
||||||
|
@ -12,15 +12,15 @@ import java.io.IOException;
|
||||||
@Data
|
@Data
|
||||||
@With
|
@With
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class ClientboundSetDisplayChatPreviewPacket implements Packet {
|
public class ClientboundSetDisplayChatPreviewPacket implements MinecraftPacket {
|
||||||
private final boolean enabled;
|
private final boolean enabled;
|
||||||
|
|
||||||
public ClientboundSetDisplayChatPreviewPacket(NetInput in) throws IOException {
|
public ClientboundSetDisplayChatPreviewPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||||
this.enabled = in.readBoolean();
|
this.enabled = in.readBoolean();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(NetOutput out) throws IOException {
|
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||||
out.writeBoolean(this.enabled);
|
out.writeBoolean(this.enabled);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
package com.github.steveice10.mc.protocol.packet.ingame.clientbound;
|
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.BuiltinSound;
|
||||||
import com.github.steveice10.mc.protocol.data.game.level.sound.SoundCategory;
|
import com.github.steveice10.mc.protocol.data.game.level.sound.SoundCategory;
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
import io.netty.buffer.ByteBuf;
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
|
||||||
import com.github.steveice10.packetlib.packet.Packet;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
|
@ -15,7 +15,7 @@ import java.io.IOException;
|
||||||
@Data
|
@Data
|
||||||
@With
|
@With
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class ClientboundSoundEntityPacket implements Packet {
|
public class ClientboundSoundEntityPacket implements MinecraftPacket {
|
||||||
private final @NonNull BuiltinSound sound;
|
private final @NonNull BuiltinSound sound;
|
||||||
private final @NonNull SoundCategory category;
|
private final @NonNull SoundCategory category;
|
||||||
private final int entityId;
|
private final int entityId;
|
||||||
|
@ -23,20 +23,20 @@ public class ClientboundSoundEntityPacket implements Packet {
|
||||||
private final float pitch;
|
private final float pitch;
|
||||||
private final long seed;
|
private final long seed;
|
||||||
|
|
||||||
public ClientboundSoundEntityPacket(NetInput in) throws IOException {
|
public ClientboundSoundEntityPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||||
this.sound = BuiltinSound.VALUES[in.readVarInt()];
|
this.sound = helper.readBuiltinSound(in);
|
||||||
this.category = SoundCategory.read(in);
|
this.category = helper.readSoundCategory(in);
|
||||||
this.entityId = in.readVarInt();
|
this.entityId = helper.readVarInt(in);
|
||||||
this.volume = in.readFloat();
|
this.volume = in.readFloat();
|
||||||
this.pitch = in.readFloat();
|
this.pitch = in.readFloat();
|
||||||
this.seed = in.readLong();
|
this.seed = in.readLong();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(NetOutput out) throws IOException {
|
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||||
out.writeVarInt(this.sound.ordinal());
|
helper.writeBuiltinSound(out, this.sound);
|
||||||
out.writeVarInt(this.category.ordinal());
|
helper.writeSoundCategory(out, this.category);
|
||||||
out.writeVarInt(this.entityId);
|
helper.writeVarInt(out, this.entityId);
|
||||||
out.writeFloat(this.volume);
|
out.writeFloat(this.volume);
|
||||||
out.writeFloat(this.pitch);
|
out.writeFloat(this.pitch);
|
||||||
out.writeLong(this.seed);
|
out.writeLong(this.seed);
|
||||||
|
|
|
@ -1,40 +1,40 @@
|
||||||
package com.github.steveice10.mc.protocol.packet.ingame.clientbound;
|
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.BuiltinSound;
|
||||||
import com.github.steveice10.mc.protocol.data.game.level.sound.CustomSound;
|
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.Sound;
|
||||||
import com.github.steveice10.mc.protocol.data.game.level.sound.SoundCategory;
|
import com.github.steveice10.mc.protocol.data.game.level.sound.SoundCategory;
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
import io.netty.buffer.ByteBuf;
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
|
||||||
import com.github.steveice10.packetlib.packet.Packet;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.With;
|
import lombok.With;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@With
|
@With
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class ClientboundStopSoundPacket implements Packet {
|
public class ClientboundStopSoundPacket implements MinecraftPacket {
|
||||||
private static final int FLAG_CATEGORY = 0x01;
|
private static final int FLAG_CATEGORY = 0x01;
|
||||||
private static final int FLAG_SOUND = 0x02;
|
private static final int FLAG_SOUND = 0x02;
|
||||||
|
|
||||||
private final @Nullable SoundCategory category;
|
private final @Nullable SoundCategory category;
|
||||||
private final @Nullable Sound sound;
|
private final @Nullable Sound sound;
|
||||||
|
|
||||||
public ClientboundStopSoundPacket(NetInput in) throws IOException {
|
public ClientboundStopSoundPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||||
int flags = in.readByte();
|
int flags = in.readByte();
|
||||||
if ((flags & FLAG_CATEGORY) != 0) {
|
if ((flags & FLAG_CATEGORY) != 0) {
|
||||||
this.category = SoundCategory.read(in);
|
this.category = helper.readSoundCategory(in);
|
||||||
} else {
|
} else {
|
||||||
this.category = null;
|
this.category = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((flags & FLAG_SOUND) != 0) {
|
if ((flags & FLAG_SOUND) != 0) {
|
||||||
String value = in.readString();
|
String value = helper.readString(in);
|
||||||
Sound sound = BuiltinSound.NAME_TO_SOUND.get(value);
|
Sound sound = helper.getBuiltinSound(value);
|
||||||
if (sound != null) {
|
if (sound != null) {
|
||||||
this.sound = sound;
|
this.sound = sound;
|
||||||
} else {
|
} else {
|
||||||
|
@ -46,7 +46,7 @@ public class ClientboundStopSoundPacket implements Packet {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(NetOutput out) throws IOException {
|
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||||
int flags = 0;
|
int flags = 0;
|
||||||
if (this.category != null) {
|
if (this.category != null) {
|
||||||
flags |= FLAG_CATEGORY;
|
flags |= FLAG_CATEGORY;
|
||||||
|
@ -69,7 +69,7 @@ public class ClientboundStopSoundPacket implements Packet {
|
||||||
value = ((BuiltinSound) this.sound).getName();
|
value = ((BuiltinSound) this.sound).getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
out.writeString(value);
|
helper.writeString(out, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
package com.github.steveice10.mc.protocol.packet.ingame.clientbound;
|
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.DefaultComponentSerializer;
|
import com.github.steveice10.mc.protocol.data.DefaultComponentSerializer;
|
||||||
import com.github.steveice10.mc.protocol.data.game.MessageType;
|
import com.github.steveice10.mc.protocol.data.game.MessageType;
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
import io.netty.buffer.ByteBuf;
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
|
||||||
import com.github.steveice10.packetlib.packet.Packet;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.With;
|
import lombok.With;
|
||||||
|
@ -15,18 +15,18 @@ import java.io.IOException;
|
||||||
@Data
|
@Data
|
||||||
@With
|
@With
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class ClientboundSystemChatPacket implements Packet {
|
public class ClientboundSystemChatPacket implements MinecraftPacket {
|
||||||
private final Component content;
|
private final Component content;
|
||||||
private final MessageType type;
|
private final MessageType type;
|
||||||
|
|
||||||
public ClientboundSystemChatPacket(NetInput in) throws IOException {
|
public ClientboundSystemChatPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||||
this.content = DefaultComponentSerializer.get().deserialize(in.readString());
|
this.content = helper.readComponent(in);
|
||||||
this.type = in.readEnum(MessageType.VALUES);
|
this.type = helper.readMessageType(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(NetOutput out) throws IOException {
|
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||||
out.writeString(DefaultComponentSerializer.get().serialize(this.content));
|
helper.writeString(out, DefaultComponentSerializer.get().serialize(this.content));
|
||||||
out.writeEnum(this.type);
|
helper.writeMessageType(out, this.type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
package com.github.steveice10.mc.protocol.packet.ingame.clientbound;
|
package com.github.steveice10.mc.protocol.packet.ingame.clientbound;
|
||||||
|
|
||||||
import com.github.steveice10.mc.protocol.data.DefaultComponentSerializer;
|
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
import com.github.steveice10.mc.protocol.codec.MinecraftPacket;
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
import io.netty.buffer.ByteBuf;
|
||||||
import com.github.steveice10.packetlib.packet.Packet;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
|
@ -15,18 +14,18 @@ import java.io.IOException;
|
||||||
@Data
|
@Data
|
||||||
@With
|
@With
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class ClientboundTabListPacket implements Packet {
|
public class ClientboundTabListPacket implements MinecraftPacket {
|
||||||
private final @NonNull Component header;
|
private final @NonNull Component header;
|
||||||
private final @NonNull Component footer;
|
private final @NonNull Component footer;
|
||||||
|
|
||||||
public ClientboundTabListPacket(NetInput in) throws IOException {
|
public ClientboundTabListPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||||
this.header = DefaultComponentSerializer.get().deserialize(in.readString());
|
this.header = helper.readComponent(in);
|
||||||
this.footer = DefaultComponentSerializer.get().deserialize(in.readString());
|
this.footer = helper.readComponent(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(NetOutput out) throws IOException {
|
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||||
out.writeString(DefaultComponentSerializer.get().serialize(this.header));
|
helper.writeComponent(out, this.header);
|
||||||
out.writeString(DefaultComponentSerializer.get().serialize(this.footer));
|
helper.writeComponent(out, this.footer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
package com.github.steveice10.mc.protocol.packet.ingame.clientbound;
|
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.DefaultComponentSerializer;
|
import com.github.steveice10.mc.protocol.data.DefaultComponentSerializer;
|
||||||
import com.github.steveice10.mc.protocol.data.MagicValues;
|
import com.github.steveice10.mc.protocol.data.MagicValues;
|
||||||
import com.github.steveice10.mc.protocol.data.game.advancement.Advancement;
|
import com.github.steveice10.mc.protocol.data.game.advancement.Advancement;
|
||||||
import com.github.steveice10.mc.protocol.data.game.advancement.Advancement.DisplayData;
|
import com.github.steveice10.mc.protocol.data.game.advancement.Advancement.DisplayData;
|
||||||
import com.github.steveice10.mc.protocol.data.game.advancement.Advancement.DisplayData.FrameType;
|
import com.github.steveice10.mc.protocol.data.game.advancement.Advancement.DisplayData.FrameType;
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
|
import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
import io.netty.buffer.ByteBuf;
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
|
||||||
import com.github.steveice10.packetlib.packet.Packet;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
|
@ -24,7 +24,7 @@ import java.util.Map;
|
||||||
@Data
|
@Data
|
||||||
@With
|
@With
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class ClientboundUpdateAdvancementsPacket implements Packet {
|
public class ClientboundUpdateAdvancementsPacket implements MinecraftPacket {
|
||||||
private static final int FLAG_HAS_BACKGROUND_TEXTURE = 0x01;
|
private static final int FLAG_HAS_BACKGROUND_TEXTURE = 0x01;
|
||||||
private static final int FLAG_SHOW_TOAST = 0x02;
|
private static final int FLAG_SHOW_TOAST = 0x02;
|
||||||
private static final int FLAG_HIDDEN = 0x04;
|
private static final int FLAG_HIDDEN = 0x04;
|
||||||
|
@ -47,26 +47,26 @@ public class ClientboundUpdateAdvancementsPacket implements Packet {
|
||||||
return progress.get(criterionId);
|
return progress.get(criterionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ClientboundUpdateAdvancementsPacket(NetInput in) throws IOException {
|
public ClientboundUpdateAdvancementsPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||||
this.reset = in.readBoolean();
|
this.reset = in.readBoolean();
|
||||||
|
|
||||||
this.advancements = new Advancement[in.readVarInt()];
|
this.advancements = new Advancement[helper.readVarInt(in)];
|
||||||
for (int i = 0; i < this.advancements.length; i++) {
|
for (int i = 0; i < this.advancements.length; i++) {
|
||||||
String id = in.readString();
|
String id = helper.readString(in);
|
||||||
String parentId = in.readBoolean() ? in.readString() : null;
|
String parentId = in.readBoolean() ? helper.readString(in) : null;
|
||||||
DisplayData displayData = null;
|
DisplayData displayData = null;
|
||||||
if (in.readBoolean()) {
|
if (in.readBoolean()) {
|
||||||
Component title = DefaultComponentSerializer.get().deserialize(in.readString());
|
Component title = helper.readComponent(in);
|
||||||
Component description = DefaultComponentSerializer.get().deserialize(in.readString());
|
Component description = helper.readComponent(in);
|
||||||
ItemStack icon = ItemStack.read(in);
|
ItemStack icon = helper.readItemStack(in);
|
||||||
FrameType frameType = MagicValues.key(FrameType.class, in.readVarInt());
|
FrameType frameType = MagicValues.key(FrameType.class, helper.readVarInt(in));
|
||||||
|
|
||||||
int flags = in.readInt();
|
int flags = in.readInt();
|
||||||
boolean hasBackgroundTexture = (flags & FLAG_HAS_BACKGROUND_TEXTURE) != 0;
|
boolean hasBackgroundTexture = (flags & FLAG_HAS_BACKGROUND_TEXTURE) != 0;
|
||||||
boolean showToast = (flags & FLAG_SHOW_TOAST) != 0;
|
boolean showToast = (flags & FLAG_SHOW_TOAST) != 0;
|
||||||
boolean hidden = (flags & FLAG_HIDDEN) != 0;
|
boolean hidden = (flags & FLAG_HIDDEN) != 0;
|
||||||
|
|
||||||
String backgroundTexture = hasBackgroundTexture ? in.readString() : null;
|
String backgroundTexture = hasBackgroundTexture ? helper.readString(in) : null;
|
||||||
float posX = in.readFloat();
|
float posX = in.readFloat();
|
||||||
float posY = in.readFloat();
|
float posY = in.readFloat();
|
||||||
|
|
||||||
|
@ -74,18 +74,18 @@ public class ClientboundUpdateAdvancementsPacket implements Packet {
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> criteria = new ArrayList<>();
|
List<String> criteria = new ArrayList<>();
|
||||||
int criteriaCount = in.readVarInt();
|
int criteriaCount = helper.readVarInt(in);
|
||||||
for (int j = 0; j < criteriaCount; j++) {
|
for (int j = 0; j < criteriaCount; j++) {
|
||||||
criteria.add(in.readString());
|
criteria.add(helper.readString(in));
|
||||||
}
|
}
|
||||||
|
|
||||||
List<List<String>> requirements = new ArrayList<>();
|
List<List<String>> requirements = new ArrayList<>();
|
||||||
int requirementCount = in.readVarInt();
|
int requirementCount = helper.readVarInt(in);
|
||||||
for (int j = 0; j < requirementCount; j++) {
|
for (int j = 0; j < requirementCount; j++) {
|
||||||
List<String> requirement = new ArrayList<>();
|
List<String> requirement = new ArrayList<>();
|
||||||
int componentCount = in.readVarInt();
|
int componentCount = helper.readVarInt(in);
|
||||||
for (int k = 0; k < componentCount; k++) {
|
for (int k = 0; k < componentCount; k++) {
|
||||||
requirement.add(in.readString());
|
requirement.add(helper.readString(in));
|
||||||
}
|
}
|
||||||
|
|
||||||
requirements.add(requirement);
|
requirements.add(requirement);
|
||||||
|
@ -94,20 +94,20 @@ public class ClientboundUpdateAdvancementsPacket implements Packet {
|
||||||
this.advancements[i] = new Advancement(id, criteria, requirements, parentId, displayData);
|
this.advancements[i] = new Advancement(id, criteria, requirements, parentId, displayData);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.removedAdvancements = new String[in.readVarInt()];
|
this.removedAdvancements = new String[helper.readVarInt(in)];
|
||||||
for (int i = 0; i < this.removedAdvancements.length; i++) {
|
for (int i = 0; i < this.removedAdvancements.length; i++) {
|
||||||
this.removedAdvancements[i] = in.readString();
|
this.removedAdvancements[i] = helper.readString(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.progress = new HashMap<>();
|
this.progress = new HashMap<>();
|
||||||
int progressCount = in.readVarInt();
|
int progressCount = helper.readVarInt(in);
|
||||||
for (int i = 0; i < progressCount; i++) {
|
for (int i = 0; i < progressCount; i++) {
|
||||||
String advancementId = in.readString();
|
String advancementId = helper.readString(in);
|
||||||
|
|
||||||
Map<String, Long> advancementProgress = new HashMap<>();
|
Map<String, Long> advancementProgress = new HashMap<>();
|
||||||
int criterionCount = in.readVarInt();
|
int criterionCount = helper.readVarInt(in);
|
||||||
for (int j = 0; j < criterionCount; j++) {
|
for (int j = 0; j < criterionCount; j++) {
|
||||||
String criterionId = in.readString();
|
String criterionId = helper.readString(in);
|
||||||
long achievedDate = in.readBoolean() ? in.readLong() : -1;
|
long achievedDate = in.readBoolean() ? in.readLong() : -1;
|
||||||
advancementProgress.put(criterionId, achievedDate);
|
advancementProgress.put(criterionId, achievedDate);
|
||||||
}
|
}
|
||||||
|
@ -117,15 +117,15 @@ public class ClientboundUpdateAdvancementsPacket implements Packet {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(NetOutput out) throws IOException {
|
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||||
out.writeBoolean(this.reset);
|
out.writeBoolean(this.reset);
|
||||||
|
|
||||||
out.writeVarInt(this.advancements.length);
|
helper.writeVarInt(out, this.advancements.length);
|
||||||
for (Advancement advancement : this.advancements) {
|
for (Advancement advancement : this.advancements) {
|
||||||
out.writeString(advancement.getId());
|
helper.writeString(out, advancement.getId());
|
||||||
if (advancement.getParentId() != null) {
|
if (advancement.getParentId() != null) {
|
||||||
out.writeBoolean(true);
|
out.writeBoolean(true);
|
||||||
out.writeString(advancement.getParentId());
|
helper.writeString(out, advancement.getParentId());
|
||||||
} else {
|
} else {
|
||||||
out.writeBoolean(false);
|
out.writeBoolean(false);
|
||||||
}
|
}
|
||||||
|
@ -133,10 +133,10 @@ public class ClientboundUpdateAdvancementsPacket implements Packet {
|
||||||
DisplayData displayData = advancement.getDisplayData();
|
DisplayData displayData = advancement.getDisplayData();
|
||||||
if (displayData != null) {
|
if (displayData != null) {
|
||||||
out.writeBoolean(true);
|
out.writeBoolean(true);
|
||||||
out.writeString(DefaultComponentSerializer.get().serialize(displayData.getTitle()));
|
helper.writeString(out, DefaultComponentSerializer.get().serialize(displayData.getTitle()));
|
||||||
out.writeString(DefaultComponentSerializer.get().serialize(displayData.getDescription()));
|
helper.writeString(out, DefaultComponentSerializer.get().serialize(displayData.getDescription()));
|
||||||
ItemStack.write(out, displayData.getIcon());
|
helper.writeItemStack(out, displayData.getIcon());
|
||||||
out.writeVarInt(MagicValues.value(Integer.class, displayData.getFrameType()));
|
helper.writeVarInt(out, MagicValues.value(Integer.class, displayData.getFrameType()));
|
||||||
String backgroundTexture = displayData.getBackgroundTexture();
|
String backgroundTexture = displayData.getBackgroundTexture();
|
||||||
|
|
||||||
int flags = 0;
|
int flags = 0;
|
||||||
|
@ -155,7 +155,7 @@ public class ClientboundUpdateAdvancementsPacket implements Packet {
|
||||||
out.writeInt(flags);
|
out.writeInt(flags);
|
||||||
|
|
||||||
if (backgroundTexture != null) {
|
if (backgroundTexture != null) {
|
||||||
out.writeString(backgroundTexture);
|
helper.writeString(out, backgroundTexture);
|
||||||
}
|
}
|
||||||
|
|
||||||
out.writeFloat(displayData.getPosX());
|
out.writeFloat(displayData.getPosX());
|
||||||
|
@ -164,32 +164,32 @@ public class ClientboundUpdateAdvancementsPacket implements Packet {
|
||||||
out.writeBoolean(false);
|
out.writeBoolean(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
out.writeVarInt(advancement.getCriteria().size());
|
helper.writeVarInt(out, advancement.getCriteria().size());
|
||||||
for (String criterion : advancement.getCriteria()) {
|
for (String criterion : advancement.getCriteria()) {
|
||||||
out.writeString(criterion);
|
helper.writeString(out, criterion);
|
||||||
}
|
}
|
||||||
|
|
||||||
out.writeVarInt(advancement.getRequirements().size());
|
helper.writeVarInt(out, advancement.getRequirements().size());
|
||||||
for (List<String> requirement : advancement.getRequirements()) {
|
for (List<String> requirement : advancement.getRequirements()) {
|
||||||
out.writeVarInt(requirement.size());
|
helper.writeVarInt(out, requirement.size());
|
||||||
for (String criterion : requirement) {
|
for (String criterion : requirement) {
|
||||||
out.writeString(criterion);
|
helper.writeString(out, criterion);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
out.writeVarInt(this.removedAdvancements.length);
|
helper.writeVarInt(out, this.removedAdvancements.length);
|
||||||
for (String id : this.removedAdvancements) {
|
for (String id : this.removedAdvancements) {
|
||||||
out.writeString(id);
|
helper.writeString(out, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
out.writeVarInt(this.progress.size());
|
helper.writeVarInt(out, this.progress.size());
|
||||||
for (Map.Entry<String, Map<String, Long>> advancement : this.progress.entrySet()) {
|
for (Map.Entry<String, Map<String, Long>> advancement : this.progress.entrySet()) {
|
||||||
out.writeString(advancement.getKey());
|
helper.writeString(out, advancement.getKey());
|
||||||
Map<String, Long> advancementProgress = advancement.getValue();
|
Map<String, Long> advancementProgress = advancement.getValue();
|
||||||
out.writeVarInt(advancementProgress.size());
|
helper.writeVarInt(out, advancementProgress.size());
|
||||||
for (Map.Entry<String, Long> criterion : advancementProgress.entrySet()) {
|
for (Map.Entry<String, Long> criterion : advancementProgress.entrySet()) {
|
||||||
out.writeString(criterion.getKey());
|
helper.writeString(out, criterion.getKey());
|
||||||
if (criterion.getValue() != -1) {
|
if (criterion.getValue() != -1) {
|
||||||
out.writeBoolean(true);
|
out.writeBoolean(true);
|
||||||
out.writeLong(criterion.getValue());
|
out.writeLong(criterion.getValue());
|
||||||
|
|
|
@ -1,20 +1,15 @@
|
||||||
package com.github.steveice10.mc.protocol.packet.ingame.clientbound;
|
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.MagicValues;
|
import com.github.steveice10.mc.protocol.data.MagicValues;
|
||||||
import com.github.steveice10.mc.protocol.data.game.Identifier;
|
import com.github.steveice10.mc.protocol.data.game.Identifier;
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
|
import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
|
||||||
import com.github.steveice10.mc.protocol.data.game.recipe.Ingredient;
|
import com.github.steveice10.mc.protocol.data.game.recipe.Ingredient;
|
||||||
import com.github.steveice10.mc.protocol.data.game.recipe.Recipe;
|
import com.github.steveice10.mc.protocol.data.game.recipe.Recipe;
|
||||||
import com.github.steveice10.mc.protocol.data.game.recipe.RecipeType;
|
import com.github.steveice10.mc.protocol.data.game.recipe.RecipeType;
|
||||||
import com.github.steveice10.mc.protocol.data.game.recipe.data.CookedRecipeData;
|
import com.github.steveice10.mc.protocol.data.game.recipe.data.*;
|
||||||
import com.github.steveice10.mc.protocol.data.game.recipe.data.RecipeData;
|
import io.netty.buffer.ByteBuf;
|
||||||
import com.github.steveice10.mc.protocol.data.game.recipe.data.ShapedRecipeData;
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.recipe.data.ShapelessRecipeData;
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.recipe.data.SmithingRecipeData;
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.recipe.data.StoneCuttingRecipeData;
|
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
|
||||||
import com.github.steveice10.packetlib.packet.Packet;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
|
@ -25,38 +20,38 @@ import java.io.IOException;
|
||||||
@Data
|
@Data
|
||||||
@With
|
@With
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class ClientboundUpdateRecipesPacket implements Packet {
|
public class ClientboundUpdateRecipesPacket implements MinecraftPacket {
|
||||||
private final @NonNull Recipe[] recipes;
|
private final @NonNull Recipe[] recipes;
|
||||||
|
|
||||||
public ClientboundUpdateRecipesPacket(NetInput in) throws IOException {
|
public ClientboundUpdateRecipesPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||||
this.recipes = new Recipe[in.readVarInt()];
|
this.recipes = new Recipe[helper.readVarInt(in)];
|
||||||
for (int i = 0; i < this.recipes.length; i++) {
|
for (int i = 0; i < this.recipes.length; i++) {
|
||||||
RecipeType type = MagicValues.key(RecipeType.class, Identifier.formalize(in.readString()));
|
RecipeType type = MagicValues.key(RecipeType.class, Identifier.formalize(helper.readString(in)));
|
||||||
String identifier = in.readString();
|
String identifier = helper.readString(in);
|
||||||
RecipeData data = null;
|
RecipeData data = null;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case CRAFTING_SHAPELESS: {
|
case CRAFTING_SHAPELESS: {
|
||||||
String group = in.readString();
|
String group = helper.readString(in);
|
||||||
Ingredient[] ingredients = new Ingredient[in.readVarInt()];
|
Ingredient[] ingredients = new Ingredient[helper.readVarInt(in)];
|
||||||
for (int j = 0; j < ingredients.length; j++) {
|
for (int j = 0; j < ingredients.length; j++) {
|
||||||
ingredients[j] = this.readIngredient(in);
|
ingredients[j] = helper.readRecipeIngredient(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemStack result = ItemStack.read(in);
|
ItemStack result = helper.readItemStack(in);
|
||||||
|
|
||||||
data = new ShapelessRecipeData(group, ingredients, result);
|
data = new ShapelessRecipeData(group, ingredients, result);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CRAFTING_SHAPED: {
|
case CRAFTING_SHAPED: {
|
||||||
int width = in.readVarInt();
|
int width = helper.readVarInt(in);
|
||||||
int height = in.readVarInt();
|
int height = helper.readVarInt(in);
|
||||||
String group = in.readString();
|
String group = helper.readString(in);
|
||||||
Ingredient[] ingredients = new Ingredient[width * height];
|
Ingredient[] ingredients = new Ingredient[width * height];
|
||||||
for (int j = 0; j < ingredients.length; j++) {
|
for (int j = 0; j < ingredients.length; j++) {
|
||||||
ingredients[j] = this.readIngredient(in);
|
ingredients[j] = helper.readRecipeIngredient(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemStack result = ItemStack.read(in);
|
ItemStack result = helper.readItemStack(in);
|
||||||
|
|
||||||
data = new ShapedRecipeData(width, height, group, ingredients, result);
|
data = new ShapedRecipeData(width, height, group, ingredients, result);
|
||||||
break;
|
break;
|
||||||
|
@ -65,27 +60,27 @@ public class ClientboundUpdateRecipesPacket implements Packet {
|
||||||
case BLASTING:
|
case BLASTING:
|
||||||
case SMOKING:
|
case SMOKING:
|
||||||
case CAMPFIRE_COOKING: {
|
case CAMPFIRE_COOKING: {
|
||||||
String group = in.readString();
|
String group = helper.readString(in);
|
||||||
Ingredient ingredient = this.readIngredient(in);
|
Ingredient ingredient = helper.readRecipeIngredient(in);
|
||||||
ItemStack result = ItemStack.read(in);
|
ItemStack result = helper.readItemStack(in);
|
||||||
float experience = in.readFloat();
|
float experience = in.readFloat();
|
||||||
int cookingTime = in.readVarInt();
|
int cookingTime = helper.readVarInt(in);
|
||||||
|
|
||||||
data = new CookedRecipeData(group, ingredient, result, experience, cookingTime);
|
data = new CookedRecipeData(group, ingredient, result, experience, cookingTime);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case STONECUTTING: {
|
case STONECUTTING: {
|
||||||
String group = in.readString();
|
String group = helper.readString(in);
|
||||||
Ingredient ingredient = this.readIngredient(in);
|
Ingredient ingredient = helper.readRecipeIngredient(in);
|
||||||
ItemStack result = ItemStack.read(in);
|
ItemStack result = helper.readItemStack(in);
|
||||||
|
|
||||||
data = new StoneCuttingRecipeData(group, ingredient, result);
|
data = new StoneCuttingRecipeData(group, ingredient, result);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SMITHING: {
|
case SMITHING: {
|
||||||
Ingredient base = this.readIngredient(in);
|
Ingredient base = helper.readRecipeIngredient(in);
|
||||||
Ingredient addition = this.readIngredient(in);
|
Ingredient addition = helper.readRecipeIngredient(in);
|
||||||
ItemStack result = ItemStack.read(in);
|
ItemStack result = helper.readItemStack(in);
|
||||||
|
|
||||||
data = new SmithingRecipeData(base, addition, result);
|
data = new SmithingRecipeData(base, addition, result);
|
||||||
break;
|
break;
|
||||||
|
@ -98,32 +93,23 @@ public class ClientboundUpdateRecipesPacket implements Packet {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Ingredient readIngredient(NetInput in) throws IOException {
|
|
||||||
ItemStack[] options = new ItemStack[in.readVarInt()];
|
|
||||||
for (int i = 0; i < options.length; i++) {
|
|
||||||
options[i] = ItemStack.read(in);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Ingredient(options);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(NetOutput out) throws IOException {
|
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||||
out.writeVarInt(this.recipes.length);
|
helper.writeVarInt(out, this.recipes.length);
|
||||||
for (Recipe recipe : this.recipes) {
|
for (Recipe recipe : this.recipes) {
|
||||||
out.writeString(MagicValues.value(String.class, recipe.getType()));
|
helper.writeString(out, MagicValues.value(String.class, recipe.getType()));
|
||||||
out.writeString(recipe.getIdentifier());
|
helper.writeString(out, recipe.getIdentifier());
|
||||||
switch (recipe.getType()) {
|
switch (recipe.getType()) {
|
||||||
case CRAFTING_SHAPELESS: {
|
case CRAFTING_SHAPELESS: {
|
||||||
ShapelessRecipeData data = (ShapelessRecipeData) recipe.getData();
|
ShapelessRecipeData data = (ShapelessRecipeData) recipe.getData();
|
||||||
|
|
||||||
out.writeString(data.getGroup());
|
helper.writeString(out, data.getGroup());
|
||||||
out.writeVarInt(data.getIngredients().length);
|
helper.writeVarInt(out, data.getIngredients().length);
|
||||||
for (Ingredient ingredient : data.getIngredients()) {
|
for (Ingredient ingredient : data.getIngredients()) {
|
||||||
this.writeIngredient(out, ingredient);
|
helper.writeRecipeIngredient(out, ingredient);
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemStack.write(out, data.getResult());
|
helper.writeItemStack(out, data.getResult());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CRAFTING_SHAPED: {
|
case CRAFTING_SHAPED: {
|
||||||
|
@ -132,14 +118,14 @@ public class ClientboundUpdateRecipesPacket implements Packet {
|
||||||
throw new IllegalStateException("Shaped recipe must have ingredient count equal to width * height.");
|
throw new IllegalStateException("Shaped recipe must have ingredient count equal to width * height.");
|
||||||
}
|
}
|
||||||
|
|
||||||
out.writeVarInt(data.getWidth());
|
helper.writeVarInt(out, data.getWidth());
|
||||||
out.writeVarInt(data.getHeight());
|
helper.writeVarInt(out, data.getHeight());
|
||||||
out.writeString(data.getGroup());
|
helper.writeString(out, data.getGroup());
|
||||||
for (Ingredient ingredient : data.getIngredients()) {
|
for (Ingredient ingredient : data.getIngredients()) {
|
||||||
this.writeIngredient(out, ingredient);
|
helper.writeRecipeIngredient(out, ingredient);
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemStack.write(out, data.getResult());
|
helper.writeItemStack(out, data.getResult());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SMELTING:
|
case SMELTING:
|
||||||
|
@ -148,27 +134,27 @@ public class ClientboundUpdateRecipesPacket implements Packet {
|
||||||
case CAMPFIRE_COOKING: {
|
case CAMPFIRE_COOKING: {
|
||||||
CookedRecipeData data = (CookedRecipeData) recipe.getData();
|
CookedRecipeData data = (CookedRecipeData) recipe.getData();
|
||||||
|
|
||||||
out.writeString(data.getGroup());
|
helper.writeString(out, data.getGroup());
|
||||||
this.writeIngredient(out, data.getIngredient());
|
helper.writeRecipeIngredient(out, data.getIngredient());
|
||||||
ItemStack.write(out, data.getResult());
|
helper.writeItemStack(out, data.getResult());
|
||||||
out.writeFloat(data.getExperience());
|
out.writeFloat(data.getExperience());
|
||||||
out.writeVarInt(data.getCookingTime());
|
helper.writeVarInt(out, data.getCookingTime());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case STONECUTTING: {
|
case STONECUTTING: {
|
||||||
StoneCuttingRecipeData data = (StoneCuttingRecipeData) recipe.getData();
|
StoneCuttingRecipeData data = (StoneCuttingRecipeData) recipe.getData();
|
||||||
|
|
||||||
out.writeString(data.getGroup());
|
helper.writeString(out, data.getGroup());
|
||||||
this.writeIngredient(out, data.getIngredient());
|
helper.writeRecipeIngredient(out, data.getIngredient());
|
||||||
ItemStack.write(out, data.getResult());
|
helper.writeItemStack(out, data.getResult());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SMITHING: {
|
case SMITHING: {
|
||||||
SmithingRecipeData data = (SmithingRecipeData) recipe.getData();
|
SmithingRecipeData data = (SmithingRecipeData) recipe.getData();
|
||||||
|
|
||||||
this.writeIngredient(out, data.getBase());
|
helper.writeRecipeIngredient(out, data.getBase());
|
||||||
this.writeIngredient(out, data.getAddition());
|
helper.writeRecipeIngredient(out, data.getAddition());
|
||||||
ItemStack.write(out, data.getResult());
|
helper.writeItemStack(out, data.getResult());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
@ -176,11 +162,4 @@ public class ClientboundUpdateRecipesPacket implements Packet {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeIngredient(NetOutput out, Ingredient ingredient) throws IOException {
|
|
||||||
out.writeVarInt(ingredient.getOptions().length);
|
|
||||||
for (ItemStack option : ingredient.getOptions()) {
|
|
||||||
ItemStack.write(out, option);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package com.github.steveice10.mc.protocol.packet.ingame.clientbound;
|
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.Identifier;
|
import com.github.steveice10.mc.protocol.data.game.Identifier;
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
import io.netty.buffer.ByteBuf;
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
|
||||||
import com.github.steveice10.packetlib.packet.Packet;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
|
@ -16,21 +16,21 @@ import java.util.Map;
|
||||||
@Data
|
@Data
|
||||||
@With
|
@With
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class ClientboundUpdateTagsPacket implements Packet {
|
public class ClientboundUpdateTagsPacket implements MinecraftPacket {
|
||||||
private final @NonNull Map<String, Map<String, int[]>> tags = new HashMap<>();
|
private final @NonNull Map<String, Map<String, int[]>> tags = new HashMap<>();
|
||||||
|
|
||||||
public ClientboundUpdateTagsPacket(NetInput in) throws IOException {
|
public ClientboundUpdateTagsPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||||
int totalTagCount = in.readVarInt();
|
int totalTagCount = helper.readVarInt(in);
|
||||||
for (int i = 0; i < totalTagCount; i++) {
|
for (int i = 0; i < totalTagCount; i++) {
|
||||||
Map<String, int[]> tag = new HashMap<>();
|
Map<String, int[]> tag = new HashMap<>();
|
||||||
String tagName = Identifier.formalize(in.readString());
|
String tagName = Identifier.formalize(helper.readString(in));
|
||||||
int tagsCount = in.readVarInt();
|
int tagsCount = helper.readVarInt(in);
|
||||||
for (int j = 0; j < tagsCount; j++) {
|
for (int j = 0; j < tagsCount; j++) {
|
||||||
String name = in.readString();
|
String name = helper.readString(in);
|
||||||
int entriesCount = in.readVarInt();
|
int entriesCount = helper.readVarInt(in);
|
||||||
int[] entries = new int[entriesCount];
|
int[] entries = new int[entriesCount];
|
||||||
for (int index = 0; index < entriesCount; index++) {
|
for (int index = 0; index < entriesCount; index++) {
|
||||||
entries[index] = in.readVarInt();
|
entries[index] = helper.readVarInt(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
tag.put(name, entries);
|
tag.put(name, entries);
|
||||||
|
@ -40,16 +40,16 @@ public class ClientboundUpdateTagsPacket implements Packet {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(NetOutput out) throws IOException {
|
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||||
out.writeVarInt(tags.size());
|
helper.writeVarInt(out, tags.size());
|
||||||
for (Map.Entry<String, Map<String, int[]>> tagSet : tags.entrySet()) {
|
for (Map.Entry<String, Map<String, int[]>> tagSet : tags.entrySet()) {
|
||||||
out.writeString(tagSet.getKey());
|
helper.writeString(out, tagSet.getKey());
|
||||||
out.writeVarInt(tagSet.getValue().size());
|
helper.writeVarInt(out, tagSet.getValue().size());
|
||||||
for (Map.Entry<String, int[]> tag : tagSet.getValue().entrySet()) {
|
for (Map.Entry<String, int[]> tag : tagSet.getValue().entrySet()) {
|
||||||
out.writeString(tag.getKey());
|
helper.writeString(out, tag.getKey());
|
||||||
out.writeVarInt(tag.getValue().length);
|
helper.writeVarInt(out, tag.getValue().length);
|
||||||
for (int id : tag.getValue()) {
|
for (int id : tag.getValue()) {
|
||||||
out.writeVarInt(id);
|
helper.writeVarInt(out, id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
package com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity;
|
package com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity;
|
||||||
|
|
||||||
|
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
|
||||||
|
import com.github.steveice10.mc.protocol.codec.MinecraftPacket;
|
||||||
import com.github.steveice10.mc.protocol.data.MagicValues;
|
import com.github.steveice10.mc.protocol.data.MagicValues;
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.player.Animation;
|
import com.github.steveice10.mc.protocol.data.game.entity.player.Animation;
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
import io.netty.buffer.ByteBuf;
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
|
||||||
import com.github.steveice10.packetlib.packet.Packet;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
|
@ -15,18 +15,18 @@ import java.io.IOException;
|
||||||
@Data
|
@Data
|
||||||
@With
|
@With
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class ClientboundAnimatePacket implements Packet {
|
public class ClientboundAnimatePacket implements MinecraftPacket {
|
||||||
private final int entityId;
|
private final int entityId;
|
||||||
private final @NonNull Animation animation;
|
private final @NonNull Animation animation;
|
||||||
|
|
||||||
public ClientboundAnimatePacket(NetInput in) throws IOException {
|
public ClientboundAnimatePacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||||
this.entityId = in.readVarInt();
|
this.entityId = helper.readVarInt(in);
|
||||||
this.animation = MagicValues.key(Animation.class, in.readUnsignedByte());
|
this.animation = MagicValues.key(Animation.class, in.readUnsignedByte());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(NetOutput out) throws IOException {
|
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||||
out.writeVarInt(this.entityId);
|
helper.writeVarInt(out, this.entityId);
|
||||||
out.writeByte(MagicValues.value(Integer.class, this.animation));
|
out.writeByte(MagicValues.value(Integer.class, this.animation));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity;
|
package com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity;
|
||||||
|
|
||||||
|
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
|
||||||
|
import com.github.steveice10.mc.protocol.codec.MinecraftPacket;
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.EntityEvent;
|
import com.github.steveice10.mc.protocol.data.game.entity.EntityEvent;
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
import io.netty.buffer.ByteBuf;
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
|
||||||
import com.github.steveice10.packetlib.packet.Packet;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
|
@ -14,18 +14,18 @@ import java.io.IOException;
|
||||||
@Data
|
@Data
|
||||||
@With
|
@With
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class ClientboundEntityEventPacket implements Packet {
|
public class ClientboundEntityEventPacket implements MinecraftPacket {
|
||||||
private final int entityId;
|
private final int entityId;
|
||||||
private final @NonNull EntityEvent status;
|
private final @NonNull EntityEvent event;
|
||||||
|
|
||||||
public ClientboundEntityEventPacket(NetInput in) throws IOException {
|
public ClientboundEntityEventPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||||
this.entityId = in.readInt();
|
this.entityId = in.readInt();
|
||||||
this.status = EntityEvent.read(in);
|
this.event = helper.readEntityEvent(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(NetOutput out) throws IOException {
|
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||||
out.writeInt(this.entityId);
|
out.writeInt(this.entityId);
|
||||||
out.writeByte(this.status.ordinal());
|
helper.writeEntityEvent(out, this.event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity;
|
package com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity;
|
||||||
|
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
import com.github.steveice10.mc.protocol.codec.MinecraftPacket;
|
||||||
import com.github.steveice10.packetlib.packet.Packet;
|
import io.netty.buffer.ByteBuf;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.With;
|
import lombok.With;
|
||||||
|
@ -12,15 +12,15 @@ import java.io.IOException;
|
||||||
@Data
|
@Data
|
||||||
@With
|
@With
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class ClientboundMoveEntityPosPacket implements Packet {
|
public class ClientboundMoveEntityPosPacket implements MinecraftPacket {
|
||||||
private final int entityId;
|
private final int entityId;
|
||||||
private final double moveX;
|
private final double moveX;
|
||||||
private final double moveY;
|
private final double moveY;
|
||||||
private final double moveZ;
|
private final double moveZ;
|
||||||
private final boolean onGround;
|
private final boolean onGround;
|
||||||
|
|
||||||
public ClientboundMoveEntityPosPacket(NetInput in) throws IOException {
|
public ClientboundMoveEntityPosPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||||
this.entityId = in.readVarInt();
|
this.entityId = helper.readVarInt(in);
|
||||||
this.moveX = in.readShort() / 4096D;
|
this.moveX = in.readShort() / 4096D;
|
||||||
this.moveY = in.readShort() / 4096D;
|
this.moveY = in.readShort() / 4096D;
|
||||||
this.moveZ = in.readShort() / 4096D;
|
this.moveZ = in.readShort() / 4096D;
|
||||||
|
@ -28,8 +28,8 @@ public class ClientboundMoveEntityPosPacket implements Packet {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(NetOutput out) throws IOException {
|
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||||
out.writeVarInt(this.entityId);
|
helper.writeVarInt(out, this.entityId);
|
||||||
out.writeShort((int) (this.moveX * 4096));
|
out.writeShort((int) (this.moveX * 4096));
|
||||||
out.writeShort((int) (this.moveY * 4096));
|
out.writeShort((int) (this.moveY * 4096));
|
||||||
out.writeShort((int) (this.moveZ * 4096));
|
out.writeShort((int) (this.moveZ * 4096));
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity;
|
package com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity;
|
||||||
|
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
import com.github.steveice10.mc.protocol.codec.MinecraftPacket;
|
||||||
import com.github.steveice10.packetlib.packet.Packet;
|
import io.netty.buffer.ByteBuf;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.With;
|
import lombok.With;
|
||||||
|
@ -12,7 +12,7 @@ import java.io.IOException;
|
||||||
@Data
|
@Data
|
||||||
@With
|
@With
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class ClientboundMoveEntityPosRotPacket implements Packet {
|
public class ClientboundMoveEntityPosRotPacket implements MinecraftPacket {
|
||||||
private final int entityId;
|
private final int entityId;
|
||||||
private final double moveX;
|
private final double moveX;
|
||||||
private final double moveY;
|
private final double moveY;
|
||||||
|
@ -21,8 +21,8 @@ public class ClientboundMoveEntityPosRotPacket implements Packet {
|
||||||
private final float pitch;
|
private final float pitch;
|
||||||
private final boolean onGround;
|
private final boolean onGround;
|
||||||
|
|
||||||
public ClientboundMoveEntityPosRotPacket(NetInput in) throws IOException {
|
public ClientboundMoveEntityPosRotPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||||
this.entityId = in.readVarInt();
|
this.entityId = helper.readVarInt(in);
|
||||||
this.moveX = in.readShort() / 4096D;
|
this.moveX = in.readShort() / 4096D;
|
||||||
this.moveY = in.readShort() / 4096D;
|
this.moveY = in.readShort() / 4096D;
|
||||||
this.moveZ = in.readShort() / 4096D;
|
this.moveZ = in.readShort() / 4096D;
|
||||||
|
@ -32,8 +32,8 @@ public class ClientboundMoveEntityPosRotPacket implements Packet {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(NetOutput out) throws IOException {
|
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||||
out.writeVarInt(this.entityId);
|
helper.writeVarInt(out, this.entityId);
|
||||||
out.writeShort((int) (this.moveX * 4096));
|
out.writeShort((int) (this.moveX * 4096));
|
||||||
out.writeShort((int) (this.moveY * 4096));
|
out.writeShort((int) (this.moveY * 4096));
|
||||||
out.writeShort((int) (this.moveZ * 4096));
|
out.writeShort((int) (this.moveZ * 4096));
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity;
|
package com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity;
|
||||||
|
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
import com.github.steveice10.mc.protocol.codec.MinecraftPacket;
|
||||||
import com.github.steveice10.packetlib.packet.Packet;
|
import io.netty.buffer.ByteBuf;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.With;
|
import lombok.With;
|
||||||
|
@ -12,22 +12,22 @@ import java.io.IOException;
|
||||||
@Data
|
@Data
|
||||||
@With
|
@With
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class ClientboundMoveEntityRotPacket implements Packet {
|
public class ClientboundMoveEntityRotPacket implements MinecraftPacket {
|
||||||
private final int entityId;
|
private final int entityId;
|
||||||
private final float yaw;
|
private final float yaw;
|
||||||
private final float pitch;
|
private final float pitch;
|
||||||
private final boolean onGround;
|
private final boolean onGround;
|
||||||
|
|
||||||
public ClientboundMoveEntityRotPacket(NetInput in) throws IOException {
|
public ClientboundMoveEntityRotPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||||
this.entityId = in.readVarInt();
|
this.entityId = helper.readVarInt(in);
|
||||||
this.yaw = in.readByte() * 360 / 256f;
|
this.yaw = in.readByte() * 360 / 256f;
|
||||||
this.pitch = in.readByte() * 360 / 256f;
|
this.pitch = in.readByte() * 360 / 256f;
|
||||||
this.onGround = in.readBoolean();
|
this.onGround = in.readBoolean();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(NetOutput out) throws IOException {
|
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||||
out.writeVarInt(this.entityId);
|
helper.writeVarInt(out, this.entityId);
|
||||||
out.writeByte((byte) (this.yaw * 256 / 360));
|
out.writeByte((byte) (this.yaw * 256 / 360));
|
||||||
out.writeByte((byte) (this.pitch * 256 / 360));
|
out.writeByte((byte) (this.pitch * 256 / 360));
|
||||||
out.writeBoolean(this.onGround);
|
out.writeBoolean(this.onGround);
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity;
|
package com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity;
|
||||||
|
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
import com.github.steveice10.mc.protocol.codec.MinecraftPacket;
|
||||||
import com.github.steveice10.packetlib.packet.Packet;
|
import io.netty.buffer.ByteBuf;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.With;
|
import lombok.With;
|
||||||
|
@ -12,14 +12,14 @@ import java.io.IOException;
|
||||||
@Data
|
@Data
|
||||||
@With
|
@With
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class ClientboundMoveVehiclePacket implements Packet {
|
public class ClientboundMoveVehiclePacket implements MinecraftPacket {
|
||||||
private final double x;
|
private final double x;
|
||||||
private final double y;
|
private final double y;
|
||||||
private final double z;
|
private final double z;
|
||||||
private final float yaw;
|
private final float yaw;
|
||||||
private final float pitch;
|
private final float pitch;
|
||||||
|
|
||||||
public ClientboundMoveVehiclePacket(NetInput in) throws IOException {
|
public ClientboundMoveVehiclePacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||||
this.x = in.readDouble();
|
this.x = in.readDouble();
|
||||||
this.y = in.readDouble();
|
this.y = in.readDouble();
|
||||||
this.z = in.readDouble();
|
this.z = in.readDouble();
|
||||||
|
@ -28,7 +28,7 @@ public class ClientboundMoveVehiclePacket implements Packet {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(NetOutput out) throws IOException {
|
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||||
out.writeDouble(this.x);
|
out.writeDouble(this.x);
|
||||||
out.writeDouble(this.y);
|
out.writeDouble(this.y);
|
||||||
out.writeDouble(this.z);
|
out.writeDouble(this.z);
|
||||||
|
|
|
@ -1,33 +1,33 @@
|
||||||
package com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity;
|
package com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity;
|
||||||
|
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
import com.github.steveice10.mc.protocol.codec.MinecraftPacket;
|
||||||
import com.github.steveice10.packetlib.packet.Packet;
|
import io.netty.buffer.ByteBuf;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.With;
|
import lombok.With;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@With
|
@With
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class ClientboundRemoveEntitiesPacket implements Packet {
|
public class ClientboundRemoveEntitiesPacket implements MinecraftPacket {
|
||||||
private final @Nonnull int[] entityIds;
|
private final @NotNull int[] entityIds;
|
||||||
|
|
||||||
public ClientboundRemoveEntitiesPacket(NetInput in) throws IOException {
|
public ClientboundRemoveEntitiesPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||||
this.entityIds = new int[in.readVarInt()];
|
this.entityIds = new int[helper.readVarInt(in)];
|
||||||
for (int i = 0; i < this.entityIds.length; i++) {
|
for (int i = 0; i < this.entityIds.length; i++) {
|
||||||
this.entityIds[i] = in.readVarInt();
|
this.entityIds[i] = helper.readVarInt(in);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(NetOutput out) throws IOException {
|
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||||
out.writeVarInt(this.entityIds.length);
|
helper.writeVarInt(out, this.entityIds.length);
|
||||||
for (int entityId : this.entityIds) {
|
for (int entityId : this.entityIds) {
|
||||||
out.writeVarInt(entityId);
|
helper.writeVarInt(out, entityId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity;
|
package com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity;
|
||||||
|
|
||||||
|
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
|
||||||
|
import com.github.steveice10.mc.protocol.codec.MinecraftPacket;
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.Effect;
|
import com.github.steveice10.mc.protocol.data.game.entity.Effect;
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
import io.netty.buffer.ByteBuf;
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
|
||||||
import com.github.steveice10.packetlib.packet.Packet;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
|
@ -14,18 +14,18 @@ import java.io.IOException;
|
||||||
@Data
|
@Data
|
||||||
@With
|
@With
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class ClientboundRemoveMobEffectPacket implements Packet {
|
public class ClientboundRemoveMobEffectPacket implements MinecraftPacket {
|
||||||
private final int entityId;
|
private final int entityId;
|
||||||
private final @NonNull Effect effect;
|
private final @NonNull Effect effect;
|
||||||
|
|
||||||
public ClientboundRemoveMobEffectPacket(NetInput in) throws IOException {
|
public ClientboundRemoveMobEffectPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||||
this.entityId = in.readVarInt();
|
this.entityId = helper.readVarInt(in);
|
||||||
this.effect = Effect.fromNetworkId(in.readVarInt());
|
this.effect = helper.readEffect(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(NetOutput out) throws IOException {
|
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||||
out.writeVarInt(this.entityId);
|
helper.writeVarInt(out, this.entityId);
|
||||||
out.writeVarInt(Effect.toNetworkId(this.effect));
|
helper.writeEffect(out, this.effect);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity;
|
package com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity;
|
||||||
|
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
import com.github.steveice10.mc.protocol.codec.MinecraftPacket;
|
||||||
import com.github.steveice10.packetlib.packet.Packet;
|
import io.netty.buffer.ByteBuf;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.With;
|
import lombok.With;
|
||||||
|
@ -12,18 +12,18 @@ import java.io.IOException;
|
||||||
@Data
|
@Data
|
||||||
@With
|
@With
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class ClientboundRotateHeadPacket implements Packet {
|
public class ClientboundRotateHeadPacket implements MinecraftPacket {
|
||||||
private final int entityId;
|
private final int entityId;
|
||||||
private final float headYaw;
|
private final float headYaw;
|
||||||
|
|
||||||
public ClientboundRotateHeadPacket(NetInput in) throws IOException {
|
public ClientboundRotateHeadPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||||
this.entityId = in.readVarInt();
|
this.entityId = helper.readVarInt(in);
|
||||||
this.headYaw = in.readByte() * 360 / 256f;
|
this.headYaw = in.readByte() * 360 / 256f;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(NetOutput out) throws IOException {
|
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||||
out.writeVarInt(this.entityId);
|
helper.writeVarInt(out, this.entityId);
|
||||||
out.writeByte((byte) (this.headYaw * 256 / 360));
|
out.writeByte((byte) (this.headYaw * 256 / 360));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity;
|
package com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity;
|
||||||
|
|
||||||
|
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
|
||||||
|
import com.github.steveice10.mc.protocol.codec.MinecraftPacket;
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
|
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
import io.netty.buffer.ByteBuf;
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
|
||||||
import com.github.steveice10.packetlib.packet.Packet;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
|
@ -14,18 +14,18 @@ import java.io.IOException;
|
||||||
@Data
|
@Data
|
||||||
@With
|
@With
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class ClientboundSetEntityDataPacket implements Packet {
|
public class ClientboundSetEntityDataPacket implements MinecraftPacket {
|
||||||
private final int entityId;
|
private final int entityId;
|
||||||
private final @NonNull EntityMetadata<?, ?>[] metadata;
|
private final @NonNull EntityMetadata<?, ?>[] metadata;
|
||||||
|
|
||||||
public ClientboundSetEntityDataPacket(NetInput in) throws IOException {
|
public ClientboundSetEntityDataPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||||
this.entityId = in.readVarInt();
|
this.entityId = helper.readVarInt(in);
|
||||||
this.metadata = EntityMetadata.read(in);
|
this.metadata = helper.readEntityMetadata(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(NetOutput out) throws IOException {
|
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||||
out.writeVarInt(this.entityId);
|
helper.writeVarInt(out, this.entityId);
|
||||||
EntityMetadata.write(out, this.metadata);
|
helper.writeEntityMetadata(out, this.metadata);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity;
|
package com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity;
|
||||||
|
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
import com.github.steveice10.mc.protocol.codec.MinecraftPacket;
|
||||||
import com.github.steveice10.packetlib.packet.Packet;
|
import io.netty.buffer.ByteBuf;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.With;
|
import lombok.With;
|
||||||
|
@ -12,17 +12,17 @@ import java.io.IOException;
|
||||||
@Data
|
@Data
|
||||||
@With
|
@With
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class ClientboundSetEntityLinkPacket implements Packet {
|
public class ClientboundSetEntityLinkPacket implements MinecraftPacket {
|
||||||
private final int entityId;
|
private final int entityId;
|
||||||
private final int attachedToId;
|
private final int attachedToId;
|
||||||
|
|
||||||
public ClientboundSetEntityLinkPacket(NetInput in) throws IOException {
|
public ClientboundSetEntityLinkPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||||
this.entityId = in.readInt();
|
this.entityId = in.readInt();
|
||||||
this.attachedToId = in.readInt();
|
this.attachedToId = in.readInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(NetOutput out) throws IOException {
|
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||||
out.writeInt(this.entityId);
|
out.writeInt(this.entityId);
|
||||||
out.writeInt(this.attachedToId);
|
out.writeInt(this.attachedToId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity;
|
package com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity;
|
||||||
|
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
import com.github.steveice10.mc.protocol.codec.MinecraftPacket;
|
||||||
import com.github.steveice10.packetlib.packet.Packet;
|
import io.netty.buffer.ByteBuf;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.With;
|
import lombok.With;
|
||||||
|
@ -12,22 +12,22 @@ import java.io.IOException;
|
||||||
@Data
|
@Data
|
||||||
@With
|
@With
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class ClientboundSetEntityMotionPacket implements Packet {
|
public class ClientboundSetEntityMotionPacket implements MinecraftPacket {
|
||||||
private final int entityId;
|
private final int entityId;
|
||||||
private final double motionX;
|
private final double motionX;
|
||||||
private final double motionY;
|
private final double motionY;
|
||||||
private final double motionZ;
|
private final double motionZ;
|
||||||
|
|
||||||
public ClientboundSetEntityMotionPacket(NetInput in) throws IOException {
|
public ClientboundSetEntityMotionPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||||
this.entityId = in.readVarInt();
|
this.entityId = helper.readVarInt(in);
|
||||||
this.motionX = in.readShort() / 8000D;
|
this.motionX = in.readShort() / 8000D;
|
||||||
this.motionY = in.readShort() / 8000D;
|
this.motionY = in.readShort() / 8000D;
|
||||||
this.motionZ = in.readShort() / 8000D;
|
this.motionZ = in.readShort() / 8000D;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(NetOutput out) throws IOException {
|
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||||
out.writeVarInt(this.entityId);
|
helper.writeVarInt(out, this.entityId);
|
||||||
out.writeShort((int) (this.motionX * 8000));
|
out.writeShort((int) (this.motionX * 8000));
|
||||||
out.writeShort((int) (this.motionY * 8000));
|
out.writeShort((int) (this.motionY * 8000));
|
||||||
out.writeShort((int) (this.motionZ * 8000));
|
out.writeShort((int) (this.motionZ * 8000));
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
package com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity;
|
package com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity;
|
||||||
|
|
||||||
|
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
|
||||||
|
import com.github.steveice10.mc.protocol.codec.MinecraftPacket;
|
||||||
import com.github.steveice10.mc.protocol.data.MagicValues;
|
import com.github.steveice10.mc.protocol.data.MagicValues;
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.EquipmentSlot;
|
import com.github.steveice10.mc.protocol.data.game.entity.EquipmentSlot;
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Equipment;
|
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Equipment;
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
|
import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
import io.netty.buffer.ByteBuf;
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
|
||||||
import com.github.steveice10.packetlib.packet.Packet;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
|
@ -19,18 +19,18 @@ import java.util.List;
|
||||||
@Data
|
@Data
|
||||||
@With
|
@With
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class ClientboundSetEquipmentPacket implements Packet {
|
public class ClientboundSetEquipmentPacket implements MinecraftPacket {
|
||||||
private final int entityId;
|
private final int entityId;
|
||||||
private final @NonNull Equipment[] equipment;
|
private final @NonNull Equipment[] equipment;
|
||||||
|
|
||||||
public ClientboundSetEquipmentPacket(NetInput in) throws IOException {
|
public ClientboundSetEquipmentPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||||
this.entityId = in.readVarInt();
|
this.entityId = helper.readVarInt(in);
|
||||||
boolean hasNextEntry = true;
|
boolean hasNextEntry = true;
|
||||||
List<Equipment> list = new ArrayList<>();
|
List<Equipment> list = new ArrayList<>();
|
||||||
while (hasNextEntry) {
|
while (hasNextEntry) {
|
||||||
int rawSlot = in.readByte();
|
int rawSlot = in.readByte();
|
||||||
EquipmentSlot slot = MagicValues.key(EquipmentSlot.class, ((byte) rawSlot) & 127);
|
EquipmentSlot slot = MagicValues.key(EquipmentSlot.class, ((byte) rawSlot) & 127);
|
||||||
ItemStack item = ItemStack.read(in);
|
ItemStack item = helper.readItemStack(in);
|
||||||
list.add(new Equipment(slot, item));
|
list.add(new Equipment(slot, item));
|
||||||
hasNextEntry = (rawSlot & 128) == 128;
|
hasNextEntry = (rawSlot & 128) == 128;
|
||||||
}
|
}
|
||||||
|
@ -38,15 +38,15 @@ public class ClientboundSetEquipmentPacket implements Packet {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(NetOutput out) throws IOException {
|
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||||
out.writeVarInt(this.entityId);
|
helper.writeVarInt(out, this.entityId);
|
||||||
for (int i = 0; i < this.equipment.length; i++) {
|
for (int i = 0; i < this.equipment.length; i++) {
|
||||||
int rawSlot = MagicValues.value(Integer.class, this.equipment[i].getSlot());
|
int rawSlot = MagicValues.value(Integer.class, this.equipment[i].getSlot());
|
||||||
if (i != equipment.length - 1) {
|
if (i != equipment.length - 1) {
|
||||||
rawSlot = rawSlot | 128;
|
rawSlot = rawSlot | 128;
|
||||||
}
|
}
|
||||||
out.writeByte(rawSlot);
|
out.writeByte(rawSlot);
|
||||||
ItemStack.write(out, this.equipment[i].getItem());
|
helper.writeItemStack(out, this.equipment[i].getItem());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity;
|
package com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity;
|
||||||
|
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
import com.github.steveice10.mc.protocol.codec.MinecraftPacket;
|
||||||
import com.github.steveice10.packetlib.packet.Packet;
|
import io.netty.buffer.ByteBuf;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
|
@ -13,24 +13,24 @@ import java.io.IOException;
|
||||||
@Data
|
@Data
|
||||||
@With
|
@With
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class ClientboundSetPassengersPacket implements Packet {
|
public class ClientboundSetPassengersPacket implements MinecraftPacket {
|
||||||
private final int entityId;
|
private final int entityId;
|
||||||
private final @NonNull int[] passengerIds;
|
private final @NonNull int[] passengerIds;
|
||||||
|
|
||||||
public ClientboundSetPassengersPacket(NetInput in) throws IOException {
|
public ClientboundSetPassengersPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||||
this.entityId = in.readVarInt();
|
this.entityId = helper.readVarInt(in);
|
||||||
this.passengerIds = new int[in.readVarInt()];
|
this.passengerIds = new int[helper.readVarInt(in)];
|
||||||
for (int index = 0; index < this.passengerIds.length; index++) {
|
for (int index = 0; index < this.passengerIds.length; index++) {
|
||||||
this.passengerIds[index] = in.readVarInt();
|
this.passengerIds[index] = helper.readVarInt(in);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(NetOutput out) throws IOException {
|
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||||
out.writeVarInt(this.entityId);
|
helper.writeVarInt(out, this.entityId);
|
||||||
out.writeVarInt(this.passengerIds.length);
|
helper.writeVarInt(out, this.passengerIds.length);
|
||||||
for (int entityId : this.passengerIds) {
|
for (int entityId : this.passengerIds) {
|
||||||
out.writeVarInt(entityId);
|
helper.writeVarInt(out, entityId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity;
|
package com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity;
|
||||||
|
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
import com.github.steveice10.mc.protocol.codec.MinecraftPacket;
|
||||||
import com.github.steveice10.packetlib.packet.Packet;
|
import io.netty.buffer.ByteBuf;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.With;
|
import lombok.With;
|
||||||
|
@ -12,21 +12,21 @@ import java.io.IOException;
|
||||||
@Data
|
@Data
|
||||||
@With
|
@With
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class ClientboundTakeItemEntityPacket implements Packet {
|
public class ClientboundTakeItemEntityPacket implements MinecraftPacket {
|
||||||
private final int collectedEntityId;
|
private final int collectedEntityId;
|
||||||
private final int collectorEntityId;
|
private final int collectorEntityId;
|
||||||
private final int itemCount;
|
private final int itemCount;
|
||||||
|
|
||||||
public ClientboundTakeItemEntityPacket(NetInput in) throws IOException {
|
public ClientboundTakeItemEntityPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||||
this.collectedEntityId = in.readVarInt();
|
this.collectedEntityId = helper.readVarInt(in);
|
||||||
this.collectorEntityId = in.readVarInt();
|
this.collectorEntityId = helper.readVarInt(in);
|
||||||
this.itemCount = in.readVarInt();
|
this.itemCount = helper.readVarInt(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(NetOutput out) throws IOException {
|
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||||
out.writeVarInt(this.collectedEntityId);
|
helper.writeVarInt(out, this.collectedEntityId);
|
||||||
out.writeVarInt(this.collectorEntityId);
|
helper.writeVarInt(out, this.collectorEntityId);
|
||||||
out.writeVarInt(this.itemCount);
|
helper.writeVarInt(out, this.itemCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity;
|
package com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity;
|
||||||
|
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
import com.github.steveice10.mc.protocol.codec.MinecraftPacket;
|
||||||
import com.github.steveice10.packetlib.packet.Packet;
|
import io.netty.buffer.ByteBuf;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.With;
|
import lombok.With;
|
||||||
|
@ -12,7 +12,7 @@ import java.io.IOException;
|
||||||
@Data
|
@Data
|
||||||
@With
|
@With
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class ClientboundTeleportEntityPacket implements Packet {
|
public class ClientboundTeleportEntityPacket implements MinecraftPacket {
|
||||||
private final int entityId;
|
private final int entityId;
|
||||||
private final double x;
|
private final double x;
|
||||||
private final double y;
|
private final double y;
|
||||||
|
@ -21,8 +21,8 @@ public class ClientboundTeleportEntityPacket implements Packet {
|
||||||
private final float pitch;
|
private final float pitch;
|
||||||
private final boolean onGround;
|
private final boolean onGround;
|
||||||
|
|
||||||
public ClientboundTeleportEntityPacket(NetInput in) throws IOException {
|
public ClientboundTeleportEntityPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||||
this.entityId = in.readVarInt();
|
this.entityId = helper.readVarInt(in);
|
||||||
this.x = in.readDouble();
|
this.x = in.readDouble();
|
||||||
this.y = in.readDouble();
|
this.y = in.readDouble();
|
||||||
this.z = in.readDouble();
|
this.z = in.readDouble();
|
||||||
|
@ -32,8 +32,8 @@ public class ClientboundTeleportEntityPacket implements Packet {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(NetOutput out) throws IOException {
|
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||||
out.writeVarInt(this.entityId);
|
helper.writeVarInt(out, this.entityId);
|
||||||
out.writeDouble(this.x);
|
out.writeDouble(this.x);
|
||||||
out.writeDouble(this.y);
|
out.writeDouble(this.y);
|
||||||
out.writeDouble(this.z);
|
out.writeDouble(this.z);
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
package com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity;
|
package com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity;
|
||||||
|
|
||||||
|
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
|
||||||
|
import com.github.steveice10.mc.protocol.codec.MinecraftPacket;
|
||||||
import com.github.steveice10.mc.protocol.data.game.Identifier;
|
import com.github.steveice10.mc.protocol.data.game.Identifier;
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.attribute.Attribute;
|
import com.github.steveice10.mc.protocol.data.game.entity.attribute.Attribute;
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.attribute.AttributeModifier;
|
import com.github.steveice10.mc.protocol.data.game.entity.attribute.AttributeModifier;
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.attribute.AttributeType;
|
import com.github.steveice10.mc.protocol.data.game.entity.attribute.AttributeType;
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.attribute.ModifierOperation;
|
import io.netty.buffer.ByteBuf;
|
||||||
import com.github.steveice10.packetlib.io.NetInput;
|
|
||||||
import com.github.steveice10.packetlib.io.NetOutput;
|
|
||||||
import com.github.steveice10.packetlib.packet.Packet;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
|
@ -20,21 +19,21 @@ import java.util.List;
|
||||||
@Data
|
@Data
|
||||||
@With
|
@With
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class ClientboundUpdateAttributesPacket implements Packet {
|
public class ClientboundUpdateAttributesPacket implements MinecraftPacket {
|
||||||
private final int entityId;
|
private final int entityId;
|
||||||
private final @NonNull List<Attribute> attributes;
|
private final @NonNull List<Attribute> attributes;
|
||||||
|
|
||||||
public ClientboundUpdateAttributesPacket(NetInput in) throws IOException {
|
public ClientboundUpdateAttributesPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||||
this.entityId = in.readVarInt();
|
this.entityId = helper.readVarInt(in);
|
||||||
this.attributes = new ArrayList<>();
|
this.attributes = new ArrayList<>();
|
||||||
int length = in.readVarInt();
|
int length = helper.readVarInt(in);
|
||||||
for (int index = 0; index < length; index++) {
|
for (int index = 0; index < length; index++) {
|
||||||
String key = in.readString();
|
String key = helper.readString(in);
|
||||||
double value = in.readDouble();
|
double value = in.readDouble();
|
||||||
List<AttributeModifier> modifiers = new ArrayList<>();
|
List<AttributeModifier> modifiers = new ArrayList<>();
|
||||||
int len = in.readVarInt();
|
int len = helper.readVarInt(in);
|
||||||
for (int ind = 0; ind < len; ind++) {
|
for (int ind = 0; ind < len; ind++) {
|
||||||
modifiers.add(new AttributeModifier(in.readUUID(), in.readDouble(), ModifierOperation.read(in)));
|
modifiers.add(new AttributeModifier(helper.readUUID(in), in.readDouble(), helper.readModifierOperation(in)));
|
||||||
}
|
}
|
||||||
|
|
||||||
AttributeType type = AttributeType.Builtin.BUILTIN.computeIfAbsent(Identifier.formalize(key), AttributeType.Custom::new);
|
AttributeType type = AttributeType.Builtin.BUILTIN.computeIfAbsent(Identifier.formalize(key), AttributeType.Custom::new);
|
||||||
|
@ -43,17 +42,17 @@ public class ClientboundUpdateAttributesPacket implements Packet {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(NetOutput out) throws IOException {
|
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||||
out.writeVarInt(this.entityId);
|
helper.writeVarInt(out, this.entityId);
|
||||||
out.writeVarInt(this.attributes.size());
|
helper.writeVarInt(out, this.attributes.size());
|
||||||
for (Attribute attribute : this.attributes) {
|
for (Attribute attribute : this.attributes) {
|
||||||
out.writeString(attribute.getType().getIdentifier());
|
helper.writeString(out, attribute.getType().getIdentifier());
|
||||||
out.writeDouble(attribute.getValue());
|
out.writeDouble(attribute.getValue());
|
||||||
out.writeVarInt(attribute.getModifiers().size());
|
helper.writeVarInt(out, attribute.getModifiers().size());
|
||||||
for (AttributeModifier modifier : attribute.getModifiers()) {
|
for (AttributeModifier modifier : attribute.getModifiers()) {
|
||||||
out.writeUUID(modifier.getUuid());
|
helper.writeUUID(out, modifier.getUuid());
|
||||||
out.writeDouble(modifier.getAmount());
|
out.writeDouble(modifier.getAmount());
|
||||||
out.writeByte(modifier.getOperation().ordinal());
|
helper.writeModifierOperation(out, modifier.getOperation());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue