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

Small cleanup to mapping file loading

Dieser Commit ist enthalten in:
Nassim Jahnke 2024-09-02 23:21:29 +02:00
Ursprung e537dbb024
Commit 6555bcda74
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: EF6771C01F6EF02F
10 geänderte Dateien mit 39 neuen und 44 gelöschten Zeilen

Datei anzeigen

@ -30,7 +30,6 @@ import com.google.gson.JsonObject;
import com.google.gson.JsonSyntaxException; import com.google.gson.JsonSyntaxException;
import com.viaversion.nbt.io.NBTIO; import com.viaversion.nbt.io.NBTIO;
import com.viaversion.nbt.io.TagReader; import com.viaversion.nbt.io.TagReader;
import com.viaversion.nbt.tag.ByteTag;
import com.viaversion.nbt.tag.CompoundTag; import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.nbt.tag.IntArrayTag; import com.viaversion.nbt.tag.IntArrayTag;
import com.viaversion.nbt.tag.IntTag; import com.viaversion.nbt.tag.IntTag;
@ -211,68 +210,64 @@ public class MappingDataLoader {
return null; return null;
} }
final ByteTag serializationStragetyTag = tag.getUnchecked("id"); final int mappedSize = tag.getIntTag("mappedSize").asInt();
final IntTag mappedSizeTag = tag.getUnchecked("mappedSize"); final byte strategy = tag.getByteTag("id").asByte();
final byte strategy = serializationStragetyTag.asByte();
final V mappings; final V mappings;
if (strategy == DIRECT_ID) { if (strategy == DIRECT_ID) {
final IntArrayTag valuesTag = tag.getIntArrayTag("val"); final IntArrayTag valuesTag = tag.getIntArrayTag("val");
return IntArrayMappings.of(valuesTag.getValue(), mappedSizeTag.asInt()); return IntArrayMappings.of(valuesTag.getValue(), mappedSize);
} else if (strategy == SHIFTS_ID) { } else if (strategy == SHIFTS_ID) {
final IntArrayTag shiftsAtTag = tag.getIntArrayTag("at"); final int[] shiftsAt = tag.getIntArrayTag("at").getValue();
final IntArrayTag shiftsTag = tag.getIntArrayTag("to"); final int[] shiftsTo = tag.getIntArrayTag("to").getValue();
final IntTag sizeTag = tag.getUnchecked("size"); final int size = tag.getIntTag("size").asInt();
final int[] shiftsAt = shiftsAtTag.getValue();
final int[] shiftsTo = shiftsTag.getValue();
final int size = sizeTag.asInt();
mappings = holderSupplier.get(size); mappings = holderSupplier.get(size);
// Handle values until first shift
if (shiftsAt[0] != 0) { if (shiftsAt[0] != 0) {
// Add identity values before the first shift
final int to = shiftsAt[0]; final int to = shiftsAt[0];
for (int id = 0; id < to; id++) { for (int id = 0; id < to; id++) {
addConsumer.addTo(mappings, id, id); addConsumer.addTo(mappings, id, id);
} }
} }
// Handle shifts // Read shifts
for (int i = 0; i < shiftsAt.length; i++) { for (int i = 0; i < shiftsAt.length; i++) {
final boolean isLast = i == shiftsAt.length - 1;
final int from = shiftsAt[i]; final int from = shiftsAt[i];
final int to = i == shiftsAt.length - 1 ? size : shiftsAt[i + 1]; final int to = isLast ? size : shiftsAt[i + 1];
int mappedId = shiftsTo[i]; int mappedId = shiftsTo[i];
for (int id = from; id < to; id++) { for (int id = from; id < to; id++) {
addConsumer.addTo(mappings, id, mappedId++); addConsumer.addTo(mappings, id, mappedId++);
} }
} }
} else if (strategy == CHANGES_ID) { } else if (strategy == CHANGES_ID) {
final IntArrayTag changesAtTag = tag.getIntArrayTag("at"); final int[] changesAt = tag.getIntArrayTag("at").getValue();
final IntArrayTag valuesTag = tag.getIntArrayTag("val"); final int[] values = tag.getIntArrayTag("val").getValue();
final IntTag sizeTag = tag.getUnchecked("size"); final int size = tag.getIntTag("size").asInt();
final boolean fillBetween = tag.get("nofill") == null; final boolean fillBetween = tag.get("nofill") == null;
final int[] changesAt = changesAtTag.getValue(); mappings = holderSupplier.get(size);
final int[] values = valuesTag.getValue();
mappings = holderSupplier.get(sizeTag.asInt());
int previousChangedId = 0;
for (int i = 0; i < changesAt.length; i++) { for (int i = 0; i < changesAt.length; i++) {
final int id = changesAt[i]; final int changedId = changesAt[i];
if (fillBetween) { if (fillBetween) {
// Fill from after the last change to before this change with unchanged ids // Fill from after the last change to before this change with unchanged ids
final int previousId = i != 0 ? changesAt[i - 1] + 1 : 0; for (int id = previousChangedId + 1; id < changedId; id++) {
for (int identity = previousId; identity < id; identity++) { addConsumer.addTo(mappings, id, id);
addConsumer.addTo(mappings, identity, identity);
} }
previousChangedId = changedId;
} }
// Assign the changed value // Assign the changed value
addConsumer.addTo(mappings, id, values[i]); addConsumer.addTo(mappings, changedId, values[i]);
} }
} else if (strategy == IDENTITY_ID) { } else if (strategy == IDENTITY_ID) {
final IntTag sizeTag = tag.getUnchecked("size"); final IntTag sizeTag = tag.getIntTag("size");
return new IdentityMappings(sizeTag.asInt(), mappedSizeTag.asInt()); return new IdentityMappings(sizeTag.asInt(), mappedSize);
} else { } else {
throw new IllegalArgumentException("Unknown serialization strategy: " + strategy); throw new IllegalArgumentException("Unknown serialization strategy: " + strategy);
} }
return mappingsSupplier.create(mappings, mappedSizeTag.asInt()); return mappingsSupplier.create(mappings, mappedSize);
} }
public @Nullable List<String> identifiersFromGlobalIds(final CompoundTag mappingsTag, final String key) { public @Nullable List<String> identifiersFromGlobalIds(final CompoundTag mappingsTag, final String key) {
@ -295,7 +290,7 @@ public class MappingDataLoader {
* @return map with indexes hashed by their id value * @return map with indexes hashed by their id value
*/ */
public Object2IntMap<String> indexedObjectToMap(final JsonObject object) { public Object2IntMap<String> indexedObjectToMap(final JsonObject object) {
final Object2IntMap<String> map = new Object2IntOpenHashMap<>(object.size(), .99F); final Object2IntMap<String> map = new Object2IntOpenHashMap<>(object.size());
map.defaultReturnValue(-1); map.defaultReturnValue(-1);
for (final Map.Entry<String, JsonElement> entry : object.entrySet()) { for (final Map.Entry<String, JsonElement> entry : object.entrySet()) {
map.put(entry.getValue().getAsString(), Integer.parseInt(entry.getKey())); map.put(entry.getValue().getAsString(), Integer.parseInt(entry.getKey()));
@ -310,7 +305,7 @@ public class MappingDataLoader {
* @return map with indexes hashed by their id value * @return map with indexes hashed by their id value
*/ */
public Object2IntMap<String> arrayToMap(final JsonArray array) { public Object2IntMap<String> arrayToMap(final JsonArray array) {
final Object2IntMap<String> map = new Object2IntOpenHashMap<>(array.size(), .99F); final Object2IntMap<String> map = new Object2IntOpenHashMap<>(array.size());
map.defaultReturnValue(-1); map.defaultReturnValue(-1);
for (int i = 0; i < array.size(); i++) { for (int i = 0; i < array.size(); i++) {
map.put(array.get(i).getAsString(), i); map.put(array.get(i).getAsString(), i);

Datei anzeigen

@ -24,7 +24,7 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
public class PotionColorMappings1_11 { public class PotionColorMappings1_11 {
//<oldData> to <newData, isInstant> mapping //<oldData> to <newData, isInstant> mapping
private static final Int2ObjectMap<Pair<Integer, Boolean>> POTIONS = new Int2ObjectOpenHashMap<>(37, 0.99F); private static final Int2ObjectMap<Pair<Integer, Boolean>> POTIONS = new Int2ObjectOpenHashMap<>(37);
static { static {
addRewrite(0, 3694022, false); addRewrite(0, 3694022, false);

Datei anzeigen

@ -23,7 +23,7 @@ import java.util.Set;
public class AchievementTranslations1_12 { public class AchievementTranslations1_12 {
private static final Object2ObjectOpenHashMap<String, String> ACHIEVEMENTS = new Object2ObjectOpenHashMap<>(150, 0.99f); private static final Object2ObjectOpenHashMap<String, String> ACHIEVEMENTS = new Object2ObjectOpenHashMap<>(150);
private static final Set<String> SPECIAL_ACHIEVEMENTS = new HashSet<>(10); private static final Set<String> SPECIAL_ACHIEVEMENTS = new HashSet<>(10);
static { static {

Datei anzeigen

@ -54,8 +54,8 @@ import java.util.Map.Entry;
public final class ConnectionData { public final class ConnectionData {
public static BlockConnectionProvider blockConnectionProvider; public static BlockConnectionProvider blockConnectionProvider;
static final Object2IntMap<String> KEY_TO_ID = new Object2IntOpenHashMap<>(8582, .99F); static final Object2IntMap<String> KEY_TO_ID = new Object2IntOpenHashMap<>(8582);
static final IntSet OCCLUDING_STATES = new IntOpenHashSet(377, .99F); static final IntSet OCCLUDING_STATES = new IntOpenHashSet(377);
static Int2ObjectMap<ConnectionHandler> connectionHandlerMap = new Int2ObjectOpenHashMap<>(); static Int2ObjectMap<ConnectionHandler> connectionHandlerMap = new Int2ObjectOpenHashMap<>();
static Int2ObjectMap<BlockData> blockConnectionData = new Int2ObjectOpenHashMap<>(); static Int2ObjectMap<BlockData> blockConnectionData = new Int2ObjectOpenHashMap<>();
private static final BlockChangeRecord1_8[] EMPTY_RECORDS = new BlockChangeRecord1_8[0]; private static final BlockChangeRecord1_8[] EMPTY_RECORDS = new BlockChangeRecord1_8[0];
@ -173,7 +173,7 @@ public final class ConnectionData {
KEY_TO_ID.put(key, id); KEY_TO_ID.put(key, id);
} }
connectionHandlerMap = new Int2ObjectOpenHashMap<>(3650, .99F); connectionHandlerMap = new Int2ObjectOpenHashMap<>(3650);
if (!Via.getConfig().isReduceBlockStorageMemory()) { if (!Via.getConfig().isReduceBlockStorageMemory()) {
blockConnectionData = new Int2ObjectOpenHashMap<>(2048); blockConnectionData = new Int2ObjectOpenHashMap<>(2048);

Datei anzeigen

@ -21,7 +21,7 @@ import it.unimi.dsi.fastutil.ints.Int2IntMap;
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
public class EntityIdMappings1_13 { public class EntityIdMappings1_13 {
private static final Int2IntMap ENTITY_TYPES = new Int2IntOpenHashMap(83, .99F); private static final Int2IntMap ENTITY_TYPES = new Int2IntOpenHashMap(83);
static { static {
ENTITY_TYPES.defaultReturnValue(-1); ENTITY_TYPES.defaultReturnValue(-1);

Datei anzeigen

@ -53,7 +53,7 @@ import java.util.Iterator;
import java.util.Optional; import java.util.Optional;
public class WorldPacketRewriter1_13 { public class WorldPacketRewriter1_13 {
private static final IntSet VALID_BIOMES = new IntOpenHashSet(70, .99F); private static final IntSet VALID_BIOMES = new IntOpenHashSet(70);
static { static {
// Client will crash if it receives an invalid biome id // Client will crash if it receives an invalid biome id

Datei anzeigen

@ -26,7 +26,7 @@ import java.util.Map;
// TODO Fix memory leak lolz (only a smol one tho) // TODO Fix memory leak lolz (only a smol one tho)
public class BlockStorage implements StorableObject { public class BlockStorage implements StorableObject {
private static final IntSet WHITELIST = new IntOpenHashSet(46, .99F); private static final IntSet WHITELIST = new IntOpenHashSet(46);
private final Map<BlockPosition, ReplacementData> blocks = new HashMap<>(); private final Map<BlockPosition, ReplacementData> blocks = new HashMap<>();
static { static {

Datei anzeigen

@ -79,8 +79,8 @@ public final class EntityPacketRewriter1_20 extends EntityRewriter<ClientboundPa
final ListTag<CompoundTag> damageTypes = TagUtil.getRegistryEntries(registry, "damage_type"); final ListTag<CompoundTag> damageTypes = TagUtil.getRegistryEntries(registry, "damage_type");
int highestId = -1; int highestId = -1;
for (final CompoundTag damageType : damageTypes) { for (final CompoundTag damageType : damageTypes) {
final IntTag id = damageType.getUnchecked("id"); final int id = damageType.getInt("id");
highestId = Math.max(highestId, id.asInt()); highestId = Math.max(highestId, id);
} }
// AaaaAAAaa // AaaaAAAaa

Datei anzeigen

@ -22,7 +22,7 @@ import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
public class EffectIdMappings1_9 { public class EffectIdMappings1_9 {
private static final Int2IntMap EFFECTS = new Int2IntOpenHashMap(19, .99F); private static final Int2IntMap EFFECTS = new Int2IntOpenHashMap(19);
static { static {
addRewrite(1005, 1010); //Play music disc addRewrite(1005, 1010); //Play music disc

Datei anzeigen

@ -27,7 +27,7 @@ public class PotionIdMappings1_9 {
public static final Map<String, Integer> POTION_NAME_TO_ID = new HashMap<>(); public static final Map<String, Integer> POTION_NAME_TO_ID = new HashMap<>();
public static final Map<Integer, String> POTION_ID_TO_NAME = new HashMap<>(); public static final Map<Integer, String> POTION_ID_TO_NAME = new HashMap<>();
public static final Int2IntMap POTION_INDEX = new Int2IntOpenHashMap(36, .99F); public static final Int2IntMap POTION_INDEX = new Int2IntOpenHashMap(36);
static { static {
register(-1, "empty"); register(-1, "empty");