diff --git a/api/src/main/java/com/viaversion/viaversion/api/data/FullMappingData.java b/api/src/main/java/com/viaversion/viaversion/api/data/FullMappingData.java new file mode 100644 index 000000000..fa6098658 --- /dev/null +++ b/api/src/main/java/com/viaversion/viaversion/api/data/FullMappingData.java @@ -0,0 +1,44 @@ +/* + * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion + * Copyright (C) 2016-2022 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.data; + +public interface FullMappingData { + + Mappings mappings(); + + /** + * Returns the unmapped integer id for the given identifier, or -1 if not found. + * + * @param identifier unmapped string identifier + * @return unmapped int id, or -1 if not found + */ + int id(String identifier); + + /** + * Returns the mapped integer id for the given mapped identifier, or -1 if not found. + * + * @param mappedIdentifier mapped string identifier + * @return mapped int id, or -1 if not found + */ + int mappedId(String mappedIdentifier); +} diff --git a/api/src/main/java/com/viaversion/viaversion/api/data/FullMappingDataBase.java b/api/src/main/java/com/viaversion/viaversion/api/data/FullMappingDataBase.java new file mode 100644 index 000000000..29ffc2677 --- /dev/null +++ b/api/src/main/java/com/viaversion/viaversion/api/data/FullMappingDataBase.java @@ -0,0 +1,55 @@ +/* + * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion + * Copyright (C) 2016-2022 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.data; + +import com.google.gson.JsonArray; +import it.unimi.dsi.fastutil.objects.Object2IntMap; + +public class FullMappingDataBase implements FullMappingData { + private final Object2IntMap stringToId; + private final Object2IntMap mappedStringToId; + private final Mappings mappings; + + public FullMappingDataBase(final JsonArray oldMappings, final JsonArray newMappings, final Mappings mappings) { + this.mappings = mappings; + stringToId = MappingDataLoader.arrayToMap(oldMappings); + mappedStringToId = MappingDataLoader.arrayToMap(newMappings); + stringToId.defaultReturnValue(-1); + mappedStringToId.defaultReturnValue(-1); + } + + @Override + public Mappings mappings() { + return mappings; + } + + @Override + public int id(final String identifier) { + return stringToId.getInt(identifier); + } + + @Override + public int mappedId(final String mappedIdentifier) { + return mappedStringToId.getInt(mappedIdentifier); + } +} diff --git a/api/src/main/java/com/viaversion/viaversion/api/data/MappingData.java b/api/src/main/java/com/viaversion/viaversion/api/data/MappingData.java index 0a804d347..3b0e3327d 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/data/MappingData.java +++ b/api/src/main/java/com/viaversion/viaversion/api/data/MappingData.java @@ -103,5 +103,5 @@ public interface MappingData { @Nullable Mappings getStatisticsMappings(); - @Nullable Mappings getArgumentTypeMappings(); + @Nullable FullMappingData getArgumentTypeMappings(); } diff --git a/api/src/main/java/com/viaversion/viaversion/api/data/MappingDataBase.java b/api/src/main/java/com/viaversion/viaversion/api/data/MappingDataBase.java index ba5c20cd0..a7781368b 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/data/MappingDataBase.java +++ b/api/src/main/java/com/viaversion/viaversion/api/data/MappingDataBase.java @@ -44,13 +44,13 @@ public class MappingDataBase implements MappingData { protected final String newVersion; protected final boolean hasDiffFile; protected Int2IntBiMap itemMappings; + protected FullMappingData argumentTypeMappings; protected ParticleMappings particleMappings; protected Mappings blockMappings; protected Mappings blockStateMappings; protected Mappings blockEntityMappings; protected Mappings soundMappings; protected Mappings statisticsMappings; - protected Mappings argumentTypeMappings; protected Map> tags; protected boolean loadItems = true; @@ -76,7 +76,12 @@ public class MappingDataBase implements MappingData { blockEntityMappings = loadFromArray(oldMappings, newMappings, diffmapping, "blockentities"); soundMappings = loadFromArray(oldMappings, newMappings, diffmapping, "sounds"); statisticsMappings = loadFromArray(oldMappings, newMappings, diffmapping, "statistics"); - argumentTypeMappings = loadFromArray(oldMappings, newMappings, diffmapping, "argumenttypes"); + + Mappings argumentTypeMappings = loadFromArray(oldMappings, newMappings, diffmapping, "argumenttypes"); + if (argumentTypeMappings != null) { + this.argumentTypeMappings = new FullMappingDataBase(oldMappings.getAsJsonArray("argumenttypes"), + newMappings.getAsJsonArray("argumenttypes"), argumentTypeMappings); + } Mappings particles = loadFromArray(oldMappings, newMappings, diffmapping, "particles"); if (particles != null) { @@ -150,7 +155,7 @@ public class MappingDataBase implements MappingData { @Override public int getNewParticleId(int id) { - return checkValidity(id, particleMappings.getMappings().getNewId(id), "particles"); + return checkValidity(id, particleMappings.mappings().getNewId(id), "particles"); } @Override @@ -194,7 +199,7 @@ public class MappingDataBase implements MappingData { } @Override - public @Nullable Mappings getArgumentTypeMappings() { + public @Nullable FullMappingData getArgumentTypeMappings() { return argumentTypeMappings; } diff --git a/api/src/main/java/com/viaversion/viaversion/api/data/ParticleMappings.java b/api/src/main/java/com/viaversion/viaversion/api/data/ParticleMappings.java index 0a2c33818..dee8778c1 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/data/ParticleMappings.java +++ b/api/src/main/java/com/viaversion/viaversion/api/data/ParticleMappings.java @@ -25,51 +25,19 @@ package com.viaversion.viaversion.api.data; import com.google.gson.JsonArray; import it.unimi.dsi.fastutil.ints.IntArrayList; import it.unimi.dsi.fastutil.ints.IntList; -import it.unimi.dsi.fastutil.objects.Object2IntMap; -public class ParticleMappings { - private final Object2IntMap stringToId; - private final Object2IntMap mappedStringToId; - private final Mappings mappings; +public class ParticleMappings extends FullMappingDataBase { private final IntList itemParticleIds = new IntArrayList(2); private final IntList blockParticleIds = new IntArrayList(4); public ParticleMappings(JsonArray oldMappings, JsonArray newMappings, Mappings mappings) { - this.mappings = mappings; - stringToId = MappingDataLoader.arrayToMap(oldMappings); - mappedStringToId = MappingDataLoader.arrayToMap(newMappings); - stringToId.defaultReturnValue(-1); - mappedStringToId.defaultReturnValue(-1); + super(oldMappings, newMappings, mappings); addBlockParticle("block"); addBlockParticle("falling_dust"); addBlockParticle("block_marker"); addItemParticle("item"); } - /** - * Returns the unmapped integer id for the given identifier, or -1 if not found. - * - * @param identifier unmapped string identifier - * @return unmapped int id, or -1 if not found - */ - public int id(String identifier) { - return stringToId.getInt(identifier); - } - - /** - * Returns the mapped integer id for the given mapped identifier, or -1 if not found. - * - * @param mappedIdentifier mapped string identifier - * @return mapped int id, or -1 if not found - */ - public int mappedId(String mappedIdentifier) { - return mappedStringToId.getInt(mappedIdentifier); - } - - public Mappings getMappings() { - return mappings; - } - public boolean addItemParticle(final String identifier) { final int id = id(identifier); return id != -1 && itemParticleIds.add(id); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/Protocol1_19To1_18_2.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/Protocol1_19To1_18_2.java index 0b3b54788..e62682d46 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/Protocol1_19To1_18_2.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/Protocol1_19To1_18_2.java @@ -19,6 +19,8 @@ package com.viaversion.viaversion.protocols.protocol1_19to1_18_2; 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.entities.Entity1_19Types; import com.viaversion.viaversion.api.protocol.AbstractProtocol; import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper; @@ -30,7 +32,6 @@ import com.viaversion.viaversion.api.type.types.version.Types1_19; import com.viaversion.viaversion.data.entity.EntityTrackerBase; import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.ServerboundPackets1_17; import com.viaversion.viaversion.protocols.protocol1_18to1_17_1.ClientboundPackets1_18; -import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.data.MappingData; import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.packets.EntityPackets; import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.packets.InventoryPackets; import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.packets.WorldPackets; @@ -41,7 +42,7 @@ import com.viaversion.viaversion.rewriter.TagRewriter; public final class Protocol1_19To1_18_2 extends AbstractProtocol { - public static final MappingData MAPPINGS = new MappingData(); + public static final MappingData MAPPINGS = new MappingDataBase("1.18", "1.19"); private final EntityPackets entityRewriter = new EntityPackets(this); private final InventoryPackets itemRewriter = new InventoryPackets(this); @@ -52,10 +53,6 @@ public final class Protocol1_19To1_18_2 extends AbstractProtocol. - */ -package com.viaversion.viaversion.protocols.protocol1_19to1_18_2.data; - -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.viaversion.viaversion.api.data.MappingDataBase; -import it.unimi.dsi.fastutil.objects.Object2IntMap; -import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; -import org.checkerframework.checker.nullness.qual.Nullable; - -public final class MappingData extends MappingDataBase { - - private final Object2IntMap argumentTypeIds = new Object2IntOpenHashMap<>(); - - public MappingData() { - super("1.18", "1.19"); - argumentTypeIds.defaultReturnValue(-1); - } - - @Override - protected void loadExtras(final JsonObject oldMappings, final JsonObject newMappings, @Nullable final JsonObject diffMappings) { - int i = 0; - for (final JsonElement element : newMappings.getAsJsonArray("argumenttypes")) { - final String id = element.getAsString(); - argumentTypeIds.put(id, i++); - } - } - - public Object2IntMap argumentTypeIds() { - return argumentTypeIds; - } -} diff --git a/common/src/main/resources/assets/viaversion/data/mapping-1.18.json b/common/src/main/resources/assets/viaversion/data/mapping-1.18.json index 503fbd4b7..8bab9732e 100644 --- a/common/src/main/resources/assets/viaversion/data/mapping-1.18.json +++ b/common/src/main/resources/assets/viaversion/data/mapping-1.18.json @@ -23684,45 +23684,45 @@ "brigadier:integer", "brigadier:long", "brigadier:string", - "entity", - "game_profile", - "block_pos", - "column_pos", - "vec3", - "vec2", - "block_state", - "block_predicate", - "item_stack", - "item_predicate", - "color", - "component", - "message", - "nbt_compound_tag", - "nbt_tag", - "nbt_path", - "objective", - "objective_criteria", - "operation", - "particle", - "angle", - "rotation", - "scoreboard_slot", - "score_holder", - "swizzle", - "team", - "item_slot", - "resource_location", - "mob_effect", - "function", - "entity_anchor", - "int_range", - "float_range", - "item_enchantment", - "entity_summon", - "dimension", - "time", - "uuid", - "resource", - "resource_or_tag" + "minecraft:entity", + "minecraft:game_profile", + "minecraft:block_pos", + "minecraft:column_pos", + "minecraft:vec3", + "minecraft:vec2", + "minecraft:block_state", + "minecraft:block_predicate", + "minecraft:item_stack", + "minecraft:item_predicate", + "minecraft:color", + "minecraft:component", + "minecraft:message", + "minecraft:nbt_compound_tag", + "minecraft:nbt_tag", + "minecraft:nbt_path", + "minecraft:objective", + "minecraft:objective_criteria", + "minecraft:operation", + "minecraft:particle", + "minecraft:angle", + "minecraft:rotation", + "minecraft:scoreboard_slot", + "minecraft:score_holder", + "minecraft:swizzle", + "minecraft:team", + "minecraft:item_slot", + "minecraft:resource_location", + "minecraft:mob_effect", + "minecraft:function", + "minecraft:entity_anchor", + "minecraft:int_range", + "minecraft:float_range", + "minecraft:item_enchantment", + "minecraft:entity_summon", + "minecraft:dimension", + "minecraft:time", + "minecraft:uuid", + "minecraft:resource", + "minecraft:resource_or_tag" ] } \ No newline at end of file diff --git a/common/src/main/resources/assets/viaversion/data/mapping-1.19.json b/common/src/main/resources/assets/viaversion/data/mapping-1.19.json index 4154dd8a8..ca819d2ae 100644 --- a/common/src/main/resources/assets/viaversion/data/mapping-1.19.json +++ b/common/src/main/resources/assets/viaversion/data/mapping-1.19.json @@ -24810,45 +24810,45 @@ "brigadier:integer", "brigadier:long", "brigadier:string", - "entity", - "game_profile", - "block_pos", - "column_pos", - "vec3", - "vec2", - "block_state", - "block_predicate", - "item_stack", - "item_predicate", - "color", - "component", - "message", - "nbt_compound_tag", - "nbt_tag", - "nbt_path", - "objective", - "objective_criteria", - "operation", - "particle", - "angle", - "rotation", - "scoreboard_slot", - "score_holder", - "swizzle", - "team", - "item_slot", - "resource_location", - "mob_effect", - "function", - "entity_anchor", - "int_range", - "float_range", - "item_enchantment", - "entity_summon", - "dimension", - "time", - "resource_or_tag", - "resource", - "uuid" + "minecraft:entity", + "minecraft:game_profile", + "minecraft:block_pos", + "minecraft:column_pos", + "minecraft:vec3", + "minecraft:vec2", + "minecraft:block_state", + "minecraft:block_predicate", + "minecraft:item_stack", + "minecraft:item_predicate", + "minecraft:color", + "minecraft:component", + "minecraft:message", + "minecraft:nbt_compound_tag", + "minecraft:nbt_tag", + "minecraft:nbt_path", + "minecraft:objective", + "minecraft:objective_criteria", + "minecraft:operation", + "minecraft:particle", + "minecraft:angle", + "minecraft:rotation", + "minecraft:scoreboard_slot", + "minecraft:score_holder", + "minecraft:swizzle", + "minecraft:team", + "minecraft:item_slot", + "minecraft:resource_location", + "minecraft:mob_effect", + "minecraft:function", + "minecraft:entity_anchor", + "minecraft:int_range", + "minecraft:float_range", + "minecraft:item_enchantment", + "minecraft:entity_summon", + "minecraft:dimension", + "minecraft:time", + "minecraft:resource_or_tag", + "minecraft:resource", + "minecraft:uuid" ] } \ No newline at end of file