Fix tag related issues to prepare for 1.21.2

- Inline tag values in 1.21 enchantments
- Fix TagRewriter addTags if the server doesn't send values for a registry
- Send the tags packet in 1.12->1.13 before the play login packet to fix tracking in 1.20->1.20.2
This commit is contained in:
Nassim Jahnke 2024-10-11 16:30:39 +02:00
parent 81682f4921
commit 50084c112d
No known key found for this signature in database
GPG Key ID: EF6771C01F6EF02F
5 changed files with 45 additions and 6 deletions

View File

@ -34,6 +34,7 @@ import com.viaversion.viaversion.api.protocol.packet.State;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler; import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.protocol.remapper.ValueTransformer; import com.viaversion.viaversion.api.protocol.remapper.ValueTransformer;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.api.type.Types; import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.misc.ParticleType; import com.viaversion.viaversion.api.type.types.misc.ParticleType;
import com.viaversion.viaversion.api.type.types.version.Types1_13; import com.viaversion.viaversion.api.type.types.version.Types1_13;
@ -145,7 +146,7 @@ public class Protocol1_12_2To1_13 extends AbstractProtocol<ClientboundPackets1_1
}).scheduleSend(Protocol1_12_2To1_13.class); }).scheduleSend(Protocol1_12_2To1_13.class);
// Send tags packet // Send tags packet
w.create(ClientboundPackets1_13.UPDATE_TAGS, wrapper -> { final PacketWrapper tagsPacket = w.create(ClientboundPackets1_13.UPDATE_TAGS, wrapper -> {
wrapper.write(Types.VAR_INT, MAPPINGS.getBlockTags().size()); // block tags wrapper.write(Types.VAR_INT, MAPPINGS.getBlockTags().size()); // block tags
for (Map.Entry<String, int[]> tag : MAPPINGS.getBlockTags().entrySet()) { for (Map.Entry<String, int[]> tag : MAPPINGS.getBlockTags().entrySet()) {
wrapper.write(Types.STRING, tag.getKey()); wrapper.write(Types.STRING, tag.getKey());
@ -164,7 +165,13 @@ public class Protocol1_12_2To1_13 extends AbstractProtocol<ClientboundPackets1_1
// Needs copy as other protocols may modify it // Needs copy as other protocols may modify it
wrapper.write(Types.VAR_INT_ARRAY_PRIMITIVE, tag.getValue().clone()); wrapper.write(Types.VAR_INT_ARRAY_PRIMITIVE, tag.getValue().clone());
} }
}).scheduleSend(Protocol1_12_2To1_13.class); });
if (w.user().getProtocolInfo().protocolVersion().newerThanOrEqualTo(ProtocolVersion.v1_20_2)) {
// Make sure it's included in the configuration packets
tagsPacket.send(Protocol1_12_2To1_13.class);
} else {
tagsPacket.scheduleSend(Protocol1_12_2To1_13.class);
}
}; };
@Override @Override

View File

@ -286,6 +286,7 @@ public final class Protocol1_20_3To1_20_5 extends AbstractProtocol<ClientboundPa
tagRewriter.renameTag(RegistryType.ITEM, "minecraft:axolotl_tempt_items", "minecraft:axolotl_food"); tagRewriter.renameTag(RegistryType.ITEM, "minecraft:axolotl_tempt_items", "minecraft:axolotl_food");
tagRewriter.removeTag(RegistryType.ITEM, "minecraft:tools"); tagRewriter.removeTag(RegistryType.ITEM, "minecraft:tools");
tagRewriter.addEmptyTags(RegistryType.BLOCK, "minecraft:badlands_terracotta"); tagRewriter.addEmptyTags(RegistryType.BLOCK, "minecraft:badlands_terracotta");
tagRewriter.addEmptyTags(RegistryType.ITEM, "minecraft:enchantable/mace");
super.onMappingDataLoaded(); super.onMappingDataLoaded();
} }

View File

@ -217,6 +217,11 @@ public final class Protocol1_20_5To1_21 extends AbstractProtocol<ClientboundPack
tagRewriter.addEmptyTags(RegistryType.ENTITY, "minecraft:can_turn_in_boats", "minecraft:deflects_projectiles", "minecraft:immune_to_infested", tagRewriter.addEmptyTags(RegistryType.ENTITY, "minecraft:can_turn_in_boats", "minecraft:deflects_projectiles", "minecraft:immune_to_infested",
"minecraft:immune_to_oozing", "minecraft:no_anger_from_wind_charge"); "minecraft:immune_to_oozing", "minecraft:no_anger_from_wind_charge");
tagRewriter.addTag(RegistryType.ENCHANTMENT, "minecraft:curse", 10, 41); // Binding and vanishing curse tagRewriter.addTag(RegistryType.ENCHANTMENT, "minecraft:curse", 10, 41); // Binding and vanishing curse
// Add other enchantment tags empty
tagRewriter.addEmptyTags(RegistryType.ENCHANTMENT, "double_trade_price", "in_enchanting_table", "non_treasure", "on_mob_spawn_equipment", "on_random_loot",
"on_traded_equipment", "prevents_bee_spawns_when_mining", "prevents_decorated_pot_shattering", "prevents_ice_melting", "prevents_infested_spawns", "smelts_loot",
"tooltip_order", "tradeable", "treasure", "exclusive_set/armor", "exclusive_set/boots", "exclusive_set/bow", "exclusive_set/crossbow", "exclusive_set/damage",
"exclusive_set/mining", "exclusive_set/riptide");
} }
@Override @Override

View File

@ -31,6 +31,7 @@ import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntList; import it.unimi.dsi.fastutil.ints.IntList;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.EnumMap; import java.util.EnumMap;
import java.util.EnumSet;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
@ -143,11 +144,14 @@ public class TagRewriter<C extends ClientboundPacketType> implements com.viavers
public void handleGeneric(final PacketWrapper wrapper) { public void handleGeneric(final PacketWrapper wrapper) {
final int length = wrapper.passthrough(Types.VAR_INT); final int length = wrapper.passthrough(Types.VAR_INT);
int editedLength = length; int finalLength = length;
final Set<RegistryType> readTypes = EnumSet.noneOf(RegistryType.class);
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
final String registryKey = wrapper.read(Types.STRING); final String registryKey = wrapper.read(Types.STRING);
if (toRemoveRegistries.contains(Key.stripMinecraftNamespace(registryKey))) { final String strippedKey = Key.stripMinecraftNamespace(registryKey);
wrapper.set(Types.VAR_INT, 0, --editedLength); if (toRemoveRegistries.contains(strippedKey)) {
finalLength--;
final int tagsSize = wrapper.read(Types.VAR_INT); final int tagsSize = wrapper.read(Types.VAR_INT);
for (int j = 0; j < tagsSize; j++) { for (int j = 0; j < tagsSize; j++) {
wrapper.read(Types.STRING); wrapper.read(Types.STRING);
@ -157,7 +161,29 @@ public class TagRewriter<C extends ClientboundPacketType> implements com.viavers
} }
wrapper.write(Types.STRING, registryKey); wrapper.write(Types.STRING, registryKey);
handle(wrapper, Key.stripMinecraftNamespace(registryKey));
final RegistryType type = RegistryType.getByKey(registryKey);
if (type != null) {
handle(wrapper, type);
readTypes.add(type);
} else {
handle(wrapper, null, null, null, null);
}
}
for (final Map.Entry<RegistryType, List<TagData>> entry : toAdd.entrySet()) {
if (readTypes.contains(entry.getKey())) {
continue;
}
// Registry wasn't present in the packet, add them here
wrapper.write(Types.STRING, entry.getKey().resourceLocation());
appendNewTags(wrapper, entry.getKey());
finalLength++;
}
if (length != finalLength) {
wrapper.set(Types.VAR_INT, 0, finalLength);
} }
} }