Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-10-02 00:10:06 +02:00
More fixes to mapping data loading
Dieser Commit ist enthalten in:
Ursprung
b94c71b699
Commit
712bbcdc02
@ -27,9 +27,12 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
|||||||
/**
|
/**
|
||||||
* Mappings containing the full string identifier mappings.
|
* Mappings containing the full string identifier mappings.
|
||||||
*/
|
*/
|
||||||
public interface FullMappings {
|
public interface FullMappings extends Mappings {
|
||||||
|
|
||||||
Mappings mappings();
|
@Deprecated
|
||||||
|
default Mappings mappings() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the unmapped integer id for the given identifier, or -1 if not found.
|
* Returns the unmapped integer id for the given identifier, or -1 if not found.
|
||||||
@ -70,4 +73,6 @@ public interface FullMappings {
|
|||||||
* @return mapped string identifier, or null if not found
|
* @return mapped string identifier, or null if not found
|
||||||
*/
|
*/
|
||||||
@Nullable String mappedIdentifier(String identifier);
|
@Nullable String mappedIdentifier(String identifier);
|
||||||
|
|
||||||
|
FullMappings createInverse();
|
||||||
}
|
}
|
||||||
|
@ -44,6 +44,14 @@ public class FullMappingsBase implements FullMappings {
|
|||||||
this. mappedIdToString = mappedIdentifiers.toArray(EMPTY_ARRAY);
|
this. mappedIdToString = mappedIdentifiers.toArray(EMPTY_ARRAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private FullMappingsBase(final Object2IntMap<String> stringToId, final Object2IntMap<String> mappedStringToId, final String[] idToString, final String[] mappedIdToString, final Mappings mappings) {
|
||||||
|
this.stringToId = stringToId;
|
||||||
|
this.mappedStringToId = mappedStringToId;
|
||||||
|
this.idToString = idToString;
|
||||||
|
this.mappedIdToString = mappedIdToString;
|
||||||
|
this.mappings = mappings;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Mappings mappings() {
|
public Mappings mappings() {
|
||||||
return mappings;
|
return mappings;
|
||||||
@ -82,6 +90,31 @@ public class FullMappingsBase implements FullMappings {
|
|||||||
return mappedId != -1 ? mappedIdentifier(mappedId) : null;
|
return mappedId != -1 ? mappedIdentifier(mappedId) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getNewId(int id) {
|
||||||
|
return mappings.getNewId(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setNewId(int id, int mappedId) {
|
||||||
|
mappings.setNewId(id, mappedId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int size() {
|
||||||
|
return mappings.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int mappedSize() {
|
||||||
|
return mappings.mappedSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FullMappings createInverse() {
|
||||||
|
return new FullMappingsBase(mappedStringToId, stringToId, mappedIdToString, idToString, mappings.createInverse());
|
||||||
|
}
|
||||||
|
|
||||||
private static Object2IntMap<String> toInverseMap(final List<String> list) {
|
private static Object2IntMap<String> toInverseMap(final List<String> list) {
|
||||||
final Object2IntMap<String> map = new Object2IntOpenHashMap<>(list.size());
|
final Object2IntMap<String> map = new Object2IntOpenHashMap<>(list.size());
|
||||||
map.defaultReturnValue(-1);
|
map.defaultReturnValue(-1);
|
||||||
|
@ -51,4 +51,9 @@ public class IdentityMappings implements Mappings {
|
|||||||
public int mappedSize() {
|
public int mappedSize() {
|
||||||
return mappedSize;
|
return mappedSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Mappings createInverse() {
|
||||||
|
return new IdentityMappings(mappedSize, size);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,12 +22,14 @@
|
|||||||
*/
|
*/
|
||||||
package com.viaversion.viaversion.api.data;
|
package com.viaversion.viaversion.api.data;
|
||||||
|
|
||||||
|
import com.viaversion.viaversion.util.Int2IntBiHashMap;
|
||||||
import com.viaversion.viaversion.util.Int2IntBiMap;
|
import com.viaversion.viaversion.util.Int2IntBiMap;
|
||||||
|
import it.unimi.dsi.fastutil.ints.Int2IntMap;
|
||||||
|
|
||||||
public class Int2IntMapBiMappings implements BiMappings {
|
public class Int2IntMapBiMappings implements BiMappings {
|
||||||
|
|
||||||
private final Int2IntBiMap mappings;
|
private final Int2IntBiMap mappings;
|
||||||
private final BiMappings inverse;
|
private final Int2IntMapBiMappings inverse;
|
||||||
|
|
||||||
protected Int2IntMapBiMappings(final Int2IntBiMap mappings) {
|
protected Int2IntMapBiMappings(final Int2IntBiMap mappings) {
|
||||||
this.mappings = mappings;
|
this.mappings = mappings;
|
||||||
@ -35,7 +37,7 @@ public class Int2IntMapBiMappings implements BiMappings {
|
|||||||
mappings.defaultReturnValue(-1);
|
mappings.defaultReturnValue(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Int2IntMapBiMappings(final Int2IntBiMap mappings, final BiMappings inverse) {
|
private Int2IntMapBiMappings(final Int2IntBiMap mappings, final Int2IntMapBiMappings inverse) {
|
||||||
this.mappings = mappings;
|
this.mappings = mappings;
|
||||||
this.inverse = inverse;
|
this.inverse = inverse;
|
||||||
}
|
}
|
||||||
@ -68,4 +70,13 @@ public class Int2IntMapBiMappings implements BiMappings {
|
|||||||
public int mappedSize() {
|
public int mappedSize() {
|
||||||
return mappings.inverse().size();
|
return mappings.inverse().size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Mappings createInverse() {
|
||||||
|
final Int2IntBiMap inverseCopy = new Int2IntBiHashMap(inverse.mappings.size());
|
||||||
|
for (final Int2IntMap.Entry entry : inverse.mappings.int2IntEntrySet()) {
|
||||||
|
inverseCopy.put(entry.getIntKey(), entry.getIntValue());
|
||||||
|
}
|
||||||
|
return of(inverseCopy);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,4 +62,13 @@ public class Int2IntMapMappings implements Mappings {
|
|||||||
public int mappedSize() {
|
public int mappedSize() {
|
||||||
return mappedIds;
|
return mappedIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Mappings createInverse() {
|
||||||
|
final Int2IntMap inverse = new Int2IntOpenHashMap();
|
||||||
|
for (final Int2IntMap.Entry entry : mappings.int2IntEntrySet()) {
|
||||||
|
inverse.put(entry.getIntValue(), entry.getIntKey());
|
||||||
|
}
|
||||||
|
return of(inverse, size());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -84,4 +84,9 @@ public class IntArrayBiMappings implements BiMappings {
|
|||||||
public int mappedSize() {
|
public int mappedSize() {
|
||||||
return mappings.mappedSize();
|
return mappings.mappedSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Mappings createInverse() {
|
||||||
|
return mappings.createInverse();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,8 @@
|
|||||||
*/
|
*/
|
||||||
package com.viaversion.viaversion.api.data;
|
package com.viaversion.viaversion.api.data;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
public class IntArrayMappings implements Mappings {
|
public class IntArrayMappings implements Mappings {
|
||||||
private final int[] mappings;
|
private final int[] mappings;
|
||||||
private final int mappedIds;
|
private final int mappedIds;
|
||||||
@ -59,6 +61,17 @@ public class IntArrayMappings implements Mappings {
|
|||||||
return mappedIds;
|
return mappedIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Mappings createInverse() {
|
||||||
|
final int[] inverse = new int[mappedIds];
|
||||||
|
Arrays.fill(inverse, -1);
|
||||||
|
for (int id = 0; id < mappings.length; id++) {
|
||||||
|
final int mappedId = mappings[id];
|
||||||
|
inverse[mappedId] = id;
|
||||||
|
}
|
||||||
|
return of(inverse, mappings.length);
|
||||||
|
}
|
||||||
|
|
||||||
public int[] raw() {
|
public int[] raw() {
|
||||||
return mappings;
|
return mappings;
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ public class MappingDataBase implements MappingData {
|
|||||||
getLogger().info("Loading " + unmappedVersion + " -> " + mappedVersion + " mappings...");
|
getLogger().info("Loading " + unmappedVersion + " -> " + mappedVersion + " mappings...");
|
||||||
}
|
}
|
||||||
|
|
||||||
final CompoundTag data = MappingDataLoader.loadNBT("mappings-" + unmappedVersion + "to" + mappedVersion + ".nbt");
|
final CompoundTag data = readNBTFile("mappings-" + unmappedVersion + "to" + mappedVersion + ".nbt");
|
||||||
blockMappings = loadMappings(data, "blocks");
|
blockMappings = loadMappings(data, "blocks");
|
||||||
blockStateMappings = loadMappings(data, "blockstates");
|
blockStateMappings = loadMappings(data, "blockstates");
|
||||||
blockEntityMappings = loadMappings(data, "blockentities");
|
blockEntityMappings = loadMappings(data, "blockentities");
|
||||||
@ -106,15 +106,23 @@ public class MappingDataBase implements MappingData {
|
|||||||
loadExtras(data);
|
loadExtras(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected @Nullable CompoundTag readNBTFile(final String name) {
|
||||||
|
return MappingDataLoader.loadNBT(name);
|
||||||
|
}
|
||||||
|
|
||||||
protected @Nullable Mappings loadMappings(final CompoundTag data, final String key) {
|
protected @Nullable Mappings loadMappings(final CompoundTag data, final String key) {
|
||||||
return MappingDataLoader.loadMappings(data, key);
|
return shouldLoad(key) ? MappingDataLoader.loadMappings(data, key) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected @Nullable FullMappings loadFullMappings(final CompoundTag data, final CompoundTag unmappedIdentifiers, final CompoundTag mappedIdentifiers, final String key) {
|
protected @Nullable FullMappings loadFullMappings(final CompoundTag data, final CompoundTag unmappedIdentifiers, final CompoundTag mappedIdentifiers, final String key) {
|
||||||
return MappingDataLoader.loadFullMappings(data, unmappedIdentifiers, mappedIdentifiers, key);
|
return shouldLoad(key) ? MappingDataLoader.loadFullMappings(data, unmappedIdentifiers, mappedIdentifiers, key) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected @Nullable BiMappings loadBiMappings(final CompoundTag data, final String key) {
|
protected @Nullable BiMappings loadBiMappings(final CompoundTag data, final String key) {
|
||||||
|
if (!shouldLoad(key)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
final Mappings mappings = loadMappings(data, key);
|
final Mappings mappings = loadMappings(data, key);
|
||||||
return mappings != null ? IntArrayBiMappings.of((IntArrayMappings) mappings) : null;
|
return mappings != null ? IntArrayBiMappings.of((IntArrayMappings) mappings) : null;
|
||||||
}
|
}
|
||||||
@ -156,7 +164,7 @@ public class MappingDataBase implements MappingData {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getNewParticleId(final int id) {
|
public int getNewParticleId(final int id) {
|
||||||
return checkValidity(id, particleMappings.mappings().getNewId(id), "particles");
|
return checkValidity(id, particleMappings.getNewId(id), "particles");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -239,6 +247,10 @@ public class MappingDataBase implements MappingData {
|
|||||||
return mappedId;
|
return mappedId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected boolean shouldLoad(final String key) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
protected void loadExtras(final CompoundTag data) {
|
protected void loadExtras(final CompoundTag data) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,6 +43,7 @@ import java.io.FileReader;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
@ -109,7 +110,11 @@ public final class MappingDataLoader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static @Nullable Mappings loadMappings(final CompoundTag mappingsTag, final String key) {
|
public static @Nullable Mappings loadMappings(final CompoundTag mappingsTag, final String key) {
|
||||||
return loadMappings(mappingsTag, key, int[]::new, (array, id, mappedId) -> array[id] = mappedId, IntArrayMappings::of);
|
return loadMappings(mappingsTag, key, size -> {
|
||||||
|
final int[] array = new int[size];
|
||||||
|
Arrays.fill(array, -1);
|
||||||
|
return array;
|
||||||
|
}, (array, id, mappedId) -> array[id] = mappedId, IntArrayMappings::of);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Beta
|
@Beta
|
||||||
@ -134,10 +139,10 @@ public final class MappingDataLoader {
|
|||||||
return IntArrayMappings.of(valuesTag.getValue(), mappedSizeTag.asInt());
|
return IntArrayMappings.of(valuesTag.getValue(), mappedSizeTag.asInt());
|
||||||
} else if (strategy == SHIFTS_ID) {
|
} else if (strategy == SHIFTS_ID) {
|
||||||
final IntArrayTag shiftsAtTag = tag.get("at");
|
final IntArrayTag shiftsAtTag = tag.get("at");
|
||||||
final IntArrayTag shiftsTag = tag.get("val");
|
final IntArrayTag shiftsTag = tag.get("to");
|
||||||
final IntTag sizeTag = tag.get("size");
|
final IntTag sizeTag = tag.get("size");
|
||||||
final int[] shiftsAt = shiftsAtTag.getValue();
|
final int[] shiftsAt = shiftsAtTag.getValue();
|
||||||
final int[] shifts = shiftsTag.getValue();
|
final int[] shiftsTo = shiftsTag.getValue();
|
||||||
final int size = sizeTag.asInt();
|
final int size = sizeTag.asInt();
|
||||||
mappings = holderSupplier.get(size);
|
mappings = holderSupplier.get(size);
|
||||||
|
|
||||||
@ -153,9 +158,9 @@ public final class MappingDataLoader {
|
|||||||
for (int i = 0; i < shiftsAt.length; i++) {
|
for (int i = 0; i < shiftsAt.length; i++) {
|
||||||
final int from = shiftsAt[i];
|
final int from = shiftsAt[i];
|
||||||
final int to = i == shiftsAt.length - 1 ? size : shiftsAt[i + 1];
|
final int to = i == shiftsAt.length - 1 ? size : shiftsAt[i + 1];
|
||||||
final int shiftBy = shifts[i];
|
int mappedId = shiftsTo[i];
|
||||||
for (int id = from; id < to; id++) {
|
for (int id = from; id < to; id++) {
|
||||||
addConsumer.addTo(mappings, id, id + shiftBy);
|
addConsumer.addTo(mappings, id, mappedId++);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (strategy == CHANGES_ID) {
|
} else if (strategy == CHANGES_ID) {
|
||||||
|
@ -83,6 +83,13 @@ public interface Mappings {
|
|||||||
*/
|
*/
|
||||||
int mappedSize();
|
int mappedSize();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new Mappings instance of the same type with the same mappings, but with the keys and values swapped.
|
||||||
|
*
|
||||||
|
* @return a new Mappings instance with the same mappings, but with the keys and values swapped
|
||||||
|
*/
|
||||||
|
Mappings createInverse();
|
||||||
|
|
||||||
static <T extends Mappings> Builder<T> builder(final MappingsSupplier<T> supplier) {
|
static <T extends Mappings> Builder<T> builder(final MappingsSupplier<T> supplier) {
|
||||||
return new Builder<>(supplier);
|
return new Builder<>(supplier);
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,7 @@ package com.viaversion.viaversion.api.data.entity;
|
|||||||
|
|
||||||
import com.viaversion.viaversion.api.data.BiMappings;
|
import com.viaversion.viaversion.api.data.BiMappings;
|
||||||
import com.viaversion.viaversion.api.data.IdentityMappings;
|
import com.viaversion.viaversion.api.data.IdentityMappings;
|
||||||
|
import com.viaversion.viaversion.api.data.Mappings;
|
||||||
|
|
||||||
public final class IdentityBiMappings extends IdentityMappings implements BiMappings {
|
public final class IdentityBiMappings extends IdentityMappings implements BiMappings {
|
||||||
|
|
||||||
@ -35,4 +36,9 @@ public final class IdentityBiMappings extends IdentityMappings implements BiMapp
|
|||||||
public BiMappings inverse() {
|
public BiMappings inverse() {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Mappings createInverse() {
|
||||||
|
return new IdentityBiMappings(mappedSize(), size());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -146,7 +146,11 @@ public class MappingData extends MappingDataBase {
|
|||||||
protected @Nullable BiMappings loadBiMappings(final CompoundTag data, final String key) {
|
protected @Nullable BiMappings loadBiMappings(final CompoundTag data, final String key) {
|
||||||
// Special cursed case
|
// Special cursed case
|
||||||
if (key.equals("items")) {
|
if (key.equals("items")) {
|
||||||
return (BiMappings) MappingDataLoader.loadMappings(data, "items", Int2IntBiHashMap::new, Int2IntBiHashMap::put, (v, mappedSize) -> Int2IntMapBiMappings.of(v));
|
return (BiMappings) MappingDataLoader.loadMappings(data, "items", size -> {
|
||||||
|
final Int2IntBiHashMap map = new Int2IntBiHashMap(size);
|
||||||
|
map.defaultReturnValue(-1);
|
||||||
|
return map;
|
||||||
|
}, Int2IntBiHashMap::put, (v, mappedSize) -> Int2IntMapBiMappings.of(v));
|
||||||
} else {
|
} else {
|
||||||
return super.loadBiMappings(data, key);
|
return super.loadBiMappings(data, key);
|
||||||
}
|
}
|
||||||
|
@ -228,7 +228,7 @@ public abstract class EntityRewriter<C extends ClientboundPacketType, T extends
|
|||||||
public void mapTypes() {
|
public void mapTypes() {
|
||||||
Preconditions.checkArgument(typeMappings == null, "Type mappings have already been set - manual type mappings should be set *after* this");
|
Preconditions.checkArgument(typeMappings == null, "Type mappings have already been set - manual type mappings should be set *after* this");
|
||||||
Preconditions.checkNotNull(protocol.getMappingData().getEntityMappings(), "Protocol does not have entity mappings");
|
Preconditions.checkNotNull(protocol.getMappingData().getEntityMappings(), "Protocol does not have entity mappings");
|
||||||
typeMappings = protocol.getMappingData().getEntityMappings().mappings();
|
typeMappings = protocol.getMappingData().getEntityMappings();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Binäre Datei nicht angezeigt.
Binäre Datei nicht angezeigt.
Binäre Datei nicht angezeigt.
Binäre Datei nicht angezeigt.
Binäre Datei nicht angezeigt.
Binäre Datei nicht angezeigt.
Binäre Datei nicht angezeigt.
Binäre Datei nicht angezeigt.
Binäre Datei nicht angezeigt.
Binäre Datei nicht angezeigt.
Binäre Datei nicht angezeigt.
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,6 +1,6 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.1-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip
|
||||||
networkTimeout=10000
|
networkTimeout=10000
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren