Skip to content

Commit

Permalink
Preserve ids for 1.20.5 RegistrySyncPacket
Browse files Browse the repository at this point in the history
  • Loading branch information
UserNugget committed May 1, 2024
1 parent 588b755 commit 637cb5b
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions plugin/src/main/java/net/elytrium/limboapi/server/LimboImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
import java.lang.invoke.MethodHandles;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Iterator;
Expand Down Expand Up @@ -289,21 +290,35 @@ private void createRegistrySyncModern(PreparedPacket packet, ProtocolVersion ini
String type = entry.getString("type");
ListBinaryTag values = entry.getList("value", BinaryTagTypes.COMPOUND);

List<Pair<String, BinaryTag>> tags = new ArrayList<>();
Pair<String, BinaryTag> emptyTag = null;
Pair<String, BinaryTag>[] tags = new Pair[0];

// TODO: handle ids?
// TODO: does optifine still breaks then "there is no specific biome"?
for (BinaryTag elementTag : values) {
CompoundBinaryTag element = (CompoundBinaryTag) elementTag;
tags.add(Pair.of(element.getString("name"), element.getCompound("element")));
int id = element.getInt("id");
if (id >= tags.length) {
tags = Arrays.copyOf(tags, id + 1);
}

tags[id] = Pair.of(element.getString("name"), element.getCompound("element"));
if (emptyTag == null) {
emptyTag = tags[id];
}
}

for (int i = 0; i < tags.length; i++) {
if (tags[i] == null) {
tags[i] = emptyTag;
}
}

Pair<String, BinaryTag>[] patchedTags = tags;
packet.prepare(version -> {
ByteBuf registry = this.plugin.getPreparedPacketFactory().getPreparedPacketAllocator().ioBuffer();

ProtocolUtils.writeString(registry, type);
ProtocolUtils.writeVarInt(registry, tags.size());
for (Pair<String, BinaryTag> tag : tags) {
ProtocolUtils.writeVarInt(registry, patchedTags.length);
for (Pair<String, BinaryTag> tag : patchedTags) {
ProtocolUtils.writeString(registry, tag.left());

registry.writeBoolean(tag.right() != null);
Expand Down

0 comments on commit 637cb5b

Please sign in to comment.