Skip to content

Commit 50084c1

Browse files
committed
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
1 parent 81682f4 commit 50084c1

File tree

5 files changed

+45
-6
lines changed

5 files changed

+45
-6
lines changed

common/src/main/java/com/viaversion/viaversion/protocols/v1_12_2to1_13/Protocol1_12_2To1_13.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
3535
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
3636
import com.viaversion.viaversion.api.protocol.remapper.ValueTransformer;
37+
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
3738
import com.viaversion.viaversion.api.type.Types;
3839
import com.viaversion.viaversion.api.type.types.misc.ParticleType;
3940
import com.viaversion.viaversion.api.type.types.version.Types1_13;
@@ -145,7 +146,7 @@ public Protocol1_12_2To1_13() {
145146
}).scheduleSend(Protocol1_12_2To1_13.class);
146147

147148
// Send tags packet
148-
w.create(ClientboundPackets1_13.UPDATE_TAGS, wrapper -> {
149+
final PacketWrapper tagsPacket = w.create(ClientboundPackets1_13.UPDATE_TAGS, wrapper -> {
149150
wrapper.write(Types.VAR_INT, MAPPINGS.getBlockTags().size()); // block tags
150151
for (Map.Entry<String, int[]> tag : MAPPINGS.getBlockTags().entrySet()) {
151152
wrapper.write(Types.STRING, tag.getKey());
@@ -164,7 +165,13 @@ public Protocol1_12_2To1_13() {
164165
// Needs copy as other protocols may modify it
165166
wrapper.write(Types.VAR_INT_ARRAY_PRIMITIVE, tag.getValue().clone());
166167
}
167-
}).scheduleSend(Protocol1_12_2To1_13.class);
168+
});
169+
if (w.user().getProtocolInfo().protocolVersion().newerThanOrEqualTo(ProtocolVersion.v1_20_2)) {
170+
// Make sure it's included in the configuration packets
171+
tagsPacket.send(Protocol1_12_2To1_13.class);
172+
} else {
173+
tagsPacket.scheduleSend(Protocol1_12_2To1_13.class);
174+
}
168175
};
169176

170177
@Override

common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/Protocol1_20_3To1_20_5.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ protected void onMappingDataLoaded() {
286286
tagRewriter.renameTag(RegistryType.ITEM, "minecraft:axolotl_tempt_items", "minecraft:axolotl_food");
287287
tagRewriter.removeTag(RegistryType.ITEM, "minecraft:tools");
288288
tagRewriter.addEmptyTags(RegistryType.BLOCK, "minecraft:badlands_terracotta");
289+
tagRewriter.addEmptyTags(RegistryType.ITEM, "minecraft:enchantable/mace");
289290

290291
super.onMappingDataLoaded();
291292
}

common/src/main/java/com/viaversion/viaversion/protocols/v1_20_5to1_21/Protocol1_20_5To1_21.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,11 @@ protected void onMappingDataLoaded() {
217217
tagRewriter.addEmptyTags(RegistryType.ENTITY, "minecraft:can_turn_in_boats", "minecraft:deflects_projectiles", "minecraft:immune_to_infested",
218218
"minecraft:immune_to_oozing", "minecraft:no_anger_from_wind_charge");
219219
tagRewriter.addTag(RegistryType.ENCHANTMENT, "minecraft:curse", 10, 41); // Binding and vanishing curse
220+
// Add other enchantment tags empty
221+
tagRewriter.addEmptyTags(RegistryType.ENCHANTMENT, "double_trade_price", "in_enchanting_table", "non_treasure", "on_mob_spawn_equipment", "on_random_loot",
222+
"on_traded_equipment", "prevents_bee_spawns_when_mining", "prevents_decorated_pot_shattering", "prevents_ice_melting", "prevents_infested_spawns", "smelts_loot",
223+
"tooltip_order", "tradeable", "treasure", "exclusive_set/armor", "exclusive_set/boots", "exclusive_set/bow", "exclusive_set/crossbow", "exclusive_set/damage",
224+
"exclusive_set/mining", "exclusive_set/riptide");
220225
}
221226

222227
@Override

common/src/main/java/com/viaversion/viaversion/rewriter/TagRewriter.java

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import it.unimi.dsi.fastutil.ints.IntList;
3232
import java.util.ArrayList;
3333
import java.util.EnumMap;
34+
import java.util.EnumSet;
3435
import java.util.HashMap;
3536
import java.util.HashSet;
3637
import java.util.List;
@@ -143,11 +144,14 @@ public PacketHandler getHandler(@Nullable RegistryType readUntilType) {
143144

144145
public void handleGeneric(final PacketWrapper wrapper) {
145146
final int length = wrapper.passthrough(Types.VAR_INT);
146-
int editedLength = length;
147+
int finalLength = length;
148+
final Set<RegistryType> readTypes = EnumSet.noneOf(RegistryType.class);
147149
for (int i = 0; i < length; i++) {
148150
final String registryKey = wrapper.read(Types.STRING);
149-
if (toRemoveRegistries.contains(Key.stripMinecraftNamespace(registryKey))) {
150-
wrapper.set(Types.VAR_INT, 0, --editedLength);
151+
final String strippedKey = Key.stripMinecraftNamespace(registryKey);
152+
if (toRemoveRegistries.contains(strippedKey)) {
153+
finalLength--;
154+
151155
final int tagsSize = wrapper.read(Types.VAR_INT);
152156
for (int j = 0; j < tagsSize; j++) {
153157
wrapper.read(Types.STRING);
@@ -157,7 +161,29 @@ public void handleGeneric(final PacketWrapper wrapper) {
157161
}
158162

159163
wrapper.write(Types.STRING, registryKey);
160-
handle(wrapper, Key.stripMinecraftNamespace(registryKey));
164+
165+
final RegistryType type = RegistryType.getByKey(registryKey);
166+
if (type != null) {
167+
handle(wrapper, type);
168+
readTypes.add(type);
169+
} else {
170+
handle(wrapper, null, null, null, null);
171+
}
172+
}
173+
174+
for (final Map.Entry<RegistryType, List<TagData>> entry : toAdd.entrySet()) {
175+
if (readTypes.contains(entry.getKey())) {
176+
continue;
177+
}
178+
179+
// Registry wasn't present in the packet, add them here
180+
wrapper.write(Types.STRING, entry.getKey().resourceLocation());
181+
appendNewTags(wrapper, entry.getKey());
182+
finalLength++;
183+
}
184+
185+
if (length != finalLength) {
186+
wrapper.set(Types.VAR_INT, 0, finalLength);
161187
}
162188
}
163189

15.9 KB
Binary file not shown.

0 commit comments

Comments
 (0)