Add methods to handle new tags format

This commit is contained in:
KennyTV 2020-12-17 11:51:51 +01:00
parent 6298eb42c5
commit ed4d0bc134
No known key found for this signature in database
GPG Key ID: 6BE3B555EBC5982B
3 changed files with 38 additions and 3 deletions

View File

@ -205,12 +205,12 @@ public class ItemRewriter {
map(Type.FLOAT); // 7 - Offset Z
map(Type.FLOAT); // 8 - Particle Data
map(Type.INT); // 9 - Particle Count
handler(getSpawnParticleHandler(itemType, coordType));
handler(getSpawnParticleHandler(itemType));
}
});
}
public PacketHandler getSpawnParticleHandler(Type<Item> itemType, Type<?> coordType) {
public PacketHandler getSpawnParticleHandler(Type<Item> itemType) {
return wrapper -> {
int id = wrapper.get(Type.INT, 0);
if (id == -1) return;

View File

@ -52,6 +52,8 @@ public class TagRewriter {
}
/**
* Pre 1.17 reading of hardcoded registry types.
*
* @param packetType packet type
* @param readUntilType read and process the types until (including) the given registry type
*/
@ -64,6 +66,20 @@ public class TagRewriter {
});
}
/**
* 1.17+ reading of generic tag types.
*
* @param packetType packet type
*/
public void registerGeneric(ClientboundPacketType packetType) {
protocol.registerOutgoing(packetType, new PacketRemapper() {
@Override
public void registerMap() {
handler(getGenericHandler());
}
});
}
public PacketHandler getHandler(@Nullable RegistryType readUntilType) {
return wrapper -> {
for (RegistryType type : RegistryType.getValues()) {
@ -77,6 +93,25 @@ public class TagRewriter {
};
}
public PacketHandler getGenericHandler() {
return wrapper -> {
int length = wrapper.passthrough(Type.VAR_INT);
for (int i = 0; i < length; i++) {
String registryKey = wrapper.passthrough(Type.STRING);
if (registryKey.startsWith("minecraft:")) {
registryKey = registryKey.substring(10);
}
RegistryType type = RegistryType.getByKey(registryKey);
if (type != null) {
handle(wrapper, getRewriter(type), getNewTags(type));
} else {
handle(wrapper, null, null);
}
}
};
}
public void handle(PacketWrapper wrapper, @Nullable IdRewriteFunction rewriteFunction, List<TagData> newTags) throws Exception {
int tagsSize = wrapper.read(Type.VAR_INT);
wrapper.write(Type.VAR_INT, newTags != null ? tagsSize + newTags.size() : tagsSize); // add new tags count

View File

@ -56,7 +56,7 @@ public class InventoryPackets {
wrapper.passthrough(Type.FLOAT); // Scale
}
});
handler(itemRewriter.getSpawnParticleHandler(Type.FLAT_VAR_INT_ITEM, Type.DOUBLE));
handler(itemRewriter.getSpawnParticleHandler(Type.FLAT_VAR_INT_ITEM));
}
});
}