3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-03 14:50:30 +01:00

Add methods to handle new tags format

Dieser Commit ist enthalten in:
KennyTV 2020-12-17 11:51:51 +01:00
Ursprung 6298eb42c5
Commit ed4d0bc134
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 6BE3B555EBC5982B
3 geänderte Dateien mit 38 neuen und 3 gelöschten Zeilen

Datei anzeigen

@ -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;

Datei anzeigen

@ -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

Datei anzeigen

@ -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));
}
});
}