Add support for 20w21a

This commit is contained in:
RednedEpic 2020-05-23 15:41:00 -05:00
parent 81de9b4577
commit 00fc4c605a
6 changed files with 42 additions and 13 deletions

View file

@ -5,7 +5,7 @@
<groupId>com.github.steveice10</groupId>
<artifactId>mcprotocollib</artifactId>
<version>20w20b-SNAPSHOT</version>
<version>20w21a-SNAPSHOT</version>
<packaging>jar</packaging>
<name>MCProtocolLib</name>

View file

@ -2,8 +2,8 @@ package com.github.steveice10.mc.protocol;
public class MinecraftConstants {
// General Constants
public static final String GAME_VERSION = "20w20b";
public static final int PROTOCOL_VERSION = 717;
public static final String GAME_VERSION = "20w21a";
public static final int PROTOCOL_VERSION = 718;
// General Key Constants
public static final String PROFILE_KEY = "profile";

View file

@ -14,6 +14,7 @@ import lombok.NonNull;
import lombok.Setter;
import java.io.IOException;
import java.util.UUID;
@Data
@Setter(AccessLevel.NONE)
@ -22,6 +23,7 @@ import java.io.IOException;
public class ServerChatPacket implements Packet {
private @NonNull Message message;
private @NonNull MessageType type;
private @NonNull UUID senderUuid;
public ServerChatPacket(@NonNull String text) {
this(Message.fromString(text));
@ -32,19 +34,29 @@ public class ServerChatPacket implements Packet {
}
public ServerChatPacket(@NonNull String text, @NonNull MessageType type) {
this(Message.fromString(text), type);
this(Message.fromString(text), type, new UUID(0, 0));
}
public ServerChatPacket(@NonNull Message message, @NonNull MessageType type) {
this(message, type, new UUID(0, 0));
}
public ServerChatPacket(@NonNull String text, @NonNull MessageType type, UUID uuid) {
this(Message.fromString(text), type, uuid);
}
@Override
public void read(NetInput in) throws IOException {
this.message = Message.fromString(in.readString());
this.type = MagicValues.key(MessageType.class, in.readByte());
this.senderUuid = in.readUUID();
}
@Override
public void write(NetOutput out) throws IOException {
out.writeString(this.message.toJsonString());
out.writeByte(MagicValues.value(Integer.class, this.type));
out.writeUUID(this.senderUuid);
}
@Override

View file

@ -1,7 +1,9 @@
package com.github.steveice10.mc.protocol.packet.ingame.server;
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.player.GameMode;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.packetlib.io.NetInput;
import com.github.steveice10.packetlib.io.NetOutput;
import com.github.steveice10.packetlib.packet.Packet;
@ -25,7 +27,8 @@ public class ServerJoinGamePacket implements Packet {
private int entityId;
private boolean hardcore;
private @NonNull GameMode gameMode;
private int dimension;
private @NonNull CompoundTag dimensionCodec;
private @NonNull String dimension;
private long hashedSeed;
private int maxPlayers;
private int viewDistance;
@ -41,8 +44,8 @@ public class ServerJoinGamePacket implements Packet {
int gameMode = in.readUnsignedByte();
this.hardcore = (gameMode & GAMEMODE_FLAG_HARDCORE) != 0;
this.gameMode = MagicValues.key(GameMode.class, gameMode & GAMEMODE_MASK);
this.dimension = in.readInt();
this.dimensionCodec = NBT.read(in);
this.dimension = in.readString();
this.hashedSeed = in.readLong();
this.maxPlayers = in.readUnsignedByte();
this.viewDistance = in.readVarInt();
@ -62,8 +65,8 @@ public class ServerJoinGamePacket implements Packet {
}
out.writeByte(gameMode);
out.writeInt(this.dimension);
NBT.write(out, this.dimensionCodec);
out.writeString(this.dimension);
out.writeLong(this.hashedSeed);
out.writeByte(this.maxPlayers);
out.writeVarInt(this.viewDistance);

View file

@ -19,7 +19,7 @@ import java.io.IOException;
@NoArgsConstructor(access = AccessLevel.PRIVATE)
@AllArgsConstructor
public class ServerRespawnPacket implements Packet {
private int dimension;
private String dimension;
private long hashedSeed;
private @NonNull GameMode gamemode;
private boolean debug;
@ -28,7 +28,7 @@ public class ServerRespawnPacket implements Packet {
@Override
public void read(NetInput in) throws IOException {
this.dimension = in.readInt();
this.dimension = in.readString();
this.hashedSeed = in.readLong();
this.gamemode = MagicValues.key(GameMode.class, in.readUnsignedByte());
this.debug = in.readBoolean();
@ -38,7 +38,7 @@ public class ServerRespawnPacket implements Packet {
@Override
public void write(NetOutput out) throws IOException {
out.writeInt(this.dimension);
out.writeString(this.dimension);
out.writeLong(this.hashedSeed);
out.writeByte(MagicValues.value(Integer.class, this.gamemode));
out.writeBoolean(this.debug);

View file

@ -9,6 +9,9 @@ import com.github.steveice10.mc.protocol.data.status.VersionInfo;
import com.github.steveice10.mc.protocol.data.status.handler.ServerInfoBuilder;
import com.github.steveice10.mc.protocol.data.status.handler.ServerInfoHandler;
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.ListTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.github.steveice10.packetlib.Client;
import com.github.steveice10.packetlib.Server;
import com.github.steveice10.packetlib.Session;
@ -44,7 +47,7 @@ public class MinecraftProtocolTest {
new TextMessage("Hello world!"),
null
);
private static final ServerJoinGamePacket JOIN_GAME_PACKET = new ServerJoinGamePacket(0, false, GameMode.SURVIVAL, 0, 100, 0, 16, false, false, false, false);
private static final ServerJoinGamePacket JOIN_GAME_PACKET = new ServerJoinGamePacket(0, false, GameMode.SURVIVAL, getDimensionTag(), "minecraft:overworld", 100, 0, 16, false, false, false, false);
private static Server server;
@ -139,4 +142,15 @@ public class MinecraftProtocolTest {
}
}
}
private static CompoundTag getDimensionTag() {
CompoundTag tag = new CompoundTag("");
ListTag dimensionTag = new ListTag("dimension");
CompoundTag overworldTag = new CompoundTag("");
overworldTag.put(new StringTag("key", "minecraft:overworld"));
overworldTag.put(new StringTag("element", "minecraft:overworld"));
dimensionTag.add(overworldTag);
tag.put(tag);
return tag;
}
}