3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-27 08:30:09 +01:00

Move some data out of extending MappingData classes

Dieser Commit ist enthalten in:
Nassim Jahnke 2024-02-13 18:41:05 +01:00
Ursprung 22bd350e35
Commit 621c02f974
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: EF6771C01F6EF02F
10 geänderte Dateien mit 133 neuen und 143 gelöschten Zeilen

Datei anzeigen

@ -63,7 +63,7 @@ public interface ViaAPI<T> {
* @return API version incremented with meaningful API changes
*/
default int apiVersion() {
return 23;
return 24;
}
/**

Datei anzeigen

@ -23,6 +23,8 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.data.MappingData;
import com.viaversion.viaversion.api.data.MappingDataBase;
import com.viaversion.viaversion.api.minecraft.RegistryType;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_16;
import com.viaversion.viaversion.api.platform.providers.ViaProviders;
@ -35,7 +37,6 @@ import com.viaversion.viaversion.api.type.types.version.Types1_16;
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ServerboundPackets1_14;
import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.data.MappingData;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.data.TranslationMappings;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.metadata.MetadataRewriter1_16To1_15_2;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.packets.EntityPackets;
@ -56,7 +57,7 @@ import java.util.UUID;
public class Protocol1_16To1_15_2 extends AbstractProtocol<ClientboundPackets1_15, ClientboundPackets1_16, ServerboundPackets1_14, ServerboundPackets1_16> {
private static final UUID ZERO_UUID = new UUID(0, 0);
public static final MappingData MAPPINGS = new MappingData();
public static final MappingData MAPPINGS = new MappingDataBase("1.15", "1.16");
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);

Datei anzeigen

@ -0,0 +1,43 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viaversion.protocols.protocol1_16to1_15_2.data;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
public final class AttributeMappings {
private static final BiMap<String, String> ATTRIBUTE_MAPPINGS = HashBiMap.create();
static {
ATTRIBUTE_MAPPINGS.put("generic.maxHealth", "minecraft:generic.max_health");
ATTRIBUTE_MAPPINGS.put("zombie.spawnReinforcements", "minecraft:zombie.spawn_reinforcements");
ATTRIBUTE_MAPPINGS.put("horse.jumpStrength", "minecraft:horse.jump_strength");
ATTRIBUTE_MAPPINGS.put("generic.followRange", "minecraft:generic.follow_range");
ATTRIBUTE_MAPPINGS.put("generic.knockbackResistance", "minecraft:generic.knockback_resistance");
ATTRIBUTE_MAPPINGS.put("generic.movementSpeed", "minecraft:generic.movement_speed");
ATTRIBUTE_MAPPINGS.put("generic.flyingSpeed", "minecraft:generic.flying_speed");
ATTRIBUTE_MAPPINGS.put("generic.attackDamage", "minecraft:generic.attack_damage");
ATTRIBUTE_MAPPINGS.put("generic.attackKnockback", "minecraft:generic.attack_knockback");
ATTRIBUTE_MAPPINGS.put("generic.attackSpeed", "minecraft:generic.attack_speed");
ATTRIBUTE_MAPPINGS.put("generic.armorToughness", "minecraft:generic.armor_toughness");
}
public static BiMap<String, String> attributeIdentifierMappings() {
return ATTRIBUTE_MAPPINGS;
}
}

Datei anzeigen

@ -1,50 +0,0 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viaversion.protocols.protocol1_16to1_15_2.data;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import com.viaversion.viaversion.api.data.MappingDataBase;
public class MappingData extends MappingDataBase {
private final BiMap<String, String> attributeMappings = HashBiMap.create();
public MappingData() {
super("1.15", "1.16");
}
@Override
protected void loadExtras(final CompoundTag data) {
attributeMappings.put("generic.maxHealth", "minecraft:generic.max_health");
attributeMappings.put("zombie.spawnReinforcements", "minecraft:zombie.spawn_reinforcements");
attributeMappings.put("horse.jumpStrength", "minecraft:horse.jump_strength");
attributeMappings.put("generic.followRange", "minecraft:generic.follow_range");
attributeMappings.put("generic.knockbackResistance", "minecraft:generic.knockback_resistance");
attributeMappings.put("generic.movementSpeed", "minecraft:generic.movement_speed");
attributeMappings.put("generic.flyingSpeed", "minecraft:generic.flying_speed");
attributeMappings.put("generic.attackDamage", "minecraft:generic.attack_damage");
attributeMappings.put("generic.attackKnockback", "minecraft:generic.attack_knockback");
attributeMappings.put("generic.attackSpeed", "minecraft:generic.attack_speed");
attributeMappings.put("generic.armorToughness", "minecraft:generic.armor_toughness");
}
public BiMap<String, String> attributeIdentifierMappings() {
return attributeMappings;
}
}

Datei anzeigen

@ -36,6 +36,7 @@ import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.ClientboundPacke
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.ClientboundPackets1_16;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.Protocol1_16To1_15_2;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.ServerboundPackets1_16;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.data.AttributeMappings;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.metadata.MetadataRewriter1_16To1_15_2;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.storage.InventoryTracker1_16;
import com.viaversion.viaversion.util.Key;
@ -241,7 +242,7 @@ public class EntityPackets {
for (int i = 0; i < size; i++) {
// Attributes have been renamed and are now namespaced identifiers
String key = wrapper.read(Type.STRING);
String attributeIdentifier = protocol.getMappingData().attributeIdentifierMappings().get(key);
String attributeIdentifier = AttributeMappings.attributeIdentifierMappings().get(key);
if (attributeIdentifier == null) {
attributeIdentifier = Key.namespaced(key);
if (!Key.isValid(attributeIdentifier)) {

Datei anzeigen

@ -32,6 +32,7 @@ import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.ClientboundPacke
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.ClientboundPackets1_16;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.Protocol1_16To1_15_2;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.ServerboundPackets1_16;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.data.AttributeMappings;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.storage.InventoryTracker1_16;
import com.viaversion.viaversion.rewriter.ItemRewriter;
import com.viaversion.viaversion.rewriter.RecipeRewriter;
@ -246,8 +247,8 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_15, Serve
attributeName = Key.namespaced(attributeName);
}
String mappedAttribute = (inverse ? Protocol1_16To1_15_2.MAPPINGS.attributeIdentifierMappings().inverse()
: Protocol1_16To1_15_2.MAPPINGS.attributeIdentifierMappings()).get(attributeName);
String mappedAttribute = (inverse ? AttributeMappings.attributeIdentifierMappings().inverse()
: AttributeMappings.attributeIdentifierMappings()).get(attributeName);
if (mappedAttribute == null) return;
attributeNameTag.setValue(mappedAttribute);

Datei anzeigen

@ -18,6 +18,8 @@
package com.viaversion.viaversion.protocols.protocol1_18to1_17_1;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.data.MappingData;
import com.viaversion.viaversion.api.data.MappingDataBase;
import com.viaversion.viaversion.api.minecraft.RegistryType;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_17;
import com.viaversion.viaversion.api.protocol.AbstractProtocol;
@ -28,7 +30,6 @@ import com.viaversion.viaversion.api.type.types.version.Types1_18;
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
import com.viaversion.viaversion.protocols.protocol1_17_1to1_17.ClientboundPackets1_17_1;
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.ServerboundPackets1_17;
import com.viaversion.viaversion.protocols.protocol1_18to1_17_1.data.MappingData;
import com.viaversion.viaversion.protocols.protocol1_18to1_17_1.packets.EntityPackets;
import com.viaversion.viaversion.protocols.protocol1_18to1_17_1.packets.InventoryPackets;
import com.viaversion.viaversion.protocols.protocol1_18to1_17_1.packets.WorldPackets;
@ -39,7 +40,7 @@ import com.viaversion.viaversion.rewriter.TagRewriter;
public final class Protocol1_18To1_17_1 extends AbstractProtocol<ClientboundPackets1_17_1, ClientboundPackets1_18, ServerboundPackets1_17, ServerboundPackets1_17> {
public static final MappingData MAPPINGS = new MappingData();
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);

Datei anzeigen

@ -0,0 +1,76 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viaversion.protocols.protocol1_18to1_17_1.data;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
public final class BlockEntities {
private static final Object2IntMap<String> BLOCK_ENTITY_IDS = new Object2IntOpenHashMap<>();
static {
BLOCK_ENTITY_IDS.defaultReturnValue(-1);
final String[] blockEntities = blockEntities();
for (int id = 0; id < blockEntities.length; id++) {
BLOCK_ENTITY_IDS.put(blockEntities[id], id);
}
}
public static Object2IntMap<String> blockEntityIds() {
return BLOCK_ENTITY_IDS;
}
private static String[] blockEntities() {
return new String[]{
"furnace",
"chest",
"trapped_chest",
"ender_chest",
"jukebox",
"dispenser",
"dropper",
"sign",
"mob_spawner",
"piston",
"brewing_stand",
"enchanting_table",
"end_portal",
"beacon",
"skull",
"daylight_detector",
"hopper",
"comparator",
"banner",
"structure_block",
"end_gateway",
"command_block",
"shulker_box",
"bed",
"conduit",
"barrel",
"smoker",
"blast_furnace",
"lectern",
"bell",
"jigsaw",
"campfire",
"beehive",
"sculk_sensor"
};
}
}

Datei anzeigen

@ -1,84 +0,0 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viaversion.protocols.protocol1_18to1_17_1.data;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.viaversion.viaversion.api.data.MappingDataBase;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
public final class MappingData extends MappingDataBase {
private final Object2IntMap<String> blockEntityIds = new Object2IntOpenHashMap<>();
public MappingData() {
super("1.17", "1.18");
blockEntityIds.defaultReturnValue(-1);
}
@Override
protected void loadExtras(final CompoundTag data) {
final String[] blockEntities = blockEntities();
for (int id = 0; id < blockEntities.length; id++) {
blockEntityIds.put(blockEntities[id], id);
}
}
public Object2IntMap<String> blockEntityIds() {
return blockEntityIds;
}
private String[] blockEntities() {
return new String[]{
"furnace",
"chest",
"trapped_chest",
"ender_chest",
"jukebox",
"dispenser",
"dropper",
"sign",
"mob_spawner",
"piston",
"brewing_stand",
"enchanting_table",
"end_portal",
"beacon",
"skull",
"daylight_detector",
"hopper",
"comparator",
"banner",
"structure_block",
"end_gateway",
"command_block",
"shulker_box",
"bed",
"conduit",
"barrel",
"smoker",
"blast_furnace",
"lectern",
"bell",
"jigsaw",
"campfire",
"beehive",
"sculk_sensor"
};
}
}

Datei anzeigen

@ -37,6 +37,7 @@ import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_18;
import com.viaversion.viaversion.protocols.protocol1_17_1to1_17.ClientboundPackets1_17_1;
import com.viaversion.viaversion.protocols.protocol1_18to1_17_1.BlockEntityIds;
import com.viaversion.viaversion.protocols.protocol1_18to1_17_1.Protocol1_18To1_17_1;
import com.viaversion.viaversion.protocols.protocol1_18to1_17_1.data.BlockEntities;
import com.viaversion.viaversion.protocols.protocol1_18to1_17_1.storage.ChunkLightStorage;
import com.viaversion.viaversion.util.Key;
import com.viaversion.viaversion.util.MathUtil;
@ -115,7 +116,7 @@ public final class WorldPackets {
}
final String id = idTag.getValue();
final int typeId = protocol.getMappingData().blockEntityIds().getInt(Key.stripMinecraftNamespace(id));
final int typeId = BlockEntities.blockEntityIds().getInt(Key.stripMinecraftNamespace(id));
if (typeId == -1) {
Via.getPlatform().getLogger().warning("Unknown block entity: " + id);
}