3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-28 00:50:13 +01:00

Clean up tags rewriting (#3856)

Dieser Commit ist enthalten in:
RK_01 2024-05-16 10:31:05 +02:00 committet von GitHub
Ursprung 1399c901d2
Commit 91f31b578f
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: B5690EEEBB952194
29 geänderte Dateien mit 140 neuen und 194 gelöschten Zeilen

Datei anzeigen

@ -107,6 +107,7 @@ public class MappingDataBase implements MappingData {
this.tags = new EnumMap<>(RegistryType.class); this.tags = new EnumMap<>(RegistryType.class);
loadTags(RegistryType.ITEM, tagsTag); loadTags(RegistryType.ITEM, tagsTag);
loadTags(RegistryType.BLOCK, tagsTag); loadTags(RegistryType.BLOCK, tagsTag);
loadTags(RegistryType.ENTITY, tagsTag);
} }
loadExtras(data); loadExtras(data);

Datei anzeigen

@ -32,7 +32,9 @@ public interface TagRewriter extends MappingDataListener {
void removeTags(String registryKey); void removeTags(String registryKey);
void renameTag(RegistryType type, String registryKey, String renameTo); void removeTag(RegistryType type, String tagId);
void renameTag(RegistryType type, String tagId, String renameTo);
/** /**
* Adds an empty tag (since the client crashes if a checked tag is not registered). * Adds an empty tag (since the client crashes if a checked tag is not registered).

Datei anzeigen

@ -151,19 +151,19 @@ public class Protocol1_12_2To1_13 extends AbstractProtocol<ClientboundPackets1_1
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());
// 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()); wrapper.write(Types.VAR_INT_ARRAY_PRIMITIVE, tag.getValue().clone());
} }
wrapper.write(Types.VAR_INT, MAPPINGS.getItemTags().size()); // item tags wrapper.write(Types.VAR_INT, MAPPINGS.getItemTags().size()); // item tags
for (Map.Entry<String, int[]> tag : MAPPINGS.getItemTags().entrySet()) { for (Map.Entry<String, int[]> tag : MAPPINGS.getItemTags().entrySet()) {
wrapper.write(Types.STRING, tag.getKey()); wrapper.write(Types.STRING, tag.getKey());
// 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()); wrapper.write(Types.VAR_INT_ARRAY_PRIMITIVE, tag.getValue().clone());
} }
wrapper.write(Types.VAR_INT, MAPPINGS.getFluidTags().size()); // fluid tags wrapper.write(Types.VAR_INT, MAPPINGS.getFluidTags().size()); // fluid tags
for (Map.Entry<String, int[]> tag : MAPPINGS.getFluidTags().entrySet()) { for (Map.Entry<String, int[]> tag : MAPPINGS.getFluidTags().entrySet()) {
wrapper.write(Types.STRING, tag.getKey()); wrapper.write(Types.STRING, tag.getKey());
// 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()); wrapper.write(Types.VAR_INT_ARRAY_PRIMITIVE, tag.getValue().clone());
} }
}).scheduleSend(Protocol1_12_2To1_13.class); }).scheduleSend(Protocol1_12_2To1_13.class);
}; };

Datei anzeigen

@ -19,9 +19,10 @@ package com.viaversion.viaversion.protocols.v1_13_2to1_14;
import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.ClientWorld; import com.viaversion.viaversion.api.minecraft.ClientWorld;
import com.viaversion.viaversion.api.minecraft.RegistryType;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_14; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_14;
import com.viaversion.viaversion.api.protocol.AbstractProtocol; import com.viaversion.viaversion.api.protocol.AbstractProtocol;
import com.viaversion.viaversion.api.type.Types; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
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_2; import com.viaversion.viaversion.api.type.types.version.Types1_13_2;
import com.viaversion.viaversion.api.type.types.version.Types1_14; import com.viaversion.viaversion.api.type.types.version.Types1_14;
@ -40,6 +41,7 @@ import com.viaversion.viaversion.rewriter.CommandRewriter;
import com.viaversion.viaversion.rewriter.ComponentRewriter; import com.viaversion.viaversion.rewriter.ComponentRewriter;
import com.viaversion.viaversion.rewriter.SoundRewriter; import com.viaversion.viaversion.rewriter.SoundRewriter;
import com.viaversion.viaversion.rewriter.StatisticsRewriter; import com.viaversion.viaversion.rewriter.StatisticsRewriter;
import com.viaversion.viaversion.rewriter.TagRewriter;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
public class Protocol1_13_2To1_14 extends AbstractProtocol<ClientboundPackets1_13, ClientboundPackets1_14, ServerboundPackets1_13, ServerboundPackets1_14> { public class Protocol1_13_2To1_14 extends AbstractProtocol<ClientboundPackets1_13, ClientboundPackets1_14, ServerboundPackets1_13, ServerboundPackets1_14> {
@ -47,6 +49,7 @@ public class Protocol1_13_2To1_14 extends AbstractProtocol<ClientboundPackets1_1
public static final MappingData1_14 MAPPINGS = new MappingData1_14(); public static final MappingData1_14 MAPPINGS = new MappingData1_14();
private final EntityPacketRewriter1_14 entityRewriter = new EntityPacketRewriter1_14(this); private final EntityPacketRewriter1_14 entityRewriter = new EntityPacketRewriter1_14(this);
private final ItemPacketRewriter1_14 itemRewriter = new ItemPacketRewriter1_14(this); private final ItemPacketRewriter1_14 itemRewriter = new ItemPacketRewriter1_14(this);
private final TagRewriter<ClientboundPackets1_13> tagRewriter = new TagRewriter<>(this);
public Protocol1_13_2To1_14() { public Protocol1_13_2To1_14() {
super(ClientboundPackets1_13.class, ClientboundPackets1_14.class, ServerboundPackets1_13.class, ServerboundPackets1_14.class); super(ClientboundPackets1_13.class, ClientboundPackets1_14.class, ServerboundPackets1_13.class, ServerboundPackets1_14.class);
@ -76,59 +79,12 @@ public class Protocol1_13_2To1_14 extends AbstractProtocol<ClientboundPackets1_1
}; };
commandRewriter.registerDeclareCommands(ClientboundPackets1_13.COMMANDS); commandRewriter.registerDeclareCommands(ClientboundPackets1_13.COMMANDS);
registerClientbound(ClientboundPackets1_13.UPDATE_TAGS, wrapper -> { registerClientbound(ClientboundPackets1_13.UPDATE_TAGS, new PacketHandlers() {
int blockTagsSize = wrapper.read(Types.VAR_INT); @Override
wrapper.write(Types.VAR_INT, blockTagsSize + 6); // block tags protected void register() {
for (int i = 0; i < blockTagsSize; i++) { handler(tagRewriter.getHandler(RegistryType.FLUID));
wrapper.passthrough(Types.STRING); handler(wrapper -> tagRewriter.appendNewTags(wrapper, RegistryType.ENTITY));
int[] blockIds = wrapper.passthrough(Types.VAR_INT_ARRAY_PRIMITIVE);
for (int j = 0; j < blockIds.length; j++) {
blockIds[j] = MAPPINGS.getNewBlockId(blockIds[j]);
} }
}
// Minecraft crashes if we not send signs tags
wrapper.write(Types.STRING, "minecraft:signs");
wrapper.write(Types.VAR_INT_ARRAY_PRIMITIVE, new int[]{
MAPPINGS.getNewBlockId(150), MAPPINGS.getNewBlockId(155)
});
wrapper.write(Types.STRING, "minecraft:wall_signs");
wrapper.write(Types.VAR_INT_ARRAY_PRIMITIVE, new int[]{
MAPPINGS.getNewBlockId(155)
});
wrapper.write(Types.STRING, "minecraft:standing_signs");
wrapper.write(Types.VAR_INT_ARRAY_PRIMITIVE, new int[]{
MAPPINGS.getNewBlockId(150)
});
// Fences and walls tags - used for block connections
wrapper.write(Types.STRING, "minecraft:fences");
wrapper.write(Types.VAR_INT_ARRAY_PRIMITIVE, new int[]{189, 248, 472, 473, 474, 475});
wrapper.write(Types.STRING, "minecraft:walls");
wrapper.write(Types.VAR_INT_ARRAY_PRIMITIVE, new int[]{271, 272});
wrapper.write(Types.STRING, "minecraft:wooden_fences");
wrapper.write(Types.VAR_INT_ARRAY_PRIMITIVE, new int[]{189, 472, 473, 474, 475});
int itemTagsSize = wrapper.read(Types.VAR_INT);
wrapper.write(Types.VAR_INT, itemTagsSize + 2); // item tags
for (int i = 0; i < itemTagsSize; i++) {
wrapper.passthrough(Types.STRING);
int[] itemIds = wrapper.passthrough(Types.VAR_INT_ARRAY_PRIMITIVE);
for (int j = 0; j < itemIds.length; j++) {
itemIds[j] = MAPPINGS.getNewItemId(itemIds[j]);
}
}
// Should fix fuel shift clicking
wrapper.write(Types.STRING, "minecraft:signs");
wrapper.write(Types.VAR_INT_ARRAY_PRIMITIVE, new int[]{
MAPPINGS.getNewItemId(541)
});
// Arrows tag (used by bow)
wrapper.write(Types.STRING, "minecraft:arrows");
wrapper.write(Types.VAR_INT_ARRAY_PRIMITIVE, new int[]{526, 825, 826});
int fluidTagsSize = wrapper.passthrough(Types.VAR_INT); // fluid tags
for (int i = 0; i < fluidTagsSize; i++) {
wrapper.passthrough(Types.STRING);
wrapper.passthrough(Types.VAR_INT_ARRAY_PRIMITIVE);
}
wrapper.write(Types.VAR_INT, 0); // new entity tags - do we need to send this?
}); });
// Set Difficulty packet added in 19w11a // Set Difficulty packet added in 19w11a
@ -157,6 +113,8 @@ public class Protocol1_13_2To1_14 extends AbstractProtocol<ClientboundPackets1_1
.reader("falling_dust", ParticleType.Readers.BLOCK) .reader("falling_dust", ParticleType.Readers.BLOCK)
.reader("item", ParticleType.Readers.ITEM1_13_2); .reader("item", ParticleType.Readers.ITEM1_13_2);
tagRewriter.addEmptyTag(RegistryType.BLOCK, "bamboo_plantable_on");
super.onMappingDataLoaded(); super.onMappingDataLoaded();
} }
@ -182,4 +140,9 @@ public class Protocol1_13_2To1_14 extends AbstractProtocol<ClientboundPackets1_1
public ItemPacketRewriter1_14 getItemRewriter() { public ItemPacketRewriter1_14 getItemRewriter() {
return itemRewriter; return itemRewriter;
} }
@Override
public TagRewriter<ClientboundPackets1_13> getTagRewriter() {
return tagRewriter;
}
} }

Datei anzeigen

@ -67,12 +67,10 @@ public class Protocol1_14_4To1_15 extends AbstractProtocol<ClientboundPackets1_1
protected void onMappingDataLoaded() { protected void onMappingDataLoaded() {
EntityTypes1_15.initialize(this); EntityTypes1_15.initialize(this);
int[] shulkerBoxes = new int[17]; tagRewriter.removeTag(RegistryType.BLOCK, "minecraft:dirt_like");
int shulkerBoxOffset = 501; tagRewriter.addEmptyTag(RegistryType.ITEM, "minecraft:lectern_books");
for (int i = 0; i < 17; i++) { tagRewriter.addEmptyTags(RegistryType.BLOCK, "minecraft:bee_growables", "minecraft:beehives");
shulkerBoxes[i] = shulkerBoxOffset + i; tagRewriter.addEmptyTag(RegistryType.ENTITY, "minecraft:beehive_inhabitors");
}
tagRewriter.addTag(RegistryType.BLOCK, "minecraft:shulker_boxes", shulkerBoxes);
super.onMappingDataLoaded(); super.onMappingDataLoaded();
} }

Datei anzeigen

@ -213,49 +213,6 @@ public class Protocol1_15_2To1_16 extends AbstractProtocol<ClientboundPackets1_1
@Override @Override
protected void onMappingDataLoaded() { protected void onMappingDataLoaded() {
int[] wallPostOverrideTag = new int[47];
int arrayIndex = 0;
wallPostOverrideTag[arrayIndex++] = 140;
wallPostOverrideTag[arrayIndex++] = 179;
wallPostOverrideTag[arrayIndex++] = 264;
for (int i = 153; i <= 158; i++) {
wallPostOverrideTag[arrayIndex++] = i;
}
for (int i = 163; i <= 168; i++) {
wallPostOverrideTag[arrayIndex++] = i;
}
for (int i = 408; i <= 439; i++) {
wallPostOverrideTag[arrayIndex++] = i;
}
tagRewriter.addTag(RegistryType.BLOCK, "minecraft:wall_post_override", wallPostOverrideTag);
tagRewriter.addTag(RegistryType.BLOCK, "minecraft:beacon_base_blocks", 133, 134, 148, 265);
tagRewriter.addTag(RegistryType.BLOCK, "minecraft:climbable", 160, 241, 658);
tagRewriter.addTag(RegistryType.BLOCK, "minecraft:fire", 142);
tagRewriter.addTag(RegistryType.BLOCK, "minecraft:campfires", 679);
tagRewriter.addTag(RegistryType.BLOCK, "minecraft:fence_gates", 242, 467, 468, 469, 470, 471);
tagRewriter.addTag(RegistryType.BLOCK, "minecraft:unstable_bottom_center", 242, 467, 468, 469, 470, 471);
tagRewriter.addTag(RegistryType.BLOCK, "minecraft:wooden_trapdoors", 193, 194, 195, 196, 197, 198);
tagRewriter.addTag(RegistryType.ITEM, "minecraft:wooden_trapdoors", 215, 216, 217, 218, 219, 220);
tagRewriter.addTag(RegistryType.ITEM, "minecraft:beacon_payment_items", 529, 530, 531, 760);
tagRewriter.addTag(RegistryType.ENTITY, "minecraft:impact_projectiles", 2, 72, 71, 37, 69, 79, 83, 15, 93);
// The client crashes if we don't send all tags it may use
tagRewriter.addEmptyTag(RegistryType.BLOCK, "minecraft:guarded_by_piglins");
tagRewriter.addEmptyTag(RegistryType.BLOCK, "minecraft:soul_speed_blocks");
tagRewriter.addEmptyTag(RegistryType.BLOCK, "minecraft:soul_fire_base_blocks");
tagRewriter.addEmptyTag(RegistryType.BLOCK, "minecraft:non_flammable_wood");
tagRewriter.addEmptyTag(RegistryType.ITEM, "minecraft:non_flammable_wood");
// The rest of not accessed tags added in older versions; #1830
tagRewriter.addEmptyTags(RegistryType.BLOCK, "minecraft:bamboo_plantable_on", "minecraft:beds", "minecraft:bee_growables",
"minecraft:beehives", "minecraft:coral_plants", "minecraft:crops", "minecraft:dragon_immune", "minecraft:flowers",
"minecraft:portals", "minecraft:shulker_boxes", "minecraft:small_flowers", "minecraft:tall_flowers", "minecraft:trapdoors",
"minecraft:underwater_bonemeals", "minecraft:wither_immune", "minecraft:wooden_fences", "minecraft:wooden_trapdoors");
tagRewriter.addEmptyTags(RegistryType.ENTITY, "minecraft:arrows", "minecraft:beehive_inhabitors", "minecraft:raiders", "minecraft:skeletons");
tagRewriter.addEmptyTags(RegistryType.ITEM, "minecraft:beds", "minecraft:coals", "minecraft:fences", "minecraft:flowers",
"minecraft:lectern_books", "minecraft:music_discs", "minecraft:small_flowers", "minecraft:tall_flowers", "minecraft:trapdoors", "minecraft:walls", "minecraft:wooden_fences");
EntityTypes1_16.initialize(this); EntityTypes1_16.initialize(this);
Types1_16.PARTICLE.filler(this) Types1_16.PARTICLE.filler(this)
.reader("block", ParticleType.Readers.BLOCK) .reader("block", ParticleType.Readers.BLOCK)
@ -263,6 +220,12 @@ public class Protocol1_15_2To1_16 extends AbstractProtocol<ClientboundPackets1_1
.reader("falling_dust", ParticleType.Readers.BLOCK) .reader("falling_dust", ParticleType.Readers.BLOCK)
.reader("item", ParticleType.Readers.ITEM1_13_2); .reader("item", ParticleType.Readers.ITEM1_13_2);
tagRewriter.addEmptyTags(RegistryType.ITEM, "minecraft:crimson_stems", "minecraft:non_flammable_wood", "minecraft:piglin_loved",
"minecraft:piglin_repellents", "minecraft:soul_fire_base_blocks", "minecraft:warped_stems");
tagRewriter.addEmptyTags(RegistryType.BLOCK, "minecraft:crimson_stems", "minecraft:guarded_by_piglins", "minecraft:hoglin_repellents",
"minecraft:non_flammable_wood", "minecraft:nylium", "minecraft:piglin_repellents", "minecraft:soul_fire_base_blocks", "minecraft:soul_speed_blocks",
"minecraft:strider_warm_blocks", "minecraft:warped_stems");
super.onMappingDataLoaded(); super.onMappingDataLoaded();
} }

Datei anzeigen

@ -26,9 +26,9 @@ import com.viaversion.viaversion.data.entity.EntityTrackerBase;
import com.viaversion.viaversion.protocols.v1_15_2to1_16.packet.ClientboundPackets1_16; import com.viaversion.viaversion.protocols.v1_15_2to1_16.packet.ClientboundPackets1_16;
import com.viaversion.viaversion.protocols.v1_15_2to1_16.packet.ServerboundPackets1_16; import com.viaversion.viaversion.protocols.v1_15_2to1_16.packet.ServerboundPackets1_16;
import com.viaversion.viaversion.protocols.v1_16_1to1_16_2.data.MappingData1_16_2; import com.viaversion.viaversion.protocols.v1_16_1to1_16_2.data.MappingData1_16_2;
import com.viaversion.viaversion.protocols.v1_16_1to1_16_2.rewriter.EntityPacketRewriter1_16_2;
import com.viaversion.viaversion.protocols.v1_16_1to1_16_2.packet.ClientboundPackets1_16_2; import com.viaversion.viaversion.protocols.v1_16_1to1_16_2.packet.ClientboundPackets1_16_2;
import com.viaversion.viaversion.protocols.v1_16_1to1_16_2.packet.ServerboundPackets1_16_2; import com.viaversion.viaversion.protocols.v1_16_1to1_16_2.packet.ServerboundPackets1_16_2;
import com.viaversion.viaversion.protocols.v1_16_1to1_16_2.rewriter.EntityPacketRewriter1_16_2;
import com.viaversion.viaversion.protocols.v1_16_1to1_16_2.rewriter.ItemPacketRewriter1_16_2; import com.viaversion.viaversion.protocols.v1_16_1to1_16_2.rewriter.ItemPacketRewriter1_16_2;
import com.viaversion.viaversion.protocols.v1_16_1to1_16_2.rewriter.WorldPacketRewriter1_16_2; import com.viaversion.viaversion.protocols.v1_16_1to1_16_2.rewriter.WorldPacketRewriter1_16_2;
import com.viaversion.viaversion.rewriter.SoundRewriter; import com.viaversion.viaversion.rewriter.SoundRewriter;
@ -86,19 +86,7 @@ public class Protocol1_16_1To1_16_2 extends AbstractProtocol<ClientboundPackets1
protected void onMappingDataLoaded() { protected void onMappingDataLoaded() {
EntityTypes1_16_2.initialize(this); EntityTypes1_16_2.initialize(this);
tagRewriter.addTag(RegistryType.ITEM, "minecraft:stone_crafting_materials", 14, 962); tagRewriter.removeTag(RegistryType.ITEM, "minecraft:furnace_materials");
tagRewriter.addEmptyTag(RegistryType.BLOCK, "minecraft:mushroom_grow_block");
// The client now wants ALL (previous) tags to be sent, sooooo :>
tagRewriter.addEmptyTags(RegistryType.ITEM, "minecraft:soul_fire_base_blocks", "minecraft:furnace_materials", "minecraft:crimson_stems",
"minecraft:gold_ores", "minecraft:piglin_loved", "minecraft:piglin_repellents", "minecraft:creeper_drop_music_discs",
"minecraft:logs_that_burn", "minecraft:stone_tool_materials", "minecraft:warped_stems");
tagRewriter.addEmptyTags(RegistryType.BLOCK, "minecraft:infiniburn_nether", "minecraft:crimson_stems",
"minecraft:wither_summon_base_blocks", "minecraft:infiniburn_overworld", "minecraft:piglin_repellents",
"minecraft:hoglin_repellents", "minecraft:prevent_mob_spawning_inside", "minecraft:wart_blocks",
"minecraft:stone_pressure_plates", "minecraft:nylium", "minecraft:gold_ores", "minecraft:pressure_plates",
"minecraft:logs_that_burn", "minecraft:strider_warm_blocks", "minecraft:warped_stems", "minecraft:infiniburn_end",
"minecraft:base_stone_nether", "minecraft:base_stone_overworld");
super.onMappingDataLoaded(); super.onMappingDataLoaded();
} }

Datei anzeigen

@ -45,8 +45,6 @@ import com.viaversion.viaversion.rewriter.TagRewriter;
public final class Protocol1_16_4To1_17 extends AbstractProtocol<ClientboundPackets1_16_2, ClientboundPackets1_17, ServerboundPackets1_16_2, ServerboundPackets1_17> { public final class Protocol1_16_4To1_17 extends AbstractProtocol<ClientboundPackets1_16_2, ClientboundPackets1_17, ServerboundPackets1_16_2, ServerboundPackets1_17> {
public static final MappingData MAPPINGS = new MappingDataBase("1.16.2", "1.17"); public static final MappingData MAPPINGS = new MappingDataBase("1.16.2", "1.17");
private static final String[] NEW_GAME_EVENT_TAGS = {"minecraft:ignore_vibrations_sneaking", "minecraft:vibrations"};
private static final int[] EMPTY_ARRAY = new int[0];
private final EntityPacketRewriter1_17 entityRewriter = new EntityPacketRewriter1_17(this); private final EntityPacketRewriter1_17 entityRewriter = new EntityPacketRewriter1_17(this);
private final ItemPacketRewriter1_17 itemRewriter = new ItemPacketRewriter1_17(this); private final ItemPacketRewriter1_17 itemRewriter = new ItemPacketRewriter1_17(this);
private final TagRewriter<ClientboundPackets1_16_2> tagRewriter = new TagRewriter<>(this); private final TagRewriter<ClientboundPackets1_16_2> tagRewriter = new TagRewriter<>(this);
@ -80,11 +78,7 @@ public final class Protocol1_16_4To1_17 extends AbstractProtocol<ClientboundPack
// New Game Event tags type // New Game Event tags type
wrapper.write(Types.STRING, RegistryType.GAME_EVENT.resourceLocation()); wrapper.write(Types.STRING, RegistryType.GAME_EVENT.resourceLocation());
wrapper.write(Types.VAR_INT, NEW_GAME_EVENT_TAGS.length); tagRewriter.appendNewTags(wrapper, RegistryType.GAME_EVENT);
for (String tag : NEW_GAME_EVENT_TAGS) {
wrapper.write(Types.STRING, tag);
wrapper.write(Types.VAR_INT_ARRAY_PRIMITIVE, EMPTY_ARRAY);
}
}); });
new StatisticsRewriter<>(this).register(ClientboundPackets1_16_2.AWARD_STATS); new StatisticsRewriter<>(this).register(ClientboundPackets1_16_2.AWARD_STATS);
@ -174,19 +168,6 @@ public final class Protocol1_16_4To1_17 extends AbstractProtocol<ClientboundPack
@Override @Override
protected void onMappingDataLoaded() { protected void onMappingDataLoaded() {
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: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",
"minecraft:snow_step_sound_blocks", "minecraft:inside_step_sound_blocks", "minecraft:occludes_vibration_signals", "minecraft:dripstone_replaceable_blocks",
"minecraft:cave_vines", "minecraft:moss_replaceable", "minecraft:deepslate_ore_replaceables", "minecraft:lush_ground_replaceable",
"minecraft:diamond_ores", "minecraft:iron_ores", "minecraft:lapis_ores", "minecraft:redstone_ores", "minecraft:stone_ore_replaceables",
"minecraft:coal_ores", "minecraft:copper_ores", "minecraft:emerald_ores", "minecraft:snow", "minecraft:small_dripleaf_placeable",
"minecraft:features_cannot_replace", "minecraft:lava_pool_stone_replaceables", "minecraft:geode_invalid_blocks");
tagRewriter.addEmptyTags(RegistryType.ENTITY, "minecraft:powder_snow_walkable_mobs", "minecraft:axolotl_always_hostiles", "minecraft:axolotl_tempted_hostiles",
"minecraft:axolotl_hunt_targets", "minecraft:freeze_hurts_extra_types", "minecraft:freeze_immune_entity_types");
EntityTypes1_17.initialize(this); EntityTypes1_17.initialize(this);
Types1_17.PARTICLE.filler(this) Types1_17.PARTICLE.filler(this)
.reader("block", ParticleType.Readers.BLOCK) .reader("block", ParticleType.Readers.BLOCK)
@ -196,6 +177,15 @@ public final class Protocol1_16_4To1_17 extends AbstractProtocol<ClientboundPack
.reader("item", ParticleType.Readers.ITEM1_13_2) .reader("item", ParticleType.Readers.ITEM1_13_2)
.reader("vibration", ParticleType.Readers.VIBRATION); .reader("vibration", ParticleType.Readers.VIBRATION);
tagRewriter.addEmptyTags(RegistryType.ITEM, "minecraft:axolotl_tempt_items", "minecraft:candles", "minecraft:cluster_max_harvestables",
"minecraft:copper_ores", "minecraft:freeze_immune_wearables", "minecraft:occludes_vibration_signals");
tagRewriter.addEmptyTags(RegistryType.BLOCK, "minecraft:candle_cakes", "minecraft:candles", "minecraft:cave_vines", "minecraft:copper_ores",
"minecraft:crystal_sound_blocks", "minecraft:deepslate_ore_replaceables", "minecraft:dripstone_replaceable_blocks", "minecraft:geode_invalid_blocks",
"minecraft:lush_ground_replaceable", "minecraft:moss_replaceable", "minecraft:occludes_vibration_signals", "minecraft:small_dripleaf_placeable");
tagRewriter.addEmptyTags(RegistryType.ENTITY, "minecraft:axolotl_always_hostiles", "minecraft:axolotl_hunt_targets",
"minecraft:freeze_hurts_extra_types", "minecraft:freeze_immune_entity_types", "minecraft:powder_snow_walkable_mobs");
tagRewriter.addEmptyTags(RegistryType.GAME_EVENT, "minecraft:ignore_vibrations_sneaking", "minecraft:vibrations");
super.onMappingDataLoaded(); super.onMappingDataLoaded();
} }

Datei anzeigen

@ -63,11 +63,6 @@ public final class Protocol1_17_1To1_18 extends AbstractProtocol<ClientboundPack
soundRewriter.registerSound(ClientboundPackets1_17_1.SOUND_ENTITY); soundRewriter.registerSound(ClientboundPackets1_17_1.SOUND_ENTITY);
tagRewriter.registerGeneric(ClientboundPackets1_17_1.UPDATE_TAGS); tagRewriter.registerGeneric(ClientboundPackets1_17_1.UPDATE_TAGS);
tagRewriter.addEmptyTags(RegistryType.BLOCK, "minecraft:lava_pool_stone_cannot_replace", "minecraft:big_dripleaf_placeable",
"minecraft:wolves_spawnable_on", "minecraft:rabbits_spawnable_on", "minecraft:polar_bears_spawnable_on_in_frozen_ocean", "minecraft:parrots_spawnable_on",
"minecraft:mooshrooms_spawnable_on", "minecraft:goats_spawnable_on", "minecraft:foxes_spawnable_on", "minecraft:axolotls_spawnable_on", "minecraft:animals_spawnable_on",
"minecraft:azalea_grows_on", "minecraft:azalea_root_replaceable", "minecraft:replaceable_plants", "minecraft:terracotta");
tagRewriter.addEmptyTags(RegistryType.ITEM, "minecraft:dirt", "minecraft:terracotta");
new StatisticsRewriter<>(this).register(ClientboundPackets1_17_1.AWARD_STATS); new StatisticsRewriter<>(this).register(ClientboundPackets1_17_1.AWARD_STATS);
@ -97,6 +92,8 @@ public final class Protocol1_17_1To1_18 extends AbstractProtocol<ClientboundPack
.reader("item", ParticleType.Readers.ITEM1_13_2) .reader("item", ParticleType.Readers.ITEM1_13_2)
.reader("vibration", ParticleType.Readers.VIBRATION); .reader("vibration", ParticleType.Readers.VIBRATION);
tagRewriter.renameTag(RegistryType.BLOCK, "minecraft:lava_pool_stone_replaceables", "minecraft:lava_pool_stone_cannot_replace");
super.onMappingDataLoaded(); super.onMappingDataLoaded();
} }
@ -125,4 +122,9 @@ public final class Protocol1_17_1To1_18 extends AbstractProtocol<ClientboundPack
public ItemPacketRewriter1_18 getItemRewriter() { public ItemPacketRewriter1_18 getItemRewriter() {
return itemRewriter; return itemRewriter;
} }
@Override
public TagRewriter<ClientboundPackets1_17_1> getTagRewriter() {
return tagRewriter;
}
} }

Datei anzeigen

@ -19,6 +19,7 @@ package com.viaversion.viaversion.protocols.v1_18_2to1_19;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.RegistryType;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_19; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_19;
import com.viaversion.viaversion.api.platform.providers.ViaProviders; import com.viaversion.viaversion.api.platform.providers.ViaProviders;
import com.viaversion.viaversion.api.protocol.AbstractProtocol; import com.viaversion.viaversion.api.protocol.AbstractProtocol;
@ -302,6 +303,18 @@ public final class Protocol1_18_2To1_19 extends AbstractProtocol<ClientboundPack
.reader("shriek", ParticleType.Readers.SHRIEK); .reader("shriek", ParticleType.Readers.SHRIEK);
EntityTypes1_19.initialize(this); EntityTypes1_19.initialize(this);
tagRewriter.removeTag(RegistryType.ITEM, "minecraft:occludes_vibration_signals");
tagRewriter.renameTag(RegistryType.ITEM, "minecraft:carpets", "minecraft:wool_carpets");
tagRewriter.renameTag(RegistryType.BLOCK, "minecraft:carpets", "minecraft:wool_carpets");
tagRewriter.renameTag(RegistryType.BLOCK, "minecraft:polar_bears_spawnable_on_in_frozen_ocean", "minecraft:polar_bears_spawnable_on_alternate");
tagRewriter.addEmptyTags(RegistryType.ITEM, "minecraft:chest_boats", "minecraft:dampens_vibrations", "minecraft:mangrove_logs", "minecraft:overworld_natural_logs");
tagRewriter.addEmptyTags(RegistryType.BLOCK, "minecraft:ancient_city_replaceable", "minecraft:convertable_to_mud", "minecraft:dampens_vibrations",
"minecraft:frog_prefer_jump_to", "minecraft:frogs_spawnable_on", "minecraft:mangrove_logs", "minecraft:mangrove_logs_can_grow_through",
"minecraft:mangrove_roots_can_grow_through", "minecraft:nether_carver_replaceables", "minecraft:overworld_carver_replaceables",
"minecraft:overworld_natural_logs", "minecraft:sculk_replaceable", "minecraft:sculk_replaceable_world_gen", "minecraft:snaps_goat_horn");
tagRewriter.addEmptyTag(RegistryType.ENTITY, "minecraft:frog_food");
tagRewriter.addEmptyTags(RegistryType.GAME_EVENT, "minecraft:allay_can_listen", "minecraft:shrieker_can_listen", "minecraft:warden_can_listen");
super.onMappingDataLoaded(); super.onMappingDataLoaded();
} }

Datei anzeigen

@ -39,7 +39,7 @@ public final class Protocol1_18To1_18_2 extends AbstractProtocol<ClientboundPack
@Override @Override
protected void registerPackets() { protected void registerPackets() {
final TagRewriter<ClientboundPackets1_18> tagRewriter = new TagRewriter<>(this); final TagRewriter<ClientboundPackets1_18> tagRewriter = new TagRewriter<>(this);
tagRewriter.addEmptyTag(RegistryType.BLOCK, "minecraft:fall_damage_resetting"); tagRewriter.addTagRaw(RegistryType.BLOCK, "minecraft:fall_damage_resetting", 169, 257, 680, 713, 714, 715, 716, 859, 860, 696, 100);
tagRewriter.registerGeneric(ClientboundPackets1_18.UPDATE_TAGS); tagRewriter.registerGeneric(ClientboundPackets1_18.UPDATE_TAGS);
registerClientbound(ClientboundPackets1_18.UPDATE_MOB_EFFECT, new PacketHandlers() { registerClientbound(ClientboundPackets1_18.UPDATE_MOB_EFFECT, new PacketHandlers() {

Datei anzeigen

@ -45,12 +45,12 @@ import com.viaversion.viaversion.protocols.base.ClientboundLoginPackets;
import com.viaversion.viaversion.protocols.base.ServerboundLoginPackets; import com.viaversion.viaversion.protocols.base.ServerboundLoginPackets;
import com.viaversion.viaversion.protocols.v1_19_1to1_19_3.packet.ClientboundPackets1_19_3; import com.viaversion.viaversion.protocols.v1_19_1to1_19_3.packet.ClientboundPackets1_19_3;
import com.viaversion.viaversion.protocols.v1_19_1to1_19_3.packet.ServerboundPackets1_19_3; import com.viaversion.viaversion.protocols.v1_19_1to1_19_3.packet.ServerboundPackets1_19_3;
import com.viaversion.viaversion.protocols.v1_19to1_19_1.packet.ClientboundPackets1_19_1;
import com.viaversion.viaversion.protocols.v1_19to1_19_1.packet.ServerboundPackets1_19_1;
import com.viaversion.viaversion.protocols.v1_19_1to1_19_3.rewriter.EntityPacketRewriter1_19_3; import com.viaversion.viaversion.protocols.v1_19_1to1_19_3.rewriter.EntityPacketRewriter1_19_3;
import com.viaversion.viaversion.protocols.v1_19_1to1_19_3.rewriter.ItemPacketRewriter1_19_3; import com.viaversion.viaversion.protocols.v1_19_1to1_19_3.rewriter.ItemPacketRewriter1_19_3;
import com.viaversion.viaversion.protocols.v1_19_1to1_19_3.storage.NonceStorage1_19_3; import com.viaversion.viaversion.protocols.v1_19_1to1_19_3.storage.NonceStorage1_19_3;
import com.viaversion.viaversion.protocols.v1_19_1to1_19_3.storage.ReceivedMessagesStorage; import com.viaversion.viaversion.protocols.v1_19_1to1_19_3.storage.ReceivedMessagesStorage;
import com.viaversion.viaversion.protocols.v1_19to1_19_1.packet.ClientboundPackets1_19_1;
import com.viaversion.viaversion.protocols.v1_19to1_19_1.packet.ServerboundPackets1_19_1;
import com.viaversion.viaversion.rewriter.CommandRewriter; import com.viaversion.viaversion.rewriter.CommandRewriter;
import com.viaversion.viaversion.rewriter.StatisticsRewriter; import com.viaversion.viaversion.rewriter.StatisticsRewriter;
import com.viaversion.viaversion.rewriter.TagRewriter; import com.viaversion.viaversion.rewriter.TagRewriter;
@ -76,12 +76,6 @@ public final class Protocol1_19_1To1_19_3 extends AbstractProtocol<ClientboundPa
@Override @Override
protected void registerPackets() { protected void registerPackets() {
// Flint and steel was hardcoded before 1.19.3 to ignite a creeper; has been moved to a tag - adding this ensures offhand doesn't trigger as well
tagRewriter.addTagRaw(RegistryType.ITEM, "minecraft:creeper_igniters", 733); // 733 = flint_and_steel 1.19.3
tagRewriter.addEmptyTags(RegistryType.ITEM, "minecraft:bookshelf_books", "minecraft:hanging_signs", "minecraft:stripped_logs");
tagRewriter.addEmptyTags(RegistryType.BLOCK, "minecraft:all_hanging_signs", "minecraft:ceiling_hanging_signs", "minecraft:invalid_spawn_inside",
"minecraft:stripped_logs", "minecraft:wall_hanging_signs");
tagRewriter.registerGeneric(ClientboundPackets1_19_1.UPDATE_TAGS); tagRewriter.registerGeneric(ClientboundPackets1_19_1.UPDATE_TAGS);
entityRewriter.register(); entityRewriter.register();
@ -359,6 +353,9 @@ public final class Protocol1_19_1To1_19_3 extends AbstractProtocol<ClientboundPa
.reader("shriek", ParticleType.Readers.SHRIEK); .reader("shriek", ParticleType.Readers.SHRIEK);
EntityTypes1_19_3.initialize(this); EntityTypes1_19_3.initialize(this);
tagRewriter.removeTag(RegistryType.ITEM, "minecraft:overworld_natural_logs");
tagRewriter.removeTag(RegistryType.BLOCK, "minecraft:non_flammable_wood");
super.onMappingDataLoaded(); super.onMappingDataLoaded();
} }

Datei anzeigen

@ -20,6 +20,7 @@ package com.viaversion.viaversion.protocols.v1_19_4to1_20;
import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.data.MappingData; import com.viaversion.viaversion.api.data.MappingData;
import com.viaversion.viaversion.api.data.MappingDataBase; import com.viaversion.viaversion.api.data.MappingDataBase;
import com.viaversion.viaversion.api.minecraft.RegistryType;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_19_4; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_19_4;
import com.viaversion.viaversion.api.protocol.AbstractProtocol; import com.viaversion.viaversion.api.protocol.AbstractProtocol;
import com.viaversion.viaversion.api.type.Types; import com.viaversion.viaversion.api.type.Types;
@ -80,6 +81,10 @@ public final class Protocol1_19_4To1_20 extends AbstractProtocol<ClientboundPack
.reader("sculk_charge", ParticleType.Readers.SCULK_CHARGE) .reader("sculk_charge", ParticleType.Readers.SCULK_CHARGE)
.reader("shriek", ParticleType.Readers.SHRIEK); .reader("shriek", ParticleType.Readers.SHRIEK);
tagRewriter.removeTag(RegistryType.BLOCK, "minecraft:replaceable_plants");
tagRewriter.addEmptyTags(RegistryType.ITEM, "minecraft:decorated_pot_ingredients", "minecraft:decorated_pot_sherds");
tagRewriter.addEmptyTag(RegistryType.BLOCK, "minecraft:trail_ruins_replaceable");
super.onMappingDataLoaded(); super.onMappingDataLoaded();
} }

Datei anzeigen

@ -34,7 +34,6 @@ import com.viaversion.viaversion.data.entity.EntityTrackerBase;
import com.viaversion.viaversion.protocols.base.ClientboundLoginPackets; import com.viaversion.viaversion.protocols.base.ClientboundLoginPackets;
import com.viaversion.viaversion.protocols.base.ServerboundLoginPackets; import com.viaversion.viaversion.protocols.base.ServerboundLoginPackets;
import com.viaversion.viaversion.protocols.v1_19_3to1_19_4.rewriter.CommandRewriter1_19_4; import com.viaversion.viaversion.protocols.v1_19_3to1_19_4.rewriter.CommandRewriter1_19_4;
import com.viaversion.viaversion.protocols.v1_20to1_20_2.packet.ServerboundConfigurationPackets1_20_2;
import com.viaversion.viaversion.protocols.v1_20_2to1_20_3.packet.ClientboundConfigurationPackets1_20_3; import com.viaversion.viaversion.protocols.v1_20_2to1_20_3.packet.ClientboundConfigurationPackets1_20_3;
import com.viaversion.viaversion.protocols.v1_20_2to1_20_3.packet.ClientboundPacket1_20_3; import com.viaversion.viaversion.protocols.v1_20_2to1_20_3.packet.ClientboundPacket1_20_3;
import com.viaversion.viaversion.protocols.v1_20_2to1_20_3.packet.ClientboundPackets1_20_3; import com.viaversion.viaversion.protocols.v1_20_2to1_20_3.packet.ClientboundPackets1_20_3;
@ -51,6 +50,7 @@ import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.rewriter.BlockItemPac
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.rewriter.ComponentRewriter1_20_5; import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.rewriter.ComponentRewriter1_20_5;
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.rewriter.EntityPacketRewriter1_20_5; import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.rewriter.EntityPacketRewriter1_20_5;
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.storage.AcknowledgedMessagesStorage; import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.storage.AcknowledgedMessagesStorage;
import com.viaversion.viaversion.protocols.v1_20to1_20_2.packet.ServerboundConfigurationPackets1_20_2;
import com.viaversion.viaversion.rewriter.ComponentRewriter; import com.viaversion.viaversion.rewriter.ComponentRewriter;
import com.viaversion.viaversion.rewriter.SoundRewriter; import com.viaversion.viaversion.rewriter.SoundRewriter;
import com.viaversion.viaversion.rewriter.StatisticsRewriter; import com.viaversion.viaversion.rewriter.StatisticsRewriter;
@ -279,7 +279,9 @@ public final class Protocol1_20_3To1_20_5 extends AbstractProtocol<ClientboundPa
.add(StructuredDataKey.LOCK).add(StructuredDataKey.CONTAINER_LOOT).add(StructuredDataKey.TOOL) .add(StructuredDataKey.LOCK).add(StructuredDataKey.CONTAINER_LOOT).add(StructuredDataKey.TOOL)
.add(StructuredDataKey.ITEM_NAME).add(StructuredDataKey.OMINOUS_BOTTLE_AMPLIFIER); .add(StructuredDataKey.ITEM_NAME).add(StructuredDataKey.OMINOUS_BOTTLE_AMPLIFIER);
tagRewriter.addTag(RegistryType.ITEM, "minecraft:dyeable", 853, 854, 855, 856, 1120); tagRewriter.renameTag(RegistryType.ITEM, "minecraft:axolotl_tempt_items", "minecraft:axolotl_food");
tagRewriter.removeTag(RegistryType.ITEM, "minecraft:tools");
tagRewriter.addEmptyTags(RegistryType.BLOCK, "minecraft:badlands_terracotta");
super.onMappingDataLoaded(); super.onMappingDataLoaded();
} }

Datei anzeigen

@ -43,7 +43,8 @@ public class TagRewriter<C extends ClientboundPacketType> implements com.viavers
private final Protocol<C, ?, ?, ?> protocol; private final Protocol<C, ?, ?, ?> protocol;
private final Map<RegistryType, List<TagData>> newTags = new EnumMap<>(RegistryType.class); private final Map<RegistryType, List<TagData>> newTags = new EnumMap<>(RegistryType.class);
private final Map<RegistryType, Map<String, String>> toRename = new EnumMap<>(RegistryType.class); private final Map<RegistryType, Map<String, String>> toRename = new EnumMap<>(RegistryType.class);
private final Set<String> toRemove = new HashSet<>(); private final Map<RegistryType, Set<String>> toRemove = new EnumMap<>(RegistryType.class);
private final Set<String> toRemoveRegistries = new HashSet<>();
public TagRewriter(final Protocol<C, ?, ?, ?> protocol) { public TagRewriter(final Protocol<C, ?, ?, ?> protocol) {
this.protocol = protocol; this.protocol = protocol;
@ -65,12 +66,17 @@ public class TagRewriter<C extends ClientboundPacketType> implements com.viavers
@Override @Override
public void removeTags(final String registryKey) { public void removeTags(final String registryKey) {
toRemove.add(registryKey); toRemoveRegistries.add(Key.stripMinecraftNamespace(registryKey));
} }
@Override @Override
public void renameTag(final RegistryType type, final String registryKey, final String renameTo) { public void removeTag(final RegistryType type, final String tagId) {
toRename.computeIfAbsent(type, t -> new HashMap<>()).put(registryKey, renameTo); toRemove.computeIfAbsent(type, t -> new HashSet<>()).add(Key.stripMinecraftNamespace(tagId));
}
@Override
public void renameTag(final RegistryType type, final String tagId, final String renameTo) {
toRename.computeIfAbsent(type, t -> new HashMap<>()).put(Key.stripMinecraftNamespace(tagId), renameTo);
} }
@Override @Override
@ -124,7 +130,7 @@ public class TagRewriter<C extends ClientboundPacketType> implements com.viavers
public PacketHandler getHandler(@Nullable RegistryType readUntilType) { public PacketHandler getHandler(@Nullable RegistryType readUntilType) {
return wrapper -> { return wrapper -> {
for (RegistryType type : RegistryType.getValues()) { for (RegistryType type : RegistryType.getValues()) {
handle(wrapper, getRewriter(type), getNewTags(type), toRename.get(type)); handle(wrapper, getRewriter(type), getNewTags(type), toRename.get(type), toRemove.get(type));
// Stop iterating // Stop iterating
if (type == readUntilType) { if (type == readUntilType) {
@ -140,7 +146,7 @@ public class TagRewriter<C extends ClientboundPacketType> implements com.viavers
int editedLength = length; int editedLength = length;
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
String registryKey = wrapper.read(Types.STRING); String registryKey = wrapper.read(Types.STRING);
if (toRemove.contains(registryKey)) { if (toRemoveRegistries.contains(Key.stripMinecraftNamespace(registryKey))) {
wrapper.set(Types.VAR_INT, 0, --editedLength); wrapper.set(Types.VAR_INT, 0, --editedLength);
int tagsSize = wrapper.read(Types.VAR_INT); int tagsSize = wrapper.read(Types.VAR_INT);
for (int j = 0; j < tagsSize; j++) { for (int j = 0; j < tagsSize; j++) {
@ -155,31 +161,30 @@ public class TagRewriter<C extends ClientboundPacketType> implements com.viavers
RegistryType type = RegistryType.getByKey(registryKey); RegistryType type = RegistryType.getByKey(registryKey);
if (type != null) { if (type != null) {
handle(wrapper, getRewriter(type), getNewTags(type), toRename.get(type)); handle(wrapper, getRewriter(type), getNewTags(type), toRename.get(type), toRemove.get(type));
} else { } else {
handle(wrapper, null, null, null); handle(wrapper, null, null, null, null);
} }
} }
}; };
} }
public void handle(PacketWrapper wrapper, @Nullable IdRewriteFunction rewriteFunction, @Nullable List<TagData> newTags) { public void handle(PacketWrapper wrapper, @Nullable IdRewriteFunction rewriteFunction, @Nullable List<TagData> newTags) {
handle(wrapper, rewriteFunction, newTags, null); handle(wrapper, rewriteFunction, newTags, null, null);
} }
public void handle(PacketWrapper wrapper, @Nullable IdRewriteFunction rewriteFunction, @Nullable List<TagData> newTags, @Nullable Map<String, String> tagsToRename) { public void handle(PacketWrapper wrapper, @Nullable IdRewriteFunction rewriteFunction, @Nullable List<TagData> newTags, @Nullable Map<String, String> tagsToRename, @Nullable Set<String> tagsToRemove) {
int tagsSize = wrapper.read(Types.VAR_INT); int tagsSize = wrapper.read(Types.VAR_INT);
wrapper.write(Types.VAR_INT, newTags != null ? tagsSize + newTags.size() : tagsSize); // add new tags count final List<TagData> tags = new ArrayList<>(newTags != null ? tagsSize + newTags.size() : tagsSize);
for (int i = 0; i < tagsSize; i++) { for (int i = 0; i < tagsSize; i++) {
String key = wrapper.read(Types.STRING); String key = wrapper.read(Types.STRING);
if (tagsToRename != null) { if (tagsToRename != null) {
String renamedKey = tagsToRename.get(key); String renamedKey = tagsToRename.get(Key.stripMinecraftNamespace(key));
if (renamedKey != null) { if (renamedKey != null) {
key = renamedKey; key = renamedKey;
} }
} }
wrapper.write(Types.STRING, key);
int[] ids = wrapper.read(Types.VAR_INT_ARRAY_PRIMITIVE); int[] ids = wrapper.read(Types.VAR_INT_ARRAY_PRIMITIVE);
if (rewriteFunction != null) { if (rewriteFunction != null) {
@ -192,20 +197,40 @@ public class TagRewriter<C extends ClientboundPacketType> implements com.viavers
} }
} }
wrapper.write(Types.VAR_INT_ARRAY_PRIMITIVE, idList.toArray(EMPTY_ARRAY)); ids = idList.toArray(EMPTY_ARRAY);
} else {
// Write the original array
wrapper.write(Types.VAR_INT_ARRAY_PRIMITIVE, ids);
}
} }
// Send new tags if present tags.add(new TagData(key, ids));
}
if (tagsToRemove != null) {
tags.removeIf(tag -> tagsToRemove.contains(Key.stripMinecraftNamespace(tag.identifier())));
}
// Add new tags if present
if (newTags != null) { if (newTags != null) {
for (TagData tag : newTags) { tags.addAll(newTags);
}
// Write the tags
wrapper.write(Types.VAR_INT, tags.size());
for (TagData tag : tags) {
wrapper.write(Types.STRING, tag.identifier()); wrapper.write(Types.STRING, tag.identifier());
wrapper.write(Types.VAR_INT_ARRAY_PRIMITIVE, tag.entries()); wrapper.write(Types.VAR_INT_ARRAY_PRIMITIVE, tag.entries());
} }
} }
public void appendNewTags(PacketWrapper wrapper, RegistryType type) {
List<TagData> newTags = getNewTags(type);
if (newTags != null) {
wrapper.write(Types.VAR_INT, newTags.size());
for (TagData tag : newTags) {
wrapper.write(Types.STRING, tag.identifier());
wrapper.write(Types.VAR_INT_ARRAY_PRIMITIVE, tag.entries().clone());
}
} else {
wrapper.write(Types.VAR_INT, 0);
}
} }
@Override @Override
@ -221,12 +246,9 @@ public class TagRewriter<C extends ClientboundPacketType> implements com.viavers
public @Nullable IdRewriteFunction getRewriter(RegistryType tagType) { public @Nullable IdRewriteFunction getRewriter(RegistryType tagType) {
MappingData mappingData = protocol.getMappingData(); MappingData mappingData = protocol.getMappingData();
return switch (tagType) { return switch (tagType) {
case BLOCK -> case BLOCK -> mappingData != null && mappingData.getBlockMappings() != null ? mappingData::getNewBlockId : null;
mappingData != null && mappingData.getBlockMappings() != null ? mappingData::getNewBlockId : null; case ITEM -> mappingData != null && mappingData.getItemMappings() != null ? mappingData::getNewItemId : null;
case ITEM -> case ENTITY -> protocol.getEntityRewriter() != null ? id -> protocol.getEntityRewriter().newEntityId(id) : null;
mappingData != null && mappingData.getItemMappings() != null ? mappingData::getNewItemId : null;
case ENTITY ->
protocol.getEntityRewriter() != null ? id -> protocol.getEntityRewriter().newEntityId(id) : null;
case FLUID, GAME_EVENT -> null; case FLUID, GAME_EVENT -> null;
}; };
} }