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

Add id->string methods to FullMappingData

Dieser Commit ist enthalten in:
Nassim Jahnke 2022-05-13 13:23:57 +02:00
Ursprung 7dc7b62cc9
Commit f0462085d3
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 6BE3B555EBC5982B
6 geänderte Dateien mit 107 neuen und 3 gelöschten Zeilen

Datei anzeigen

@ -22,6 +22,8 @@
*/ */
package com.viaversion.viaversion.api.data; package com.viaversion.viaversion.api.data;
import org.checkerframework.checker.nullness.qual.Nullable;
public interface FullMappingData { public interface FullMappingData {
Mappings mappings(); Mappings mappings();
@ -41,4 +43,28 @@ public interface FullMappingData {
* @return mapped int id, or -1 if not found * @return mapped int id, or -1 if not found
*/ */
int mappedId(String mappedIdentifier); int mappedId(String mappedIdentifier);
/**
* Returns the unmapped string identifier for the given mapped id.
*
* @param id unmapped id
* @return unmapped string identifier
*/
String identifier(int id);
/**
* Returns the mapped string identifier for the given mapped id.
*
* @param mappedId mapped id
* @return mapped string identifier
*/
String mappedIdentifier(int mappedId);
/**
* Returns the mapped string identifier for the given unmapped identifier.
*
* @param identifier unmapped identifier
* @return mapped string identifier, or null if not found
*/
@Nullable String mappedIdentifier(String identifier);
} }

Datei anzeigen

@ -24,10 +24,13 @@ package com.viaversion.viaversion.api.data;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import it.unimi.dsi.fastutil.objects.Object2IntMap; import it.unimi.dsi.fastutil.objects.Object2IntMap;
import org.checkerframework.checker.nullness.qual.Nullable;
public class FullMappingDataBase implements FullMappingData { public class FullMappingDataBase implements FullMappingData {
private final Object2IntMap<String> stringToId; private final Object2IntMap<String> stringToId;
private final Object2IntMap<String> mappedStringToId; private final Object2IntMap<String> mappedStringToId;
private final String[] idToString;
private final String[] mappedIdToString;
private final Mappings mappings; private final Mappings mappings;
public FullMappingDataBase(final JsonArray oldMappings, final JsonArray newMappings, final Mappings mappings) { public FullMappingDataBase(final JsonArray oldMappings, final JsonArray newMappings, final Mappings mappings) {
@ -36,6 +39,16 @@ public class FullMappingDataBase implements FullMappingData {
mappedStringToId = MappingDataLoader.arrayToMap(newMappings); mappedStringToId = MappingDataLoader.arrayToMap(newMappings);
stringToId.defaultReturnValue(-1); stringToId.defaultReturnValue(-1);
mappedStringToId.defaultReturnValue(-1); mappedStringToId.defaultReturnValue(-1);
idToString = new String[oldMappings.size()];
for (int i = 0; i < oldMappings.size(); i++) {
idToString[i] = oldMappings.get(i).getAsString();
}
mappedIdToString = new String[newMappings.size()];
for (int i = 0; i < newMappings.size(); i++) {
mappedIdToString[i] = newMappings.get(i).getAsString();
}
} }
@Override @Override
@ -52,4 +65,25 @@ public class FullMappingDataBase implements FullMappingData {
public int mappedId(final String mappedIdentifier) { public int mappedId(final String mappedIdentifier) {
return mappedStringToId.getInt(mappedIdentifier); return mappedStringToId.getInt(mappedIdentifier);
} }
@Override
public String identifier(final int id) {
return idToString[id];
}
@Override
public String mappedIdentifier(final int mappedId) {
return mappedIdToString[mappedId];
}
@Override
public @Nullable String mappedIdentifier(final String identifier) {
final int id = id(identifier);
if (id == -1) {
return null;
}
final int mappedId = mappings.getNewId(id);
return mappedId != -1 ? mappedIdentifier(mappedId) : null;
}
} }

Datei anzeigen

@ -28,7 +28,7 @@ public class CommandRewriter1_14 extends CommandRewriter {
} }
@Override @Override
protected @Nullable String handleArgumentType(String argumentType) { public @Nullable String handleArgumentType(String argumentType) {
if (argumentType.equals("minecraft:nbt")) { if (argumentType.equals("minecraft:nbt")) {
return "minecraft:nbt_compound_tag"; return "minecraft:nbt_compound_tag";
} }

Datei anzeigen

@ -47,6 +47,7 @@ import java.util.Map;
public final class EntityPackets extends EntityRewriter<Protocol1_19To1_18_2> { public final class EntityPackets extends EntityRewriter<Protocol1_19To1_18_2> {
//TODO move to compressed nbt file
private static final String CHAT_REGISTRY_SNBT = "{\n" + private static final String CHAT_REGISTRY_SNBT = "{\n" +
" \"minecraft:chat_type\":{\n" + " \"minecraft:chat_type\":{\n" +
" \"type\":\"minecraft:chat_type\",\n" + " \"type\":\"minecraft:chat_type\",\n" +

Datei anzeigen

@ -122,13 +122,57 @@ public class CommandRewriter {
}); });
} }
public void registerDeclareCommands1_19(ClientboundPacketType packetType) {
protocol.registerClientbound(packetType, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
int size = wrapper.passthrough(Type.VAR_INT);
for (int i = 0; i < size; i++) {
byte flags = wrapper.passthrough(Type.BYTE);
wrapper.passthrough(Type.VAR_INT_ARRAY_PRIMITIVE); // Children indices
if ((flags & 0x08) != 0) {
wrapper.passthrough(Type.VAR_INT); // Redirect node index
}
byte nodeType = (byte) (flags & 0x03);
if (nodeType == 1 || nodeType == 2) { // Literal/argument node
wrapper.passthrough(Type.STRING); // Name
}
if (nodeType == 2) { // Argument node
int argumentTypeId = wrapper.read(Type.VAR_INT);
String argumentType = protocol.getMappingData().getArgumentTypeMappings().identifier(argumentTypeId);
String newArgumentType = handleArgumentType(argumentType);
if (newArgumentType != null) {
wrapper.write(Type.VAR_INT, protocol.getMappingData().getArgumentTypeMappings().mappedId(newArgumentType));
}
// Always call the handler using the previous name
handleArgument(wrapper, argumentType);
}
if ((flags & 0x10) != 0) {
wrapper.passthrough(Type.STRING); // Suggestion type
}
}
wrapper.passthrough(Type.VAR_INT); // Root node index
});
}
});
}
/** /**
* Can be overridden if needed. * Can be overridden if needed.
* *
* @param argumentType argument type * @param argumentType argument type
* @return new argument type, or null if it should be removed * @return new argument type, or null if it should be removed
*/ */
protected @Nullable String handleArgumentType(String argumentType) { public @Nullable String handleArgumentType(String argumentType) {
if (protocol.getMappingData().getArgumentTypeMappings() != null) {
return protocol.getMappingData().getArgumentTypeMappings().mappedIdentifier(argumentType);
}
return argumentType; return argumentType;
} }

Datei anzeigen

@ -112,7 +112,6 @@
"257": "minecraft:flowering_azalea_leaves[distance=6,persistent=false,waterlogged=false]", "257": "minecraft:flowering_azalea_leaves[distance=6,persistent=false,waterlogged=false]",
"258": "minecraft:flowering_azalea_leaves[distance=7,persistent=true,waterlogged=false]", "258": "minecraft:flowering_azalea_leaves[distance=7,persistent=true,waterlogged=false]",
"259": "minecraft:flowering_azalea_leaves[distance=7,persistent=false,waterlogged=false]", "259": "minecraft:flowering_azalea_leaves[distance=7,persistent=false,waterlogged=false]",
"1416": "minecraft:piston_head[type=normal,facing=north,short=true]", "1416": "minecraft:piston_head[type=normal,facing=north,short=true]",
"1417": "minecraft:piston_head[type=sticky,facing=north,short=true]", "1417": "minecraft:piston_head[type=sticky,facing=north,short=true]",
"1418": "minecraft:piston_head[type=normal,facing=north,short=false]", "1418": "minecraft:piston_head[type=normal,facing=north,short=false]",