Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-28 09:00:09 +01:00
Fix tag processing in older versions, small refactor
Dieser Commit ist enthalten in:
Ursprung
ff91dd7082
Commit
3aa35395f4
@ -6,5 +6,11 @@ public enum RegistryType {
|
||||
ITEM,
|
||||
FLUID,
|
||||
ENTITY,
|
||||
GAME_EVENT
|
||||
GAME_EVENT;
|
||||
|
||||
private static final RegistryType[] VALUES = values();
|
||||
|
||||
public static RegistryType[] getValues() {
|
||||
return VALUES;
|
||||
}
|
||||
}
|
||||
|
@ -51,28 +51,37 @@ public class TagRewriter {
|
||||
newTags.add(new TagData(id, oldIds));
|
||||
}
|
||||
|
||||
public void register(ClientboundPacketType packetType) {
|
||||
register(packetType, false);
|
||||
}
|
||||
|
||||
public void register(ClientboundPacketType packetType, boolean hasGameEvents) {
|
||||
/**
|
||||
* @param packetType packet type
|
||||
* @param readUntilType read and process the types until (including) the given registry type
|
||||
*/
|
||||
public void register(ClientboundPacketType packetType, @Nullable RegistryType readUntilType) {
|
||||
protocol.registerOutgoing(packetType, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
handler(getHandler(hasGameEvents));
|
||||
handler(getHandler(readUntilType));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public PacketHandler getHandler(boolean hasGameEvents) {
|
||||
/**
|
||||
* Registers the handler, reading and processing until and including the entity tags.
|
||||
*
|
||||
* @param packetType packet type
|
||||
*/
|
||||
public void register(ClientboundPacketType packetType) {
|
||||
register(packetType, RegistryType.ENTITY);
|
||||
}
|
||||
|
||||
public PacketHandler getHandler(@Nullable RegistryType readUntilType) {
|
||||
return wrapper -> {
|
||||
MappingData mappingData = protocol.getMappingData();
|
||||
handle(wrapper, id -> mappingData != null ? mappingData.getNewBlockId(id) : null, getNewTags(RegistryType.BLOCK));
|
||||
handle(wrapper, id -> mappingData != null ? mappingData.getNewItemId(id) : null, getNewTags(RegistryType.ITEM));
|
||||
handle(wrapper, null, getNewTags(RegistryType.FLUID));
|
||||
handle(wrapper, entityRewriter, getNewTags(RegistryType.ENTITY));
|
||||
if (hasGameEvents) {
|
||||
handle(wrapper, null, getNewTags(RegistryType.GAME_EVENT));
|
||||
for (RegistryType type : RegistryType.getValues()) {
|
||||
handle(wrapper, getRewriter(type), getNewTags(type));
|
||||
|
||||
// Stop iterating
|
||||
if (type == readUntilType) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -102,7 +111,7 @@ public class TagRewriter {
|
||||
}
|
||||
|
||||
// Send new tags if present
|
||||
if (newTags != null && !newTags.isEmpty()) {
|
||||
if (newTags != null) {
|
||||
for (TagData tag : newTags) {
|
||||
wrapper.write(Type.STRING, tag.identifier);
|
||||
wrapper.write(Type.VAR_INT_ARRAY_PRIMITIVE, tag.entries);
|
||||
@ -121,14 +130,16 @@ public class TagRewriter {
|
||||
|
||||
@Nullable
|
||||
private IdRewriteFunction getRewriter(RegistryType tagType) {
|
||||
MappingData mappingData = protocol.getMappingData();
|
||||
switch (tagType) {
|
||||
case BLOCK:
|
||||
return protocol.getMappingData().getBlockMappings() != null ? id -> protocol.getMappingData().getNewBlockId(id) : null;
|
||||
return mappingData != null && mappingData.getBlockMappings() != null ? mappingData::getNewBlockId : null;
|
||||
case ITEM:
|
||||
return protocol.getMappingData().getItemMappings() != null ? id -> protocol.getMappingData().getNewItemId(id) : null;
|
||||
return mappingData != null && mappingData.getItemMappings() != null ? mappingData::getNewItemId : null;
|
||||
case ENTITY:
|
||||
return entityRewriter;
|
||||
case FLUID:
|
||||
case GAME_EVENT:
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import us.myles.ViaVersion.api.protocol.Protocol;
|
||||
import us.myles.ViaVersion.api.remapper.PacketHandler;
|
||||
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
||||
import us.myles.ViaVersion.api.remapper.ValueTransformer;
|
||||
import us.myles.ViaVersion.api.rewriters.RegistryType;
|
||||
import us.myles.ViaVersion.api.rewriters.StatisticsRewriter;
|
||||
import us.myles.ViaVersion.api.rewriters.TagRewriter;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
@ -123,7 +124,7 @@ public class Protocol1_13_1To1_13 extends Protocol<ClientboundPackets1_13, Clien
|
||||
}
|
||||
});
|
||||
|
||||
new TagRewriter(this, null).register(ClientboundPackets1_13.TAGS);
|
||||
new TagRewriter(this, null).register(ClientboundPackets1_13.TAGS, RegistryType.BLOCK);
|
||||
new StatisticsRewriter(this, null).register(ClientboundPackets1_13.STATISTICS);
|
||||
}
|
||||
|
||||
|
@ -51,7 +51,7 @@ public class Protocol1_15To1_14_4 extends Protocol<ClientboundPackets1_14, Clien
|
||||
});
|
||||
|
||||
tagRewriter = new TagRewriter(this, EntityPackets::getNewEntityId);
|
||||
tagRewriter.register(ClientboundPackets1_14.TAGS);
|
||||
tagRewriter.register(ClientboundPackets1_14.TAGS, RegistryType.ENTITY);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -36,7 +36,7 @@ public class Protocol1_16_2To1_16_1 extends Protocol<ClientboundPackets1_16, Cli
|
||||
InventoryPackets.register(this);
|
||||
|
||||
tagRewriter = new TagRewriter(this, metadataRewriter::getNewEntityId);
|
||||
tagRewriter.register(ClientboundPackets1_16.TAGS);
|
||||
tagRewriter.register(ClientboundPackets1_16.TAGS, RegistryType.ENTITY);
|
||||
|
||||
new StatisticsRewriter(this, metadataRewriter::getNewEntityId).register(ClientboundPackets1_16.STATISTICS);
|
||||
|
||||
|
@ -52,7 +52,7 @@ public class Protocol1_16To1_15_2 extends Protocol<ClientboundPackets1_15, Clien
|
||||
InventoryPackets.register(this);
|
||||
|
||||
tagRewriter = new TagRewriter(this, metadataRewriter::getNewEntityId);
|
||||
tagRewriter.register(ClientboundPackets1_15.TAGS);
|
||||
tagRewriter.register(ClientboundPackets1_15.TAGS, RegistryType.ENTITY);
|
||||
|
||||
new StatisticsRewriter(this, metadataRewriter::getNewEntityId).register(ClientboundPackets1_15.STATISTICS);
|
||||
|
||||
|
@ -41,7 +41,7 @@ public class Protocol1_17To1_16_4 extends Protocol<ClientboundPackets1_16_2, Cli
|
||||
registerOutgoing(ClientboundPackets1_16_2.TAGS, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
handler(tagRewriter.getHandler(false));
|
||||
handler(tagRewriter.getHandler(RegistryType.ENTITY));
|
||||
handler(wrapper -> {
|
||||
// New Game Event tags type
|
||||
wrapper.write(Type.VAR_INT, NEW_GAME_EVENT_TAGS.length);
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren