3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-19 14:30:16 +01:00

Always call onMappingDataLoaded in TagRewriter

In case they are needed in the future, so that we don't also have to check whether the different methods are actually called
Dieser Commit ist enthalten in:
Nassim Jahnke 2024-04-18 16:12:57 +02:00
Ursprung 4302dd61aa
Commit a99273db2e
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: EF6771C01F6EF02F
23 geänderte Dateien mit 236 neuen und 72 gelöschten Zeilen

Datei anzeigen

@ -38,6 +38,7 @@ import com.viaversion.viaversion.api.protocol.packet.provider.PacketTypeMap;
import com.viaversion.viaversion.api.protocol.packet.provider.PacketTypesProvider;
import com.viaversion.viaversion.api.protocol.packet.provider.SimplePacketTypesProvider;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
import com.viaversion.viaversion.api.rewriter.MappingDataListener;
import com.viaversion.viaversion.api.rewriter.Rewriter;
import com.viaversion.viaversion.exception.CancelException;
import com.viaversion.viaversion.exception.InformativeException;
@ -211,6 +212,7 @@ public abstract class AbstractProtocol<CU extends ClientboundPacketType, CM exte
protected void onMappingDataLoaded() {
callOnMappingDataLoaded(getEntityRewriter());
callOnMappingDataLoaded(getItemRewriter());
callOnMappingDataLoaded(getTagRewriter());
}
private void callRegister(@Nullable Rewriter<?> rewriter) {
@ -219,7 +221,7 @@ public abstract class AbstractProtocol<CU extends ClientboundPacketType, CM exte
}
}
private void callOnMappingDataLoaded(@Nullable Rewriter<?> rewriter) {
private void callOnMappingDataLoaded(@Nullable MappingDataListener rewriter) {
if (rewriter != null) {
rewriter.onMappingDataLoaded();
}

Datei anzeigen

@ -36,6 +36,8 @@ import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
import com.viaversion.viaversion.api.rewriter.EntityRewriter;
import com.viaversion.viaversion.api.rewriter.ItemRewriter;
import com.viaversion.viaversion.api.rewriter.Rewriter;
import com.viaversion.viaversion.api.rewriter.TagRewriter;
import org.checkerframework.checker.nullness.qual.Nullable;
/**
@ -350,6 +352,15 @@ public interface Protocol<CU extends ClientboundPacketType, CM extends Clientbou
return null;
}
/**
* Returns the protocol's tag rewriter if present.
*
* @return tag rewriter
*/
default @Nullable TagRewriter getTagRewriter() {
return null;
}
/**
* Returns whether this protocol is a base protocol.
*

Datei anzeigen

@ -0,0 +1,29 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 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.rewriter;
public interface MappingDataListener {
default void onMappingDataLoaded() {
}
}

Datei anzeigen

@ -24,7 +24,7 @@ package com.viaversion.viaversion.api.rewriter;
import com.viaversion.viaversion.api.protocol.Protocol;
public interface Rewriter<T extends Protocol> {
public interface Rewriter<T extends Protocol> extends MappingDataListener {
/**
* Registers any packet handlers or rewrites needed.
@ -37,7 +37,4 @@ public interface Rewriter<T extends Protocol> {
* @return protocol of the rewriter
*/
T protocol();
default void onMappingDataLoaded() {
}
}

Datei anzeigen

@ -0,0 +1,77 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 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.rewriter;
import com.viaversion.viaversion.api.minecraft.RegistryType;
import com.viaversion.viaversion.api.minecraft.TagData;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import java.util.List;
import org.checkerframework.checker.nullness.qual.Nullable;
public interface TagRewriter extends MappingDataListener {
void removeTags(String registryKey);
void renameTag(RegistryType type, String registryKey, String renameTo);
/**
* Adds an empty tag (since the client crashes if a checked tag is not registered).
*
* @param tagType registry tag type
* @param tagId tag id
*/
void addEmptyTag(RegistryType tagType, String tagId);
void addEmptyTags(RegistryType tagType, String... tagIds);
/**
* Adds an entity tag type to be filled with the given entity type ids.
*
* @param tagId registry tag type
* @param entities mapped entity types
*/
void addEntityTag(String tagId, EntityType... entities);
/**
* 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
*/
void addTag(RegistryType tagType, String tagId, int... 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
*/
void addTagRaw(RegistryType tagType, String tagId, int... ids);
@Nullable
List<TagData> getNewTags(RegistryType tagType);
List<TagData> getOrComputeNewTags(RegistryType tagType);
}

Datei anzeigen

@ -44,6 +44,7 @@ public class Protocol1_13_1To1_13 extends AbstractProtocol<ClientboundPackets1_1
public static final MappingData MAPPINGS = new MappingDataBase("1.13", "1.13.2");
private final MetadataRewriter1_13_1To1_13 entityRewriter = new MetadataRewriter1_13_1To1_13(this);
private final InventoryPackets itemRewriter = new InventoryPackets(this);
private final TagRewriter<ClientboundPackets1_13> tagRewriter = new TagRewriter<>(this);
public Protocol1_13_1To1_13() {
super(ClientboundPackets1_13.class, ClientboundPackets1_13.class, ServerboundPackets1_13.class, ServerboundPackets1_13.class);
@ -128,7 +129,7 @@ public class Protocol1_13_1To1_13 extends AbstractProtocol<ClientboundPackets1_1
}
});
new TagRewriter<>(this).register(ClientboundPackets1_13.TAGS, RegistryType.ITEM);
tagRewriter.register(ClientboundPackets1_13.TAGS, RegistryType.ITEM);
new StatisticsRewriter<>(this).register(ClientboundPackets1_13.STATISTICS);
}
@ -154,4 +155,9 @@ public class Protocol1_13_1To1_13 extends AbstractProtocol<ClientboundPackets1_1
public InventoryPackets getItemRewriter() {
return itemRewriter;
}
@Override
public TagRewriter<ClientboundPackets1_13> getTagRewriter() {
return tagRewriter;
}
}

Datei anzeigen

@ -843,6 +843,7 @@ public class Protocol1_13To1_12_2 extends AbstractProtocol<ClientboundPackets1_1
@Override
protected void onMappingDataLoaded() {
super.onMappingDataLoaded();
ConnectionData.init();
RecipeData.init();
BlockIdData.init();

Datei anzeigen

@ -140,6 +140,7 @@ public class Protocol1_14To1_13_2 extends AbstractProtocol<ClientboundPackets1_1
@Override
protected void onMappingDataLoaded() {
super.onMappingDataLoaded();
WorldPackets.air = MAPPINGS.getBlockStateMappings().getNewId(0);
WorldPackets.voidAir = MAPPINGS.getBlockStateMappings().getNewId(8591);
WorldPackets.caveAir = MAPPINGS.getBlockStateMappings().getNewId(8592);

Datei anzeigen

@ -40,7 +40,7 @@ public class Protocol1_15To1_14_4 extends AbstractProtocol<ClientboundPackets1_1
public static final MappingData MAPPINGS = new MappingDataBase("1.14", "1.15");
private final MetadataRewriter1_15To1_14_4 metadataRewriter = new MetadataRewriter1_15To1_14_4(this);
private final InventoryPackets itemRewriter = new InventoryPackets(this);
private TagRewriter<ClientboundPackets1_14_4> tagRewriter;
private final TagRewriter<ClientboundPackets1_14_4> tagRewriter = new TagRewriter<>(this);
public Protocol1_15To1_14_4() {
super(ClientboundPackets1_14_4.class, ClientboundPackets1_15.class, ServerboundPackets1_14.class, ServerboundPackets1_14.class);
@ -61,12 +61,13 @@ public class Protocol1_15To1_14_4 extends AbstractProtocol<ClientboundPackets1_1
registerServerbound(ServerboundPackets1_14.EDIT_BOOK, wrapper -> itemRewriter.handleItemToServer(wrapper.passthrough(Type.ITEM1_13_2)));
tagRewriter = new TagRewriter<>(this);
tagRewriter.register(ClientboundPackets1_14_4.TAGS, RegistryType.ENTITY);
}
@Override
protected void onMappingDataLoaded() {
super.onMappingDataLoaded();
int[] shulkerBoxes = new int[17];
int shulkerBoxOffset = 501;
for (int i = 0; i < 17; i++) {
@ -94,4 +95,9 @@ public class Protocol1_15To1_14_4 extends AbstractProtocol<ClientboundPackets1_1
public InventoryPackets getItemRewriter() {
return itemRewriter;
}
@Override
public TagRewriter<ClientboundPackets1_14_4> getTagRewriter() {
return tagRewriter;
}
}

Datei anzeigen

@ -39,7 +39,7 @@ public class Protocol1_16_2To1_16_1 extends AbstractProtocol<ClientboundPackets1
public static final MappingData MAPPINGS = new MappingData();
private final MetadataRewriter1_16_2To1_16_1 metadataRewriter = new MetadataRewriter1_16_2To1_16_1(this);
private final InventoryPackets itemRewriter = new InventoryPackets(this);
private TagRewriter<ClientboundPackets1_16> tagRewriter;
private final TagRewriter<ClientboundPackets1_16> tagRewriter = new TagRewriter<>(this);
public Protocol1_16_2To1_16_1() {
super(ClientboundPackets1_16.class, ClientboundPackets1_16_2.class, ServerboundPackets1_16.class, ServerboundPackets1_16_2.class);
@ -52,7 +52,6 @@ public class Protocol1_16_2To1_16_1 extends AbstractProtocol<ClientboundPackets1
EntityPackets.register(this);
WorldPackets.register(this);
tagRewriter = new TagRewriter<>(this);
tagRewriter.register(ClientboundPackets1_16.TAGS, RegistryType.ENTITY);
new StatisticsRewriter<>(this).register(ClientboundPackets1_16.STATISTICS);
@ -85,19 +84,21 @@ public class Protocol1_16_2To1_16_1 extends AbstractProtocol<ClientboundPackets1
@Override
protected void onMappingDataLoaded() {
super.onMappingDataLoaded();
tagRewriter.addTag(RegistryType.ITEM, "minecraft:stone_crafting_materials", 14, 962);
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");
"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");
"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");
}
@Override
@ -119,4 +120,9 @@ public class Protocol1_16_2To1_16_1 extends AbstractProtocol<ClientboundPackets1
public InventoryPackets getItemRewriter() {
return itemRewriter;
}
@Override
public TagRewriter<ClientboundPackets1_16> getTagRewriter() {
return tagRewriter;
}
}

Datei anzeigen

@ -61,7 +61,7 @@ public class Protocol1_16To1_15_2 extends AbstractProtocol<ClientboundPackets1_1
private final MetadataRewriter1_16To1_15_2 metadataRewriter = new MetadataRewriter1_16To1_15_2(this);
private final InventoryPackets itemRewriter = new InventoryPackets(this);
private final TranslationMappings componentRewriter = new TranslationMappings(this);
private TagRewriter<ClientboundPackets1_15> tagRewriter;
private final TagRewriter<ClientboundPackets1_15> tagRewriter = new TagRewriter<>(this);
public Protocol1_16To1_15_2() {
super(ClientboundPackets1_15.class, ClientboundPackets1_16.class, ServerboundPackets1_14.class, ServerboundPackets1_16.class);
@ -74,7 +74,6 @@ public class Protocol1_16To1_15_2 extends AbstractProtocol<ClientboundPackets1_1
EntityPackets.register(this);
WorldPackets.register(this);
tagRewriter = new TagRewriter<>(this);
tagRewriter.register(ClientboundPackets1_15.TAGS, RegistryType.ENTITY);
new StatisticsRewriter<>(this).register(ClientboundPackets1_15.STATISTICS);
@ -213,6 +212,8 @@ public class Protocol1_16To1_15_2 extends AbstractProtocol<ClientboundPackets1_1
@Override
protected void onMappingDataLoaded() {
super.onMappingDataLoaded();
int[] wallPostOverrideTag = new int[47];
int arrayIndex = 0;
wallPostOverrideTag[arrayIndex++] = 140;
@ -292,4 +293,9 @@ public class Protocol1_16To1_15_2 extends AbstractProtocol<ClientboundPackets1_1
public TranslationMappings getComponentRewriter() {
return componentRewriter;
}
@Override
public TagRewriter<ClientboundPackets1_15> getTagRewriter() {
return tagRewriter;
}
}

Datei anzeigen

@ -188,7 +188,7 @@ public final class Protocol1_17To1_16_4 extends AbstractProtocol<ClientboundPack
@Override
protected void onMappingDataLoaded() {
tagRewriter.loadFromMappingData(); // Load filled extra tags
super.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",
@ -232,4 +232,9 @@ public final class Protocol1_17To1_16_4 extends AbstractProtocol<ClientboundPack
public InventoryPackets getItemRewriter() {
return itemRewriter;
}
@Override
public TagRewriter<ClientboundPackets1_16_2> getTagRewriter() {
return tagRewriter;
}
}

Datei anzeigen

@ -31,6 +31,7 @@ import com.viaversion.viaversion.rewriter.TagRewriter;
public final class Protocol1_18_2To1_18 extends AbstractProtocol<ClientboundPackets1_18, ClientboundPackets1_18, ServerboundPackets1_17, ServerboundPackets1_17> {
public Protocol1_18_2To1_18() {
super(ClientboundPackets1_18.class, ClientboundPackets1_18.class, ServerboundPackets1_17.class, ServerboundPackets1_17.class);
}

Datei anzeigen

@ -43,6 +43,7 @@ public final class Protocol1_18To1_17_1 extends AbstractProtocol<ClientboundPack
public static final MappingData MAPPINGS = new MappingDataBase("1.17", "1.18");
private final EntityPackets entityRewriter = new EntityPackets(this);
private final InventoryPackets itemRewriter = new InventoryPackets(this);
private final TagRewriter<ClientboundPackets1_17_1> tagRewriter = new TagRewriter<>(this);
public Protocol1_18To1_17_1() {
super(ClientboundPackets1_17_1.class, ClientboundPackets1_18.class, ServerboundPackets1_17.class, ServerboundPackets1_17.class);
@ -58,7 +59,6 @@ public final class Protocol1_18To1_17_1 extends AbstractProtocol<ClientboundPack
soundRewriter.registerSound(ClientboundPackets1_17_1.SOUND);
soundRewriter.registerSound(ClientboundPackets1_17_1.ENTITY_SOUND);
final TagRewriter<ClientboundPackets1_17_1> tagRewriter = new TagRewriter<>(this);
tagRewriter.registerGeneric(ClientboundPackets1_17_1.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",
@ -85,6 +85,7 @@ public final class Protocol1_18To1_17_1 extends AbstractProtocol<ClientboundPack
@Override
protected void onMappingDataLoaded() {
super.onMappingDataLoaded();
Types1_18.PARTICLE.filler(this)
.reader("block", ParticleType.Readers.BLOCK)
.reader("block_marker", ParticleType.Readers.BLOCK)

Datei anzeigen

@ -67,6 +67,7 @@ public final class Protocol1_19_3To1_19_1 extends AbstractProtocol<ClientboundPa
private static final byte[] EMPTY_BYTES = new byte[0];
private final EntityPackets entityRewriter = new EntityPackets(this);
private final InventoryPackets itemRewriter = new InventoryPackets(this);
private final TagRewriter<ClientboundPackets1_19_1> tagRewriter = new TagRewriter<>(this);
public Protocol1_19_3To1_19_1() {
super(ClientboundPackets1_19_1.class, ClientboundPackets1_19_3.class, ServerboundPackets1_19_1.class, ServerboundPackets1_19_3.class);
@ -74,8 +75,6 @@ public final class Protocol1_19_3To1_19_1 extends AbstractProtocol<ClientboundPa
@Override
protected void registerPackets() {
final TagRewriter<ClientboundPackets1_19_1> tagRewriter = new TagRewriter<>(this);
// 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
@ -378,4 +377,9 @@ public final class Protocol1_19_3To1_19_1 extends AbstractProtocol<ClientboundPa
public InventoryPackets getItemRewriter() {
return itemRewriter;
}
@Override
public TagRewriter<ClientboundPackets1_19_1> getTagRewriter() {
return tagRewriter;
}
}

Datei anzeigen

@ -45,6 +45,7 @@ public final class Protocol1_19_4To1_19_3 extends AbstractProtocol<ClientboundPa
public static final MappingData MAPPINGS = new MappingData();
private final EntityPackets entityRewriter = new EntityPackets(this);
private final InventoryPackets itemRewriter = new InventoryPackets(this);
private final TagRewriter<ClientboundPackets1_19_3> tagRewriter = new TagRewriter<>(this);
public Protocol1_19_4To1_19_3() {
super(ClientboundPackets1_19_3.class, ClientboundPackets1_19_4.class, ServerboundPackets1_19_3.class, ServerboundPackets1_19_4.class);
@ -54,7 +55,7 @@ public final class Protocol1_19_4To1_19_3 extends AbstractProtocol<ClientboundPa
protected void registerPackets() {
super.registerPackets();
new TagRewriter<>(this).registerGeneric(ClientboundPackets1_19_3.TAGS);
tagRewriter.registerGeneric(ClientboundPackets1_19_3.TAGS);
new StatisticsRewriter<>(this).register(ClientboundPackets1_19_3.STATISTICS);
final SoundRewriter<ClientboundPackets1_19_3> soundRewriter = new SoundRewriter<>(this);
@ -127,4 +128,9 @@ public final class Protocol1_19_4To1_19_3 extends AbstractProtocol<ClientboundPa
public InventoryPackets getItemRewriter() {
return itemRewriter;
}
@Override
public TagRewriter<ClientboundPackets1_19_3> getTagRewriter() {
return tagRewriter;
}
}

Datei anzeigen

@ -55,6 +55,7 @@ public final class Protocol1_19To1_18_2 extends AbstractProtocol<ClientboundPack
public static final MappingData MAPPINGS = new MappingData();
private final EntityPackets entityRewriter = new EntityPackets(this);
private final InventoryPackets itemRewriter = new InventoryPackets(this);
private final TagRewriter<ClientboundPackets1_18> tagRewriter = new TagRewriter<>(this);
public Protocol1_19To1_18_2() {
super(ClientboundPackets1_18.class, ClientboundPackets1_19.class, ServerboundPackets1_17.class, ServerboundPackets1_19.class);
@ -74,7 +75,6 @@ public final class Protocol1_19To1_18_2 extends AbstractProtocol<ClientboundPack
@Override
protected void registerPackets() {
final TagRewriter<ClientboundPackets1_18> tagRewriter = new TagRewriter<>(this);
tagRewriter.registerGeneric(ClientboundPackets1_18.TAGS);
entityRewriter.register();
@ -331,4 +331,9 @@ public final class Protocol1_19To1_18_2 extends AbstractProtocol<ClientboundPack
public InventoryPackets getItemRewriter() {
return itemRewriter;
}
@Override
public TagRewriter<ClientboundPackets1_18> getTagRewriter() {
return tagRewriter;
}
}

Datei anzeigen

@ -62,6 +62,7 @@ public final class Protocol1_20_2To1_20 extends AbstractProtocol<ClientboundPack
public static final MappingData MAPPINGS = new MappingDataBase("1.20", "1.20.2");
private final EntityPacketRewriter1_20_2 entityPacketRewriter = new EntityPacketRewriter1_20_2(this);
private final BlockItemPacketRewriter1_20_2 itemPacketRewriter = new BlockItemPacketRewriter1_20_2(this);
private final TagRewriter<ClientboundPackets1_19_4> tagRewriter = new TagRewriter<>(this);
public Protocol1_20_2To1_20() {
super(ClientboundPackets1_19_4.class, ClientboundPackets1_20_2.class, ServerboundPackets1_19_4.class, ServerboundPackets1_20_2.class);
@ -100,7 +101,6 @@ public final class Protocol1_20_2To1_20 extends AbstractProtocol<ClientboundPack
wrapper.user().put(new LastResourcePack(url, hash, required, prompt));
});
final TagRewriter<ClientboundPackets1_19_4> tagRewriter = new TagRewriter<>(this);
registerClientbound(ClientboundPackets1_19_4.TAGS, wrapper -> {
tagRewriter.getGenericHandler().handle(wrapper);
wrapper.resetReader();
@ -354,4 +354,9 @@ public final class Protocol1_20_2To1_20 extends AbstractProtocol<ClientboundPack
public ItemRewriter<Protocol1_20_2To1_20> getItemRewriter() {
return itemPacketRewriter;
}
@Override
public TagRewriter<ClientboundPackets1_19_4> getTagRewriter() {
return tagRewriter;
}
}

Datei anzeigen

@ -61,6 +61,7 @@ public final class Protocol1_20_3To1_20_2 extends AbstractProtocol<ClientboundPa
public static final MappingData MAPPINGS = new MappingDataBase("1.20.2", "1.20.3");
private final BlockItemPacketRewriter1_20_3 itemRewriter = new BlockItemPacketRewriter1_20_3(this);
private final EntityPacketRewriter1_20_3 entityRewriter = new EntityPacketRewriter1_20_3(this);
private final TagRewriter<ClientboundPacket1_20_2> tagRewriter = new TagRewriter<>(this);
public Protocol1_20_3To1_20_2() {
super(ClientboundPacket1_20_2.class, ClientboundPacket1_20_3.class, ServerboundPacket1_20_2.class, ServerboundPacket1_20_3.class);
@ -72,7 +73,6 @@ public final class Protocol1_20_3To1_20_2 extends AbstractProtocol<ClientboundPa
cancelServerbound(ServerboundPackets1_20_3.CONTAINER_SLOT_STATE_CHANGED);
final TagRewriter<ClientboundPacket1_20_2> tagRewriter = new TagRewriter<>(this);
tagRewriter.registerGeneric(ClientboundPackets1_20_2.TAGS);
final SoundRewriter<ClientboundPacket1_20_2> soundRewriter = new SoundRewriter<>(this);
@ -383,6 +383,11 @@ public final class Protocol1_20_3To1_20_2 extends AbstractProtocol<ClientboundPa
return entityRewriter;
}
@Override
public TagRewriter<ClientboundPacket1_20_2> getTagRewriter() {
return tagRewriter;
}
@Override
protected PacketTypesProvider<ClientboundPacket1_20_2, ClientboundPacket1_20_3, ServerboundPacket1_20_2, ServerboundPacket1_20_3> createPacketTypesProvider() {
return new SimplePacketTypesProvider<>(

Datei anzeigen

@ -184,6 +184,11 @@ public final class Protocol1_20_5To1_20_3 extends AbstractProtocol<ClientboundPa
return itemRewriter;
}
@Override
public TagRewriter<ClientboundPacket1_20_3> getTagRewriter() {
return tagRewriter;
}
@Override
protected PacketTypesProvider<ClientboundPacket1_20_3, ClientboundPacket1_20_5, ServerboundPacket1_20_3, ServerboundPacket1_20_5> createPacketTypesProvider() {
return new SimplePacketTypesProvider<>(

Datei anzeigen

@ -39,6 +39,7 @@ public final class Protocol1_20To1_19_4 extends AbstractProtocol<ClientboundPack
public static final MappingData MAPPINGS = new MappingDataBase("1.19.4", "1.20");
private final EntityPackets entityRewriter = new EntityPackets(this);
private final InventoryPackets itemRewriter = new InventoryPackets(this);
private final TagRewriter<ClientboundPackets1_19_4> tagRewriter = new TagRewriter<>(this);
public Protocol1_20To1_19_4() {
super(ClientboundPackets1_19_4.class, ClientboundPackets1_19_4.class, ServerboundPackets1_19_4.class, ServerboundPackets1_19_4.class);
@ -48,7 +49,6 @@ public final class Protocol1_20To1_19_4 extends AbstractProtocol<ClientboundPack
protected void registerPackets() {
super.registerPackets();
final TagRewriter<ClientboundPackets1_19_4> tagRewriter = new TagRewriter<>(this);
tagRewriter.registerGeneric(ClientboundPackets1_19_4.TAGS);
final SoundRewriter<ClientboundPackets1_19_4> soundRewriter = new SoundRewriter<>(this);
@ -101,4 +101,9 @@ public final class Protocol1_20To1_19_4 extends AbstractProtocol<ClientboundPack
public InventoryPackets getItemRewriter() {
return itemRewriter;
}
@Override
public TagRewriter<ClientboundPackets1_19_4> getTagRewriter() {
return tagRewriter;
}
}

Datei anzeigen

@ -38,7 +38,7 @@ import java.util.Map;
import java.util.Set;
import org.checkerframework.checker.nullness.qual.Nullable;
public class TagRewriter<C extends ClientboundPacketType> {
public class TagRewriter<C extends ClientboundPacketType> implements com.viaversion.viaversion.api.rewriter.TagRewriter {
private static final int[] EMPTY_ARRAY = {};
private final Protocol<C, ?, ?, ?> protocol;
private final Map<RegistryType, List<TagData>> newTags = new EnumMap<>(RegistryType.class);
@ -49,10 +49,12 @@ public class TagRewriter<C extends ClientboundPacketType> {
this.protocol = protocol;
}
/**
* Gets new tags from the protocol's {@link MappingData} instance.
*/
public void loadFromMappingData() {
@Override
public void onMappingDataLoaded() {
if (protocol.getMappingData() == null) {
return;
}
for (RegistryType type : RegistryType.getValues()) {
List<TagData> tags = protocol.getMappingData().getTags(type);
if (tags != null) {
@ -61,24 +63,22 @@ public class TagRewriter<C extends ClientboundPacketType> {
}
}
@Override
public void removeTags(final String registryKey) {
toRemove.add(registryKey);
}
@Override
public void renameTag(final RegistryType type, final String registryKey, final String renameTo) {
toRename.computeIfAbsent(type, t -> new HashMap<>()).put(registryKey, renameTo);
}
/**
* Adds an empty tag (since the client crashes if a checked tag is not registered).
*
* @param tagType registry tag type
* @param tagId tag id
*/
@Override
public void addEmptyTag(RegistryType tagType, String tagId) {
getOrComputeNewTags(tagType).add(new TagData(tagId, EMPTY_ARRAY));
}
@Override
public void addEmptyTags(RegistryType tagType, String... tagIds) {
List<TagData> tagList = getOrComputeNewTags(tagType);
for (String id : tagIds) {
@ -86,12 +86,7 @@ public class TagRewriter<C extends ClientboundPacketType> {
}
}
/**
* Adds an entity tag type to be filled with the given entity type ids.
*
* @param tagId registry tag type
* @param entities mapped entity types
*/
@Override
public void addEntityTag(String tagId, EntityType... entities) {
int[] ids = new int[entities.length];
for (int i = 0; i < entities.length; i++) {
@ -100,13 +95,7 @@ public class TagRewriter<C extends ClientboundPacketType> {
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
*/
@Override
public void addTag(RegistryType tagType, String tagId, int... unmappedIds) {
List<TagData> newTags = getOrComputeNewTags(tagType);
IdRewriteFunction rewriteFunction = getRewriter(tagType);
@ -119,32 +108,15 @@ public class TagRewriter<C extends ClientboundPacketType> {
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
*/
@Override
public void addTagRaw(RegistryType tagType, String tagId, int... ids) {
getOrComputeNewTags(tagType).add(new TagData(tagId, ids));
}
/**
* Pre 1.17 reading of hardcoded registry types.
*
* @param packetType packet type
* @param readUntilType read and process the types until (including) the given registry type
*/
public void register(C packetType, @Nullable RegistryType readUntilType) {
protocol.registerClientbound(packetType, getHandler(readUntilType));
}
/**
* 1.17+ reading of generic tag types.
*
* @param packetType packet type
*/
public void registerGeneric(C packetType) {
protocol.registerClientbound(packetType, getGenericHandler());
}
@ -236,10 +208,12 @@ public class TagRewriter<C extends ClientboundPacketType> {
}
}
@Override
public @Nullable List<TagData> getNewTags(RegistryType tagType) {
return newTags.get(tagType);
}
@Override
public List<TagData> getOrComputeNewTags(RegistryType tagType) {
return newTags.computeIfAbsent(tagType, type -> new ArrayList<>());
}

Datei anzeigen

@ -45,6 +45,7 @@ public final class Protocol1_99To_98 extends AbstractProtocol<ClientboundPacket1
public static final MappingData MAPPINGS = new MappingDataBase("1.98", "1.99");
private final EntityPacketRewriter1_99 entityRewriter = new EntityPacketRewriter1_99(this);
private final BlockItemPacketRewriter1_99 itemRewriter = new BlockItemPacketRewriter1_99(this);
private final TagRewriter<ClientboundPacket1_20_5> tagRewriter = new TagRewriter<>(this);
public Protocol1_99To_98() {
// Passing the class types into the super constructor is needed for automatic packet type id remapping, but can otherwise be omitted
@ -55,7 +56,6 @@ public final class Protocol1_99To_98 extends AbstractProtocol<ClientboundPacket1
protected void registerPackets() {
super.registerPackets();
final TagRewriter<ClientboundPacket1_20_5> tagRewriter = new TagRewriter<>(this);
tagRewriter.registerGeneric(ClientboundPackets1_20_5.TAGS);
tagRewriter.registerGeneric(ClientboundConfigurationPackets1_20_5.UPDATE_TAGS);
@ -107,7 +107,8 @@ public final class Protocol1_99To_98 extends AbstractProtocol<ClientboundPacket1
addEntityTracker(connection, new EntityTrackerBase(connection, EntityTypes1_20_5.PLAYER));
}
// Overriding these three methods is important as they are relied on various rewriter classes
// Overriding these four methods is important as they are relied on various rewriter classes
// and have mapping load methods called in AbstractProtocol via the getters
@Override
public MappingData getMappingData() {
return MAPPINGS;
@ -122,4 +123,9 @@ public final class Protocol1_99To_98 extends AbstractProtocol<ClientboundPacket1
public BlockItemPacketRewriter1_99 getItemRewriter() {
return itemRewriter;
}
@Override
public TagRewriter<ClientboundPacket1_20_5> getTagRewriter() {
return tagRewriter;
}
}