mirror of
https://github.com/ViaVersion/ViaFabric.git
synced 2024-11-28 12:45:25 +01:00
move client code to own class, some cleanup
This commit is contained in:
parent
9e337d45c1
commit
1d6363bbb9
@ -103,9 +103,9 @@ or registry synchronization (fabric-registry-sync mod).
|
||||
- You can disable it in the menu or by setting global protocol version to -1 (this will keep per-server translations still enabled)
|
||||
|
||||
|
||||
### How to use protocol auto detector?:
|
||||
### How to use protocol detection?:
|
||||
- For using globally, set the protocol to AUTO or -2. For using in a specific server: ``ddns.example.com._v-2.viafabric``
|
||||
- The protocol auto detector will try to ping with the client native protocol version. If you have ViaVersion or
|
||||
- The protocol detector will try to ping with the client native protocol version. If you have ViaVersion or
|
||||
similar in the server it may use the translated version, differently than multiconnect which uses -1 version,
|
||||
which may get the native server version.
|
||||
- It may hold your handshake for up to 10 seconds.
|
||||
|
@ -63,11 +63,8 @@ public class AddressParser {
|
||||
}
|
||||
|
||||
String arg = part.substring(2);
|
||||
switch (option) {
|
||||
case "v": {
|
||||
parseProtocol(arg);
|
||||
break;
|
||||
}
|
||||
if ("v".equals(option)) {
|
||||
parseProtocol(arg);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -7,7 +7,7 @@ import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import java.util.UUID;
|
||||
|
||||
public class UserCommandSender implements ViaCommandSender {
|
||||
private UserConnection con;
|
||||
private final UserConnection con;
|
||||
|
||||
public UserCommandSender(UserConnection con) {
|
||||
this.con = con;
|
||||
|
@ -9,7 +9,6 @@ import io.netty.channel.ChannelHandler;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.MessageToMessageDecoder;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.List;
|
||||
|
||||
@ChannelHandler.Sharable
|
||||
|
@ -46,7 +46,7 @@ public class FabricInjector implements ViaInjector {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getServerProtocolVersion() throws Exception {
|
||||
public int getServerProtocolVersion() {
|
||||
return getServerProtocolVersions().firstInt();
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ import java.util.Map;
|
||||
|
||||
public class FabricViaConfig extends AbstractViaConfig {
|
||||
// Based on Sponge ViaVersion
|
||||
private static List<String> UNSUPPORTED = Arrays.asList("anti-xray-patch", "bungee-ping-interval",
|
||||
private static final List<String> UNSUPPORTED = Arrays.asList("anti-xray-patch", "bungee-ping-interval",
|
||||
"bungee-ping-save", "bungee-servers", "quick-move-action-fix", "nms-player-ticking",
|
||||
"velocity-ping-interval", "velocity-ping-save", "velocity-servers",
|
||||
"blockconnection-method", "change-1_9-hitbox", "change-1_14-hitbox");
|
||||
|
@ -3,6 +3,7 @@ package com.viaversion.fabric.common.provider;
|
||||
import com.viaversion.fabric.common.platform.FabricViaAPI;
|
||||
import com.viaversion.fabric.common.platform.FabricViaConfig;
|
||||
import com.viaversion.fabric.common.platform.NativeVersionProvider;
|
||||
import com.viaversion.fabric.common.util.FutureTaskId;
|
||||
import com.viaversion.fabric.common.util.JLoggerToLog4j;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.ViaAPI;
|
||||
@ -11,6 +12,9 @@ import com.viaversion.viaversion.api.configuration.ViaVersionConfig;
|
||||
import com.viaversion.viaversion.api.platform.ViaPlatform;
|
||||
import com.viaversion.viaversion.libs.gson.JsonArray;
|
||||
import com.viaversion.viaversion.libs.gson.JsonObject;
|
||||
import io.netty.channel.EventLoop;
|
||||
import io.netty.util.concurrent.Future;
|
||||
import io.netty.util.concurrent.GenericFutureListener;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.fabricmc.loader.api.ModContainer;
|
||||
import net.fabricmc.loader.api.Version;
|
||||
@ -20,6 +24,10 @@ import org.apache.logging.log4j.LogManager;
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CancellationException;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public abstract class AbstractFabricPlatform implements ViaPlatform<UUID> {
|
||||
@ -35,6 +43,51 @@ public abstract class AbstractFabricPlatform implements ViaPlatform<UUID> {
|
||||
api = new FabricViaAPI();
|
||||
}
|
||||
|
||||
protected abstract ExecutorService asyncService();
|
||||
|
||||
protected abstract EventLoop eventLoop();
|
||||
|
||||
protected FutureTaskId runEventLoop(Runnable runnable) {
|
||||
return new FutureTaskId(eventLoop().submit(runnable).addListener(errorLogger()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public FutureTaskId runAsync(Runnable runnable) {
|
||||
return new FutureTaskId(CompletableFuture.runAsync(runnable, asyncService())
|
||||
.exceptionally(throwable -> {
|
||||
if (!(throwable instanceof CancellationException)) {
|
||||
throwable.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
public FutureTaskId runSync(Runnable runnable, long ticks) {
|
||||
// ViaVersion seems to not need to run delayed tasks on main thread
|
||||
return new FutureTaskId(eventLoop()
|
||||
.schedule(() -> runSync(runnable), ticks * 50, TimeUnit.MILLISECONDS)
|
||||
.addListener(errorLogger())
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FutureTaskId runRepeatingSync(Runnable runnable, long ticks) {
|
||||
// ViaVersion seems to not need to run repeating tasks on main thread
|
||||
return new FutureTaskId(eventLoop()
|
||||
.scheduleAtFixedRate(() -> runSync(runnable), 0, ticks * 50, TimeUnit.MILLISECONDS)
|
||||
.addListener(errorLogger())
|
||||
);
|
||||
}
|
||||
|
||||
protected <T extends Future<?>> GenericFutureListener<T> errorLogger() {
|
||||
return future -> {
|
||||
if (!future.isCancelled() && future.cause() != null) {
|
||||
future.cause().printStackTrace();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isProxy() {
|
||||
// We kinda of have all server versions
|
||||
@ -110,7 +163,7 @@ public abstract class AbstractFabricPlatform implements ViaPlatform<UUID> {
|
||||
mod.getMetadata().getAuthors().stream().map(it -> {
|
||||
JsonObject info = new JsonObject();
|
||||
JsonObject contact = new JsonObject();
|
||||
it.getContact().asMap().entrySet().stream()
|
||||
it.getContact().asMap().entrySet()
|
||||
.forEach(c -> contact.addProperty(c.getKey(), c.getValue()));
|
||||
if (contact.size() != 0) {
|
||||
info.add("contact", contact);
|
||||
|
@ -0,0 +1,27 @@
|
||||
package com.viaversion.fabric.common.util;
|
||||
|
||||
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
|
||||
public class RemappingUtil {
|
||||
public static int swordId(String id) {
|
||||
// https://github.com/ViaVersion/ViaVersion/blob/8de26a0ad33f5b739f5394ed80f69d14197fddc7/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/Protocol1_9To1_8.java#L86
|
||||
switch (id) {
|
||||
case "minecraft:iron_sword":
|
||||
return 267;
|
||||
case "minecraft:wooden_sword":
|
||||
return 268;
|
||||
case "minecraft:golden_sword":
|
||||
return 272;
|
||||
case "minecraft:diamond_sword":
|
||||
return 276;
|
||||
case "minecraft:stone_sword":
|
||||
return 283;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static String legacyToJson(String legacy) {
|
||||
return GsonComponentSerializer.gson().serialize(LegacyComponentSerializer.legacySection().deserialize(legacy));
|
||||
}
|
||||
}
|
@ -1,29 +1,28 @@
|
||||
package com.viaversion.fabric.mc114;
|
||||
|
||||
import com.viaversion.fabric.common.config.VFConfig;
|
||||
import com.viaversion.fabric.common.platform.FabricInjector;
|
||||
import com.viaversion.fabric.mc114.commands.VRCommandHandler;
|
||||
import com.viaversion.fabric.mc114.platform.VFLoader;
|
||||
import com.viaversion.fabric.mc114.platform.FabricPlatform;
|
||||
import com.viaversion.fabric.common.protocol.HostnameParserProtocol;
|
||||
import com.viaversion.fabric.common.util.JLoggerToLog4j;
|
||||
import com.google.common.collect.Range;
|
||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||
import io.netty.channel.DefaultEventLoop;
|
||||
import io.netty.channel.EventLoop;
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
|
||||
import net.fabricmc.fabric.api.registry.CommandRegistry;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.server.command.CommandSource;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import com.viaversion.fabric.common.config.VFConfig;
|
||||
import com.viaversion.fabric.common.platform.FabricInjector;
|
||||
import com.viaversion.fabric.common.protocol.HostnameParserProtocol;
|
||||
import com.viaversion.fabric.common.util.JLoggerToLog4j;
|
||||
import com.viaversion.fabric.mc114.commands.VRCommandHandler;
|
||||
import com.viaversion.fabric.mc114.platform.FabricPlatform;
|
||||
import com.viaversion.fabric.mc114.platform.VFLoader;
|
||||
import com.viaversion.viaversion.ViaManagerImpl;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.data.MappingDataLoader;
|
||||
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
||||
import io.netty.channel.DefaultEventLoop;
|
||||
import io.netty.channel.EventLoop;
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.server.command.CommandSource;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
@ -35,7 +34,7 @@ public class ViaFabric implements ModInitializer {
|
||||
public static final Logger JLOGGER = new JLoggerToLog4j(LogManager.getLogger("ViaFabric"));
|
||||
public static final ExecutorService ASYNC_EXECUTOR;
|
||||
public static final EventLoop EVENT_LOOP;
|
||||
public static CompletableFuture<Void> INIT_FUTURE = new CompletableFuture<>();
|
||||
public static final CompletableFuture<Void> INIT_FUTURE = new CompletableFuture<>();
|
||||
public static VFConfig config;
|
||||
|
||||
static {
|
||||
@ -73,16 +72,7 @@ public class ViaFabric implements ModInitializer {
|
||||
|
||||
FabricLoader.getInstance().getEntrypoints("viafabric:via_api_initialized", Runnable.class).forEach(Runnable::run);
|
||||
|
||||
try {
|
||||
registerCommandsV1();
|
||||
} catch (NoClassDefFoundError ignored) {
|
||||
try {
|
||||
registerCommandsV0();
|
||||
JLOGGER.info("Using Fabric Commands V0");
|
||||
} catch (NoClassDefFoundError ignored2) {
|
||||
JLOGGER.info("Couldn't register command as Fabric Commands isn't installed");
|
||||
}
|
||||
}
|
||||
registerCommandsV1();
|
||||
|
||||
config = new VFConfig(FabricLoader.getInstance().getConfigDir().resolve("ViaFabric")
|
||||
.resolve("viafabric.yml").toFile());
|
||||
@ -91,15 +81,12 @@ public class ViaFabric implements ModInitializer {
|
||||
}
|
||||
|
||||
private void registerCommandsV1() {
|
||||
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> dispatcher.register(command("viaversion")));
|
||||
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> dispatcher.register(command("viaver")));
|
||||
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> dispatcher.register(command("vvfabric")));
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private void registerCommandsV0() {
|
||||
CommandRegistry.INSTANCE.register(false, dispatcher -> dispatcher.register(command("viaversion")));
|
||||
CommandRegistry.INSTANCE.register(false, dispatcher -> dispatcher.register(command("viaver")));
|
||||
CommandRegistry.INSTANCE.register(false, dispatcher -> dispatcher.register(command("vvfabric")));
|
||||
try {
|
||||
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> dispatcher.register(command("viaversion")));
|
||||
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> dispatcher.register(command("viaver")));
|
||||
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> dispatcher.register(command("vvfabric")));
|
||||
} catch (NoClassDefFoundError ignored) {
|
||||
JLOGGER.info("Couldn't register command as Fabric Commands V1 isn't installed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,7 @@
|
||||
package com.viaversion.fabric.mc114.commands;
|
||||
|
||||
import com.viaversion.fabric.common.util.RemappingUtil;
|
||||
import com.viaversion.viaversion.api.command.ViaCommandSender;
|
||||
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
@ -30,17 +29,13 @@ public class NMSCommandSender implements ViaCommandSender {
|
||||
@Override
|
||||
public void sendMessage(String s) {
|
||||
if (source instanceof ServerCommandSource) {
|
||||
((ServerCommandSource) source).sendFeedback(Text.Serializer.fromJson(legacyToJson(s)), false);
|
||||
((ServerCommandSource) source).sendFeedback(Text.Serializer.fromJson(RemappingUtil.legacyToJson(s)), false);
|
||||
} else if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT
|
||||
&& source instanceof ClientCommandSource) {
|
||||
MinecraftClient.getInstance().player.addChatMessage(Text.Serializer.fromJson(legacyToJson(s)), false);
|
||||
MinecraftClient.getInstance().player.addChatMessage(Text.Serializer.fromJson(RemappingUtil.legacyToJson(s)), false);
|
||||
}
|
||||
}
|
||||
|
||||
private String legacyToJson(String legacy) {
|
||||
return GsonComponentSerializer.gson().serialize(LegacyComponentSerializer.legacySection().deserialize(legacy));
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getUUID() {
|
||||
if (source instanceof ServerCommandSource) {
|
||||
|
@ -2,7 +2,6 @@ package com.viaversion.fabric.mc114.gui;
|
||||
|
||||
import com.viaversion.fabric.mc114.ViaFabric;
|
||||
import com.viaversion.fabric.common.util.ProtocolUtils;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
|
@ -3,14 +3,12 @@ package com.viaversion.fabric.mc114.platform;
|
||||
import com.viaversion.fabric.common.commands.UserCommandSender;
|
||||
import com.viaversion.fabric.common.provider.AbstractFabricPlatform;
|
||||
import com.viaversion.fabric.common.util.FutureTaskId;
|
||||
import com.viaversion.fabric.common.util.RemappingUtil;
|
||||
import com.viaversion.fabric.mc114.ViaFabric;
|
||||
import com.viaversion.fabric.mc114.commands.NMSCommandSender;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.command.ViaCommandSender;
|
||||
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import io.netty.util.concurrent.Future;
|
||||
import io.netty.util.concurrent.GenericFutureListener;
|
||||
import io.netty.channel.EventLoop;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
@ -22,9 +20,8 @@ import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CancellationException;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.logging.Level;
|
||||
|
||||
@ -41,23 +38,6 @@ public class FabricPlatform extends AbstractFabricPlatform {
|
||||
return MinecraftClient.getInstance().getServer();
|
||||
}
|
||||
|
||||
public static String legacyToJson(String legacy) {
|
||||
return GsonComponentSerializer.gson().serialize(LegacyComponentSerializer.legacySection().deserialize(legacy));
|
||||
}
|
||||
|
||||
@Override
|
||||
public FutureTaskId runAsync(Runnable runnable) {
|
||||
return new FutureTaskId(CompletableFuture
|
||||
.runAsync(runnable, ViaFabric.ASYNC_EXECUTOR)
|
||||
.exceptionally(throwable -> {
|
||||
if (!(throwable instanceof CancellationException)) {
|
||||
throwable.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FutureTaskId runSync(Runnable runnable) {
|
||||
if (getServer() != null) {
|
||||
@ -72,42 +52,6 @@ public class FabricPlatform extends AbstractFabricPlatform {
|
||||
return new FutureTaskId(CompletableFuture.runAsync(runnable, getServer()));
|
||||
}
|
||||
|
||||
private FutureTaskId runEventLoop(Runnable runnable) {
|
||||
return new FutureTaskId(
|
||||
ViaFabric.EVENT_LOOP
|
||||
.submit(runnable)
|
||||
.addListener(errorLogger())
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FutureTaskId runSync(Runnable runnable, long ticks) {
|
||||
// ViaVersion seems to not need to run delayed tasks on main thread
|
||||
return new FutureTaskId(
|
||||
ViaFabric.EVENT_LOOP
|
||||
.schedule(() -> runSync(runnable), ticks * 50, TimeUnit.MILLISECONDS)
|
||||
.addListener(errorLogger())
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FutureTaskId runRepeatingSync(Runnable runnable, long ticks) {
|
||||
// ViaVersion seems to not need to run repeating tasks on main thread
|
||||
return new FutureTaskId(
|
||||
ViaFabric.EVENT_LOOP
|
||||
.scheduleAtFixedRate(() -> runSync(runnable), 0, ticks * 50, TimeUnit.MILLISECONDS)
|
||||
.addListener(errorLogger())
|
||||
);
|
||||
}
|
||||
|
||||
private <T extends Future<?>> GenericFutureListener<T> errorLogger() {
|
||||
return future -> {
|
||||
if (!future.isCancelled() && future.cause() != null) {
|
||||
future.cause().printStackTrace();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public ViaCommandSender[] getOnlinePlayers() {
|
||||
MinecraftServer server = getServer();
|
||||
@ -137,7 +81,7 @@ public class FabricPlatform extends AbstractFabricPlatform {
|
||||
runServerSync(() -> {
|
||||
ServerPlayerEntity player = server.getPlayerManager().getPlayer(uuid);
|
||||
if (player == null) return;
|
||||
player.sendChatMessage(Text.Serializer.fromJson(legacyToJson(s)), MessageType.SYSTEM);
|
||||
player.sendChatMessage(Text.Serializer.fromJson(RemappingUtil.legacyToJson(s)), MessageType.SYSTEM);
|
||||
});
|
||||
}
|
||||
|
||||
@ -152,7 +96,7 @@ public class FabricPlatform extends AbstractFabricPlatform {
|
||||
Supplier<Boolean> kickTask = () -> {
|
||||
ServerPlayerEntity player = server.getPlayerManager().getPlayer(uuid);
|
||||
if (player == null) return false;
|
||||
player.networkHandler.disconnect(Text.Serializer.fromJson(legacyToJson(s)));
|
||||
player.networkHandler.disconnect(Text.Serializer.fromJson(RemappingUtil.legacyToJson(s)));
|
||||
return true;
|
||||
};
|
||||
if (server.isOnThread()) {
|
||||
@ -163,4 +107,14 @@ public class FabricPlatform extends AbstractFabricPlatform {
|
||||
}
|
||||
return false; // Can't know if it worked
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ExecutorService asyncService() {
|
||||
return ViaFabric.ASYNC_EXECUTOR;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EventLoop eventLoop() {
|
||||
return ViaFabric.EVENT_LOOP;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.viaversion.fabric.mc114.providers;
|
||||
|
||||
import com.viaversion.fabric.common.util.RemappingUtil;
|
||||
import com.viaversion.fabric.mc114.ViaFabric;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
@ -21,7 +22,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class VRHandItemProvider extends HandItemProvider {
|
||||
public Item clientItem = null;
|
||||
public Map<UUID, Item> serverPlayers = new ConcurrentHashMap<>();
|
||||
public final Map<UUID, Item> serverPlayers = new ConcurrentHashMap<>();
|
||||
|
||||
@Override
|
||||
public Item getHandItem(UserConnection info) {
|
||||
@ -50,7 +51,7 @@ public class VRHandItemProvider extends HandItemProvider {
|
||||
}
|
||||
});
|
||||
} catch (NoClassDefFoundError ignored2) {
|
||||
ViaFabric.JLOGGER.info("Fabric Lifecycle V0/V1 isn't installed");
|
||||
ViaFabric.JLOGGER.info("Fabric Lifecycle V0 isn't installed");
|
||||
}
|
||||
}
|
||||
|
||||
@ -77,25 +78,7 @@ public class VRHandItemProvider extends HandItemProvider {
|
||||
|
||||
private Item fromNative(ItemStack original) {
|
||||
Identifier iid = Registry.ITEM.getId(original.getItem());
|
||||
if (iid == null) return new DataItem(0, (byte) 0, (short) 0, null);
|
||||
int id = swordId(iid.toString());
|
||||
int id = RemappingUtil.swordId(iid.toString());
|
||||
return new DataItem(id, (byte) original.getCount(), (short) original.getDamage(), null);
|
||||
}
|
||||
|
||||
private int swordId(String id) {
|
||||
// https://github.com/ViaVersion/ViaVersion/blob/8de26a0ad33f5b739f5394ed80f69d14197fddc7/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/Protocol1_9To1_8.java#L86
|
||||
switch (id) {
|
||||
case "minecraft:iron_sword":
|
||||
return 267;
|
||||
case "minecraft:wooden_sword":
|
||||
return 268;
|
||||
case "minecraft:golden_sword":
|
||||
return 272;
|
||||
case "minecraft:diamond_sword":
|
||||
return 276;
|
||||
case "minecraft:stone_sword":
|
||||
return 283;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ import java.util.logging.Level;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class ProtocolAutoDetector {
|
||||
private static LoadingCache<InetSocketAddress, CompletableFuture<ProtocolVersion>> SERVER_VER = CacheBuilder.newBuilder()
|
||||
private static final LoadingCache<InetSocketAddress, CompletableFuture<ProtocolVersion>> SERVER_VER = CacheBuilder.newBuilder()
|
||||
.expireAfterWrite(30, TimeUnit.SECONDS)
|
||||
.build(CacheLoader.from((address) -> {
|
||||
CompletableFuture<ProtocolVersion> future = new CompletableFuture<>();
|
||||
|
@ -10,8 +10,8 @@ import com.viaversion.fabric.common.platform.FabricInjector;
|
||||
import com.viaversion.fabric.common.protocol.HostnameParserProtocol;
|
||||
import com.viaversion.fabric.common.util.JLoggerToLog4j;
|
||||
import com.viaversion.fabric.mc115.commands.VRCommandHandler;
|
||||
import com.viaversion.fabric.mc115.platform.VFLoader;
|
||||
import com.viaversion.fabric.mc115.platform.FabricPlatform;
|
||||
import com.viaversion.fabric.mc115.platform.VFLoader;
|
||||
import com.viaversion.viaversion.ViaManagerImpl;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.data.MappingDataLoader;
|
||||
@ -20,7 +20,6 @@ import io.netty.channel.DefaultEventLoop;
|
||||
import io.netty.channel.EventLoop;
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
|
||||
import net.fabricmc.fabric.api.registry.CommandRegistry;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.server.command.CommandSource;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
@ -35,7 +34,7 @@ public class ViaFabric implements ModInitializer {
|
||||
public static final Logger JLOGGER = new JLoggerToLog4j(LogManager.getLogger("ViaFabric"));
|
||||
public static final ExecutorService ASYNC_EXECUTOR;
|
||||
public static final EventLoop EVENT_LOOP;
|
||||
public static CompletableFuture<Void> INIT_FUTURE = new CompletableFuture<>();
|
||||
public static final CompletableFuture<Void> INIT_FUTURE = new CompletableFuture<>();
|
||||
public static VFConfig config;
|
||||
|
||||
static {
|
||||
@ -73,16 +72,7 @@ public class ViaFabric implements ModInitializer {
|
||||
|
||||
FabricLoader.getInstance().getEntrypoints("viafabric:via_api_initialized", Runnable.class).forEach(Runnable::run);
|
||||
|
||||
try {
|
||||
registerCommandsV1();
|
||||
} catch (NoClassDefFoundError ignored) {
|
||||
try {
|
||||
registerCommandsV0();
|
||||
JLOGGER.info("Using Fabric Commands V0");
|
||||
} catch (NoClassDefFoundError ignored2) {
|
||||
JLOGGER.info("Couldn't register command as Fabric Commands isn't installed");
|
||||
}
|
||||
}
|
||||
registerCommandsV1();
|
||||
|
||||
config = new VFConfig(FabricLoader.getInstance().getConfigDir().resolve("ViaFabric")
|
||||
.resolve("viafabric.yml").toFile());
|
||||
@ -91,15 +81,12 @@ public class ViaFabric implements ModInitializer {
|
||||
}
|
||||
|
||||
private void registerCommandsV1() {
|
||||
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> dispatcher.register(command("viaversion")));
|
||||
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> dispatcher.register(command("viaver")));
|
||||
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> dispatcher.register(command("vvfabric")));
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private void registerCommandsV0() {
|
||||
CommandRegistry.INSTANCE.register(false, dispatcher -> dispatcher.register(command("viaversion")));
|
||||
CommandRegistry.INSTANCE.register(false, dispatcher -> dispatcher.register(command("viaver")));
|
||||
CommandRegistry.INSTANCE.register(false, dispatcher -> dispatcher.register(command("vvfabric")));
|
||||
try {
|
||||
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> dispatcher.register(command("viaversion")));
|
||||
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> dispatcher.register(command("viaver")));
|
||||
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> dispatcher.register(command("vvfabric")));
|
||||
} catch (NoClassDefFoundError ignored) {
|
||||
JLOGGER.info("Couldn't register command as Fabric Commands V1 isn't installed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,7 @@
|
||||
package com.viaversion.fabric.mc115.commands;
|
||||
|
||||
import com.viaversion.fabric.common.util.RemappingUtil;
|
||||
import com.viaversion.viaversion.api.command.ViaCommandSender;
|
||||
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
@ -30,16 +29,12 @@ public class NMSCommandSender implements ViaCommandSender {
|
||||
@Override
|
||||
public void sendMessage(String s) {
|
||||
if (source instanceof ServerCommandSource) {
|
||||
((ServerCommandSource) source).sendFeedback(Text.Serializer.fromJson(legacyToJson(s)), false);
|
||||
((ServerCommandSource) source).sendFeedback(Text.Serializer.fromJson(RemappingUtil.legacyToJson(s)), false);
|
||||
} else if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT && source instanceof ClientCommandSource) {
|
||||
MinecraftClient.getInstance().player.addChatMessage(Text.Serializer.fromJson(legacyToJson(s)), false);
|
||||
MinecraftClient.getInstance().player.addChatMessage(Text.Serializer.fromJson(RemappingUtil.legacyToJson(s)), false);
|
||||
}
|
||||
}
|
||||
|
||||
private String legacyToJson(String legacy) {
|
||||
return GsonComponentSerializer.gson().serialize(LegacyComponentSerializer.legacySection().deserialize(legacy));
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getUUID() {
|
||||
if (source instanceof ServerCommandSource) {
|
||||
|
@ -2,7 +2,6 @@ package com.viaversion.fabric.mc115.gui;
|
||||
|
||||
import com.viaversion.fabric.mc115.ViaFabric;
|
||||
import com.viaversion.fabric.common.util.ProtocolUtils;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
|
@ -1,52 +1,29 @@
|
||||
package com.viaversion.fabric.mc115.platform;
|
||||
|
||||
import com.viaversion.fabric.common.commands.UserCommandSender;
|
||||
import com.viaversion.fabric.common.platform.FabricViaAPI;
|
||||
import com.viaversion.fabric.common.platform.FabricViaConfig;
|
||||
import com.viaversion.fabric.common.provider.AbstractFabricPlatform;
|
||||
import com.viaversion.fabric.common.util.FutureTaskId;
|
||||
import com.viaversion.fabric.common.util.JLoggerToLog4j;
|
||||
import com.viaversion.fabric.common.util.RemappingUtil;
|
||||
import com.viaversion.fabric.mc115.ViaFabric;
|
||||
import com.viaversion.fabric.mc115.commands.NMSCommandSender;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.ViaAPI;
|
||||
import com.viaversion.viaversion.api.command.ViaCommandSender;
|
||||
import com.viaversion.viaversion.api.configuration.ConfigurationProvider;
|
||||
import com.viaversion.viaversion.api.configuration.ViaVersionConfig;
|
||||
import com.viaversion.viaversion.api.platform.ViaPlatform;
|
||||
import com.viaversion.viaversion.dump.PluginInfo;
|
||||
import com.viaversion.viaversion.libs.gson.JsonObject;
|
||||
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import com.viaversion.viaversion.util.GsonUtil;
|
||||
import io.netty.util.concurrent.Future;
|
||||
import io.netty.util.concurrent.GenericFutureListener;
|
||||
import io.netty.channel.EventLoop;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.fabricmc.loader.api.ModContainer;
|
||||
import net.fabricmc.loader.api.Version;
|
||||
import net.fabricmc.loader.api.metadata.ModMetadata;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.network.MessageType;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.Text;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CancellationException;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class FabricPlatform extends AbstractFabricPlatform {
|
||||
public static MinecraftServer getServer() {
|
||||
@ -61,21 +38,14 @@ public class FabricPlatform extends AbstractFabricPlatform {
|
||||
return MinecraftClient.getInstance().getServer();
|
||||
}
|
||||
|
||||
public static String legacyToJson(String legacy) {
|
||||
return GsonComponentSerializer.gson().serialize(LegacyComponentSerializer.legacySection().deserialize(legacy));
|
||||
@Override
|
||||
protected ExecutorService asyncService() {
|
||||
return ViaFabric.ASYNC_EXECUTOR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FutureTaskId runAsync(Runnable runnable) {
|
||||
return new FutureTaskId(CompletableFuture
|
||||
.runAsync(runnable, ViaFabric.ASYNC_EXECUTOR)
|
||||
.exceptionally(throwable -> {
|
||||
if (!(throwable instanceof CancellationException)) {
|
||||
throwable.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
})
|
||||
);
|
||||
protected EventLoop eventLoop() {
|
||||
return ViaFabric.EVENT_LOOP;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -92,42 +62,6 @@ public class FabricPlatform extends AbstractFabricPlatform {
|
||||
return new FutureTaskId(CompletableFuture.runAsync(runnable, getServer()));
|
||||
}
|
||||
|
||||
private FutureTaskId runEventLoop(Runnable runnable) {
|
||||
return new FutureTaskId(
|
||||
ViaFabric.EVENT_LOOP
|
||||
.submit(runnable)
|
||||
.addListener(errorLogger())
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FutureTaskId runSync(Runnable runnable, long ticks) {
|
||||
// ViaVersion seems to not need to run delayed tasks on main thread
|
||||
return new FutureTaskId(
|
||||
ViaFabric.EVENT_LOOP
|
||||
.schedule(() -> runSync(runnable), ticks * 50, TimeUnit.MILLISECONDS)
|
||||
.addListener(errorLogger())
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FutureTaskId runRepeatingSync(Runnable runnable, long ticks) {
|
||||
// ViaVersion seems to not need to run repeating tasks on main thread
|
||||
return new FutureTaskId(
|
||||
ViaFabric.EVENT_LOOP
|
||||
.scheduleAtFixedRate(() -> runSync(runnable), 0, ticks * 50, TimeUnit.MILLISECONDS)
|
||||
.addListener(errorLogger())
|
||||
);
|
||||
}
|
||||
|
||||
private <T extends Future<?>> GenericFutureListener<T> errorLogger() {
|
||||
return future -> {
|
||||
if (!future.isCancelled() && future.cause() != null) {
|
||||
future.cause().printStackTrace();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public ViaCommandSender[] getOnlinePlayers() {
|
||||
MinecraftServer server = getServer();
|
||||
@ -157,7 +91,7 @@ public class FabricPlatform extends AbstractFabricPlatform {
|
||||
runServerSync(() -> {
|
||||
ServerPlayerEntity player = server.getPlayerManager().getPlayer(uuid);
|
||||
if (player == null) return;
|
||||
player.sendChatMessage(Text.Serializer.fromJson(legacyToJson(s)), MessageType.SYSTEM);
|
||||
player.sendChatMessage(Text.Serializer.fromJson(RemappingUtil.legacyToJson(s)), MessageType.SYSTEM);
|
||||
});
|
||||
}
|
||||
|
||||
@ -172,7 +106,7 @@ public class FabricPlatform extends AbstractFabricPlatform {
|
||||
Supplier<Boolean> kickTask = () -> {
|
||||
ServerPlayerEntity player = server.getPlayerManager().getPlayer(uuid);
|
||||
if (player == null) return false;
|
||||
player.networkHandler.disconnect(Text.Serializer.fromJson(legacyToJson(s)));
|
||||
player.networkHandler.disconnect(Text.Serializer.fromJson(RemappingUtil.legacyToJson(s)));
|
||||
return true;
|
||||
};
|
||||
if (server.isOnThread()) {
|
||||
|
@ -1,21 +1,21 @@
|
||||
package com.viaversion.fabric.mc115.providers;
|
||||
|
||||
import com.viaversion.fabric.common.util.RemappingUtil;
|
||||
import com.viaversion.fabric.mc115.ViaFabric;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
|
||||
import net.fabricmc.fabric.api.event.world.WorldTickCallback;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.network.ClientPlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.world.World;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.item.DataItem;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.HandItemProvider;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.network.ClientPlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
@ -23,7 +23,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class VRHandItemProvider extends HandItemProvider {
|
||||
public Item clientItem = null;
|
||||
public Map<UUID, Item> serverPlayers = new ConcurrentHashMap<>();
|
||||
public final Map<UUID, Item> serverPlayers = new ConcurrentHashMap<>();
|
||||
|
||||
@Override
|
||||
public Item getHandItem(UserConnection info) {
|
||||
@ -48,15 +48,7 @@ public class VRHandItemProvider extends HandItemProvider {
|
||||
try {
|
||||
ClientTickEvents.END_WORLD_TICK.register(clientWorld -> tickClient());
|
||||
} catch (NoClassDefFoundError ignored) {
|
||||
try {
|
||||
WorldTickCallback.EVENT.register(world -> {
|
||||
if (world.isClient) {
|
||||
tickClient();
|
||||
}
|
||||
});
|
||||
} catch (NoClassDefFoundError ignored2) {
|
||||
ViaFabric.JLOGGER.info("Fabric Lifecycle V0/V1 isn't installed");
|
||||
}
|
||||
ViaFabric.JLOGGER.info("Fabric Lifecycle V1 isn't installed");
|
||||
}
|
||||
}
|
||||
|
||||
@ -64,11 +56,6 @@ public class VRHandItemProvider extends HandItemProvider {
|
||||
try {
|
||||
ServerTickEvents.END_WORLD_TICK.register(this::tickServer);
|
||||
} catch (NoClassDefFoundError ignored) {
|
||||
WorldTickCallback.EVENT.register(world -> {
|
||||
if (!world.isClient) {
|
||||
tickServer(world);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -87,25 +74,7 @@ public class VRHandItemProvider extends HandItemProvider {
|
||||
|
||||
private Item fromNative(ItemStack original) {
|
||||
Identifier iid = Registry.ITEM.getId(original.getItem());
|
||||
if (iid == null) return new DataItem(0, (byte) 0, (short) 0, null);
|
||||
int id = swordId(iid.toString());
|
||||
int id = RemappingUtil.swordId(iid.toString());
|
||||
return new DataItem(id, (byte) original.getCount(), (short) original.getDamage(), null);
|
||||
}
|
||||
|
||||
private int swordId(String id) {
|
||||
// https://github.com/ViaVersion/ViaVersion/blob/8de26a0ad33f5b739f5394ed80f69d14197fddc7/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/Protocol1_9To1_8.java#L86
|
||||
switch (id) {
|
||||
case "minecraft:iron_sword":
|
||||
return 267;
|
||||
case "minecraft:wooden_sword":
|
||||
return 268;
|
||||
case "minecraft:golden_sword":
|
||||
return 272;
|
||||
case "minecraft:diamond_sword":
|
||||
return 276;
|
||||
case "minecraft:stone_sword":
|
||||
return 283;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ import java.util.logging.Level;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class ProtocolAutoDetector {
|
||||
private static LoadingCache<InetSocketAddress, CompletableFuture<ProtocolVersion>> SERVER_VER = CacheBuilder.newBuilder()
|
||||
private static final LoadingCache<InetSocketAddress, CompletableFuture<ProtocolVersion>> SERVER_VER = CacheBuilder.newBuilder()
|
||||
.expireAfterWrite(30, TimeUnit.SECONDS)
|
||||
.build(CacheLoader.from((address) -> {
|
||||
CompletableFuture<ProtocolVersion> future = new CompletableFuture<>();
|
||||
|
@ -1,17 +1,21 @@
|
||||
package com.viaversion.fabric.mc116;
|
||||
|
||||
import com.viaversion.fabric.common.config.VFConfig;
|
||||
import com.viaversion.fabric.common.platform.FabricInjector;
|
||||
import com.viaversion.fabric.mc116.commands.VRCommandHandler;
|
||||
import com.viaversion.fabric.mc116.platform.VFLoader;
|
||||
import com.viaversion.fabric.mc116.platform.FabricPlatform;
|
||||
import com.viaversion.fabric.common.protocol.HostnameParserProtocol;
|
||||
import com.viaversion.fabric.common.util.JLoggerToLog4j;
|
||||
import com.google.common.collect.Range;
|
||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||
import com.viaversion.fabric.common.config.VFConfig;
|
||||
import com.viaversion.fabric.common.platform.FabricInjector;
|
||||
import com.viaversion.fabric.common.protocol.HostnameParserProtocol;
|
||||
import com.viaversion.fabric.common.util.JLoggerToLog4j;
|
||||
import com.viaversion.fabric.mc116.commands.VRCommandHandler;
|
||||
import com.viaversion.fabric.mc116.platform.FabricPlatform;
|
||||
import com.viaversion.fabric.mc116.platform.VFLoader;
|
||||
import com.viaversion.viaversion.ViaManagerImpl;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.data.MappingDataLoader;
|
||||
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
||||
import io.netty.channel.DefaultEventLoop;
|
||||
import io.netty.channel.EventLoop;
|
||||
import net.fabricmc.api.EnvType;
|
||||
@ -21,10 +25,6 @@ import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.command.CommandSource;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import com.viaversion.viaversion.ViaManagerImpl;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.data.MappingDataLoader;
|
||||
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
@ -36,7 +36,7 @@ public class ViaFabric implements ModInitializer {
|
||||
public static final Logger JLOGGER = new JLoggerToLog4j(LogManager.getLogger("ViaFabric"));
|
||||
public static final ExecutorService ASYNC_EXECUTOR;
|
||||
public static final EventLoop EVENT_LOOP;
|
||||
public static CompletableFuture<Void> INIT_FUTURE = new CompletableFuture<>();
|
||||
public static final CompletableFuture<Void> INIT_FUTURE = new CompletableFuture<>();
|
||||
public static VFConfig config;
|
||||
|
||||
static {
|
||||
@ -74,11 +74,7 @@ public class ViaFabric implements ModInitializer {
|
||||
|
||||
FabricLoader.getInstance().getEntrypoints("viafabric:via_api_initialized", Runnable.class).forEach(Runnable::run);
|
||||
|
||||
try {
|
||||
registerCommandsV1();
|
||||
} catch (NoClassDefFoundError ignored) {
|
||||
JLOGGER.info("Couldn't register command as Fabric Commands isn't installed");
|
||||
}
|
||||
registerCommandsV1();
|
||||
|
||||
config = new VFConfig(FabricLoader.getInstance().getConfigDir().resolve("ViaFabric")
|
||||
.resolve("viafabric.yml").toFile());
|
||||
@ -87,11 +83,15 @@ public class ViaFabric implements ModInitializer {
|
||||
}
|
||||
|
||||
private void registerCommandsV1() {
|
||||
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> dispatcher.register(command("viaversion")));
|
||||
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> dispatcher.register(command("viaver")));
|
||||
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> dispatcher.register(command("vvfabric")));
|
||||
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
|
||||
ClientCommandManager.DISPATCHER.register(command("viafabricclient"));
|
||||
try {
|
||||
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> dispatcher.register(command("viaversion")));
|
||||
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> dispatcher.register(command("viaver")));
|
||||
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> dispatcher.register(command("vvfabric")));
|
||||
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
|
||||
ClientCommandManager.DISPATCHER.register(command("viafabricclient"));
|
||||
}
|
||||
} catch (NoClassDefFoundError ignored) {
|
||||
JLOGGER.info("Couldn't register command as Fabric Commands V1 isn't installed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,12 @@
|
||||
package com.viaversion.fabric.mc116.commands;
|
||||
|
||||
import com.viaversion.fabric.mc116.platform.FabricPlatform;
|
||||
import com.viaversion.fabric.common.util.RemappingUtil;
|
||||
import com.viaversion.viaversion.api.command.ViaCommandSender;
|
||||
import net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource;
|
||||
import net.minecraft.command.CommandSource;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.text.Text;
|
||||
import com.viaversion.viaversion.api.command.ViaCommandSender;
|
||||
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@ -28,16 +26,12 @@ public class NMSCommandSender implements ViaCommandSender {
|
||||
@Override
|
||||
public void sendMessage(String s) {
|
||||
if (source instanceof ServerCommandSource) {
|
||||
((ServerCommandSource) source).sendFeedback(Text.Serializer.fromJson(FabricPlatform.legacyToJson(s)), false);
|
||||
((ServerCommandSource) source).sendFeedback(Text.Serializer.fromJson(RemappingUtil.legacyToJson(s)), false);
|
||||
} else if (source instanceof FabricClientCommandSource) {
|
||||
((FabricClientCommandSource) source).sendFeedback(Text.Serializer.fromJson(FabricPlatform.legacyToJson(s)));
|
||||
((FabricClientCommandSource) source).sendFeedback(Text.Serializer.fromJson(RemappingUtil.legacyToJson(s)));
|
||||
}
|
||||
}
|
||||
|
||||
private String legacyToJson(String legacy) {
|
||||
return GsonComponentSerializer.gson().serialize(LegacyComponentSerializer.legacySection().deserialize(legacy));
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getUUID() {
|
||||
if (source instanceof ServerCommandSource) {
|
||||
|
@ -2,7 +2,6 @@ package com.viaversion.fabric.mc116.gui;
|
||||
|
||||
import com.viaversion.fabric.mc116.ViaFabric;
|
||||
import com.viaversion.fabric.common.util.ProtocolUtils;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
|
@ -3,14 +3,12 @@ package com.viaversion.fabric.mc116.platform;
|
||||
import com.viaversion.fabric.common.commands.UserCommandSender;
|
||||
import com.viaversion.fabric.common.provider.AbstractFabricPlatform;
|
||||
import com.viaversion.fabric.common.util.FutureTaskId;
|
||||
import com.viaversion.fabric.common.util.RemappingUtil;
|
||||
import com.viaversion.fabric.mc116.ViaFabric;
|
||||
import com.viaversion.fabric.mc116.commands.NMSCommandSender;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.command.ViaCommandSender;
|
||||
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import io.netty.util.concurrent.Future;
|
||||
import io.netty.util.concurrent.GenericFutureListener;
|
||||
import io.netty.channel.EventLoop;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
@ -21,9 +19,8 @@ import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CancellationException;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.logging.Level;
|
||||
|
||||
@ -40,21 +37,14 @@ public class FabricPlatform extends AbstractFabricPlatform {
|
||||
return MinecraftClient.getInstance().getServer();
|
||||
}
|
||||
|
||||
public static String legacyToJson(String legacy) {
|
||||
return GsonComponentSerializer.gson().serialize(LegacyComponentSerializer.legacySection().deserialize(legacy));
|
||||
@Override
|
||||
protected ExecutorService asyncService() {
|
||||
return ViaFabric.ASYNC_EXECUTOR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FutureTaskId runAsync(Runnable runnable) {
|
||||
return new FutureTaskId(CompletableFuture
|
||||
.runAsync(runnable, ViaFabric.ASYNC_EXECUTOR)
|
||||
.exceptionally(throwable -> {
|
||||
if (!(throwable instanceof CancellationException)) {
|
||||
throwable.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
})
|
||||
);
|
||||
protected EventLoop eventLoop() {
|
||||
return ViaFabric.EVENT_LOOP;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -71,42 +61,6 @@ public class FabricPlatform extends AbstractFabricPlatform {
|
||||
return new FutureTaskId(CompletableFuture.runAsync(runnable, getServer()));
|
||||
}
|
||||
|
||||
private FutureTaskId runEventLoop(Runnable runnable) {
|
||||
return new FutureTaskId(
|
||||
ViaFabric.EVENT_LOOP
|
||||
.submit(runnable)
|
||||
.addListener(errorLogger())
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FutureTaskId runSync(Runnable runnable, long ticks) {
|
||||
// ViaVersion seems to not need to run delayed tasks on main thread
|
||||
return new FutureTaskId(
|
||||
ViaFabric.EVENT_LOOP
|
||||
.schedule(() -> runSync(runnable), ticks * 50, TimeUnit.MILLISECONDS)
|
||||
.addListener(errorLogger())
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FutureTaskId runRepeatingSync(Runnable runnable, long ticks) {
|
||||
// ViaVersion seems to not need to run repeating tasks on main thread
|
||||
return new FutureTaskId(
|
||||
ViaFabric.EVENT_LOOP
|
||||
.scheduleAtFixedRate(() -> runSync(runnable), 0, ticks * 50, TimeUnit.MILLISECONDS)
|
||||
.addListener(errorLogger())
|
||||
);
|
||||
}
|
||||
|
||||
private <T extends Future<?>> GenericFutureListener<T> errorLogger() {
|
||||
return future -> {
|
||||
if (!future.isCancelled() && future.cause() != null) {
|
||||
future.cause().printStackTrace();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public ViaCommandSender[] getOnlinePlayers() {
|
||||
MinecraftServer server = getServer();
|
||||
@ -137,7 +91,7 @@ public class FabricPlatform extends AbstractFabricPlatform {
|
||||
ServerPlayerEntity player = server.getPlayerManager().getPlayer(uuid);
|
||||
if (player == null) return;
|
||||
player.sendMessage(Text.Serializer.fromJson(
|
||||
legacyToJson(s)
|
||||
RemappingUtil.legacyToJson(s)
|
||||
), false);
|
||||
});
|
||||
}
|
||||
@ -153,7 +107,7 @@ public class FabricPlatform extends AbstractFabricPlatform {
|
||||
Supplier<Boolean> kickTask = () -> {
|
||||
ServerPlayerEntity player = server.getPlayerManager().getPlayer(uuid);
|
||||
if (player == null) return false;
|
||||
player.networkHandler.disconnect(Text.Serializer.fromJson(legacyToJson(s)));
|
||||
player.networkHandler.disconnect(Text.Serializer.fromJson(RemappingUtil.legacyToJson(s)));
|
||||
return true;
|
||||
};
|
||||
if (server.isOnThread()) {
|
||||
|
@ -1,21 +1,21 @@
|
||||
package com.viaversion.fabric.mc116.providers;
|
||||
|
||||
import com.viaversion.fabric.common.util.RemappingUtil;
|
||||
import com.viaversion.fabric.mc116.ViaFabric;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
|
||||
import net.fabricmc.fabric.api.event.world.WorldTickCallback;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.network.ClientPlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.world.World;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.item.DataItem;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.HandItemProvider;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.network.ClientPlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
@ -23,7 +23,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class VRHandItemProvider extends HandItemProvider {
|
||||
public Item clientItem = null;
|
||||
public Map<UUID, Item> serverPlayers = new ConcurrentHashMap<>();
|
||||
public final Map<UUID, Item> serverPlayers = new ConcurrentHashMap<>();
|
||||
|
||||
@Override
|
||||
public Item getHandItem(UserConnection info) {
|
||||
@ -48,15 +48,7 @@ public class VRHandItemProvider extends HandItemProvider {
|
||||
try {
|
||||
ClientTickEvents.END_WORLD_TICK.register(clientWorld -> tickClient());
|
||||
} catch (NoClassDefFoundError ignored) {
|
||||
try {
|
||||
WorldTickCallback.EVENT.register(world -> {
|
||||
if (world.isClient) {
|
||||
tickClient();
|
||||
}
|
||||
});
|
||||
} catch (NoClassDefFoundError ignored2) {
|
||||
ViaFabric.JLOGGER.info("Fabric Lifecycle V0/V1 isn't installed");
|
||||
}
|
||||
ViaFabric.JLOGGER.info("Fabric Lifecycle V1 isn't installed");
|
||||
}
|
||||
}
|
||||
|
||||
@ -64,11 +56,6 @@ public class VRHandItemProvider extends HandItemProvider {
|
||||
try {
|
||||
ServerTickEvents.END_WORLD_TICK.register(this::tickServer);
|
||||
} catch (NoClassDefFoundError ignored) {
|
||||
WorldTickCallback.EVENT.register(world -> {
|
||||
if (!world.isClient) {
|
||||
tickServer(world);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -87,25 +74,7 @@ public class VRHandItemProvider extends HandItemProvider {
|
||||
|
||||
private Item fromNative(ItemStack original) {
|
||||
Identifier iid = Registry.ITEM.getId(original.getItem());
|
||||
if (iid == null) return new DataItem(0, (byte) 0, (short) 0, null);
|
||||
int id = swordId(iid.toString());
|
||||
int id = RemappingUtil.swordId(iid.toString());
|
||||
return new DataItem(id, (byte) original.getCount(), (short) original.getDamage(), null);
|
||||
}
|
||||
|
||||
private int swordId(String id) {
|
||||
// https://github.com/ViaVersion/ViaVersion/blob/8de26a0ad33f5b739f5394ed80f69d14197fddc7/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/Protocol1_9To1_8.java#L86
|
||||
switch (id) {
|
||||
case "minecraft:iron_sword":
|
||||
return 267;
|
||||
case "minecraft:wooden_sword":
|
||||
return 268;
|
||||
case "minecraft:golden_sword":
|
||||
return 272;
|
||||
case "minecraft:diamond_sword":
|
||||
return 276;
|
||||
case "minecraft:stone_sword":
|
||||
return 283;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ import java.util.logging.Level;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class ProtocolAutoDetector {
|
||||
private static LoadingCache<InetSocketAddress, CompletableFuture<ProtocolVersion>> SERVER_VER = CacheBuilder.newBuilder()
|
||||
private static final LoadingCache<InetSocketAddress, CompletableFuture<ProtocolVersion>> SERVER_VER = CacheBuilder.newBuilder()
|
||||
.expireAfterWrite(30, TimeUnit.SECONDS)
|
||||
.build(CacheLoader.from((address) -> {
|
||||
CompletableFuture<ProtocolVersion> future = new CompletableFuture<>();
|
||||
|
@ -10,8 +10,6 @@ import com.viaversion.fabric.common.platform.FabricInjector;
|
||||
import com.viaversion.fabric.common.protocol.HostnameParserProtocol;
|
||||
import com.viaversion.fabric.common.util.JLoggerToLog4j;
|
||||
import com.viaversion.fabric.mc117.commands.VRCommandHandler;
|
||||
import com.viaversion.fabric.mc117.gui.ViaConfigScreen;
|
||||
import com.viaversion.fabric.mc117.mixin.gui.client.ScreenAccessor;
|
||||
import com.viaversion.fabric.mc117.platform.FabricPlatform;
|
||||
import com.viaversion.fabric.mc117.platform.VFLoader;
|
||||
import com.viaversion.viaversion.ViaManagerImpl;
|
||||
@ -23,16 +21,9 @@ import io.netty.channel.EventLoop;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.fabricmc.fabric.api.client.command.v1.ClientCommandManager;
|
||||
import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents;
|
||||
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.screen.multiplayer.MultiplayerScreen;
|
||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||
import net.minecraft.client.gui.widget.TexturedButtonWidget;
|
||||
import net.minecraft.command.CommandSource;
|
||||
import net.minecraft.text.TranslatableText;
|
||||
import net.minecraft.util.Identifier;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
@ -45,7 +36,7 @@ public class ViaFabric implements ModInitializer {
|
||||
public static final Logger JLOGGER = new JLoggerToLog4j(LogManager.getLogger("ViaFabric"));
|
||||
public static final ExecutorService ASYNC_EXECUTOR;
|
||||
public static final EventLoop EVENT_LOOP;
|
||||
public static CompletableFuture<Void> INIT_FUTURE = new CompletableFuture<>();
|
||||
public static final CompletableFuture<Void> INIT_FUTURE = new CompletableFuture<>();
|
||||
public static VFConfig config;
|
||||
|
||||
static {
|
||||
@ -84,7 +75,6 @@ public class ViaFabric implements ModInitializer {
|
||||
FabricLoader.getInstance().getEntrypoints("viafabric:via_api_initialized", Runnable.class).forEach(Runnable::run);
|
||||
|
||||
registerCommandsV1();
|
||||
registerGui();
|
||||
|
||||
config = new VFConfig(FabricLoader.getInstance().getConfigDir().resolve("ViaFabric")
|
||||
.resolve("viafabric.yml").toFile());
|
||||
@ -92,27 +82,6 @@ public class ViaFabric implements ModInitializer {
|
||||
INIT_FUTURE.complete(null);
|
||||
}
|
||||
|
||||
private void registerGui() {
|
||||
if (FabricLoader.getInstance().getEnvironmentType() != EnvType.CLIENT) return;
|
||||
try {
|
||||
ScreenEvents.AFTER_INIT.register((client, screen, scaledWidth, scaledHeight) -> {
|
||||
if (!(screen instanceof MultiplayerScreen)) return;
|
||||
ButtonWidget enableClientSideViaVersion = new TexturedButtonWidget(scaledWidth / 2 + 113, 10,
|
||||
40, 20, // Size
|
||||
0, 0, // Start pos of texture
|
||||
20, // v Hover offset
|
||||
new Identifier("viafabric:textures/gui/widgets.png"),
|
||||
256, 256, // Texture size
|
||||
it -> MinecraftClient.getInstance().setScreen(new ViaConfigScreen(screen)),
|
||||
new TranslatableText("gui.via_button"));
|
||||
if (ViaFabric.config.isHideButton()) enableClientSideViaVersion.visible = false;
|
||||
((ScreenAccessor) screen).callAddDrawableChild(enableClientSideViaVersion);
|
||||
});
|
||||
} catch (NoClassDefFoundError ignored) {
|
||||
JLOGGER.info("Couldn't register screen handler as Fabric Screen isn't installed");
|
||||
}
|
||||
}
|
||||
|
||||
private void registerCommandsV1() {
|
||||
try {
|
||||
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> dispatcher.register(command("viaversion")));
|
||||
@ -122,7 +91,7 @@ public class ViaFabric implements ModInitializer {
|
||||
ClientCommandManager.DISPATCHER.register(command("viafabricclient"));
|
||||
}
|
||||
} catch (NoClassDefFoundError ignored) {
|
||||
JLOGGER.info("Couldn't register command as Fabric Commands isn't installed");
|
||||
JLOGGER.info("Couldn't register command as Fabric Commands V1 isn't installed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,39 @@
|
||||
package com.viaversion.fabric.mc117;
|
||||
|
||||
import com.viaversion.fabric.mc117.gui.ViaConfigScreen;
|
||||
import com.viaversion.fabric.mc117.mixin.gui.client.ScreenAccessor;
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.screen.multiplayer.MultiplayerScreen;
|
||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||
import net.minecraft.client.gui.widget.TexturedButtonWidget;
|
||||
import net.minecraft.text.TranslatableText;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
public class ViaFabricClient implements ClientModInitializer {
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
registerGui();
|
||||
}
|
||||
|
||||
private void registerGui() {
|
||||
try {
|
||||
ScreenEvents.AFTER_INIT.register((client, screen, scaledWidth, scaledHeight) -> {
|
||||
if (!(screen instanceof MultiplayerScreen)) return;
|
||||
ButtonWidget enableClientSideViaVersion = new TexturedButtonWidget(scaledWidth / 2 + 113, 10,
|
||||
40, 20, // Size
|
||||
0, 0, // Start pos of texture
|
||||
20, // v Hover offset
|
||||
new Identifier("viafabric:textures/gui/widgets.png"),
|
||||
256, 256, // Texture size
|
||||
it -> MinecraftClient.getInstance().setScreen(new ViaConfigScreen(screen)),
|
||||
new TranslatableText("gui.via_button"));
|
||||
if (ViaFabric.config.isHideButton()) enableClientSideViaVersion.visible = false;
|
||||
((ScreenAccessor) screen).callAddDrawableChild(enableClientSideViaVersion);
|
||||
});
|
||||
} catch (NoClassDefFoundError ignored) {
|
||||
ViaFabric.JLOGGER.info("Couldn't register screen handler as Fabric Screen isn't installed");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package com.viaversion.fabric.mc117.commands;
|
||||
|
||||
import com.viaversion.fabric.common.util.RemappingUtil;
|
||||
import com.viaversion.fabric.mc117.platform.FabricPlatform;
|
||||
import net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource;
|
||||
import net.minecraft.command.CommandSource;
|
||||
@ -26,9 +27,9 @@ public class NMSCommandSender implements ViaCommandSender {
|
||||
@Override
|
||||
public void sendMessage(String s) {
|
||||
if (source instanceof ServerCommandSource) {
|
||||
((ServerCommandSource) source).sendFeedback(Text.Serializer.fromJson(FabricPlatform.legacyToJson(s)), false);
|
||||
((ServerCommandSource) source).sendFeedback(Text.Serializer.fromJson(RemappingUtil.legacyToJson(s)), false);
|
||||
} else if (source instanceof FabricClientCommandSource) {
|
||||
((FabricClientCommandSource) source).sendFeedback(Text.Serializer.fromJson(FabricPlatform.legacyToJson(s)));
|
||||
((FabricClientCommandSource) source).sendFeedback(Text.Serializer.fromJson(RemappingUtil.legacyToJson(s)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,6 @@ package com.viaversion.fabric.mc117.gui;
|
||||
|
||||
import com.viaversion.fabric.mc117.ViaFabric;
|
||||
import com.viaversion.fabric.common.util.ProtocolUtils;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
|
@ -3,14 +3,12 @@ package com.viaversion.fabric.mc117.platform;
|
||||
import com.viaversion.fabric.common.commands.UserCommandSender;
|
||||
import com.viaversion.fabric.common.provider.AbstractFabricPlatform;
|
||||
import com.viaversion.fabric.common.util.FutureTaskId;
|
||||
import com.viaversion.fabric.common.util.RemappingUtil;
|
||||
import com.viaversion.fabric.mc117.ViaFabric;
|
||||
import com.viaversion.fabric.mc117.commands.NMSCommandSender;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.command.ViaCommandSender;
|
||||
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import io.netty.util.concurrent.Future;
|
||||
import io.netty.util.concurrent.GenericFutureListener;
|
||||
import io.netty.channel.EventLoop;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
@ -21,9 +19,8 @@ import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CancellationException;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.logging.Level;
|
||||
|
||||
@ -40,23 +37,6 @@ public class FabricPlatform extends AbstractFabricPlatform {
|
||||
return MinecraftClient.getInstance().getServer();
|
||||
}
|
||||
|
||||
public static String legacyToJson(String legacy) {
|
||||
return GsonComponentSerializer.gson().serialize(LegacyComponentSerializer.legacySection().deserialize(legacy));
|
||||
}
|
||||
|
||||
@Override
|
||||
public FutureTaskId runAsync(Runnable runnable) {
|
||||
return new FutureTaskId(CompletableFuture
|
||||
.runAsync(runnable, ViaFabric.ASYNC_EXECUTOR)
|
||||
.exceptionally(throwable -> {
|
||||
if (!(throwable instanceof CancellationException)) {
|
||||
throwable.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FutureTaskId runSync(Runnable runnable) {
|
||||
if (getServer() != null) {
|
||||
@ -71,42 +51,6 @@ public class FabricPlatform extends AbstractFabricPlatform {
|
||||
return new FutureTaskId(CompletableFuture.runAsync(runnable, getServer()));
|
||||
}
|
||||
|
||||
private FutureTaskId runEventLoop(Runnable runnable) {
|
||||
return new FutureTaskId(
|
||||
ViaFabric.EVENT_LOOP
|
||||
.submit(runnable)
|
||||
.addListener(errorLogger())
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FutureTaskId runSync(Runnable runnable, long ticks) {
|
||||
// ViaVersion seems to not need to run delayed tasks on main thread
|
||||
return new FutureTaskId(
|
||||
ViaFabric.EVENT_LOOP
|
||||
.schedule(() -> runSync(runnable), ticks * 50, TimeUnit.MILLISECONDS)
|
||||
.addListener(errorLogger())
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FutureTaskId runRepeatingSync(Runnable runnable, long ticks) {
|
||||
// ViaVersion seems to not need to run repeating tasks on main thread
|
||||
return new FutureTaskId(
|
||||
ViaFabric.EVENT_LOOP
|
||||
.scheduleAtFixedRate(() -> runSync(runnable), 0, ticks * 50, TimeUnit.MILLISECONDS)
|
||||
.addListener(errorLogger())
|
||||
);
|
||||
}
|
||||
|
||||
private <T extends Future<?>> GenericFutureListener<T> errorLogger() {
|
||||
return future -> {
|
||||
if (!future.isCancelled() && future.cause() != null) {
|
||||
future.cause().printStackTrace();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public ViaCommandSender[] getOnlinePlayers() {
|
||||
MinecraftServer server = getServer();
|
||||
@ -137,7 +81,7 @@ public class FabricPlatform extends AbstractFabricPlatform {
|
||||
ServerPlayerEntity player = server.getPlayerManager().getPlayer(uuid);
|
||||
if (player == null) return;
|
||||
player.sendMessage(Text.Serializer.fromJson(
|
||||
legacyToJson(s)
|
||||
RemappingUtil.legacyToJson(s)
|
||||
), false);
|
||||
});
|
||||
}
|
||||
@ -153,7 +97,7 @@ public class FabricPlatform extends AbstractFabricPlatform {
|
||||
Supplier<Boolean> kickTask = () -> {
|
||||
ServerPlayerEntity player = server.getPlayerManager().getPlayer(uuid);
|
||||
if (player == null) return false;
|
||||
player.networkHandler.disconnect(Text.Serializer.fromJson(legacyToJson(s)));
|
||||
player.networkHandler.disconnect(Text.Serializer.fromJson(RemappingUtil.legacyToJson(s)));
|
||||
return true;
|
||||
};
|
||||
if (server.isOnThread()) {
|
||||
@ -164,4 +108,14 @@ public class FabricPlatform extends AbstractFabricPlatform {
|
||||
}
|
||||
return false; // Can't know if it worked
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ExecutorService asyncService() {
|
||||
return ViaFabric.ASYNC_EXECUTOR;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EventLoop eventLoop() {
|
||||
return ViaFabric.EVENT_LOOP;
|
||||
}
|
||||
}
|
||||
|
@ -1,29 +1,29 @@
|
||||
package com.viaversion.fabric.mc117.providers;
|
||||
|
||||
import com.viaversion.fabric.common.util.RemappingUtil;
|
||||
import com.viaversion.fabric.mc117.ViaFabric;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
|
||||
import net.fabricmc.fabric.api.event.world.WorldTickCallback;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.network.ClientPlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.world.World;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.item.DataItem;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.HandItemProvider;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.network.ClientPlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class VRHandItemProvider extends HandItemProvider {
|
||||
public final Map<UUID, Item> serverPlayers = new ConcurrentHashMap<>();
|
||||
public Item clientItem = null;
|
||||
public Map<UUID, Item> serverPlayers = new ConcurrentHashMap<>();
|
||||
|
||||
@Override
|
||||
public Item getHandItem(UserConnection info) {
|
||||
@ -48,15 +48,7 @@ public class VRHandItemProvider extends HandItemProvider {
|
||||
try {
|
||||
ClientTickEvents.END_WORLD_TICK.register(clientWorld -> tickClient());
|
||||
} catch (NoClassDefFoundError ignored) {
|
||||
try {
|
||||
WorldTickCallback.EVENT.register(world -> {
|
||||
if (world.isClient) {
|
||||
tickClient();
|
||||
}
|
||||
});
|
||||
} catch (NoClassDefFoundError ignored2) {
|
||||
ViaFabric.JLOGGER.info("Fabric Lifecycle V0/V1 isn't installed");
|
||||
}
|
||||
ViaFabric.JLOGGER.info("Fabric Lifecycle V1 isn't installed");
|
||||
}
|
||||
}
|
||||
|
||||
@ -64,11 +56,6 @@ public class VRHandItemProvider extends HandItemProvider {
|
||||
try {
|
||||
ServerTickEvents.END_WORLD_TICK.register(this::tickServer);
|
||||
} catch (NoClassDefFoundError ignored) {
|
||||
WorldTickCallback.EVENT.register(world -> {
|
||||
if (!world.isClient) {
|
||||
tickServer(world);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -87,25 +74,7 @@ public class VRHandItemProvider extends HandItemProvider {
|
||||
|
||||
private Item fromNative(ItemStack original) {
|
||||
Identifier iid = Registry.ITEM.getId(original.getItem());
|
||||
if (iid == null) return new DataItem(0, (byte) 0, (short) 0, null);
|
||||
int id = swordId(iid.toString());
|
||||
int id = RemappingUtil.swordId(iid.toString());
|
||||
return new DataItem(id, (byte) original.getCount(), (short) original.getDamage(), null);
|
||||
}
|
||||
|
||||
private int swordId(String id) {
|
||||
// https://github.com/ViaVersion/ViaVersion/blob/8de26a0ad33f5b739f5394ed80f69d14197fddc7/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/Protocol1_9To1_8.java#L86
|
||||
switch (id) {
|
||||
case "minecraft:iron_sword":
|
||||
return 267;
|
||||
case "minecraft:wooden_sword":
|
||||
return 268;
|
||||
case "minecraft:golden_sword":
|
||||
return 272;
|
||||
case "minecraft:diamond_sword":
|
||||
return 276;
|
||||
case "minecraft:stone_sword":
|
||||
return 283;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ import java.util.logging.Level;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class ProtocolAutoDetector {
|
||||
private static LoadingCache<InetSocketAddress, CompletableFuture<ProtocolVersion>> SERVER_VER = CacheBuilder.newBuilder()
|
||||
private static final LoadingCache<InetSocketAddress, CompletableFuture<ProtocolVersion>> SERVER_VER = CacheBuilder.newBuilder()
|
||||
.expireAfterWrite(30, TimeUnit.SECONDS)
|
||||
.build(CacheLoader.from((address) -> {
|
||||
CompletableFuture<ProtocolVersion> future = new CompletableFuture<>();
|
||||
|
@ -31,6 +31,9 @@
|
||||
"main": [
|
||||
"com.viaversion.fabric.mc117.ViaFabric"
|
||||
],
|
||||
"client": [
|
||||
"com.viaversion.fabric.mc117.ViaFabricClient"
|
||||
],
|
||||
"modmenu": [
|
||||
"com.viaversion.fabric.mc117.gui.ModMenuConfig"
|
||||
]
|
||||
|
@ -10,8 +10,6 @@ import com.viaversion.fabric.common.platform.FabricInjector;
|
||||
import com.viaversion.fabric.common.protocol.HostnameParserProtocol;
|
||||
import com.viaversion.fabric.common.util.JLoggerToLog4j;
|
||||
import com.viaversion.fabric.mc118.commands.VRCommandHandler;
|
||||
import com.viaversion.fabric.mc118.gui.ViaConfigScreen;
|
||||
import com.viaversion.fabric.mc118.mixin.gui.client.ScreenAccessor;
|
||||
import com.viaversion.fabric.mc118.platform.FabricPlatform;
|
||||
import com.viaversion.fabric.mc118.platform.VFLoader;
|
||||
import com.viaversion.viaversion.ViaManagerImpl;
|
||||
@ -23,16 +21,9 @@ import io.netty.channel.EventLoop;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.fabricmc.fabric.api.client.command.v1.ClientCommandManager;
|
||||
import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents;
|
||||
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.screen.multiplayer.MultiplayerScreen;
|
||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||
import net.minecraft.client.gui.widget.TexturedButtonWidget;
|
||||
import net.minecraft.command.CommandSource;
|
||||
import net.minecraft.text.TranslatableText;
|
||||
import net.minecraft.util.Identifier;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
@ -45,7 +36,7 @@ public class ViaFabric implements ModInitializer {
|
||||
public static final Logger JLOGGER = new JLoggerToLog4j(LogManager.getLogger("ViaFabric"));
|
||||
public static final ExecutorService ASYNC_EXECUTOR;
|
||||
public static final EventLoop EVENT_LOOP;
|
||||
public static CompletableFuture<Void> INIT_FUTURE = new CompletableFuture<>();
|
||||
public static final CompletableFuture<Void> INIT_FUTURE = new CompletableFuture<>();
|
||||
public static VFConfig config;
|
||||
|
||||
static {
|
||||
@ -84,7 +75,6 @@ public class ViaFabric implements ModInitializer {
|
||||
FabricLoader.getInstance().getEntrypoints("viafabric:via_api_initialized", Runnable.class).forEach(Runnable::run);
|
||||
|
||||
registerCommandsV1();
|
||||
registerGui();
|
||||
|
||||
config = new VFConfig(FabricLoader.getInstance().getConfigDir().resolve("ViaFabric")
|
||||
.resolve("viafabric.yml").toFile());
|
||||
@ -92,26 +82,6 @@ public class ViaFabric implements ModInitializer {
|
||||
INIT_FUTURE.complete(null);
|
||||
}
|
||||
|
||||
private void registerGui() {
|
||||
if (FabricLoader.getInstance().getEnvironmentType() != EnvType.CLIENT) return;
|
||||
try {
|
||||
ScreenEvents.AFTER_INIT.register((client, screen, scaledWidth, scaledHeight) -> {
|
||||
if (!(screen instanceof MultiplayerScreen)) return;
|
||||
ButtonWidget enableClientSideViaVersion = new TexturedButtonWidget(scaledWidth / 2 + 113, 10,
|
||||
40, 20, // Size
|
||||
0, 0, // Start pos of texture
|
||||
20, // v Hover offset
|
||||
new Identifier("viafabric:textures/gui/widgets.png"),
|
||||
256, 256, // Texture size
|
||||
it -> MinecraftClient.getInstance().setScreen(new ViaConfigScreen(screen)),
|
||||
new TranslatableText("gui.via_button"));
|
||||
if (ViaFabric.config.isHideButton()) enableClientSideViaVersion.visible = false;
|
||||
((ScreenAccessor) screen).callAddDrawableChild(enableClientSideViaVersion);
|
||||
});
|
||||
} catch (NoClassDefFoundError ignored) {
|
||||
JLOGGER.info("Couldn't register screen handler as Fabric Screen isn't installed");
|
||||
}
|
||||
}
|
||||
|
||||
private void registerCommandsV1() {
|
||||
try {
|
||||
@ -122,7 +92,7 @@ public class ViaFabric implements ModInitializer {
|
||||
ClientCommandManager.DISPATCHER.register(command("viafabricclient"));
|
||||
}
|
||||
} catch (NoClassDefFoundError ignored) {
|
||||
JLOGGER.info("Couldn't register command as Fabric Commands isn't installed");
|
||||
JLOGGER.info("Couldn't register command as Fabric Commands V1 isn't installed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,39 @@
|
||||
package com.viaversion.fabric.mc118;
|
||||
|
||||
import com.viaversion.fabric.mc118.gui.ViaConfigScreen;
|
||||
import com.viaversion.fabric.mc118.mixin.gui.client.ScreenAccessor;
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.screen.multiplayer.MultiplayerScreen;
|
||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||
import net.minecraft.client.gui.widget.TexturedButtonWidget;
|
||||
import net.minecraft.text.TranslatableText;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
public class ViaFabricClient implements ClientModInitializer {
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
registerGui();
|
||||
}
|
||||
|
||||
private void registerGui() {
|
||||
try {
|
||||
ScreenEvents.AFTER_INIT.register((client, screen, scaledWidth, scaledHeight) -> {
|
||||
if (!(screen instanceof MultiplayerScreen)) return;
|
||||
ButtonWidget enableClientSideViaVersion = new TexturedButtonWidget(scaledWidth / 2 + 113, 10,
|
||||
40, 20, // Size
|
||||
0, 0, // Start pos of texture
|
||||
20, // v Hover offset
|
||||
new Identifier("viafabric:textures/gui/widgets.png"),
|
||||
256, 256, // Texture size
|
||||
it -> MinecraftClient.getInstance().setScreen(new ViaConfigScreen(screen)),
|
||||
new TranslatableText("gui.via_button"));
|
||||
if (ViaFabric.config.isHideButton()) enableClientSideViaVersion.visible = false;
|
||||
((ScreenAccessor) screen).callAddDrawableChild(enableClientSideViaVersion);
|
||||
});
|
||||
} catch (NoClassDefFoundError ignored) {
|
||||
ViaFabric.JLOGGER.info("Couldn't register screen handler as Fabric Screen isn't installed");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package com.viaversion.fabric.mc118.commands;
|
||||
|
||||
import com.viaversion.fabric.common.util.RemappingUtil;
|
||||
import com.viaversion.fabric.mc118.platform.FabricPlatform;
|
||||
import net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource;
|
||||
import net.minecraft.command.CommandSource;
|
||||
@ -26,9 +27,9 @@ public class NMSCommandSender implements ViaCommandSender {
|
||||
@Override
|
||||
public void sendMessage(String s) {
|
||||
if (source instanceof ServerCommandSource) {
|
||||
((ServerCommandSource) source).sendFeedback(Text.Serializer.fromJson(FabricPlatform.legacyToJson(s)), false);
|
||||
((ServerCommandSource) source).sendFeedback(Text.Serializer.fromJson(RemappingUtil.legacyToJson(s)), false);
|
||||
} else if (source instanceof FabricClientCommandSource) {
|
||||
((FabricClientCommandSource) source).sendFeedback(Text.Serializer.fromJson(FabricPlatform.legacyToJson(s)));
|
||||
((FabricClientCommandSource) source).sendFeedback(Text.Serializer.fromJson(RemappingUtil.legacyToJson(s)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,6 @@ package com.viaversion.fabric.mc118.gui;
|
||||
|
||||
import com.viaversion.fabric.mc118.ViaFabric;
|
||||
import com.viaversion.fabric.common.util.ProtocolUtils;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
|
@ -3,14 +3,12 @@ package com.viaversion.fabric.mc118.platform;
|
||||
import com.viaversion.fabric.common.commands.UserCommandSender;
|
||||
import com.viaversion.fabric.common.provider.AbstractFabricPlatform;
|
||||
import com.viaversion.fabric.common.util.FutureTaskId;
|
||||
import com.viaversion.fabric.common.util.RemappingUtil;
|
||||
import com.viaversion.fabric.mc118.ViaFabric;
|
||||
import com.viaversion.fabric.mc118.commands.NMSCommandSender;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.command.ViaCommandSender;
|
||||
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import io.netty.util.concurrent.Future;
|
||||
import io.netty.util.concurrent.GenericFutureListener;
|
||||
import io.netty.channel.EventLoop;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
@ -21,9 +19,8 @@ import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CancellationException;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.logging.Level;
|
||||
|
||||
@ -40,23 +37,6 @@ public class FabricPlatform extends AbstractFabricPlatform {
|
||||
return MinecraftClient.getInstance().getServer();
|
||||
}
|
||||
|
||||
public static String legacyToJson(String legacy) {
|
||||
return GsonComponentSerializer.gson().serialize(LegacyComponentSerializer.legacySection().deserialize(legacy));
|
||||
}
|
||||
|
||||
@Override
|
||||
public FutureTaskId runAsync(Runnable runnable) {
|
||||
return new FutureTaskId(CompletableFuture
|
||||
.runAsync(runnable, ViaFabric.ASYNC_EXECUTOR)
|
||||
.exceptionally(throwable -> {
|
||||
if (!(throwable instanceof CancellationException)) {
|
||||
throwable.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FutureTaskId runSync(Runnable runnable) {
|
||||
if (getServer() != null) {
|
||||
@ -71,42 +51,6 @@ public class FabricPlatform extends AbstractFabricPlatform {
|
||||
return new FutureTaskId(CompletableFuture.runAsync(runnable, getServer()));
|
||||
}
|
||||
|
||||
private FutureTaskId runEventLoop(Runnable runnable) {
|
||||
return new FutureTaskId(
|
||||
ViaFabric.EVENT_LOOP
|
||||
.submit(runnable)
|
||||
.addListener(errorLogger())
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FutureTaskId runSync(Runnable runnable, long ticks) {
|
||||
// ViaVersion seems to not need to run delayed tasks on main thread
|
||||
return new FutureTaskId(
|
||||
ViaFabric.EVENT_LOOP
|
||||
.schedule(() -> runSync(runnable), ticks * 50, TimeUnit.MILLISECONDS)
|
||||
.addListener(errorLogger())
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FutureTaskId runRepeatingSync(Runnable runnable, long ticks) {
|
||||
// ViaVersion seems to not need to run repeating tasks on main thread
|
||||
return new FutureTaskId(
|
||||
ViaFabric.EVENT_LOOP
|
||||
.scheduleAtFixedRate(() -> runSync(runnable), 0, ticks * 50, TimeUnit.MILLISECONDS)
|
||||
.addListener(errorLogger())
|
||||
);
|
||||
}
|
||||
|
||||
private <T extends Future<?>> GenericFutureListener<T> errorLogger() {
|
||||
return future -> {
|
||||
if (!future.isCancelled() && future.cause() != null) {
|
||||
future.cause().printStackTrace();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public ViaCommandSender[] getOnlinePlayers() {
|
||||
MinecraftServer server = getServer();
|
||||
@ -137,7 +81,7 @@ public class FabricPlatform extends AbstractFabricPlatform {
|
||||
ServerPlayerEntity player = server.getPlayerManager().getPlayer(uuid);
|
||||
if (player == null) return;
|
||||
player.sendMessage(Text.Serializer.fromJson(
|
||||
legacyToJson(s)
|
||||
RemappingUtil.legacyToJson(s)
|
||||
), false);
|
||||
});
|
||||
}
|
||||
@ -153,7 +97,7 @@ public class FabricPlatform extends AbstractFabricPlatform {
|
||||
Supplier<Boolean> kickTask = () -> {
|
||||
ServerPlayerEntity player = server.getPlayerManager().getPlayer(uuid);
|
||||
if (player == null) return false;
|
||||
player.networkHandler.disconnect(Text.Serializer.fromJson(legacyToJson(s)));
|
||||
player.networkHandler.disconnect(Text.Serializer.fromJson(RemappingUtil.legacyToJson(s)));
|
||||
return true;
|
||||
};
|
||||
if (server.isOnThread()) {
|
||||
@ -164,4 +108,14 @@ public class FabricPlatform extends AbstractFabricPlatform {
|
||||
}
|
||||
return false; // Can't know if it worked
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ExecutorService asyncService() {
|
||||
return ViaFabric.ASYNC_EXECUTOR;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EventLoop eventLoop() {
|
||||
return ViaFabric.EVENT_LOOP;
|
||||
}
|
||||
}
|
||||
|
@ -1,21 +1,21 @@
|
||||
package com.viaversion.fabric.mc118.providers;
|
||||
|
||||
import com.viaversion.fabric.common.util.RemappingUtil;
|
||||
import com.viaversion.fabric.mc118.ViaFabric;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
|
||||
import net.fabricmc.fabric.api.event.world.WorldTickCallback;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.network.ClientPlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.world.World;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.item.DataItem;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.HandItemProvider;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.network.ClientPlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
@ -23,7 +23,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class VRHandItemProvider extends HandItemProvider {
|
||||
public Item clientItem = null;
|
||||
public Map<UUID, Item> serverPlayers = new ConcurrentHashMap<>();
|
||||
public final Map<UUID, Item> serverPlayers = new ConcurrentHashMap<>();
|
||||
|
||||
@Override
|
||||
public Item getHandItem(UserConnection info) {
|
||||
@ -48,15 +48,7 @@ public class VRHandItemProvider extends HandItemProvider {
|
||||
try {
|
||||
ClientTickEvents.END_WORLD_TICK.register(clientWorld -> tickClient());
|
||||
} catch (NoClassDefFoundError ignored) {
|
||||
try {
|
||||
WorldTickCallback.EVENT.register(world -> {
|
||||
if (world.isClient) {
|
||||
tickClient();
|
||||
}
|
||||
});
|
||||
} catch (NoClassDefFoundError ignored2) {
|
||||
ViaFabric.JLOGGER.info("Fabric Lifecycle V0/V1 isn't installed");
|
||||
}
|
||||
ViaFabric.JLOGGER.info("Fabric Lifecycle V1 isn't installed");
|
||||
}
|
||||
}
|
||||
|
||||
@ -64,11 +56,6 @@ public class VRHandItemProvider extends HandItemProvider {
|
||||
try {
|
||||
ServerTickEvents.END_WORLD_TICK.register(this::tickServer);
|
||||
} catch (NoClassDefFoundError ignored) {
|
||||
WorldTickCallback.EVENT.register(world -> {
|
||||
if (!world.isClient) {
|
||||
tickServer(world);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -87,25 +74,7 @@ public class VRHandItemProvider extends HandItemProvider {
|
||||
|
||||
private Item fromNative(ItemStack original) {
|
||||
Identifier iid = Registry.ITEM.getId(original.getItem());
|
||||
if (iid == null) return new DataItem(0, (byte) 0, (short) 0, null);
|
||||
int id = swordId(iid.toString());
|
||||
int id = RemappingUtil.swordId(iid.toString());
|
||||
return new DataItem(id, (byte) original.getCount(), (short) original.getDamage(), null);
|
||||
}
|
||||
|
||||
private int swordId(String id) {
|
||||
// https://github.com/ViaVersion/ViaVersion/blob/8de26a0ad33f5b739f5394ed80f69d14197fddc7/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/Protocol1_9To1_8.java#L86
|
||||
switch (id) {
|
||||
case "minecraft:iron_sword":
|
||||
return 267;
|
||||
case "minecraft:wooden_sword":
|
||||
return 268;
|
||||
case "minecraft:golden_sword":
|
||||
return 272;
|
||||
case "minecraft:diamond_sword":
|
||||
return 276;
|
||||
case "minecraft:stone_sword":
|
||||
return 283;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ import java.util.logging.Level;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class ProtocolAutoDetector {
|
||||
private static LoadingCache<InetSocketAddress, CompletableFuture<ProtocolVersion>> SERVER_VER = CacheBuilder.newBuilder()
|
||||
private static final LoadingCache<InetSocketAddress, CompletableFuture<ProtocolVersion>> SERVER_VER = CacheBuilder.newBuilder()
|
||||
.expireAfterWrite(30, TimeUnit.SECONDS)
|
||||
.build(CacheLoader.from((address) -> {
|
||||
CompletableFuture<ProtocolVersion> future = new CompletableFuture<>();
|
||||
|
@ -31,6 +31,9 @@
|
||||
"main": [
|
||||
"com.viaversion.fabric.mc118.ViaFabric"
|
||||
],
|
||||
"client": [
|
||||
"com.viaversion.fabric.mc118.ViaFabricClient"
|
||||
],
|
||||
"modmenu": [
|
||||
"com.viaversion.fabric.mc118.gui.ModMenuConfig"
|
||||
]
|
||||
|
@ -1,24 +1,25 @@
|
||||
package com.viaversion.fabric.mc18;
|
||||
|
||||
import com.viaversion.fabric.common.platform.FabricInjector;
|
||||
import com.viaversion.fabric.mc18.commands.NMSCommandImpl;
|
||||
import com.viaversion.fabric.mc18.commands.VRCommandHandler;
|
||||
import com.viaversion.fabric.common.config.VFConfig;
|
||||
import com.viaversion.fabric.mc18.platform.VFLoader;
|
||||
import com.viaversion.fabric.mc18.platform.FabricPlatform;
|
||||
import com.viaversion.fabric.common.protocol.HostnameParserProtocol;
|
||||
import com.viaversion.fabric.common.util.JLoggerToLog4j;
|
||||
import com.google.common.collect.Range;
|
||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||
import io.netty.channel.EventLoop;
|
||||
import io.netty.channel.local.LocalEventLoopGroup;
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import com.viaversion.fabric.common.config.VFConfig;
|
||||
import com.viaversion.fabric.common.platform.FabricInjector;
|
||||
import com.viaversion.fabric.common.protocol.HostnameParserProtocol;
|
||||
import com.viaversion.fabric.common.util.JLoggerToLog4j;
|
||||
import com.viaversion.fabric.mc18.commands.NMSCommandImpl;
|
||||
import com.viaversion.fabric.mc18.commands.VRCommandHandler;
|
||||
import com.viaversion.fabric.mc18.platform.FabricPlatform;
|
||||
import com.viaversion.fabric.mc18.platform.VFLoader;
|
||||
import com.viaversion.viaversion.ViaManagerImpl;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.data.MappingDataLoader;
|
||||
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
||||
import io.netty.channel.EventLoop;
|
||||
import io.netty.channel.local.LocalEventLoopGroup;
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.legacyfabric.fabric.api.registry.CommandRegistry;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
@ -26,13 +27,11 @@ import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import net.legacyfabric.fabric.api.registry.CommandRegistry;
|
||||
|
||||
public class ViaFabric implements ModInitializer {
|
||||
public static final Logger JLOGGER = new JLoggerToLog4j(LogManager.getLogger("ViaFabric"));
|
||||
public static final ExecutorService ASYNC_EXECUTOR;
|
||||
public static final EventLoop EVENT_LOOP;
|
||||
public static CompletableFuture<Void> INIT_FUTURE = new CompletableFuture<>();
|
||||
public static final CompletableFuture<Void> INIT_FUTURE = new CompletableFuture<>();
|
||||
public static VFConfig config;
|
||||
|
||||
static {
|
||||
@ -59,11 +58,7 @@ public class ViaFabric implements ModInitializer {
|
||||
|
||||
FabricLoader.getInstance().getEntrypoints("viafabric:via_api_initialized", Runnable.class).forEach(Runnable::run);
|
||||
|
||||
try {
|
||||
registerCommandsV0();
|
||||
} catch (NoClassDefFoundError ignored2) {
|
||||
JLOGGER.info("Couldn't register command as Fabric Commands isn't installed");
|
||||
}
|
||||
registerCommandsV0();
|
||||
|
||||
config = new VFConfig(FabricLoader.getInstance().getConfigDir().resolve("ViaFabric")
|
||||
.resolve("viafabric.yml").toFile());
|
||||
@ -71,8 +66,11 @@ public class ViaFabric implements ModInitializer {
|
||||
INIT_FUTURE.complete(null);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private void registerCommandsV0() {
|
||||
CommandRegistry.INSTANCE.register(new NMSCommandImpl(Via.getManager().getCommandHandler()));
|
||||
try {
|
||||
CommandRegistry.INSTANCE.register(new NMSCommandImpl(Via.getManager().getCommandHandler()));
|
||||
} catch (NoClassDefFoundError ignored2) {
|
||||
JLOGGER.info("Couldn't register command as Fabric Commands isn't installed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class NMSCommandImpl extends AbstractCommand {
|
||||
private ViaVersionCommand handler;
|
||||
private final ViaVersionCommand handler;
|
||||
|
||||
public NMSCommandImpl(ViaVersionCommand handler) {
|
||||
this.handler = handler;
|
||||
|
@ -1,11 +1,10 @@
|
||||
package com.viaversion.fabric.mc18.commands;
|
||||
|
||||
import com.viaversion.fabric.common.util.RemappingUtil;
|
||||
import com.viaversion.viaversion.api.command.ViaCommandSender;
|
||||
import net.minecraft.command.CommandSource;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.text.Text;
|
||||
import com.viaversion.viaversion.api.command.ViaCommandSender;
|
||||
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@ -24,11 +23,7 @@ public class NMSCommandSender implements ViaCommandSender {
|
||||
|
||||
@Override
|
||||
public void sendMessage(String s) {
|
||||
source.sendMessage(Text.Serializer.deserialize(legacyToJson(s)));
|
||||
}
|
||||
|
||||
private String legacyToJson(String legacy) {
|
||||
return GsonComponentSerializer.gson().serialize(LegacyComponentSerializer.legacySection().deserialize(legacy));
|
||||
source.sendMessage(Text.Serializer.deserialize(RemappingUtil.legacyToJson(s)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -5,7 +5,7 @@ import net.minecraft.client.gui.widget.PagedEntryListWidget;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class ChangedListener implements PagedEntryListWidget.Listener {
|
||||
private Consumer<String> consumer;
|
||||
private final Consumer<String> consumer;
|
||||
|
||||
public ChangedListener(Consumer<String> consumer) {
|
||||
this.consumer = consumer;
|
||||
|
@ -5,12 +5,7 @@ import net.minecraft.client.gui.widget.ButtonWidget;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class ListeneableButton extends ButtonWidget {
|
||||
private Consumer<ButtonWidget> click;
|
||||
|
||||
public ListeneableButton(int id, int x, int y, String message, Consumer<ButtonWidget> click) {
|
||||
super(id, x, y, message);
|
||||
this.click = click;
|
||||
}
|
||||
private final Consumer<ButtonWidget> click;
|
||||
|
||||
public ListeneableButton(int id, int x, int y, int width, int height, String message, Consumer<ButtonWidget> click) {
|
||||
super(id, x, y, width, height, message);
|
||||
|
@ -10,11 +10,11 @@ import java.util.function.Consumer;
|
||||
|
||||
public class ViaButton extends ButtonWidget {
|
||||
// Meant to be similar to higher versions TexturedButtonWidget
|
||||
private int startU;
|
||||
private int startV;
|
||||
private int offsetHoverV;
|
||||
private Identifier texturePath;
|
||||
private Consumer<ViaButton> onClick;
|
||||
private final int startU;
|
||||
private final int startV;
|
||||
private final int offsetHoverV;
|
||||
private final Identifier texturePath;
|
||||
private final Consumer<ViaButton> onClick;
|
||||
|
||||
public ViaButton(int id, int x, int y, int width, int height, int startU, int startV, int offsetHoverV, Identifier texturePath,
|
||||
int textureSizeX, int textureSizeY, Consumer<ViaButton> onClick, String altTxt) {
|
||||
@ -34,12 +34,11 @@ public class ViaButton extends ButtonWidget {
|
||||
client.getTextureManager().bindTexture(texturePath);
|
||||
GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
boolean hover = mouseX >= this.x && mouseY >= this.y && mouseX < this.x + this.width && mouseY < this.y + this.height;
|
||||
int u = startU;
|
||||
int v = startV;
|
||||
if (hover) {
|
||||
v += offsetHoverV;
|
||||
}
|
||||
this.drawTexture(this.x, this.y, u, v, this.width, this.height);
|
||||
this.drawTexture(this.x, this.y, startU, v, this.width, this.height);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,6 @@ package com.viaversion.fabric.mc18.gui;
|
||||
|
||||
import com.viaversion.fabric.mc18.ViaFabric;
|
||||
import com.viaversion.fabric.common.util.ProtocolUtils;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
@ -20,7 +19,7 @@ public class ViaConfigScreen extends Screen {
|
||||
private static CompletableFuture<Void> latestProtocolSave;
|
||||
private final Screen parent;
|
||||
private TextFieldWidget protocolVersion;
|
||||
private Text title;
|
||||
private final Text title;
|
||||
|
||||
public ViaConfigScreen(Screen parent) {
|
||||
super();
|
||||
@ -91,10 +90,6 @@ public class ViaConfigScreen extends Screen {
|
||||
validProtocol = true;
|
||||
} else {
|
||||
validProtocol = false;
|
||||
String[] suggestions = ProtocolUtils.getProtocolSuggestions(text);
|
||||
if (suggestions.length == 1) {
|
||||
//protocolVersion.setSuggestion(suggestions[0].substring(text.length()));
|
||||
}
|
||||
}
|
||||
|
||||
protocolVersion.setEditableColor(
|
||||
@ -137,11 +132,6 @@ public class ViaConfigScreen extends Screen {
|
||||
ViaFabric.config.saveConfig();
|
||||
}
|
||||
|
||||
//@Override
|
||||
//public void onClose() {
|
||||
// MinecraftClient.getInstance().openScreen(this.parent);
|
||||
//}
|
||||
|
||||
private TranslatableText getClientSideText() {
|
||||
return ViaFabric.config.isClientSideEnabled() ?
|
||||
new TranslatableText("gui.client_side.disable")
|
||||
|
@ -21,7 +21,7 @@ public class MixinDebugHud {
|
||||
protected void getLeftText(CallbackInfoReturnable<List<String>> info) {
|
||||
String line = "[ViaFabric] I: " + Via.getManager().getConnectionManager().getConnections().size() + " (F: "
|
||||
+ Via.getManager().getConnectionManager().getConnectedClients().size() + ")";
|
||||
@SuppressWarnings("ConstantConditions") ChannelHandler viaDecoder = ((MixinClientConnectionAccessor) MinecraftClient.getInstance().getNetworkHandler()
|
||||
ChannelHandler viaDecoder = ((MixinClientConnectionAccessor) MinecraftClient.getInstance().getNetworkHandler()
|
||||
.getClientConnection()).getChannel().pipeline().get(CommonTransformer.HANDLER_DECODER_NAME);
|
||||
if (viaDecoder instanceof FabricDecodeHandler) {
|
||||
ProtocolInfo protocol = ((FabricDecodeHandler) viaDecoder).getInfo().getProtocolInfo();
|
||||
|
@ -3,14 +3,12 @@ package com.viaversion.fabric.mc18.platform;
|
||||
import com.viaversion.fabric.common.commands.UserCommandSender;
|
||||
import com.viaversion.fabric.common.provider.AbstractFabricPlatform;
|
||||
import com.viaversion.fabric.common.util.FutureTaskId;
|
||||
import com.viaversion.fabric.common.util.RemappingUtil;
|
||||
import com.viaversion.fabric.mc18.ViaFabric;
|
||||
import com.viaversion.fabric.mc18.commands.NMSCommandSender;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.command.ViaCommandSender;
|
||||
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import io.netty.util.concurrent.Future;
|
||||
import io.netty.util.concurrent.GenericFutureListener;
|
||||
import io.netty.channel.EventLoop;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
@ -22,7 +20,7 @@ import java.util.UUID;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.CancellationException;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.logging.Level;
|
||||
|
||||
@ -34,8 +32,14 @@ public class FabricPlatform extends AbstractFabricPlatform {
|
||||
return MinecraftServer.getServer();
|
||||
}
|
||||
|
||||
public static String legacyToJson(String legacy) {
|
||||
return GsonComponentSerializer.gson().serialize(LegacyComponentSerializer.legacySection().deserialize(legacy));
|
||||
@Override
|
||||
protected ExecutorService asyncService() {
|
||||
return ViaFabric.ASYNC_EXECUTOR;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EventLoop eventLoop() {
|
||||
return ViaFabric.EVENT_LOOP;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -68,42 +72,6 @@ public class FabricPlatform extends AbstractFabricPlatform {
|
||||
})));
|
||||
}
|
||||
|
||||
private FutureTaskId runEventLoop(Runnable runnable) {
|
||||
return new FutureTaskId(
|
||||
ViaFabric.EVENT_LOOP
|
||||
.submit(runnable)
|
||||
.addListener(errorLogger())
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FutureTaskId runSync(Runnable runnable, long ticks) {
|
||||
// ViaVersion seems to not need to run delayed tasks on main thread
|
||||
return new FutureTaskId(
|
||||
ViaFabric.EVENT_LOOP
|
||||
.schedule(() -> runSync(runnable), ticks * 50, TimeUnit.MILLISECONDS)
|
||||
.addListener(errorLogger())
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FutureTaskId runRepeatingSync(Runnable runnable, long ticks) {
|
||||
// ViaVersion seems to not need to run repeating tasks on main thread
|
||||
return new FutureTaskId(
|
||||
ViaFabric.EVENT_LOOP
|
||||
.scheduleAtFixedRate(() -> runSync(runnable), 0, ticks * 50, TimeUnit.MILLISECONDS)
|
||||
.addListener(errorLogger())
|
||||
);
|
||||
}
|
||||
|
||||
private <T extends Future<?>> GenericFutureListener<T> errorLogger() {
|
||||
return future -> {
|
||||
if (!future.isCancelled() && future.cause() != null) {
|
||||
future.cause().printStackTrace();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public ViaCommandSender[] getOnlinePlayers() {
|
||||
MinecraftServer server = getServer();
|
||||
@ -132,7 +100,7 @@ public class FabricPlatform extends AbstractFabricPlatform {
|
||||
runServerSync(() -> {
|
||||
ServerPlayerEntity player = server.getPlayerManager().getPlayer(uuid);
|
||||
if (player == null) return;
|
||||
player.sendMessage(Text.Serializer.deserialize(legacyToJson(s)));
|
||||
player.sendMessage(Text.Serializer.deserialize(RemappingUtil.legacyToJson(s)));
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class VRHandItemProvider extends HandItemProvider {
|
||||
public Item clientItem = null;
|
||||
public Map<UUID, Item> serverPlayers = new ConcurrentHashMap<>();
|
||||
public final Map<UUID, Item> serverPlayers = new ConcurrentHashMap<>();
|
||||
|
||||
@Override
|
||||
public Item getHandItem(UserConnection info) {
|
||||
@ -75,21 +75,4 @@ public class VRHandItemProvider extends HandItemProvider {
|
||||
int id = net.minecraft.item.Item.getRawId(original.getItem());
|
||||
return new DataItem(id, (byte) original.count, (short) original.getDamage(), null);
|
||||
}
|
||||
|
||||
private int swordId(String id) {
|
||||
// https://github.com/ViaVersion/ViaVersion/blob/8de26a0ad33f5b739f5394ed80f69d14197fddc7/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/Protocol1_9To1_8.java#L86
|
||||
switch (id) {
|
||||
case "minecraft:iron_sword":
|
||||
return 267;
|
||||
case "minecraft:wooden_sword":
|
||||
return 268;
|
||||
case "minecraft:golden_sword":
|
||||
return 272;
|
||||
case "minecraft:diamond_sword":
|
||||
return 276;
|
||||
case "minecraft:stone_sword":
|
||||
return 283;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ import java.util.logging.Level;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class ProtocolAutoDetector {
|
||||
private static LoadingCache<InetSocketAddress, CompletableFuture<ProtocolVersion>> SERVER_VER = CacheBuilder.newBuilder()
|
||||
private static final LoadingCache<InetSocketAddress, CompletableFuture<ProtocolVersion>> SERVER_VER = CacheBuilder.newBuilder()
|
||||
.expireAfterWrite(30, TimeUnit.SECONDS)
|
||||
.build(CacheLoader.from((address) -> {
|
||||
CompletableFuture<ProtocolVersion> future = new CompletableFuture<>();
|
||||
|
Loading…
Reference in New Issue
Block a user