Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-26 16:12:42 +01:00
Mapping and protocolregistry cleanup
Dieser Commit ist enthalten in:
Ursprung
4542e9511b
Commit
ad8e723005
@ -224,7 +224,7 @@ public class PacketWrapper {
|
|||||||
if (id != -1) {
|
if (id != -1) {
|
||||||
Type.VAR_INT.write(buffer, id);
|
Type.VAR_INT.write(buffer, id);
|
||||||
}
|
}
|
||||||
if (readableObjects.size() > 0) {
|
if (!readableObjects.isEmpty()) {
|
||||||
packetValues.addAll(readableObjects);
|
packetValues.addAll(readableObjects);
|
||||||
readableObjects.clear();
|
readableObjects.clear();
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,34 @@
|
|||||||
package us.myles.ViaVersion.api.data;
|
package us.myles.ViaVersion.api.data;
|
||||||
|
|
||||||
public interface Mappings {
|
import com.google.gson.JsonArray;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
|
||||||
int getNewId(int old);
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class Mappings {
|
||||||
|
protected final short[] oldToNew;
|
||||||
|
|
||||||
|
public Mappings(int size, JsonObject oldMapping, JsonObject newMapping) {
|
||||||
|
oldToNew = new short[size];
|
||||||
|
Arrays.fill(oldToNew, (short) -1);
|
||||||
|
MappingDataLoader.mapIdentifiers(oldToNew, oldMapping, newMapping);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Mappings(JsonObject oldMapping, JsonObject newMapping) {
|
||||||
|
this(oldMapping.entrySet().size(), oldMapping, newMapping);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Mappings(int size, JsonArray oldMapping, JsonArray newMapping) {
|
||||||
|
oldToNew = new short[size];
|
||||||
|
Arrays.fill(oldToNew, (short) -1);
|
||||||
|
MappingDataLoader.mapIdentifiers(oldToNew, oldMapping, newMapping);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Mappings(JsonArray oldMapping, JsonArray newMapping) {
|
||||||
|
this(oldMapping.size(), oldMapping, newMapping);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getNewId(int old) {
|
||||||
|
return old >= 0 && old < oldToNew.length ? oldToNew[old] : -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,33 +43,44 @@ public class ProtocolRegistry {
|
|||||||
static {
|
static {
|
||||||
// Base Protocol
|
// Base Protocol
|
||||||
registerBaseProtocol(BASE_PROTOCOL, Range.lessThan(Integer.MIN_VALUE));
|
registerBaseProtocol(BASE_PROTOCOL, Range.lessThan(Integer.MIN_VALUE));
|
||||||
registerBaseProtocol(new BaseProtocol1_7(), Range.<Integer>all());
|
registerBaseProtocol(new BaseProtocol1_7(), Range.all());
|
||||||
|
|
||||||
// Register built in protocols
|
// Register built in protocols
|
||||||
registerProtocol(new Protocol1_9To1_8(), Collections.singletonList(ProtocolVersion.v1_9.getId()), ProtocolVersion.v1_8.getId());
|
registerProtocol(new Protocol1_9To1_8(), ProtocolVersion.v1_9, ProtocolVersion.v1_8);
|
||||||
registerProtocol(new Protocol1_9_1To1_9(), Arrays.asList(ProtocolVersion.v1_9_1.getId(), ProtocolVersion.v1_9_2.getId()), ProtocolVersion.v1_9.getId());
|
registerProtocol(new Protocol1_9_1To1_9(), Arrays.asList(ProtocolVersion.v1_9_1.getId(), ProtocolVersion.v1_9_2.getId()), ProtocolVersion.v1_9.getId());
|
||||||
registerProtocol(new Protocol1_9_3To1_9_1_2(), Collections.singletonList(ProtocolVersion.v1_9_3.getId()), ProtocolVersion.v1_9_2.getId());
|
registerProtocol(new Protocol1_9_3To1_9_1_2(), ProtocolVersion.v1_9_3, ProtocolVersion.v1_9_2);
|
||||||
// Only supported for 1.9.4 server to 1.9 (nothing else)
|
// Only supported for 1.9.4 server to 1.9 (nothing else)
|
||||||
registerProtocol(new Protocol1_9To1_9_1(), Collections.singletonList(ProtocolVersion.v1_9.getId()), ProtocolVersion.v1_9_2.getId());
|
registerProtocol(new Protocol1_9To1_9_1(), ProtocolVersion.v1_9, ProtocolVersion.v1_9_2);
|
||||||
registerProtocol(new Protocol1_9_1_2To1_9_3_4(), Arrays.asList(ProtocolVersion.v1_9_1.getId(), ProtocolVersion.v1_9_2.getId()), ProtocolVersion.v1_9_3.getId());
|
registerProtocol(new Protocol1_9_1_2To1_9_3_4(), Arrays.asList(ProtocolVersion.v1_9_1.getId(), ProtocolVersion.v1_9_2.getId()), ProtocolVersion.v1_9_3.getId());
|
||||||
registerProtocol(new Protocol1_10To1_9_3_4(), Collections.singletonList(ProtocolVersion.v1_10.getId()), ProtocolVersion.v1_9_3.getId());
|
registerProtocol(new Protocol1_10To1_9_3_4(), ProtocolVersion.v1_10, ProtocolVersion.v1_9_3);
|
||||||
|
|
||||||
registerProtocol(new Protocol1_11To1_10(), Collections.singletonList(ProtocolVersion.v1_11.getId()), ProtocolVersion.v1_10.getId());
|
registerProtocol(new Protocol1_11To1_10(), ProtocolVersion.v1_11, ProtocolVersion.v1_10);
|
||||||
registerProtocol(new Protocol1_11_1To1_11(), Collections.singletonList(ProtocolVersion.v1_11_1.getId()), ProtocolVersion.v1_11.getId());
|
registerProtocol(new Protocol1_11_1To1_11(), ProtocolVersion.v1_11_1, ProtocolVersion.v1_11);
|
||||||
|
|
||||||
registerProtocol(new Protocol1_12To1_11_1(), Collections.singletonList(ProtocolVersion.v1_12.getId()), ProtocolVersion.v1_11_1.getId());
|
registerProtocol(new Protocol1_12To1_11_1(), ProtocolVersion.v1_12, ProtocolVersion.v1_11_1);
|
||||||
registerProtocol(new Protocol1_12_1To1_12(), Collections.singletonList(ProtocolVersion.v1_12_1.getId()), ProtocolVersion.v1_12.getId());
|
registerProtocol(new Protocol1_12_1To1_12(), ProtocolVersion.v1_12_1, ProtocolVersion.v1_12);
|
||||||
registerProtocol(new Protocol1_12_2To1_12_1(), Collections.singletonList(ProtocolVersion.v1_12_2.getId()), ProtocolVersion.v1_12_1.getId());
|
registerProtocol(new Protocol1_12_2To1_12_1(), ProtocolVersion.v1_12_2, ProtocolVersion.v1_12_1);
|
||||||
|
|
||||||
registerProtocol(new Protocol1_13To1_12_2(), Collections.singletonList(ProtocolVersion.v1_13.getId()), ProtocolVersion.v1_12_2.getId());
|
registerProtocol(new Protocol1_13To1_12_2(), ProtocolVersion.v1_13, ProtocolVersion.v1_12_2);
|
||||||
registerProtocol(new Protocol1_13_1To1_13(), Collections.singletonList(ProtocolVersion.v1_13_1.getId()), ProtocolVersion.v1_13.getId());
|
registerProtocol(new Protocol1_13_1To1_13(), ProtocolVersion.v1_13_1, ProtocolVersion.v1_13);
|
||||||
registerProtocol(new Protocol1_13_2To1_13_1(), Collections.singletonList(ProtocolVersion.v1_13_2.getId()), ProtocolVersion.v1_13_1.getId());
|
registerProtocol(new Protocol1_13_2To1_13_1(), ProtocolVersion.v1_13_2, ProtocolVersion.v1_13_1);
|
||||||
|
|
||||||
registerProtocol(new Protocol1_14To1_13_2(), Collections.singletonList(ProtocolVersion.v1_14.getId()), ProtocolVersion.v1_13_2.getId());
|
registerProtocol(new Protocol1_14To1_13_2(), ProtocolVersion.v1_14, ProtocolVersion.v1_13_2);
|
||||||
registerProtocol(new Protocol1_14_1To1_14(), Collections.singletonList(ProtocolVersion.v1_14_1.getId()), ProtocolVersion.v1_14.getId());
|
registerProtocol(new Protocol1_14_1To1_14(), ProtocolVersion.v1_14_1, ProtocolVersion.v1_14);
|
||||||
registerProtocol(new Protocol1_14_2To1_14_1(), Collections.singletonList(ProtocolVersion.v1_14_2.getId()), ProtocolVersion.v1_14_1.getId());
|
registerProtocol(new Protocol1_14_2To1_14_1(), ProtocolVersion.v1_14_2, ProtocolVersion.v1_14_1);
|
||||||
registerProtocol(new Protocol1_14_3To1_14_2(), Collections.singletonList(ProtocolVersion.v1_14_3.getId()), ProtocolVersion.v1_14_2.getId());
|
registerProtocol(new Protocol1_14_3To1_14_2(), ProtocolVersion.v1_14_3, ProtocolVersion.v1_14_2);
|
||||||
registerProtocol(new Protocol1_14_4To1_14_3(), Collections.singletonList(ProtocolVersion.v1_14_4.getId()), ProtocolVersion.v1_14_3.getId());
|
registerProtocol(new Protocol1_14_4To1_14_3(), ProtocolVersion.v1_14_4, ProtocolVersion.v1_14_3);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register a protocol
|
||||||
|
*
|
||||||
|
* @param protocol The protocol to register.
|
||||||
|
* @param supported Supported client versions.
|
||||||
|
* @param output The output server version it converts to.
|
||||||
|
*/
|
||||||
|
public static void registerProtocol(Protocol protocol, ProtocolVersion supported, ProtocolVersion output) {
|
||||||
|
registerProtocol(protocol, Collections.singletonList(supported.getId()), output.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -81,7 +92,7 @@ public class ProtocolRegistry {
|
|||||||
*/
|
*/
|
||||||
public static void registerProtocol(Protocol protocol, List<Integer> supported, Integer output) {
|
public static void registerProtocol(Protocol protocol, List<Integer> supported, Integer output) {
|
||||||
// Clear cache as this may make new routes.
|
// Clear cache as this may make new routes.
|
||||||
if (pathCache.size() > 0)
|
if (!pathCache.isEmpty())
|
||||||
pathCache.clear();
|
pathCache.clear();
|
||||||
|
|
||||||
for (Integer version : supported) {
|
for (Integer version : supported) {
|
||||||
|
@ -16,7 +16,6 @@ import java.io.IOException;
|
|||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -46,17 +45,14 @@ public class MappingData {
|
|||||||
loadTags(fluidTags, mapping1_13.getAsJsonObject("fluid_tags"));
|
loadTags(fluidTags, mapping1_13.getAsJsonObject("fluid_tags"));
|
||||||
Via.getPlatform().getLogger().info("Loading 1.12.2 -> 1.13 enchantment mapping...");
|
Via.getPlatform().getLogger().info("Loading 1.12.2 -> 1.13 enchantment mapping...");
|
||||||
loadEnchantments(oldEnchantmentsIds, mapping1_12.getAsJsonObject("enchantments"));
|
loadEnchantments(oldEnchantmentsIds, mapping1_12.getAsJsonObject("enchantments"));
|
||||||
enchantmentMappings = new EnchantmentMappingByteArray(mapping1_12.getAsJsonObject("enchantments"), mapping1_13.getAsJsonObject("enchantments"));
|
enchantmentMappings = new Mappings(72, mapping1_12.getAsJsonObject("enchantments"), mapping1_13.getAsJsonObject("enchantments"));
|
||||||
Via.getPlatform().getLogger().info("Loading 1.12.2 -> 1.13 sound mapping...");
|
Via.getPlatform().getLogger().info("Loading 1.12.2 -> 1.13 sound mapping...");
|
||||||
soundMappings = new SoundMappingShortArray(mapping1_12.getAsJsonArray("sounds"), mapping1_13.getAsJsonArray("sounds"));
|
soundMappings = new Mappings(662, mapping1_12.getAsJsonArray("sounds"), mapping1_13.getAsJsonArray("sounds"));
|
||||||
Via.getPlatform().getLogger().info("Loading translation mappping");
|
Via.getPlatform().getLogger().info("Loading translation mappping");
|
||||||
Map<String, String> translateData = GsonUtil.getGson().fromJson(
|
Map<String, String> translateData = GsonUtil.getGson().fromJson(
|
||||||
new InputStreamReader(
|
new InputStreamReader(MappingData.class.getClassLoader().getResourceAsStream("assets/viaversion/data/mapping-lang-1.12-1.13.json")),
|
||||||
MappingData.class.getClassLoader()
|
new TypeToken<Map<String, String>>() {
|
||||||
.getResourceAsStream("assets/viaversion/data/mapping-lang-1.12-1.13.json")
|
}.getType());
|
||||||
),
|
|
||||||
(new TypeToken<Map<String, String>>() {
|
|
||||||
}).getType());
|
|
||||||
try {
|
try {
|
||||||
String[] lines;
|
String[] lines;
|
||||||
try (Reader reader = new InputStreamReader(MappingData.class.getClassLoader()
|
try (Reader reader = new InputStreamReader(MappingData.class.getClassLoader()
|
||||||
@ -100,12 +96,11 @@ public class MappingData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class BlockMappingsShortArray implements Mappings {
|
private static class BlockMappingsShortArray extends Mappings {
|
||||||
private short[] oldToNew = new short[4084];
|
|
||||||
|
|
||||||
private BlockMappingsShortArray(JsonObject mapping1_12, JsonObject mapping1_13) {
|
private BlockMappingsShortArray(JsonObject mapping1_12, JsonObject mapping1_13) {
|
||||||
Arrays.fill(oldToNew, (short) -1);
|
super(4084, mapping1_12, mapping1_13);
|
||||||
MappingDataLoader.mapIdentifiers(oldToNew, mapping1_12, mapping1_13);
|
|
||||||
// Map minecraft:snow[layers=1] of 1.12 to minecraft:snow[layers=2] in 1.13
|
// Map minecraft:snow[layers=1] of 1.12 to minecraft:snow[layers=2] in 1.13
|
||||||
if (Via.getConfig().isSnowCollisionFix()) {
|
if (Via.getConfig().isSnowCollisionFix()) {
|
||||||
oldToNew[1248] = 3416;
|
oldToNew[1248] = 3416;
|
||||||
@ -119,38 +114,5 @@ public class MappingData {
|
|||||||
oldToNew[1556] = 3985; // cracked stone bricks
|
oldToNew[1556] = 3985; // cracked stone bricks
|
||||||
oldToNew[1557] = 3986; // chiseled stone bricks
|
oldToNew[1557] = 3986; // chiseled stone bricks
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getNewId(int old) {
|
|
||||||
return old >= 0 && old < oldToNew.length ? oldToNew[old] : -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class SoundMappingShortArray implements Mappings {
|
|
||||||
private short[] oldToNew = new short[662];
|
|
||||||
|
|
||||||
private SoundMappingShortArray(JsonArray mapping1_12, JsonArray mapping1_13) {
|
|
||||||
Arrays.fill(oldToNew, (short) -1);
|
|
||||||
MappingDataLoader.mapIdentifiers(oldToNew, mapping1_12, mapping1_13);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getNewId(int old) {
|
|
||||||
return old >= 0 && old < oldToNew.length ? oldToNew[old] : -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class EnchantmentMappingByteArray implements Mappings {
|
|
||||||
private byte[] oldToNew = new byte[72];
|
|
||||||
|
|
||||||
private EnchantmentMappingByteArray(JsonObject m1_12, JsonObject m1_13) {
|
|
||||||
Arrays.fill(oldToNew, (byte) -1);
|
|
||||||
MappingDataLoader.mapIdentifiers(oldToNew, m1_12, m1_13);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getNewId(int old) {
|
|
||||||
return old >= 0 && old < oldToNew.length ? oldToNew[old] : -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,10 +9,13 @@ import us.myles.ViaVersion.api.Via;
|
|||||||
import us.myles.ViaVersion.api.data.MappingDataLoader;
|
import us.myles.ViaVersion.api.data.MappingDataLoader;
|
||||||
import us.myles.ViaVersion.api.data.Mappings;
|
import us.myles.ViaVersion.api.data.Mappings;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class MappingData {
|
public class MappingData {
|
||||||
public final static BiMap<Integer, Integer> oldToNewItems = HashBiMap.create();
|
public static final BiMap<Integer, Integer> oldToNewItems = HashBiMap.create();
|
||||||
public static Mappings blockStateMappings;
|
public static Mappings blockStateMappings;
|
||||||
public static Mappings blockMappings;
|
public static Mappings blockMappings;
|
||||||
public static Mappings soundMappings;
|
public static Mappings soundMappings;
|
||||||
@ -23,13 +26,13 @@ public class MappingData {
|
|||||||
JsonObject mapping1_14 = MappingDataLoader.loadData("mapping-1.14.json");
|
JsonObject mapping1_14 = MappingDataLoader.loadData("mapping-1.14.json");
|
||||||
|
|
||||||
Via.getPlatform().getLogger().info("Loading 1.13.2 -> 1.14 blockstate mapping...");
|
Via.getPlatform().getLogger().info("Loading 1.13.2 -> 1.14 blockstate mapping...");
|
||||||
blockStateMappings = new BlockMappingsShortArray(mapping1_13_2.getAsJsonObject("blockstates"), mapping1_14.getAsJsonObject("blockstates"));
|
blockStateMappings = new Mappings(mapping1_13_2.getAsJsonObject("blockstates"), mapping1_14.getAsJsonObject("blockstates"));
|
||||||
Via.getPlatform().getLogger().info("Loading 1.13.2 -> 1.14 block mapping...");
|
Via.getPlatform().getLogger().info("Loading 1.13.2 -> 1.14 block mapping...");
|
||||||
blockMappings = new BlockMappingsShortArray(mapping1_13_2.getAsJsonObject("blocks"), mapping1_14.getAsJsonObject("blocks"));
|
blockMappings = new Mappings(mapping1_13_2.getAsJsonObject("blocks"), mapping1_14.getAsJsonObject("blocks"));
|
||||||
Via.getPlatform().getLogger().info("Loading 1.13.2 -> 1.14 item mapping...");
|
Via.getPlatform().getLogger().info("Loading 1.13.2 -> 1.14 item mapping...");
|
||||||
MappingDataLoader.mapIdentifiers(oldToNewItems, mapping1_13_2.getAsJsonObject("items"), mapping1_14.getAsJsonObject("items"));
|
MappingDataLoader.mapIdentifiers(oldToNewItems, mapping1_13_2.getAsJsonObject("items"), mapping1_14.getAsJsonObject("items"));
|
||||||
Via.getPlatform().getLogger().info("Loading 1.13.2 -> 1.14 sound mapping...");
|
Via.getPlatform().getLogger().info("Loading 1.13.2 -> 1.14 sound mapping...");
|
||||||
soundMappings = new SoundMappingShortArray(mapping1_13_2.getAsJsonArray("sounds"), mapping1_14.getAsJsonArray("sounds"));
|
soundMappings = new Mappings(mapping1_13_2.getAsJsonArray("sounds"), mapping1_14.getAsJsonArray("sounds"));
|
||||||
|
|
||||||
Via.getPlatform().getLogger().info("Loading 1.14 blockstates...");
|
Via.getPlatform().getLogger().info("Loading 1.14 blockstates...");
|
||||||
JsonObject blockStates = mapping1_14.getAsJsonObject("blockstates");
|
JsonObject blockStates = mapping1_14.getAsJsonObject("blockstates");
|
||||||
@ -52,34 +55,4 @@ public class MappingData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class SoundMappingShortArray implements Mappings {
|
|
||||||
private short[] oldToNew;
|
|
||||||
|
|
||||||
private SoundMappingShortArray(JsonArray mapping1_13_2, JsonArray mapping1_14) {
|
|
||||||
oldToNew = new short[mapping1_13_2.size()];
|
|
||||||
Arrays.fill(oldToNew, (short) -1);
|
|
||||||
MappingDataLoader.mapIdentifiers(oldToNew, mapping1_13_2, mapping1_14);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getNewId(int old) {
|
|
||||||
return old >= 0 && old < oldToNew.length ? oldToNew[old] : -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class BlockMappingsShortArray implements Mappings {
|
|
||||||
private short[] oldToNew;
|
|
||||||
|
|
||||||
private BlockMappingsShortArray(JsonObject mapping1_13_2, JsonObject mapping1_14) {
|
|
||||||
oldToNew = new short[mapping1_13_2.entrySet().size()];
|
|
||||||
Arrays.fill(oldToNew, (short) -1);
|
|
||||||
MappingDataLoader.mapIdentifiers(oldToNew, mapping1_13_2, mapping1_14);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getNewId(int old) {
|
|
||||||
return old >= 0 && old < oldToNew.length ? oldToNew[old] : -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren