Add method to load extra tags from diff files

This commit is contained in:
KennyTV 2021-06-06 16:18:15 +02:00
parent 38b3f40f7d
commit 24efb48004
No known key found for this signature in database
GPG Key ID: 6BE3B555EBC5982B
15 changed files with 318 additions and 104 deletions

View File

@ -22,9 +22,13 @@
*/
package com.viaversion.viaversion.api.data;
import com.viaversion.viaversion.api.minecraft.RegistryType;
import com.viaversion.viaversion.api.minecraft.TagData;
import com.viaversion.viaversion.util.Int2IntBiMap;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.List;
public interface MappingData {
/**
@ -77,6 +81,14 @@ public interface MappingData {
*/
int getNewParticleId(int id);
/**
* Returns a list of tags to send if present.
*
* @param type registry tag type
* @return list of tags to send if present, else null
*/
@Nullable List<TagData> getTags(RegistryType type);
@Nullable Int2IntBiMap getItemMappings();
@Nullable ParticleMappings getParticleMappings();

View File

@ -22,12 +22,21 @@
*/
package com.viaversion.viaversion.api.data;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.minecraft.RegistryType;
import com.viaversion.viaversion.api.minecraft.TagData;
import com.viaversion.viaversion.util.Int2IntBiHashMap;
import com.viaversion.viaversion.util.Int2IntBiMap;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.ArrayList;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
public class MappingDataBase implements MappingData {
@ -40,6 +49,7 @@ public class MappingDataBase implements MappingData {
protected Mappings blockStateMappings;
protected Mappings soundMappings;
protected Mappings statisticsMappings;
protected Map<RegistryType, List<TagData>> tags;
protected boolean loadItems = true;
public MappingDataBase(String oldVersion, String newVersion) {
@ -76,9 +86,42 @@ public class MappingDataBase implements MappingData {
diffmapping != null ? diffmapping.getAsJsonObject("items") : null);
}
if (diffmapping != null && diffmapping.has("tags")) {
this.tags = new EnumMap<>(RegistryType.class);
JsonObject tags = diffmapping.getAsJsonObject("tags");
if (tags.has(RegistryType.ITEM.getResourceLocation())) {
loadTags(RegistryType.ITEM, tags, MappingDataLoader.indexedObjectToMap(newMappings.getAsJsonObject("items")));
}
if (tags.has(RegistryType.BLOCK.getResourceLocation())) {
loadTags(RegistryType.BLOCK, tags, MappingDataLoader.indexedObjectToMap(newMappings.getAsJsonObject("blocks")));
}
}
loadExtras(oldMappings, newMappings, diffmapping);
}
private void loadTags(RegistryType type, JsonObject object, Object2IntMap<String> typeMapping) {
JsonObject tags = object.getAsJsonObject(type.getResourceLocation());
List<TagData> tagsList = new ArrayList<>(tags.size());
for (Map.Entry<String, JsonElement> entry : tags.entrySet()) {
JsonArray array = entry.getValue().getAsJsonArray();
int[] entries = new int[array.size()];
int i = 0;
for (JsonElement element : array) {
String stringId = element.getAsString();
if (!typeMapping.containsKey(stringId) && !typeMapping.containsKey(stringId = stringId.replace("minecraft:", ""))) { // aaa
getLogger().warning(type + " Tags contains invalid type identifier " + stringId + " in tag " + entry.getKey());
continue;
}
entries[i++] = typeMapping.getInt(stringId);
}
tagsList.add(new TagData(entry.getKey(), entries));
}
this.tags.put(type, tagsList);
}
@Override
public int getNewBlockStateId(int id) {
return checkValidity(id, blockStateMappings.getNewId(id), "blockstate");
@ -106,6 +149,11 @@ public class MappingDataBase implements MappingData {
return checkValidity(id, particleMappings.getMappings().getNewId(id), "particles");
}
@Override
public @Nullable List<TagData> getTags(RegistryType type) {
return tags != null ? tags.get(type) : null;
}
@Override
public @Nullable Int2IntBiMap getItemMappings() {
return itemMappings;

View File

@ -150,7 +150,7 @@ public class MappingDataLoader {
}
public static void mapIdentifiers(int[] output, JsonObject oldIdentifiers, JsonObject newIdentifiers, @Nullable JsonObject diffIdentifiers) {
Object2IntMap newIdentifierMap = MappingDataLoader.indexedObjectToMap(newIdentifiers);
Object2IntMap<String> newIdentifierMap = MappingDataLoader.indexedObjectToMap(newIdentifiers);
for (Map.Entry<String, JsonElement> entry : oldIdentifiers.entrySet()) {
int value = mapIdentifierEntry(entry, newIdentifierMap, diffIdentifiers);
if (value != -1) {

View File

@ -0,0 +1,64 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2021 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.minecraft;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.HashMap;
import java.util.Map;
public enum RegistryType {
BLOCK("block"),
ITEM("item"),
FLUID("fluid"),
ENTITY("entity_type"),
GAME_EVENT("game_event");
private static final Map<String, RegistryType> MAP = new HashMap<>();
private static final RegistryType[] VALUES = values();
static {
for (RegistryType type : getValues()) {
MAP.put(type.resourceLocation, type);
}
}
public static RegistryType[] getValues() {
return VALUES;
}
public static @Nullable RegistryType getByKey(String resourceKey) {
return MAP.get(resourceKey);
}
private final String resourceLocation;
RegistryType(final String resourceLocation) {
this.resourceLocation = resourceLocation;
}
public String getResourceLocation() {
return resourceLocation;
}
}

View File

@ -0,0 +1,41 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2021 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.minecraft;
public final class TagData {
private final String identifier;
private final int[] entries;
public TagData(String identifier, int[] entries) {
this.identifier = identifier;
this.entries = entries;
}
public String identifier() {
return identifier;
}
public int[] entries() {
return entries;
}
}

View File

@ -467,12 +467,15 @@ public class ProtocolManagerImpl implements ProtocolManager {
private void shutdownLoaderExecutor() {
Preconditions.checkArgument(!mappingsLoaded);
// If this log message is missing, something is wrong
Via.getPlatform().getLogger().info("Finished mapping loading, shutting down loader executor!");
mappingsLoaded = true;
mappingLoaderExecutor.shutdown();
mappingLoaderExecutor = null;
mappingLoaderFutures.clear();
mappingLoaderFutures = null;
// Clear cached json files
if (MappingDataLoader.isCacheJsonMappings()) {
MappingDataLoader.getMappingsCache().clear();
}

View File

@ -38,7 +38,7 @@ import com.viaversion.viaversion.protocols.protocol1_13_1to1_13.packets.WorldPac
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ServerboundPackets1_13;
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
import com.viaversion.viaversion.rewriter.RegistryType;
import com.viaversion.viaversion.api.minecraft.RegistryType;
import com.viaversion.viaversion.rewriter.StatisticsRewriter;
import com.viaversion.viaversion.rewriter.TagRewriter;

View File

@ -33,7 +33,7 @@ import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.packets.EntityPa
import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.packets.InventoryPackets;
import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.packets.PlayerPackets;
import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.packets.WorldPackets;
import com.viaversion.viaversion.rewriter.RegistryType;
import com.viaversion.viaversion.api.minecraft.RegistryType;
import com.viaversion.viaversion.rewriter.SoundRewriter;
import com.viaversion.viaversion.rewriter.StatisticsRewriter;
import com.viaversion.viaversion.rewriter.TagRewriter;

View File

@ -32,7 +32,7 @@ import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.packets.Invent
import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.packets.WorldPackets;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.ClientboundPackets1_16;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.ServerboundPackets1_16;
import com.viaversion.viaversion.rewriter.RegistryType;
import com.viaversion.viaversion.api.minecraft.RegistryType;
import com.viaversion.viaversion.rewriter.SoundRewriter;
import com.viaversion.viaversion.rewriter.StatisticsRewriter;
import com.viaversion.viaversion.rewriter.TagRewriter;

View File

@ -41,7 +41,7 @@ import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.packets.Inventor
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.packets.WorldPackets;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.storage.InventoryTracker1_16;
import com.viaversion.viaversion.rewriter.ComponentRewriter;
import com.viaversion.viaversion.rewriter.RegistryType;
import com.viaversion.viaversion.api.minecraft.RegistryType;
import com.viaversion.viaversion.rewriter.SoundRewriter;
import com.viaversion.viaversion.rewriter.StatisticsRewriter;
import com.viaversion.viaversion.rewriter.TagRewriter;

View File

@ -21,6 +21,7 @@ import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.data.MappingData;
import com.viaversion.viaversion.api.data.MappingDataBase;
import com.viaversion.viaversion.api.minecraft.RegistryType;
import com.viaversion.viaversion.api.minecraft.entities.Entity1_17Types;
import com.viaversion.viaversion.api.protocol.AbstractProtocol;
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
@ -35,7 +36,6 @@ import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.packets.EntityPa
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.packets.InventoryPackets;
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.packets.WorldPackets;
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.storage.InventoryAcknowledgements;
import com.viaversion.viaversion.rewriter.RegistryType;
import com.viaversion.viaversion.rewriter.SoundRewriter;
import com.viaversion.viaversion.rewriter.StatisticsRewriter;
import com.viaversion.viaversion.rewriter.TagRewriter;
@ -208,8 +208,10 @@ public final class Protocol1_17To1_16_4 extends AbstractProtocol<ClientboundPack
@Override
protected void onMappingDataLoaded() {
tagRewriter.loadFromMappingData(); // Load filled extra tags
tagRewriter.addEmptyTags(RegistryType.ITEM, "minecraft:candles", "minecraft:ignored_by_piglin_babies", "minecraft:piglin_food", "minecraft:freeze_immune_wearables",
"minecraft:axolotl_tempt_items", "minecraft:occludes_vibration_signals",
"minecraft:axolotl_tempt_items", "minecraft:occludes_vibration_signals", "minecraft:fox_food",
"minecraft:diamond_ores", "minecraft:iron_ores", "minecraft:lapis_ores", "minecraft:redstone_ores",
"minecraft:coal_ores", "minecraft:copper_ores", "minecraft:emerald_ores", "minecraft:cluster_max_harvestables");
tagRewriter.addEmptyTags(RegistryType.BLOCK, "minecraft:crystal_sound_blocks", "minecraft:candle_cakes", "minecraft:candles",
@ -223,15 +225,7 @@ public final class Protocol1_17To1_16_4 extends AbstractProtocol<ClientboundPack
// Mmmm numbers
tagRewriter.addTag(RegistryType.BLOCK, "minecraft:mineable/axe", 74, 246, 245, 622, 668, 730, 731, 497, 138, 238, 132, 680, 306, 671, 202, 147, 492, 491, 267, 728, 151, 697, 333, 97, 96, 672, 95, 203, 190, 162, 415, 674, 254, 667, 248, 244, 240, 258, 307, 247, 192, 239, 133, 666, 675, 681, 189, 682, 414, 329, 702, 701, 249, 688, 700, 699, 152, 416, 417, 418, 419, 420, 421, 422, 423, 424, 425, 426, 427, 428, 429, 430, 431, 432, 433, 434, 435, 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, 446, 447, 478, 476, 479, 477, 250, 475, 714, 715, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 131, 130, 410, 411, 413, 412, 40, 52, 45, 58, 35, 47, 46, 53, 39, 51, 44, 57, 37, 49, 42, 55, 38, 50, 43, 56, 36, 48, 41, 54, 692, 693, 694, 695, 683, 684, 685, 686, 13, 14, 15, 16, 17, 18, 704, 705, 19, 20, 21, 22, 23, 24, 155, 156, 157, 158, 159, 160, 722, 723, 165, 166, 167, 168, 169, 170, 724, 725, 308, 309, 310, 311, 312, 313, 718, 719, 161, 485, 486, 487, 488, 489, 720, 721, 191, 483, 484, 480, 481, 482, 710, 711, 174, 175, 176, 177, 178, 179, 708, 709, 452, 453, 454, 455, 456, 457, 706, 707, 146, 274, 275, 276, 375, 376, 716, 717, 226, 224, 227, 225, 222, 223, 712, 713);
tagRewriter.addTag(RegistryType.BLOCK, "minecraft:mineable/hoe", 504, 689, 390, 576, 729, 698, 65, 66, 62, 59, 60, 64, 63, 61);
tagRewriter.addTag(RegistryType.BLOCK, "minecraft:mineable/pickaxe", 1, 2, 3, 4, 5, 6, 7, 12, 31, 32, 33, 34, 68, 69, 70, 71, 72, 73, 134, 135, 136, 139, 140, 145, 149, 150, 154, 164, 172, 173, 180, 193, 196, 197, 228, 229, 230, 231, 241, 242, 251, 252, 255, 256, 257, 259, 260, 264, 268, 269, 270, 273, 330, 331, 334, 335, 336, 337, 338, 339, 340, 342, 343, 344, 345, 346, 347, 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, 379, 380, 381, 382, 383, 384, 385, 386, 387, 388, 407, 408, 448, 449, 450, 451, 458, 459, 460, 461, 462, 463, 464, 465, 466, 467, 468, 469, 470, 471, 472, 473, 474, 493, 494, 495, 496, 503, 505, 506, 508, 526, 527, 528, 529, 530, 531, 532, 533, 534, 535, 536, 537, 538, 539, 540, 541, 542, 543, 544, 545, 546, 547, 548, 549, 550, 551, 552, 553, 554, 555, 556, 557, 578, 579, 580, 581, 582, 583, 584, 585, 586, 587, 588, 589, 590, 591, 592, 598, 599, 600, 601, 602, 608, 609, 610, 611, 612, 627, 628, 629, 630, 631, 632, 633, 634, 635, 636, 637, 638, 639, 640, 641, 642, 643, 644, 645, 646, 647, 648, 649, 650, 651, 652, 653, 669, 670, 673, 676, 677, 678, 679, 687, 696, 734, 735, 736, 737, 742, 743, 744, 746, 747, 748, 749, 750, 751, 752, 754, 755, 756, 757, 760, 761, 762, 185, 409, 619, 183, 100, 93, 101, 233, 237, 236, 232, 235, 234, 279, 280, 654, 655, 656, 657, 658, 659, 660, 661, 662, 663, 664, 665, 745, 753, 759, 509, 525, 521, 522, 519, 517, 523, 513, 518, 515, 512, 511, 516, 520, 524, 510, 514, 326, 327, 328, 261, 163, 91, 92, 341);
tagRewriter.addTag(RegistryType.BLOCK, "minecraft:mineable/shovel", 188, 9, 10, 11, 153, 8, 30, 253, 28, 29, 186, 184, 194, 558, 559, 560, 561, 562, 563, 564, 565, 566, 567, 568, 569, 570, 571, 572, 573, 195);
tagRewriter.addTag(RegistryType.BLOCK, "minecraft:needs_stone_tool", 135, 32, 69, 68);
tagRewriter.addTag(RegistryType.BLOCK, "minecraft:needs_diamond_tool", 140, 736, 734, 737, 735);
tagRewriter.addTag(RegistryType.BLOCK, "minecraft:needs_iron_tool", 150, 149, 269, 273, 134, 31, 180);
tagRewriter.addTag(RegistryType.BLOCK, "minecraft:cauldrons", 261);
tagRewriter.addTag(RegistryType.ITEM, "minecraft:fox_food", 948);
}
@Override

View File

@ -1,59 +0,0 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2021 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viaversion.rewriter;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.HashMap;
import java.util.Map;
public enum RegistryType {
BLOCK("block"),
ITEM("item"),
FLUID("fluid"),
ENTITY("entity_type"),
GAME_EVENT("game_event");
private static final Map<String, RegistryType> MAP = new HashMap<>();
private static final RegistryType[] VALUES = values();
static {
for (RegistryType type : getValues()) {
MAP.put(type.resourceLocation, type);
}
}
public static RegistryType[] getValues() {
return VALUES;
}
public static @Nullable RegistryType getByKey(String resourceKey) {
return MAP.get(resourceKey);
}
private final String resourceLocation;
RegistryType(final String resourceLocation) {
this.resourceLocation = resourceLocation;
}
public String getResourceLocation() {
return resourceLocation;
}
}

View File

@ -17,6 +17,7 @@
*/
package com.viaversion.viaversion.rewriter;
import com.viaversion.viaversion.api.minecraft.RegistryType;
import com.viaversion.viaversion.api.protocol.Protocol;
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;

View File

@ -18,6 +18,9 @@
package com.viaversion.viaversion.rewriter;
import com.viaversion.viaversion.api.data.MappingData;
import com.viaversion.viaversion.api.minecraft.RegistryType;
import com.viaversion.viaversion.api.minecraft.TagData;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.protocol.Protocol;
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
@ -43,27 +46,74 @@ public class TagRewriter {
}
/**
* Adds an empty tag (since the client crashes if a checked tag is not registered.)
* Gets new tags from the protocol's {@link MappingData} instance.
*/
public void addEmptyTag(RegistryType tagType, String id) {
getOrComputeNewTags(tagType).add(new TagData(id, EMPTY_ARRAY));
public void loadFromMappingData() {
for (RegistryType type : RegistryType.getValues()) {
List<TagData> tags = protocol.getMappingData().getTags(type);
if (tags != null) {
getOrComputeNewTags(type).addAll(tags);
}
}
}
public void addEmptyTags(RegistryType tagType, String... ids) {
/**
* Adds an empty tag (since the client crashes if a checked tag is not registered).
*
* @param tagType registry tag type
* @param tagId tag id
*/
public void addEmptyTag(RegistryType tagType, String tagId) {
getOrComputeNewTags(tagType).add(new TagData(tagId, EMPTY_ARRAY));
}
public void addEmptyTags(RegistryType tagType, String... tagIds) {
List<TagData> tagList = getOrComputeNewTags(tagType);
for (String id : ids) {
for (String id : tagIds) {
tagList.add(new TagData(id, EMPTY_ARRAY));
}
}
public void addTag(RegistryType tagType, String id, int... oldIds) {
/**
* Adds an entity tag type to be filled with the given entity type ids.
*
* @param tagId registry tag type
* @param entities mapped entity types
*/
public void addEntityTag(String tagId, EntityType... entities) {
int[] ids = new int[entities.length];
for (int i = 0; i < entities.length; i++) {
ids[i] = entities[i].getId();
}
addTagRaw(RegistryType.ENTITY, tagId, ids);
}
/**
* Adds a tag type to be filled with the given type ids after being mapped to new ids.
*
* @param tagType registry tag type
* @param tagId tag id
* @param unmappedIds unmapped type ids
*/
public void addTag(RegistryType tagType, String tagId, int... unmappedIds) {
List<TagData> newTags = getOrComputeNewTags(tagType);
IdRewriteFunction rewriteFunction = getRewriter(tagType);
for (int i = 0; i < oldIds.length; i++) {
int oldId = oldIds[i];
oldIds[i] = rewriteFunction.rewrite(oldId);
for (int i = 0; i < unmappedIds.length; i++) {
int oldId = unmappedIds[i];
unmappedIds[i] = rewriteFunction.rewrite(oldId);
}
newTags.add(new TagData(id, oldIds));
newTags.add(new TagData(tagId, unmappedIds));
}
/**
* Adds a tag type to be filled with the given raw type ids.
*
* @param tagType registry tag type
* @param tagId tag id
* @param ids raw type ids
*/
public void addTagRaw(RegistryType tagType, String tagId, int... ids) {
getOrComputeNewTags(tagType).add(new TagData(tagId, ids));
}
/**
@ -154,8 +204,8 @@ public class TagRewriter {
// Send new tags if present
if (newTags != null) {
for (TagData tag : newTags) {
wrapper.write(Type.STRING, tag.identifier);
wrapper.write(Type.VAR_INT_ARRAY_PRIMITIVE, tag.entries);
wrapper.write(Type.STRING, tag.identifier());
wrapper.write(Type.VAR_INT_ARRAY_PRIMITIVE, tag.entries());
}
}
}
@ -183,22 +233,4 @@ public class TagRewriter {
return null;
}
}
public static final class TagData {
private final String identifier;
private final int[] entries;
public TagData(String identifier, int[] entries) {
this.identifier = identifier;
this.entries = entries;
}
public String getIdentifier() {
return identifier;
}
public int[] getEntries() {
return entries;
}
}
}

View File

@ -60,5 +60,83 @@
},
"items": {
"372": "minecraft:dirt_path"
},
"tags": {
"block": {
"minecraft:cauldrons": [
"minecraft:cauldron"
],
"minecraft:mineable/hoe": [
"minecraft:nether_wart_block",
"minecraft:warped_wart_block",
"minecraft:hay_block",
"minecraft:dried_kelp_block",
"minecraft:target",
"minecraft:shroomlight",
"minecraft:sponge",
"minecraft:wet_sponge",
"minecraft:jungle_leaves",
"minecraft:oak_leaves",
"minecraft:spruce_leaves",
"minecraft:dark_oak_leaves",
"minecraft:acacia_leaves",
"minecraft:birch_leaves"
],
"minecraft:mineable/shovel": [
"minecraft:clay",
"minecraft:dirt",
"minecraft:coarse_dirt",
"minecraft:podzol",
"minecraft:farmland",
"minecraft:grass_block",
"minecraft:gravel",
"minecraft:mycelium",
"minecraft:sand",
"minecraft:red_sand",
"minecraft:snow_block",
"minecraft:snow",
"minecraft:soul_sand",
"minecraft:dirt_path",
"minecraft:white_concrete_powder",
"minecraft:orange_concrete_powder",
"minecraft:magenta_concrete_powder",
"minecraft:light_blue_concrete_powder",
"minecraft:yellow_concrete_powder",
"minecraft:lime_concrete_powder",
"minecraft:pink_concrete_powder",
"minecraft:gray_concrete_powder",
"minecraft:light_gray_concrete_powder",
"minecraft:cyan_concrete_powder",
"minecraft:purple_concrete_powder",
"minecraft:blue_concrete_powder",
"minecraft:brown_concrete_powder",
"minecraft:green_concrete_powder",
"minecraft:red_concrete_powder",
"minecraft:black_concrete_powder",
"minecraft:soul_soil"
],
"minecraft:needs_diamond_tool": [
"minecraft:obsidian",
"minecraft:crying_obsidian",
"minecraft:netherite_block",
"minecraft:respawn_anchor",
"minecraft:ancient_debris"
],
"minecraft:needs_iron_tool": [
"minecraft:diamond_block",
"minecraft:diamond_ore",
"minecraft:emerald_ore",
"minecraft:emerald_block",
"minecraft:gold_block",
"minecraft:gold_ore",
"minecraft:redstone_ore"
],
"minecraft:needs_stone_tool": [
"minecraft:iron_block",
"minecraft:iron_ore",
"minecraft:lapis_block",
"minecraft:lapis_ore"
]
}
}
}