Skip to content

1.20.5 support #94

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
limboapiVersion=1.1.14
limboapiVersion=1.1.23
velocityVersion=3.3.0-SNAPSHOT
nettyVersion=4.1.86.Final
fastutilVersion=8.5.11
2 changes: 2 additions & 0 deletions src/main/java/net/elytrium/limbofilter/LimboFilter.java
Original file line number Diff line number Diff line change
@@ -279,6 +279,7 @@ public void reload() {
new PacketMapping(0x10, ProtocolVersion.MINECRAFT_1_19_4, false),
new PacketMapping(0x12, ProtocolVersion.MINECRAFT_1_20_2, false),
new PacketMapping(0x13, ProtocolVersion.MINECRAFT_1_20_3, false),
new PacketMapping(0x16, ProtocolVersion.MINECRAFT_1_20_5, false),
})
.registerPacket(PacketDirection.CLIENTBOUND, SetEntityMetadata.class, SetEntityMetadata::new, new PacketMapping[]{
new PacketMapping(0x1C, ProtocolVersion.MINIMUM_VERSION, true),
@@ -294,6 +295,7 @@ public void reload() {
new PacketMapping(0x52, ProtocolVersion.MINECRAFT_1_19_4, true),
new PacketMapping(0x54, ProtocolVersion.MINECRAFT_1_20_2, true),
new PacketMapping(0x56, ProtocolVersion.MINECRAFT_1_20_3, true),
new PacketMapping(0x58, ProtocolVersion.MINECRAFT_1_20_5, true),
})
.registerPacket(PacketDirection.CLIENTBOUND, SpawnEntity.class, SpawnEntity::new, new PacketMapping[]{
new PacketMapping(0x0E, ProtocolVersion.MINIMUM_VERSION, true),
19 changes: 17 additions & 2 deletions src/main/java/net/elytrium/limbofilter/cache/CachedPackets.java
Original file line number Diff line number Diff line change
@@ -36,6 +36,7 @@
import net.elytrium.limboapi.api.material.Item;
import net.elytrium.limboapi.api.material.VirtualItem;
import net.elytrium.limboapi.api.protocol.PreparedPacket;
import net.elytrium.limboapi.api.protocol.item.ItemComponentMap;
import net.elytrium.limboapi.api.protocol.packets.PacketFactory;
import net.elytrium.limbofilter.LimboFilter;
import net.elytrium.limbofilter.Settings;
@@ -170,7 +171,12 @@ private PreparedPacket[] createCaptchaAttemptsPacket(LimboFactory limboFactory,
this.createSetSlotPacketModern(
packetFactory, limboFactory.getItem(Item.FILLED_MAP), 1,
CompoundBinaryTag.builder().put("map", IntBinaryTag.intBinaryTag(0)).build()
), ProtocolVersion.MINECRAFT_1_17
), ProtocolVersion.MINECRAFT_1_17, ProtocolVersion.MINECRAFT_1_20_3
).prepare(
this.createSetSlotPacketComponent(
packetFactory, limboFactory.getItem(Item.FILLED_MAP), 1,
limboFactory.createItemComponentMap().add(ProtocolVersion.MINECRAFT_1_20_5, "minecraft:map_id", 0)
), ProtocolVersion.MINECRAFT_1_20_5
);
}
packets[i] = packet.build();
@@ -191,7 +197,12 @@ private PreparedPacket[] createCaptchaAttemptsPacket(LimboFactory limboFactory,
this.createSetSlotPacketModern(
packetFactory, limboFactory.getItem(Item.FILLED_MAP), 1,
CompoundBinaryTag.builder().put("map", IntBinaryTag.intBinaryTag(0)).build()
), ProtocolVersion.MINECRAFT_1_17
), ProtocolVersion.MINECRAFT_1_17, ProtocolVersion.MINECRAFT_1_20_3
).prepare(
this.createSetSlotPacketComponent(
packetFactory, limboFactory.getItem(Item.FILLED_MAP), 1,
limboFactory.createItemComponentMap().add(ProtocolVersion.MINECRAFT_1_20_5, "minecraft:map_id", 0)
), ProtocolVersion.MINECRAFT_1_20_5
);
}
packets[Settings.IMP.MAIN.CAPTCHA_ATTEMPTS].build();
@@ -320,6 +331,10 @@ private MinecraftPacket createSetSlotPacketModern(PacketFactory packetFactory, V
return (MinecraftPacket) packetFactory.createSetSlotPacket(0, Settings.IMP.MAIN.CAPTCHA_LEFT_HAND ? 45 : 36, item, count, 0, nbt);
}

private MinecraftPacket createSetSlotPacketComponent(PacketFactory packetFactory, VirtualItem item, int count, ItemComponentMap map) {
return (MinecraftPacket) packetFactory.createSetSlotPacket(0, Settings.IMP.MAIN.CAPTCHA_LEFT_HAND ? 45 : 36, item, count, 0, map);
}

public void createChatPacket(PreparedPacket packet, String text) {
packet
.prepare(new LegacyChatPacket(
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@
import io.netty.buffer.ByteBuf;
import java.util.Map;
import net.elytrium.limboapi.api.material.VirtualItem;
import net.elytrium.limboapi.api.protocol.item.ItemComponentMap;
import net.kyori.adventure.nbt.CompoundBinaryTag;

public class EntityMetadata {
@@ -40,25 +41,52 @@ public static class SlotEntry implements Entry {
private final int count;
private final int data;
private final CompoundBinaryTag nbt;
private final ItemComponentMap map;

public SlotEntry(boolean present, VirtualItem item, int count, int data, CompoundBinaryTag nbt) {
public SlotEntry(boolean present, VirtualItem item, int count, int data, CompoundBinaryTag nbt, ItemComponentMap map) {
this.present = present;
this.item = item;
this.count = count;
this.data = data;
this.nbt = nbt;
this.map = map;
}

public SlotEntry(VirtualItem item, int count, int data, CompoundBinaryTag nbt) {
this(true, item, count, data, nbt);
public SlotEntry(VirtualItem item, int count, int data, CompoundBinaryTag nbt, ItemComponentMap map) {
this(true, item, count, data, nbt, map);
}

public SlotEntry() {
this(false, null, 0, 0, null);
this(false, null, 0, 0, null, null);
}

@Override
public void encode(ByteBuf buf, ProtocolVersion protocolVersion) {
if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_20_5) >= 0) {
this.encodeModern(buf, protocolVersion);
} else {
this.encodeLegacy(buf, protocolVersion);
}
}

public void encodeModern(ByteBuf buf, ProtocolVersion protocolVersion) {
int id = this.item.getID(protocolVersion);
if (id == 0) {
ProtocolUtils.writeVarInt(buf, 0);
} else {
ProtocolUtils.writeVarInt(buf, this.count);
ProtocolUtils.writeVarInt(buf, id);

if (this.map != null) {
this.map.write(protocolVersion, buf);
} else {
ProtocolUtils.writeVarInt(buf, 0);
ProtocolUtils.writeVarInt(buf, 0);
}
}
}

public void encodeLegacy(ByteBuf buf, ProtocolVersion protocolVersion) {
if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_13_2) >= 0) {
buf.writeBoolean(this.present);
}
Original file line number Diff line number Diff line change
@@ -43,8 +43,10 @@ public static int getID(ProtocolVersion protocolVersion) {
return 46;
} else if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_20_2) <= 0) {
return 56;
} else {
} else if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_20_3) <= 0) {
return 57;
} else {
return 60;
}
}

@@ -67,12 +69,13 @@ public static byte getMetadataIndex(ProtocolVersion protocolVersion) {
public static EntityMetadata createMapMetadata(LimboFactory limboFactory, ProtocolVersion protocolVersion, int mapId) {
if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_12_2) <= 0) {
return new EntityMetadata(Map.of(
getMetadataIndex(protocolVersion), new EntityMetadata.SlotEntry(limboFactory.getItem(Item.FILLED_MAP), 1, mapId, null)
getMetadataIndex(protocolVersion), new EntityMetadata.SlotEntry(limboFactory.getItem(Item.FILLED_MAP), 1, mapId, null, null)
));
} else {
return new EntityMetadata(Map.of(
getMetadataIndex(protocolVersion), new EntityMetadata.SlotEntry(limboFactory.getItem(Item.FILLED_MAP), 1, 0,
CompoundBinaryTag.builder().put("map", IntBinaryTag.intBinaryTag(mapId)).build())
CompoundBinaryTag.builder().put("map", IntBinaryTag.intBinaryTag(mapId)).build(),
limboFactory.createItemComponentMap().add(ProtocolVersion.MINECRAFT_1_20_5, "minecraft:map_id", mapId))
));
}
}