3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-26 00:00:28 +01:00

Asynchronously load mappings (until needed), create optional mappings cache for VB

Dieser Commit ist enthalten in:
KennyTV 2020-03-23 01:23:17 +01:00
Ursprung b5e5118450
Commit e658304405
19 geänderte Dateien mit 225 neuen und 66 gelöschten Zeilen

Datei anzeigen

@ -10,6 +10,7 @@ import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.ViaAPI;
import us.myles.ViaVersion.api.command.ViaCommandSender;
import us.myles.ViaVersion.api.configuration.ConfigurationProvider;
import us.myles.ViaVersion.api.data.MappingDataLoader;
import us.myles.ViaVersion.api.platform.TaskId;
import us.myles.ViaVersion.api.platform.ViaPlatform;
import us.myles.ViaVersion.bukkit.classgenerator.ClassGenerator;
@ -82,6 +83,10 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform {
compatSpigotBuild = false;
}
if (getServer().getPluginManager().getPlugin("ViaBackwards") != null) {
MappingDataLoader.setCacheJsonMappings(true);
}
// Generate classes needed (only works if it's compat or ps)
ClassGenerator.generate();
lateBind = !BukkitViaInjector.isBinded();

Datei anzeigen

@ -12,6 +12,7 @@ import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.ViaAPI;
import us.myles.ViaVersion.api.command.ViaCommandSender;
import us.myles.ViaVersion.api.configuration.ConfigurationProvider;
import us.myles.ViaVersion.api.data.MappingDataLoader;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.platform.TaskId;
import us.myles.ViaVersion.api.platform.ViaPlatform;
@ -37,7 +38,7 @@ public class BungeePlugin extends Plugin implements ViaPlatform, Listener {
@Override
public void onLoad() {
try {
ProtocolConstants.class.getField("MINECRAFT_1_14_4");
ProtocolConstants.class.getField("MINECRAFT_1_15_2");
} catch (NoSuchFieldException e) {
getLogger().warning(" / \\");
getLogger().warning(" / \\");
@ -47,10 +48,12 @@ public class BungeePlugin extends Plugin implements ViaPlatform, Listener {
getLogger().warning(" / o \\");
getLogger().warning("/_____________\\");
}
api = new BungeeViaAPI();
config = new BungeeViaConfig(getDataFolder());
commandHandler = new BungeeCommandHandler();
ProxyServer.getInstance().getPluginManager().registerCommand(this, new BungeeCommand(commandHandler));
// Init platform
Via.init(ViaManager.builder()
.platform(this)
@ -62,6 +65,10 @@ public class BungeePlugin extends Plugin implements ViaPlatform, Listener {
@Override
public void onEnable() {
if (ProxyServer.getInstance().getPluginManager().getPlugin("ViaBackwards") != null) {
MappingDataLoader.setCacheJsonMappings(true);
}
// Inject
Via.getManager().init();
}

Datei anzeigen

@ -7,6 +7,7 @@ import us.myles.ViaVersion.api.platform.ViaPlatform;
public class Via {
private static ViaPlatform platform;
private static ViaManager manager;
private static boolean cacheJsonMappings;
/**
* Register the ViaManager associated with the platform.

Datei anzeigen

@ -5,10 +5,36 @@ import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.util.GsonUtil;
import java.io.*;
import java.util.HashMap;
import java.util.Map;
public class MappingDataLoader {
private static final Map<String, JsonObject> MAPPINGS_CACHE = new HashMap<>();
private static boolean cacheJsonMappings;
/**
* Returns true if a selected number of mappings should be cached.
* If enabled, cleanup should be done after the cache is no longer needed.
*
* @return true if mappings should be cached
*/
public static boolean cacheJsonMappings() {
return cacheJsonMappings;
}
public static void setCacheJsonMappings(boolean cacheJsonMappings) {
MappingDataLoader.cacheJsonMappings = cacheJsonMappings;
Via.getPlatform().getLogger().info("Enabled caching of mappingdata for ViaBackwards!");
}
/**
* @see #cacheJsonMappings()
*/
public static Map<String, JsonObject> getMappingsCache() {
return MAPPINGS_CACHE;
}
public static JsonObject loadFromDataDir(String name) {
File file = new File(Via.getPlatform().getDataFolder(), name);
if (!file.exists()) return loadData(name);
@ -27,10 +53,18 @@ public class MappingDataLoader {
}
public static JsonObject loadData(String name) {
return loadData(name, false);
}
public static JsonObject loadData(String name, boolean cacheIfEnabled) {
InputStream stream = getResource(name);
InputStreamReader reader = new InputStreamReader(stream);
try {
return GsonUtil.getGson().fromJson(reader, JsonObject.class);
JsonObject object = GsonUtil.getGson().fromJson(reader, JsonObject.class);
if (cacheIfEnabled && cacheJsonMappings) {
MAPPINGS_CACHE.put(name, object);
}
return object;
} finally {
try {
reader.close();

Datei anzeigen

@ -18,8 +18,14 @@ public abstract class Protocol {
private final Map<Packet, ProtocolPacket> incoming = new HashMap<>();
private final Map<Packet, ProtocolPacket> outgoing = new HashMap<>();
private final Map<Class, Object> storedObjects = new HashMap<>(); // currently only used for MetadataRewriters
private final boolean hasMappingDataToLoad;
public Protocol() {
this(false);
}
public Protocol(boolean hasMappingDataToLoad) {
this.hasMappingDataToLoad = hasMappingDataToLoad;
registerPackets();
}
@ -51,6 +57,14 @@ public abstract class Protocol {
*/
protected abstract void registerPackets();
/**
* Load mapping data for the protocol.
* <p>
* To be overridden if needed.
*/
protected void loadMappingData() {
}
/**
* Handle protocol registration phase, use this to register providers / tasks.
* <p>
@ -164,6 +178,10 @@ public abstract class Protocol {
cancelOutgoing(state, oldPacketID, -1);
}
public boolean hasMappingDataToLoad() {
return hasMappingDataToLoad;
}
/**
* Transform a packet using this protocol
*

Datei anzeigen

@ -2,9 +2,9 @@ package us.myles.ViaVersion.api.protocol;
import com.google.common.collect.Lists;
import com.google.common.collect.Range;
import com.google.common.collect.Sets;
import us.myles.ViaVersion.api.Pair;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.MappingDataLoader;
import us.myles.ViaVersion.protocols.base.BaseProtocol;
import us.myles.ViaVersion.protocols.base.BaseProtocol1_7;
import us.myles.ViaVersion.protocols.protocol1_10to1_9_3.Protocol1_10To1_9_3_4;
@ -32,7 +32,7 @@ import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
import us.myles.ViaVersion.protocols.protocol1_9to1_9_1.Protocol1_9To1_9_1;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.*;
public class ProtocolRegistry {
public static final Protocol BASE_PROTOCOL = new BaseProtocol();
@ -40,11 +40,17 @@ public class ProtocolRegistry {
// Input Version -> Output Version & Protocol (Allows fast lookup)
private static final Map<Integer, Map<Integer, Protocol>> registryMap = new ConcurrentHashMap<>();
private static final Map<Pair<Integer, Integer>, List<Pair<Integer, Protocol>>> pathCache = new ConcurrentHashMap<>();
private static final List<Protocol> registerList = Lists.newCopyOnWriteArrayList();
private static final Set<Integer> supportedVersions = Sets.newConcurrentHashSet();
private static final List<Protocol> registerList = new ArrayList<>();
private static final Set<Integer> supportedVersions = new HashSet<>();
private static final List<Pair<Range<Integer>, Protocol>> baseProtocols = Lists.newCopyOnWriteArrayList();
private static Map<Class<? extends Protocol>, CompletableFuture<Void>> mappingLoaderFutures = new ConcurrentHashMap<>();
private static ThreadPoolExecutor mappingLoaderExecutor;
static {
mappingLoaderExecutor = new ThreadPoolExecutor(5, 16, 45L, TimeUnit.SECONDS, new SynchronousQueue<>());
mappingLoaderExecutor.allowCoreThreadTimeOut(true);
// Base Protocol
registerBaseProtocol(BASE_PROTOCOL, Range.lessThan(Integer.MIN_VALUE));
registerBaseProtocol(new BaseProtocol1_7(), Range.all());
@ -102,15 +108,13 @@ public class ProtocolRegistry {
*/
public static void registerProtocol(Protocol protocol, List<Integer> supported, Integer output) {
// Clear cache as this may make new routes.
if (!pathCache.isEmpty())
if (!pathCache.isEmpty()) {
pathCache.clear();
}
for (Integer version : supported) {
if (!registryMap.containsKey(version)) {
registryMap.put(version, new HashMap<>());
}
registryMap.get(version).put(output, protocol);
Map<Integer, Protocol> protocolMap = registryMap.computeIfAbsent(version, k -> new HashMap<>());
protocolMap.put(output, protocol);
}
if (Via.getPlatform().isPluginEnabled()) {
@ -119,6 +123,21 @@ public class ProtocolRegistry {
} else {
registerList.add(protocol);
}
if (protocol.hasMappingDataToLoad()) {
if (mappingLoaderExecutor != null) {
// Submit mapping data loading
CompletableFuture<Void> future = new CompletableFuture<>();
mappingLoaderFutures.put(protocol.getClass(), future);
mappingLoaderExecutor.execute(() -> {
protocol.loadMappingData();
future.complete(null);
});
} else {
// Late protocol adding - just do it on the current thread
protocol.loadMappingData();
}
}
}
/**
@ -248,7 +267,7 @@ public class ProtocolRegistry {
return protocolList;
}
// Generate path
List<Pair<Integer, Protocol>> outputPath = getProtocolPath(new ArrayList<Pair<Integer, Protocol>>(), clientVersion, serverVersion);
List<Pair<Integer, Protocol>> outputPath = getProtocolPath(new ArrayList<>(), clientVersion, serverVersion);
// If it found a path, cache it.
if (outputPath != null) {
pathCache.put(protocolKey, outputPath);
@ -274,4 +293,53 @@ public class ProtocolRegistry {
return false;
}
/**
* Ensure that mapping data for that protocol has already been loaded, completes it otherwise.
*
* @param protocolClass protocol class
*/
public static void completeMappingDataLoading(Class<? extends Protocol> protocolClass) throws Exception {
if (mappingLoaderFutures == null) return;
CompletableFuture<Void> future = mappingLoaderFutures.remove(protocolClass);
if (future == null) return;
future.get();
if (mappingLoaderFutures.isEmpty()) {
shutdownLoaderExecutor();
}
}
/**
* Ensure that all mapping data has already been loaded, completes it otherwise.
*/
public static void completeMappingDataLoading() throws Exception {
if (mappingLoaderFutures == null) return;
for (CompletableFuture<Void> future : mappingLoaderFutures.values()) {
future.get();
}
mappingLoaderFutures.clear();
shutdownLoaderExecutor();
}
private static void shutdownLoaderExecutor() {
mappingLoaderExecutor.shutdown();
mappingLoaderExecutor = null;
mappingLoaderFutures = null;
if (MappingDataLoader.cacheJsonMappings()) {
MappingDataLoader.getMappingsCache().clear();
}
}
public static void getMappingLoaderFuture(Class<? extends Protocol> protocolClass, Runnable runnable) {
CompletableFuture<Void> future = mappingLoaderFutures.get(protocolClass);
if (future != null) {
future.whenComplete((v, t) -> runnable.run());
} else {
runnable.run();
}
}
}

Datei anzeigen

@ -58,6 +58,8 @@ public class BaseProtocol extends Protocol {
if (protocols != null) {
for (Pair<Integer, Protocol> prot : protocols) {
pipeline.add(prot.getValue());
// Ensure mapping data has already been loaded
ProtocolRegistry.completeMappingDataLoading(prot.getValue().getClass());
}
wrapper.set(Type.VAR_INT, 0, protocol);
}

Datei anzeigen

@ -42,14 +42,15 @@ import java.util.Map;
public class Protocol1_13To1_12_2 extends Protocol {
public static final PacketHandler POS_TO_3_INT = new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
Position position = wrapper.read(Type.POSITION);
wrapper.write(Type.INT, position.getX());
wrapper.write(Type.INT, (int) position.getY());
wrapper.write(Type.INT, position.getZ());
}
public Protocol1_13To1_12_2() {
super(true);
}
public static final PacketHandler POS_TO_3_INT = wrapper -> {
Position position = wrapper.read(Type.POSITION);
wrapper.write(Type.INT, position.getX());
wrapper.write(Type.INT, (int) position.getY());
wrapper.write(Type.INT, position.getZ());
};
public static final PacketHandler SEND_DECLARE_COMMANDS_AND_TAGS =
@ -132,11 +133,6 @@ public class Protocol1_13To1_12_2 extends Protocol {
SCOREBOARD_TEAM_NAME_REWRITE.put(ChatColor.UNDERLINE, ':');
SCOREBOARD_TEAM_NAME_REWRITE.put(ChatColor.ITALIC, ';');
SCOREBOARD_TEAM_NAME_REWRITE.put(ChatColor.RESET, '/');
MappingData.init();
ConnectionData.init();
RecipeData.init();
BlockIdData.init();
}
@Override
@ -1151,6 +1147,14 @@ public class Protocol1_13To1_12_2 extends Protocol {
registerIncoming(State.PLAY, 0x20, 0x2A);
}
@Override
protected void loadMappingData() {
MappingData.init();
ConnectionData.init();
RecipeData.init();
BlockIdData.init();
}
@Override
public void init(UserConnection userConnection) {
userConnection.put(new EntityTracker1_13(userConnection));

Datei anzeigen

@ -195,7 +195,7 @@ public class ConnectionData {
public static void init() {
if (!Via.getConfig().isServersideBlockConnections()) return;
Via.getPlatform().getLogger().info("Loading block connection mappings ...");
JsonObject mapping1_13 = MappingDataLoader.loadData("mapping-1.13.json");
JsonObject mapping1_13 = MappingDataLoader.loadData("mapping-1.13.json", true);
JsonObject blocks1_13 = mapping1_13.getAsJsonObject("blocks");
for (Entry<String, JsonElement> blockState : blocks1_13.entrySet()) {
Integer id = Integer.parseInt(blockState.getKey());

Datei anzeigen

@ -33,23 +33,19 @@ public class MappingData {
public static Mappings blockMappings;
public static void init() {
JsonObject mapping1_12 = MappingDataLoader.loadData("mapping-1.12.json");
JsonObject mapping1_13 = MappingDataLoader.loadData("mapping-1.13.json");
JsonObject mapping1_12 = MappingDataLoader.loadData("mapping-1.12.json", true);
JsonObject mapping1_13 = MappingDataLoader.loadData("mapping-1.13.json", true);
Via.getPlatform().getLogger().info("Loading 1.12.2 -> 1.13 mappings...");
Via.getPlatform().getLogger().info("Loading 1.12.2 -> 1.13 block mapping...");
blockMappings = new BlockMappingsShortArray(mapping1_12.getAsJsonObject("blocks"), mapping1_13.getAsJsonObject("blocks"));
Via.getPlatform().getLogger().info("Loading 1.12.2 -> 1.13 item mapping...");
MappingDataLoader.mapIdentifiers(oldToNewItems, mapping1_12.getAsJsonObject("items"), mapping1_13.getAsJsonObject("items"));
Via.getPlatform().getLogger().info("Loading new 1.13 tags...");
loadTags(blockTags, mapping1_13.getAsJsonObject("block_tags"));
loadTags(itemTags, mapping1_13.getAsJsonObject("item_tags"));
loadTags(fluidTags, mapping1_13.getAsJsonObject("fluid_tags"));
Via.getPlatform().getLogger().info("Loading 1.12.2 -> 1.13 enchantment mapping...");
loadEnchantments(oldEnchantmentsIds, mapping1_12.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...");
soundMappings = new Mappings(662, mapping1_12.getAsJsonArray("sounds"), mapping1_13.getAsJsonArray("sounds"));
Via.getPlatform().getLogger().info("Loading 1.12.2 -> 1.13 plugin channel mappings...");
JsonObject object = MappingDataLoader.loadFromDataDir("channelmappings-1.13.json");
if (object != null) {
@ -64,7 +60,6 @@ public class MappingData {
}
}
Via.getPlatform().getLogger().info("Loading translation mappping");
Map<String, String> translateData = GsonUtil.getGson().fromJson(
new InputStreamReader(MappingData.class.getClassLoader().getResourceAsStream("assets/viaversion/data/mapping-lang-1.12-1.13.json")),
new TypeToken<Map<String, String>>() {

Datei anzeigen

@ -19,8 +19,8 @@ import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
public class Protocol1_14To1_13_2 extends Protocol {
static {
MappingData.init();
public Protocol1_14To1_13_2() {
super(true);
}
@Override
@ -254,6 +254,14 @@ public class Protocol1_14To1_13_2 extends Protocol {
registerIncoming(State.PLAY, 0x2A, 0x2D);
}
@Override
protected void loadMappingData() {
MappingData.init();
WorldPackets.air = MappingData.blockStateMappings.getNewId(0);
WorldPackets.voidAir = MappingData.blockStateMappings.getNewId(8591);
WorldPackets.caveAir = MappingData.blockStateMappings.getNewId(8592);
}
public static int getNewSoundId(int id) {
int newId = MappingData.soundMappings.getNewId(id);
if (newId == -1) {

Datei anzeigen

@ -23,26 +23,21 @@ public class MappingData {
public static Set<Integer> nonFullBlocks;
public static void init() {
JsonObject mapping1_13_2 = MappingDataLoader.loadData("mapping-1.13.2.json");
JsonObject mapping1_14 = MappingDataLoader.loadData("mapping-1.14.json");
JsonObject mapping1_13_2 = MappingDataLoader.loadData("mapping-1.13.2.json", true);
JsonObject mapping1_14 = MappingDataLoader.loadData("mapping-1.14.json", true);
Via.getPlatform().getLogger().info("Loading 1.13.2 -> 1.14 mappings...");
Via.getPlatform().getLogger().info("Loading 1.13.2 -> 1.14 blockstate mapping...");
blockStateMappings = new Mappings(mapping1_13_2.getAsJsonObject("blockstates"), mapping1_14.getAsJsonObject("blockstates"));
Via.getPlatform().getLogger().info("Loading 1.13.2 -> 1.14 block mapping...");
blockMappings = new Mappings(mapping1_13_2.getAsJsonObject("blocks"), mapping1_14.getAsJsonObject("blocks"));
Via.getPlatform().getLogger().info("Loading 1.13.2 -> 1.14 item mapping...");
MappingDataLoader.mapIdentifiers(oldToNewItems, mapping1_13_2.getAsJsonObject("items"), mapping1_14.getAsJsonObject("items"));
Via.getPlatform().getLogger().info("Loading 1.13.2 -> 1.14 sound mapping...");
soundMappings = new Mappings(mapping1_13_2.getAsJsonArray("sounds"), mapping1_14.getAsJsonArray("sounds"));
Via.getPlatform().getLogger().info("Loading 1.14 blockstates...");
JsonObject blockStates = mapping1_14.getAsJsonObject("blockstates");
Map<String, Integer> blockStateMap = new HashMap<>(blockStates.entrySet().size());
for (Map.Entry<String, JsonElement> entry : blockStates.entrySet()) {
blockStateMap.put(entry.getValue().getAsString(), Integer.parseInt(entry.getKey()));
}
Via.getPlatform().getLogger().info("Loading 1.14 heightmap data...");
JsonObject heightMapData = MappingDataLoader.loadData("heightMapData-1.14.json");
JsonArray motionBlocking = heightMapData.getAsJsonArray("MOTION_BLOCKING");
us.myles.ViaVersion.protocols.protocol1_14to1_13_2.data.MappingData.motionBlocking = new HashSet<>(motionBlocking.size());

Datei anzeigen

@ -28,11 +28,11 @@ import us.myles.ViaVersion.util.CompactArrayUtil;
import java.util.Arrays;
public class WorldPackets {
private static final int AIR = MappingData.blockStateMappings.getNewId(0);
private static final int VOID_AIR = MappingData.blockStateMappings.getNewId(8591);
private static final int CAVE_AIR = MappingData.blockStateMappings.getNewId(8592);
public static final int SERVERSIDE_VIEW_DISTANCE = 64;
private static final byte[] FULL_LIGHT = new byte[2048];
public static int air;
public static int voidAir;
public static int caveAir;
static {
Arrays.fill(FULL_LIGHT, (byte) 0xff);
@ -156,7 +156,7 @@ public class WorldPackets {
for (int i = 0; i < section.getPaletteSize(); i++) {
int old = section.getPaletteEntry(i);
int newId = Protocol1_14To1_13_2.getNewBlockStateId(old);
if (!hasBlock && newId != AIR && newId != VOID_AIR && newId != CAVE_AIR) { // air, void_air, cave_air
if (!hasBlock && newId != air && newId != voidAir && newId != caveAir) { // air, void_air, cave_air
hasBlock = true;
}
section.setPaletteEntry(i, newId);
@ -171,7 +171,7 @@ public class WorldPackets {
for (int y = 0; y < 16; y++) {
for (int z = 0; z < 16; z++) {
int id = section.getFlatBlock(x, y, z);
if (id != AIR && id != VOID_AIR && id != CAVE_AIR) {
if (id != air && id != voidAir && id != caveAir) {
nonAirBlockCount++;
worldSurface[x + z * 16] = y + s * 16 + 1; // +1 (top of the block)
}

Datei anzeigen

@ -21,11 +21,14 @@ import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
public class Protocol1_15To1_14_4 extends Protocol {
public Protocol1_15To1_14_4() {
super(true);
}
@Override
protected void registerPackets() {
new MetadataRewriter1_15To1_14_4(this);
MappingData.init();
EntityPackets.register(this);
PlayerPackets.register(this);
WorldPackets.register(this);
@ -203,6 +206,11 @@ public class Protocol1_15To1_14_4 extends Protocol {
registerOutgoing(State.PLAY, 0x59, 0x5A);
}
@Override
protected void loadMappingData() {
MappingData.init();
}
public static int getNewBlockStateId(int id) {
int newId = MappingData.blockStateMappings.getNewId(id);
if (newId == -1) {

Datei anzeigen

@ -15,16 +15,13 @@ public class MappingData {
public static void init() {
JsonObject diffmapping = MappingDataLoader.loadData("mappingdiff-1.14to1.15.json");
JsonObject mapping1_14 = MappingDataLoader.loadData("mapping-1.14.json");
JsonObject mapping1_15 = MappingDataLoader.loadData("mapping-1.15.json");
JsonObject mapping1_14 = MappingDataLoader.loadData("mapping-1.14.json", true);
JsonObject mapping1_15 = MappingDataLoader.loadData("mapping-1.15.json", true);
Via.getPlatform().getLogger().info("Loading 1.14.4 -> 1.15 mappings...");
Via.getPlatform().getLogger().info("Loading 1.14.4 -> 1.15 blockstate mapping...");
blockStateMappings = new Mappings(mapping1_14.getAsJsonObject("blockstates"), mapping1_15.getAsJsonObject("blockstates"), diffmapping.getAsJsonObject("blockstates"));
Via.getPlatform().getLogger().info("Loading 1.14.4 -> 1.15 block mapping...");
blockMappings = new Mappings(mapping1_14.getAsJsonObject("blocks"), mapping1_15.getAsJsonObject("blocks"));
Via.getPlatform().getLogger().info("Loading 1.14.4 -> 1.15 item mapping...");
MappingDataLoader.mapIdentifiers(oldToNewItems, mapping1_14.getAsJsonObject("items"), mapping1_15.getAsJsonObject("items"));
Via.getPlatform().getLogger().info("Loading 1.14.4 -> 1.15 sound mapping...");
soundMappings = new Mappings(mapping1_14.getAsJsonArray("sounds"), mapping1_15.getAsJsonArray("sounds"), false);
}
}

Datei anzeigen

@ -20,11 +20,14 @@ import java.util.UUID;
public class Protocol1_16To1_15_2 extends Protocol {
public Protocol1_16To1_15_2() {
super(true);
}
@Override
protected void registerPackets() {
MetadataRewriter1_16To1_15_2 metadataRewriter = new MetadataRewriter1_16To1_15_2(this);
MappingData.init();
EntityPackets.register(this);
WorldPackets.register(this);
InventoryPackets.register(this);
@ -132,6 +135,11 @@ public class Protocol1_16To1_15_2 extends Protocol {
registerOutgoing(State.PLAY, 0x4E, 0x43);
}
@Override
protected void loadMappingData() {
MappingData.init();
}
public static int getNewBlockStateId(int id) {
int newId = MappingData.blockStateMappings.getNewId(id);
if (newId == -1) {

Datei anzeigen

@ -19,16 +19,13 @@ public class MappingData {
public static void init() {
JsonObject diffmapping = MappingDataLoader.loadData("mappingdiff-1.15to1.16.json");
JsonObject mapping1_15 = MappingDataLoader.loadData("mapping-1.15.json");
JsonObject mapping1_16 = MappingDataLoader.loadData("mapping-1.16.json");
JsonObject mapping1_15 = MappingDataLoader.loadData("mapping-1.15.json", true);
JsonObject mapping1_16 = MappingDataLoader.loadData("mapping-1.16.json", true);
Via.getPlatform().getLogger().info("Loading 1.15 -> 1.16 mappings...");
Via.getPlatform().getLogger().info("Loading 1.15 -> 1.16 blockstate mapping...");
blockStateMappings = new Mappings(mapping1_15.getAsJsonObject("blockstates"), mapping1_16.getAsJsonObject("blockstates"), diffmapping.getAsJsonObject("blockstates"));
Via.getPlatform().getLogger().info("Loading 1.15 -> 1.16 block mapping...");
blockMappings = new Mappings(mapping1_15.getAsJsonObject("blocks"), mapping1_16.getAsJsonObject("blocks"));
Via.getPlatform().getLogger().info("Loading 1.15 -> 1.16 item mapping...");
MappingDataLoader.mapIdentifiers(oldToNewItems, mapping1_15.getAsJsonObject("items"), mapping1_16.getAsJsonObject("items"), diffmapping.getAsJsonObject("items"));
Via.getPlatform().getLogger().info("Loading 1.15 -> 1.16 sound mapping...");
soundMappings = new Mappings(mapping1_15.getAsJsonArray("sounds"), mapping1_16.getAsJsonArray("sounds"), diffmapping.getAsJsonObject("sounds"));
attributeMappings.put("generic.maxHealth", "minecraft:generic.max_health");

Datei anzeigen

@ -19,6 +19,7 @@ import org.spongepowered.api.text.serializer.TextSerializers;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.command.ViaCommandSender;
import us.myles.ViaVersion.api.configuration.ConfigurationProvider;
import us.myles.ViaVersion.api.data.MappingDataLoader;
import us.myles.ViaVersion.api.platform.TaskId;
import us.myles.ViaVersion.api.platform.ViaPlatform;
import us.myles.ViaVersion.dump.PluginInfo;
@ -68,7 +69,8 @@ public class SpongePlugin implements ViaPlatform {
conf = new SpongeViaConfig(container, defaultConfig.getParentFile());
SpongeCommandHandler commandHandler = new SpongeCommandHandler();
game.getCommandManager().register(this, commandHandler, "viaversion", "viaver", "vvsponge");
getLogger().info("ViaVersion " + getPluginVersion() + " is now loaded!");
logger.info("ViaVersion " + getPluginVersion() + " is now loaded!");
// Init platform
Via.init(ViaManager.builder()
.platform(this)
@ -80,6 +82,10 @@ public class SpongePlugin implements ViaPlatform {
@Listener
public void onServerStart(GameAboutToStartServerEvent event) {
if (game.getPluginManager().getPlugin("ViaBackwards").isPresent()) {
MappingDataLoader.setCacheJsonMappings(true);
}
// Inject!
logger.info("ViaVersion is injecting!");
Via.getManager().init();

Datei anzeigen

@ -18,6 +18,7 @@ import org.slf4j.Logger;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.command.ViaCommandSender;
import us.myles.ViaVersion.api.configuration.ConfigurationProvider;
import us.myles.ViaVersion.api.data.MappingDataLoader;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.platform.TaskId;
import us.myles.ViaVersion.api.platform.ViaPlatform;
@ -73,6 +74,11 @@ public class VelocityPlugin implements ViaPlatform<Player> {
.commandHandler(commandHandler)
.loader(new VelocityViaLoader())
.injector(new VelocityViaInjector()).build());
if (proxy.getPluginManager().getPlugin("ViaBackwards").isPresent()) {
MappingDataLoader.setCacheJsonMappings(true);
}
Via.getManager().init();
}