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,
|
ITEM,
|
||||||
FLUID,
|
FLUID,
|
||||||
ENTITY,
|
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));
|
newTags.add(new TagData(id, oldIds));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void register(ClientboundPacketType packetType) {
|
/**
|
||||||
register(packetType, false);
|
* @param packetType packet type
|
||||||
}
|
* @param readUntilType read and process the types until (including) the given registry type
|
||||||
|
*/
|
||||||
public void register(ClientboundPacketType packetType, boolean hasGameEvents) {
|
public void register(ClientboundPacketType packetType, @Nullable RegistryType readUntilType) {
|
||||||
protocol.registerOutgoing(packetType, new PacketRemapper() {
|
protocol.registerOutgoing(packetType, new PacketRemapper() {
|
||||||
@Override
|
@Override
|
||||||
public void registerMap() {
|
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 -> {
|
return wrapper -> {
|
||||||
MappingData mappingData = protocol.getMappingData();
|
for (RegistryType type : RegistryType.getValues()) {
|
||||||
handle(wrapper, id -> mappingData != null ? mappingData.getNewBlockId(id) : null, getNewTags(RegistryType.BLOCK));
|
handle(wrapper, getRewriter(type), getNewTags(type));
|
||||||
handle(wrapper, id -> mappingData != null ? mappingData.getNewItemId(id) : null, getNewTags(RegistryType.ITEM));
|
|
||||||
handle(wrapper, null, getNewTags(RegistryType.FLUID));
|
// Stop iterating
|
||||||
handle(wrapper, entityRewriter, getNewTags(RegistryType.ENTITY));
|
if (type == readUntilType) {
|
||||||
if (hasGameEvents) {
|
break;
|
||||||
handle(wrapper, null, getNewTags(RegistryType.GAME_EVENT));
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -102,7 +111,7 @@ public class TagRewriter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Send new tags if present
|
// Send new tags if present
|
||||||
if (newTags != null && !newTags.isEmpty()) {
|
if (newTags != null) {
|
||||||
for (TagData tag : newTags) {
|
for (TagData tag : newTags) {
|
||||||
wrapper.write(Type.STRING, tag.identifier);
|
wrapper.write(Type.STRING, tag.identifier);
|
||||||
wrapper.write(Type.VAR_INT_ARRAY_PRIMITIVE, tag.entries);
|
wrapper.write(Type.VAR_INT_ARRAY_PRIMITIVE, tag.entries);
|
||||||
@ -121,14 +130,16 @@ public class TagRewriter {
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private IdRewriteFunction getRewriter(RegistryType tagType) {
|
private IdRewriteFunction getRewriter(RegistryType tagType) {
|
||||||
|
MappingData mappingData = protocol.getMappingData();
|
||||||
switch (tagType) {
|
switch (tagType) {
|
||||||
case BLOCK:
|
case BLOCK:
|
||||||
return protocol.getMappingData().getBlockMappings() != null ? id -> protocol.getMappingData().getNewBlockId(id) : null;
|
return mappingData != null && mappingData.getBlockMappings() != null ? mappingData::getNewBlockId : null;
|
||||||
case ITEM:
|
case ITEM:
|
||||||
return protocol.getMappingData().getItemMappings() != null ? id -> protocol.getMappingData().getNewItemId(id) : null;
|
return mappingData != null && mappingData.getItemMappings() != null ? mappingData::getNewItemId : null;
|
||||||
case ENTITY:
|
case ENTITY:
|
||||||
return entityRewriter;
|
return entityRewriter;
|
||||||
case FLUID:
|
case FLUID:
|
||||||
|
case GAME_EVENT:
|
||||||
default:
|
default:
|
||||||
return null;
|
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.PacketHandler;
|
||||||
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
||||||
import us.myles.ViaVersion.api.remapper.ValueTransformer;
|
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.StatisticsRewriter;
|
||||||
import us.myles.ViaVersion.api.rewriters.TagRewriter;
|
import us.myles.ViaVersion.api.rewriters.TagRewriter;
|
||||||
import us.myles.ViaVersion.api.type.Type;
|
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);
|
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 = new TagRewriter(this, EntityPackets::getNewEntityId);
|
||||||
tagRewriter.register(ClientboundPackets1_14.TAGS);
|
tagRewriter.register(ClientboundPackets1_14.TAGS, RegistryType.ENTITY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -36,7 +36,7 @@ public class Protocol1_16_2To1_16_1 extends Protocol<ClientboundPackets1_16, Cli
|
|||||||
InventoryPackets.register(this);
|
InventoryPackets.register(this);
|
||||||
|
|
||||||
tagRewriter = new TagRewriter(this, metadataRewriter::getNewEntityId);
|
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);
|
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);
|
InventoryPackets.register(this);
|
||||||
|
|
||||||
tagRewriter = new TagRewriter(this, metadataRewriter::getNewEntityId);
|
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);
|
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() {
|
registerOutgoing(ClientboundPackets1_16_2.TAGS, new PacketRemapper() {
|
||||||
@Override
|
@Override
|
||||||
public void registerMap() {
|
public void registerMap() {
|
||||||
handler(tagRewriter.getHandler(false));
|
handler(tagRewriter.getHandler(RegistryType.ENTITY));
|
||||||
handler(wrapper -> {
|
handler(wrapper -> {
|
||||||
// New Game Event tags type
|
// New Game Event tags type
|
||||||
wrapper.write(Type.VAR_INT, NEW_GAME_EVENT_TAGS.length);
|
wrapper.write(Type.VAR_INT, NEW_GAME_EVENT_TAGS.length);
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren