Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-11-08 17:20:24 +01:00
Add methods to handle new tags format
Dieser Commit ist enthalten in:
Ursprung
6298eb42c5
Commit
ed4d0bc134
@ -205,12 +205,12 @@ public class ItemRewriter {
|
|||||||
map(Type.FLOAT); // 7 - Offset Z
|
map(Type.FLOAT); // 7 - Offset Z
|
||||||
map(Type.FLOAT); // 8 - Particle Data
|
map(Type.FLOAT); // 8 - Particle Data
|
||||||
map(Type.INT); // 9 - Particle Count
|
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 -> {
|
return wrapper -> {
|
||||||
int id = wrapper.get(Type.INT, 0);
|
int id = wrapper.get(Type.INT, 0);
|
||||||
if (id == -1) return;
|
if (id == -1) return;
|
||||||
|
@ -52,6 +52,8 @@ public class TagRewriter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Pre 1.17 reading of hardcoded registry types.
|
||||||
|
*
|
||||||
* @param packetType packet type
|
* @param packetType packet type
|
||||||
* @param readUntilType read and process the types until (including) the given registry 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) {
|
public PacketHandler getHandler(@Nullable RegistryType readUntilType) {
|
||||||
return wrapper -> {
|
return wrapper -> {
|
||||||
for (RegistryType type : RegistryType.getValues()) {
|
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 {
|
public void handle(PacketWrapper wrapper, @Nullable IdRewriteFunction rewriteFunction, List<TagData> newTags) throws Exception {
|
||||||
int tagsSize = wrapper.read(Type.VAR_INT);
|
int tagsSize = wrapper.read(Type.VAR_INT);
|
||||||
wrapper.write(Type.VAR_INT, newTags != null ? tagsSize + newTags.size() : tagsSize); // add new tags count
|
wrapper.write(Type.VAR_INT, newTags != null ? tagsSize + newTags.size() : tagsSize); // add new tags count
|
||||||
|
@ -56,7 +56,7 @@ public class InventoryPackets {
|
|||||||
wrapper.passthrough(Type.FLOAT); // Scale
|
wrapper.passthrough(Type.FLOAT); // Scale
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
handler(itemRewriter.getSpawnParticleHandler(Type.FLAT_VAR_INT_ITEM, Type.DOUBLE));
|
handler(itemRewriter.getSpawnParticleHandler(Type.FLAT_VAR_INT_ITEM));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren