Skip to content

Commit

Permalink
1.0.3 Release: 1.20.2 protocol support
Browse files Browse the repository at this point in the history
  • Loading branch information
hevav committed Dec 11, 2023
1 parent f8fcb00 commit 2889eb3
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 4 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.2
1.0.3
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {
}

setGroup("net.elytrium")
setVersion("1.0.2")
setVersion("1.0.3")

compileJava {
getOptions().setEncoding("UTF-8")
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/net/elytrium/limbohub/LimboHub.java
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ public void reload() {
new PacketMapping(0x04, ProtocolVersion.MINECRAFT_1_16, true),
new PacketMapping(0x02, ProtocolVersion.MINECRAFT_1_19, true),
new PacketMapping(0x03, ProtocolVersion.MINECRAFT_1_19_4, true),
// There is no SpawnPlayer packet since Minecraft 1.20.2
})
.registerPacket(PacketDirection.CLIENTBOUND, CloseContainer.class, CloseContainer::new, new PacketMapping[]{
new PacketMapping(0x2E, ProtocolVersion.MINECRAFT_1_8, true),
Expand All @@ -368,6 +369,7 @@ public void reload() {
new PacketMapping(0x10, ProtocolVersion.MINECRAFT_1_19, true),
new PacketMapping(0x0F, ProtocolVersion.MINECRAFT_1_19_3, true),
new PacketMapping(0x11, ProtocolVersion.MINECRAFT_1_19_4, true),
new PacketMapping(0x12, ProtocolVersion.MINECRAFT_1_20_2, true),
})
.registerPacket(PacketDirection.CLIENTBOUND, SetContainerContent.class, SetContainerContent::new, new PacketMapping[]{
new PacketMapping(0x30, ProtocolVersion.MINECRAFT_1_8, true),
Expand All @@ -381,6 +383,7 @@ public void reload() {
new PacketMapping(0x11, ProtocolVersion.MINECRAFT_1_19, true),
new PacketMapping(0x10, ProtocolVersion.MINECRAFT_1_19_3, true),
new PacketMapping(0x12, ProtocolVersion.MINECRAFT_1_19_4, true),
new PacketMapping(0x13, ProtocolVersion.MINECRAFT_1_20_2, true),
})
.registerPacket(PacketDirection.CLIENTBOUND, SetContainerSlot.class, SetContainerSlot::new, new PacketMapping[]{
new PacketMapping(0x2F, ProtocolVersion.MINECRAFT_1_8, true),
Expand All @@ -394,6 +397,7 @@ public void reload() {
new PacketMapping(0x13, ProtocolVersion.MINECRAFT_1_19, true),
new PacketMapping(0x12, ProtocolVersion.MINECRAFT_1_19_3, true),
new PacketMapping(0x14, ProtocolVersion.MINECRAFT_1_19_4, true),
new PacketMapping(0x15, ProtocolVersion.MINECRAFT_1_20_2, true),
})
.registerPacket(PacketDirection.CLIENTBOUND, OpenScreen.class, OpenScreen::new, new PacketMapping[]{
new PacketMapping(0x2D, ProtocolVersion.MINECRAFT_1_8, true),
Expand All @@ -408,6 +412,7 @@ public void reload() {
new PacketMapping(0x2D, ProtocolVersion.MINECRAFT_1_19_1, true),
new PacketMapping(0x2C, ProtocolVersion.MINECRAFT_1_19_3, true),
new PacketMapping(0x30, ProtocolVersion.MINECRAFT_1_19_4, true),
new PacketMapping(0x31, ProtocolVersion.MINECRAFT_1_20_2, true),
})
.registerPacket(PacketDirection.CLIENTBOUND, SetHeadRotation.class, SetHeadRotation::new, new PacketMapping[]{
new PacketMapping(0x19, ProtocolVersion.MINECRAFT_1_8, true),
Expand All @@ -424,6 +429,7 @@ public void reload() {
new PacketMapping(0x3F, ProtocolVersion.MINECRAFT_1_19_1, true),
new PacketMapping(0x3E, ProtocolVersion.MINECRAFT_1_19_3, true),
new PacketMapping(0x42, ProtocolVersion.MINECRAFT_1_19_4, true),
new PacketMapping(0x44, ProtocolVersion.MINECRAFT_1_20_2, true),
})
.registerPacket(PacketDirection.CLIENTBOUND, DisplayObjective.class, DisplayObjective::new, new PacketMapping[]{
new PacketMapping(0x3D, ProtocolVersion.MINECRAFT_1_8, true),
Expand All @@ -437,6 +443,7 @@ public void reload() {
new PacketMapping(0x4F, ProtocolVersion.MINECRAFT_1_19_1, true),
new PacketMapping(0x4D, ProtocolVersion.MINECRAFT_1_19_3, true),
new PacketMapping(0x51, ProtocolVersion.MINECRAFT_1_19_4, true),
new PacketMapping(0x53, ProtocolVersion.MINECRAFT_1_20_2, true),
})
.registerPacket(PacketDirection.CLIENTBOUND, SetEntityMetadata.class, SetEntityMetadata::new, new PacketMapping[]{
new PacketMapping(0x1C, ProtocolVersion.MINECRAFT_1_8, true),
Expand All @@ -450,6 +457,7 @@ public void reload() {
new PacketMapping(0x50, ProtocolVersion.MINECRAFT_1_19_1, true),
new PacketMapping(0x4E, ProtocolVersion.MINECRAFT_1_19_3, true),
new PacketMapping(0x52, ProtocolVersion.MINECRAFT_1_19_4, true),
new PacketMapping(0x54, ProtocolVersion.MINECRAFT_1_20_2, true),
})
.registerPacket(PacketDirection.CLIENTBOUND, UpdateObjectives.class, UpdateObjectives::new, new PacketMapping[]{
new PacketMapping(0x3B, ProtocolVersion.MINECRAFT_1_8, true),
Expand All @@ -463,6 +471,7 @@ public void reload() {
new PacketMapping(0x56, ProtocolVersion.MINECRAFT_1_19_1, true),
new PacketMapping(0x54, ProtocolVersion.MINECRAFT_1_19_3, true),
new PacketMapping(0x58, ProtocolVersion.MINECRAFT_1_19_4, true),
new PacketMapping(0x5A, ProtocolVersion.MINECRAFT_1_20_2, true),
})
.registerPacket(PacketDirection.CLIENTBOUND, ScoreboardTeam.class, ScoreboardTeam::new, new PacketMapping[]{
new PacketMapping(0x3E, ProtocolVersion.MINECRAFT_1_8, true),
Expand All @@ -476,6 +485,7 @@ public void reload() {
new PacketMapping(0x58, ProtocolVersion.MINECRAFT_1_19_1, true),
new PacketMapping(0x56, ProtocolVersion.MINECRAFT_1_19_3, true),
new PacketMapping(0x5A, ProtocolVersion.MINECRAFT_1_19_4, true),
new PacketMapping(0x5C, ProtocolVersion.MINECRAFT_1_20_2, true),
})
.registerPacket(PacketDirection.CLIENTBOUND, UpdateScore.class, UpdateScore::new, new PacketMapping[]{
new PacketMapping(0x3C, ProtocolVersion.MINECRAFT_1_8, true),
Expand All @@ -489,6 +499,7 @@ public void reload() {
new PacketMapping(0x59, ProtocolVersion.MINECRAFT_1_19_1, true),
new PacketMapping(0x57, ProtocolVersion.MINECRAFT_1_19_3, true),
new PacketMapping(0x5B, ProtocolVersion.MINECRAFT_1_19_4, true),
new PacketMapping(0x5D, ProtocolVersion.MINECRAFT_1_20_2, true),
})
.registerPacket(PacketDirection.SERVERBOUND, Interact.class, Interact::new, new PacketMapping[]{
new PacketMapping(0x02, ProtocolVersion.MINECRAFT_1_8, false),
Expand All @@ -502,6 +513,7 @@ public void reload() {
new PacketMapping(0x10, ProtocolVersion.MINECRAFT_1_19_1, false),
new PacketMapping(0x0F, ProtocolVersion.MINECRAFT_1_19_3, false),
new PacketMapping(0x10, ProtocolVersion.MINECRAFT_1_19_4, false),
new PacketMapping(0x12, ProtocolVersion.MINECRAFT_1_20_2, true),
})
.registerPacket(PacketDirection.SERVERBOUND, ClickContainer.class, ClickContainer::new, new PacketMapping[]{
new PacketMapping(0x0E, ProtocolVersion.MINECRAFT_1_8, false),
Expand All @@ -515,6 +527,7 @@ public void reload() {
new PacketMapping(0x0B, ProtocolVersion.MINECRAFT_1_19_1, false),
new PacketMapping(0x0A, ProtocolVersion.MINECRAFT_1_19_3, false),
new PacketMapping(0x0B, ProtocolVersion.MINECRAFT_1_19_4, false),
new PacketMapping(0x0D, ProtocolVersion.MINECRAFT_1_20_2, true),
});

this.commands.clear();
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/net/elytrium/limbohub/entities/NPC.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,13 @@ public void spawn(LimboPlayer player) {
);
}

player.writePacketAndFlush(new SpawnPlayer(this.entityId, this.uuid, this.positionX, this.positionY, this.positionZ, this.yaw, this.pitch));
if (player.getProxyPlayer().getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_20_2) >= 0) {
player.writePacketAndFlush(new SpawnEntity(this.entityId, this.uuid, Player::getEntityType,
this.positionX, this.positionY, this.positionZ, this.pitch, this.yaw, this.yaw, 0));
} else {
player.writePacketAndFlush(new SpawnPlayer(this.entityId, this.uuid, this.positionX, this.positionY, this.positionZ, this.yaw, this.pitch));
}

player.writePacketAndFlush(new SetHeadRotation(this.entityId, this.yaw));
player.writePacketAndFlush(new ScoreboardTeam("sb" + this.entityId, (byte) 0, "never",
"always", 0, Component.empty(), Component.empty(), List.of(this.username)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@

public class Player {

public static int getEntityType(ProtocolVersion version) {
if (version.compareTo(ProtocolVersion.MINECRAFT_1_20_2) >= 0) {
return 122;
} else {
throw new IllegalArgumentException("Player is not supported on versions below Minecraft 1.20.2");
}
}

public static EntityMetadata buildSkinPartsMetadata(ProtocolVersion version, byte skinParts) {
if (version.compareTo(ProtocolVersion.MINECRAFT_1_17) >= 0) {
return new EntityMetadata(Map.of((byte) 17, new EntityMetadataByteEntry(skinParts)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersi

@Override
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
buf.writeByte(this.position);
if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_20_2) >= 0) {
ProtocolUtils.writeVarInt(buf, this.position);
} else {
buf.writeByte(this.position);
}

ProtocolUtils.writeString(buf, this.scoreName);
}

Expand Down

0 comments on commit 2889eb3

Please sign in to comment.