Skip to content

Commit

Permalink
Minecraft 1.21.2 and Velocity b443+ support (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
UserNugget authored Oct 24, 2024
1 parent c91f7be commit e632cff
Show file tree
Hide file tree
Showing 18 changed files with 236 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public enum BlockEntityVersion {
MINECRAFT_1_20_2(EnumSet.of(ProtocolVersion.MINECRAFT_1_20_2)),
MINECRAFT_1_20_3(EnumSet.of(ProtocolVersion.MINECRAFT_1_20_3)),
MINECRAFT_1_20_5(EnumSet.of(ProtocolVersion.MINECRAFT_1_20_5)),
MINECRAFT_1_21(EnumSet.of(ProtocolVersion.MINECRAFT_1_21));
MINECRAFT_1_21(EnumSet.of(ProtocolVersion.MINECRAFT_1_21)),
MINECRAFT_1_21_2(EnumSet.of(ProtocolVersion.MINECRAFT_1_21_2));

private static final EnumMap<ProtocolVersion, BlockEntityVersion> MC_VERSION_TO_ITEM_VERSIONS = new EnumMap<>(ProtocolVersion.class);

Expand Down Expand Up @@ -64,6 +65,7 @@ public static BlockEntityVersion parse(String from) {
case "1.20.3" -> MINECRAFT_1_20_3;
case "1.20.5" -> MINECRAFT_1_20_5;
case "1.21" -> MINECRAFT_1_21;
case "1.21.2" -> MINECRAFT_1_21_2;
default -> LEGACY;
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public enum WorldVersion {
MINECRAFT_1_19_4(EnumSet.range(ProtocolVersion.MINECRAFT_1_19_4, ProtocolVersion.MINECRAFT_1_20)),
MINECRAFT_1_20(EnumSet.range(ProtocolVersion.MINECRAFT_1_20, ProtocolVersion.MINECRAFT_1_20_2)),
MINECRAFT_1_20_3(ProtocolVersion.MINECRAFT_1_20_3),
MINECRAFT_1_20_5(EnumSet.range(ProtocolVersion.MINECRAFT_1_20_5, ProtocolVersion.MAXIMUM_VERSION));
MINECRAFT_1_20_5(EnumSet.range(ProtocolVersion.MINECRAFT_1_20_5, ProtocolVersion.MINECRAFT_1_21)),
MINECRAFT_1_21_2(EnumSet.range(ProtocolVersion.MINECRAFT_1_21_2, ProtocolVersion.MAXIMUM_VERSION));

private static final EnumMap<ProtocolVersion, WorldVersion> MC_VERSION_TO_ITEM_VERSIONS = new EnumMap<>(ProtocolVersion.class);

Expand Down Expand Up @@ -72,6 +73,7 @@ public static WorldVersion parse(String from) {
case "1.20" -> MINECRAFT_1_20;
case "1.20.3" -> MINECRAFT_1_20_3;
case "1.20.5" -> MINECRAFT_1_20_5;
case "1.21.2" -> MINECRAFT_1_21_2;
default -> LEGACY;
};
}
Expand Down
3 changes: 1 addition & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
org.gradle.jvmargs=-Xmx4096m
fastPrepareVersion=1.0.13
velocityVersion=3.3.0-SNAPSHOT
velocityApiVersion=3.4.0-SNAPSHOT
velocityVersion=3.4.0-SNAPSHOT
nettyVersion=4.1.86.Final
fastutilVersion=8.5.11
bstatsVersion=3.0.0
Expand Down
13 changes: 5 additions & 8 deletions plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ dependencies() {
implementation("net.elytrium.commons:kyori:$elytriumCommonsVersion")

implementation("net.elytrium:fastprepare:$fastPrepareVersion")
compileOnly("com.velocitypowered:velocity-api:$velocityApiVersion")
compileOnly("com.velocitypowered:velocity-api:$velocityVersion")
annotationProcessor("com.velocitypowered:velocity-api:$velocityVersion")
compileOnly("com.velocitypowered:velocity-proxy:$velocityVersion") // From Elytrium Repo.
compileOnly("com.velocitypowered:velocity-native:$velocityVersion")
Expand Down Expand Up @@ -128,7 +128,8 @@ enum MinecraftVersion {
MINECRAFT_1_20_2(764),
MINECRAFT_1_20_3(765),
MINECRAFT_1_20_5(766),
MINECRAFT_1_21(767)
MINECRAFT_1_21(767),
MINECRAFT_1_21_2(768)

public static final List<MinecraftVersion> WORLD_VERSIONS = List.of(
MINECRAFT_1_13,
Expand All @@ -143,12 +144,8 @@ enum MinecraftVersion {
MINECRAFT_1_19_4,
MINECRAFT_1_20,
MINECRAFT_1_20_3,
MINECRAFT_1_20_5
)

public static final List<MinecraftVersion> COMPONENT_VERSIONS = List.of(
MINECRAFT_1_20_5,
MINECRAFT_1_21
MINECRAFT_1_21_2
)

public static final MinecraftVersion MINIMUM_VERSION = MINECRAFT_1_7_2
Expand Down Expand Up @@ -552,7 +549,7 @@ void generateRegistryMappings(File targetDir, Map<MinecraftVersion, Object> regi
.findAll({ e -> MinecraftVersion.WORLD_VERSIONS.contains(e.getKey()) }))
this.generateRegistryMapping("block", targetDir, registriesReports)
this.generateRegistryMapping("data_component_type", targetDir, registriesReports
.findAll({ e -> MinecraftVersion.COMPONENT_VERSIONS.contains(e.getKey()) }))
.findAll({ e -> e.getKey() >= MinecraftVersion.MINECRAFT_1_20_5 }))

File blockEntitiesMappingFile = new File(targetDir, "blockentities_mapping.json");

Expand Down
26 changes: 26 additions & 0 deletions plugin/mapping/fallbackdata.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,30 @@
{
"MINECRAFT_1_21": {
"minecraft:pale_oak_wood": "minecraft:birch_wood",
"minecraft:pale_oak_planks": "minecraft:birch_planks",
"minecraft:pale_oak_sapling": "minecraft:birch_sapling",
"minecraft:pale_oak_log": "minecraft:birch_log",
"minecraft:stripped_pale_oak_log": "minecraft:stripped_birch_log",
"minecraft:stripped_pale_oak_wood": "minecraft:stripped_birch_wood",
"minecraft:pale_oak_leaves": "minecraft:birch_leaves",
"minecraft:creaking_heart": "minecraft:oak_wood",
"minecraft:pale_oak_sign": "minecraft:birch_sign",
"minecraft:pale_oak_wall_sign": "minecraft:birch_wall_sign",
"minecraft:pale_oak_hanging_sign": "minecraft:birch_hanging_sign",
"minecraft:pale_oak_wall_hanging_sign": "minecraft:birch_wall_hanging_sign",
"minecraft:pale_oak_pressure_plate": "minecraft:birch_pressure_plate",
"minecraft:pale_oak_trapdoor": "minecraft:birch_trapdoor",
"minecraft:potted_pale_oak_sapling": "minecraft:potted_birch_sapling",
"minecraft:pale_oak_button": "minecraft:birch_button",
"minecraft:pale_oak_stairs": "minecraft:birch_stairs",
"minecraft:pale_oak_slab": "minecraft:birch_slab",
"minecraft:pale_oak_fence_gate": "minecraft:birch_fence_gate",
"minecraft:pale_oak_fence": "minecraft:birch_fence",
"minecraft:pale_oak_door": "minecraft:birch_door",
"minecraft:pale_moss_block": "minecraft:moss_block",
"minecraft:pale_hanging_moss": "minecraft:hanging_roots",
"minecraft:pale_moss_carpet": "minecraft:moss_carpet"
},
"MINECRAFT_1_20_3": {
"minecraft:vault": "minecraft:spawner",
"minecraft:heavy_core": "minecraft:wither_skeleton_skull"
Expand Down
2 changes: 1 addition & 1 deletion plugin/src/main/java/net/elytrium/limboapi/LimboAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
@SuppressFBWarnings("MS_EXPOSE_REP")
public class LimboAPI implements LimboFactory {

private static final int SUPPORTED_MAXIMUM_PROTOCOL_VERSION_NUMBER = 767;
private static final int SUPPORTED_MAXIMUM_PROTOCOL_VERSION_NUMBER = 768;

@MonotonicNonNull
private static Logger LOGGER;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ public static void init() throws Throwable {
createMapping(0x1C, ProtocolVersion.MINECRAFT_1_19_3, true),
createMapping(0x1F, ProtocolVersion.MINECRAFT_1_19_4, true),
createMapping(0x20, ProtocolVersion.MINECRAFT_1_20_2, true),
createMapping(0x22, ProtocolVersion.MINECRAFT_1_20_5, true)
createMapping(0x22, ProtocolVersion.MINECRAFT_1_20_5, true),
createMapping(0x23, ProtocolVersion.MINECRAFT_1_21_2, true)
);
register(LIMBO_STATE_REGISTRY, PacketDirection.CLIENTBOUND,
ChunkDataPacket.class, ChunkDataPacket::new,
Expand All @@ -211,7 +212,8 @@ public static void init() throws Throwable {
createMapping(0x20, ProtocolVersion.MINECRAFT_1_19_3, true),
createMapping(0x24, ProtocolVersion.MINECRAFT_1_19_4, true),
createMapping(0x25, ProtocolVersion.MINECRAFT_1_20_2, true),
createMapping(0x27, ProtocolVersion.MINECRAFT_1_20_5, true)
createMapping(0x27, ProtocolVersion.MINECRAFT_1_20_5, true),
createMapping(0x28, ProtocolVersion.MINECRAFT_1_21_2, true)
);
register(LIMBO_STATE_REGISTRY, PacketDirection.CLIENTBOUND,
DefaultSpawnPositionPacket.class, DefaultSpawnPositionPacket::new,
Expand All @@ -230,7 +232,8 @@ public static void init() throws Throwable {
createMapping(0x50, ProtocolVersion.MINECRAFT_1_19_4, true),
createMapping(0x52, ProtocolVersion.MINECRAFT_1_20_2, true),
createMapping(0x54, ProtocolVersion.MINECRAFT_1_20_3, true),
createMapping(0x56, ProtocolVersion.MINECRAFT_1_20_5, true)
createMapping(0x56, ProtocolVersion.MINECRAFT_1_20_5, true),
createMapping(0x5B, ProtocolVersion.MINECRAFT_1_21_2, true)
);
register(LIMBO_STATE_REGISTRY, PacketDirection.CLIENTBOUND,
MapDataPacket.class, MapDataPacket::new,
Expand All @@ -246,7 +249,8 @@ public static void init() throws Throwable {
createMapping(0x25, ProtocolVersion.MINECRAFT_1_19_3, true),
createMapping(0x29, ProtocolVersion.MINECRAFT_1_19_4, true),
createMapping(0x2A, ProtocolVersion.MINECRAFT_1_20_2, true),
createMapping(0x2C, ProtocolVersion.MINECRAFT_1_20_5, true)
createMapping(0x2C, ProtocolVersion.MINECRAFT_1_20_5, true),
createMapping(0x2D, ProtocolVersion.MINECRAFT_1_21_2, true)
);
register(LIMBO_STATE_REGISTRY, PacketDirection.CLIENTBOUND,
PlayerAbilitiesPacket.class, PlayerAbilitiesPacket::new,
Expand All @@ -264,7 +268,8 @@ public static void init() throws Throwable {
createMapping(0x30, ProtocolVersion.MINECRAFT_1_19_3, true),
createMapping(0x34, ProtocolVersion.MINECRAFT_1_19_4, true),
createMapping(0x36, ProtocolVersion.MINECRAFT_1_20_2, true),
createMapping(0x38, ProtocolVersion.MINECRAFT_1_20_5, true)
createMapping(0x38, ProtocolVersion.MINECRAFT_1_20_5, true),
createMapping(0x3A, ProtocolVersion.MINECRAFT_1_21_2, true)
);
register(LIMBO_STATE_REGISTRY, PacketDirection.CLIENTBOUND,
PositionRotationPacket.class, PositionRotationPacket::new,
Expand All @@ -282,7 +287,8 @@ public static void init() throws Throwable {
createMapping(0x38, ProtocolVersion.MINECRAFT_1_19_3, true),
createMapping(0x3C, ProtocolVersion.MINECRAFT_1_19_4, true),
createMapping(0x3E, ProtocolVersion.MINECRAFT_1_20_2, true),
createMapping(0x40, ProtocolVersion.MINECRAFT_1_20_5, true)
createMapping(0x40, ProtocolVersion.MINECRAFT_1_20_5, true),
createMapping(0x42, ProtocolVersion.MINECRAFT_1_21_2, true)
);
register(LIMBO_STATE_REGISTRY, PacketDirection.CLIENTBOUND,
SetExperiencePacket.class, SetExperiencePacket::new,
Expand All @@ -299,7 +305,8 @@ public static void init() throws Throwable {
createMapping(0x56, ProtocolVersion.MINECRAFT_1_19_4, true),
createMapping(0x58, ProtocolVersion.MINECRAFT_1_20_2, true),
createMapping(0x5A, ProtocolVersion.MINECRAFT_1_20_3, true),
createMapping(0x5C, ProtocolVersion.MINECRAFT_1_20_5, true)
createMapping(0x5C, ProtocolVersion.MINECRAFT_1_20_5, true),
createMapping(0x61, ProtocolVersion.MINECRAFT_1_21_2, true)
);
register(LIMBO_STATE_REGISTRY, PacketDirection.CLIENTBOUND,
SetSlotPacket.class, SetSlotPacket::new,
Expand Down Expand Up @@ -333,7 +340,8 @@ public static void init() throws Throwable {
createMapping(0x5E, ProtocolVersion.MINECRAFT_1_19_4, true),
createMapping(0x60, ProtocolVersion.MINECRAFT_1_20_2, true),
createMapping(0x62, ProtocolVersion.MINECRAFT_1_20_3, true),
createMapping(0x64, ProtocolVersion.MINECRAFT_1_20_5, true)
createMapping(0x64, ProtocolVersion.MINECRAFT_1_20_5, true),
createMapping(0x6B, ProtocolVersion.MINECRAFT_1_21_2, true)
);
register(LIMBO_STATE_REGISTRY, PacketDirection.CLIENTBOUND,
UpdateViewPositionPacket.class, UpdateViewPositionPacket::new, // ViewCentre, ChunkRenderDistanceCenter
Expand All @@ -347,7 +355,8 @@ public static void init() throws Throwable {
createMapping(0x4E, ProtocolVersion.MINECRAFT_1_19_4, true),
createMapping(0x50, ProtocolVersion.MINECRAFT_1_20_2, true),
createMapping(0x52, ProtocolVersion.MINECRAFT_1_20_3, true),
createMapping(0x54, ProtocolVersion.MINECRAFT_1_20_5, true)
createMapping(0x54, ProtocolVersion.MINECRAFT_1_20_5, true),
createMapping(0x58, ProtocolVersion.MINECRAFT_1_21_2, true)
);
register(LIMBO_STATE_REGISTRY, PacketDirection.CLIENTBOUND,
UpdateTagsPacket.class, UpdateTagsPacket::new,
Expand All @@ -363,7 +372,8 @@ public static void init() throws Throwable {
createMapping(0x6E, ProtocolVersion.MINECRAFT_1_19_4, true),
createMapping(0x70, ProtocolVersion.MINECRAFT_1_20_2, true),
createMapping(0x74, ProtocolVersion.MINECRAFT_1_20_3, true),
createMapping(0x78, ProtocolVersion.MINECRAFT_1_20_5, true)
createMapping(0x78, ProtocolVersion.MINECRAFT_1_20_5, true),
createMapping(0x7F, ProtocolVersion.MINECRAFT_1_21_2, true)
);

register(LIMBO_STATE_REGISTRY, PacketDirection.SERVERBOUND,
Expand All @@ -382,7 +392,8 @@ public static void init() throws Throwable {
createMapping(0x15, ProtocolVersion.MINECRAFT_1_19_4, false),
createMapping(0x17, ProtocolVersion.MINECRAFT_1_20_2, false),
createMapping(0x18, ProtocolVersion.MINECRAFT_1_20_3, false),
createMapping(0x1B, ProtocolVersion.MINECRAFT_1_20_5, false)
createMapping(0x1B, ProtocolVersion.MINECRAFT_1_20_5, false),
createMapping(0x1D, ProtocolVersion.MINECRAFT_1_21_2, false)
);
register(LIMBO_STATE_REGISTRY, PacketDirection.SERVERBOUND,
MovePositionOnlyPacket.class, MovePositionOnlyPacket::new,
Expand All @@ -400,7 +411,8 @@ public static void init() throws Throwable {
createMapping(0x14, ProtocolVersion.MINECRAFT_1_19_4, false),
createMapping(0x16, ProtocolVersion.MINECRAFT_1_20_2, false),
createMapping(0x17, ProtocolVersion.MINECRAFT_1_20_3, false),
createMapping(0x1A, ProtocolVersion.MINECRAFT_1_20_5, false)
createMapping(0x1A, ProtocolVersion.MINECRAFT_1_20_5, false),
createMapping(0x1C, ProtocolVersion.MINECRAFT_1_21_2, false)
);
register(LIMBO_STATE_REGISTRY, PacketDirection.SERVERBOUND,
MoveRotationOnlyPacket.class, MoveRotationOnlyPacket::new,
Expand All @@ -418,7 +430,8 @@ public static void init() throws Throwable {
createMapping(0x16, ProtocolVersion.MINECRAFT_1_19_4, false),
createMapping(0x18, ProtocolVersion.MINECRAFT_1_20_2, false),
createMapping(0x19, ProtocolVersion.MINECRAFT_1_20_3, false),
createMapping(0x1C, ProtocolVersion.MINECRAFT_1_20_5, false)
createMapping(0x1C, ProtocolVersion.MINECRAFT_1_20_5, false),
createMapping(0x1E, ProtocolVersion.MINECRAFT_1_21_2, false)
);
register(LIMBO_STATE_REGISTRY, PacketDirection.SERVERBOUND,
MoveOnGroundOnlyPacket.class, MoveOnGroundOnlyPacket::new,
Expand All @@ -436,7 +449,8 @@ public static void init() throws Throwable {
createMapping(0x17, ProtocolVersion.MINECRAFT_1_19_4, false),
createMapping(0x19, ProtocolVersion.MINECRAFT_1_20_2, false),
createMapping(0x1A, ProtocolVersion.MINECRAFT_1_20_3, false),
createMapping(0x1D, ProtocolVersion.MINECRAFT_1_20_5, false)
createMapping(0x1D, ProtocolVersion.MINECRAFT_1_20_5, false),
createMapping(0x1F, ProtocolVersion.MINECRAFT_1_21_2, false)
);
register(LIMBO_STATE_REGISTRY, PacketDirection.SERVERBOUND,
TeleportConfirmPacket.class, TeleportConfirmPacket::new,
Expand All @@ -447,7 +461,8 @@ public static void init() throws Throwable {
PlayerChatSessionPacket.class, PlayerChatSessionPacket::new,
createMapping(0x20, ProtocolVersion.MINECRAFT_1_19_3, false),
createMapping(0x06, ProtocolVersion.MINECRAFT_1_19_4, false),
createMapping(0x07, ProtocolVersion.MINECRAFT_1_20_5, false)
createMapping(0x07, ProtocolVersion.MINECRAFT_1_20_5, false),
createMapping(0x08, ProtocolVersion.MINECRAFT_1_21_2, false)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,17 @@
public class MoveOnGroundOnlyPacket implements MinecraftPacket {

private boolean onGround;
private boolean collideHorizontally;

@Override
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
this.onGround = buf.readBoolean();
if (protocolVersion.lessThan(ProtocolVersion.MINECRAFT_1_21_2)) {
this.onGround = buf.readBoolean();
} else {
int flags = buf.readUnsignedByte();
this.onGround = (flags & 1) != 0;
this.collideHorizontally = (flags & 2) != 0;
}
}

@Override
Expand Down Expand Up @@ -61,10 +68,15 @@ public int expectedMinLength(ByteBuf buf, ProtocolUtils.Direction direction, Pro
public String toString() {
return "Player{"
+ "onGround=" + this.onGround
+ ", collideHorizontally=" + this.collideHorizontally
+ "}";
}

public boolean isOnGround() {
return this.onGround;
}

public boolean isCollideHorizontally() {
return this.collideHorizontally;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class MovePacket implements MinecraftPacket {
private float yaw;
private float pitch;
private boolean onGround;
private boolean collideHorizontally;

@Override
public void decode(ByteBuf buf, Direction direction, ProtocolVersion protocolVersion) {
Expand All @@ -44,7 +45,14 @@ public void decode(ByteBuf buf, Direction direction, ProtocolVersion protocolVer
this.posZ = buf.readDouble();
this.yaw = buf.readFloat();
this.pitch = buf.readFloat();
this.onGround = buf.readBoolean();

if (protocolVersion.lessThan(ProtocolVersion.MINECRAFT_1_21_2)) {
this.onGround = buf.readBoolean();
} else {
int flags = buf.readUnsignedByte();
this.onGround = (flags & 1) != 0;
this.collideHorizontally = (flags & 2) != 0;
}
}

@Override
Expand Down Expand Up @@ -80,6 +88,7 @@ public String toString() {
+ ", yaw=" + this.yaw
+ ", pitch=" + this.pitch
+ ", onGround=" + this.onGround
+ ", collideHorizontally=" + this.collideHorizontally
+ "}";
}

Expand All @@ -106,4 +115,8 @@ public float getPitch() {
public boolean isOnGround() {
return this.onGround;
}

public boolean isCollideHorizontally() {
return this.collideHorizontally;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class MovePositionOnlyPacket implements MinecraftPacket {
private double posY;
private double posZ;
private boolean onGround;
private boolean collideHorizontally;

@Override
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion) {
Expand All @@ -39,7 +40,14 @@ public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersi
}
this.posY = buf.readDouble();
this.posZ = buf.readDouble();
this.onGround = buf.readBoolean();

if (protocolVersion.lessThan(ProtocolVersion.MINECRAFT_1_21_2)) {
this.onGround = buf.readBoolean();
} else {
int flags = buf.readUnsignedByte();
this.onGround = (flags & 1) != 0;
this.collideHorizontally = (flags & 2) != 0;
}
}

@Override
Expand Down Expand Up @@ -73,6 +81,7 @@ public String toString() {
+ ", posY=" + this.posY
+ ", posZ=" + this.posZ
+ ", onGround=" + this.onGround
+ ", collideHorizontally=" + this.collideHorizontally
+ "}";
}

Expand All @@ -91,4 +100,8 @@ public double getZ() {
public boolean isOnGround() {
return this.onGround;
}

public boolean isCollideHorizontally() {
return this.collideHorizontally;
}
}
Loading

0 comments on commit e632cff

Please sign in to comment.