cursed 1.8.9 backport

This commit is contained in:
creeper123123321 2020-07-12 16:25:02 -03:00
parent f601cf279d
commit 7a1f99abdf
28 changed files with 329 additions and 252 deletions

View File

@ -16,7 +16,7 @@ deploy:
on:
repo: ViaVersion/ViaFabric
all_branches: true
condition: $TRAVIS_BRANCH =~ ^(master|ver\/.*)$
condition: $TRAVIS_BRANCH =~ ^(mc\-.*)$
install: true
script:
# Set up git user name and tag this commit

View File

@ -10,19 +10,27 @@
Allows the connection to/from different Minecraft versions on your Minecraft client/server (LAN worlds too)
This mod supports 1.14.4/1.15.x (on `ver/1.14` branch) and 1.16.x/snapshots (on `master` branch) with Fabric Loader. Check the Minecraft version in file name when downloading from GitHub Releases.
This mod supports 1.8.9 (in `mc-1.8` branch), 1.14.4/1.15.2 (in `mc-1.14-1.15` branch) and 1.16.x/snapshots (in `mc-1.16` branch) with Fabric Loader. Check the Minecraft version in file name when downloading from CurseForge/GitHub Releases.
Note: ViaVersion is not designed for modded Minecraft with registry synchronization (fabric-registry-sync mod).
**Dependencies:**
| Dependency | Download |
| --------------------------------- | --------------------------------------------------------------------- |
| ViaVersion 3.0.2+ | dev builds at https://ci.viaversion.com/job/ViaVersion/ |
| Fabric Textures v0 | https://www.curseforge.com/minecraft/mc-mods/fabric-api |
| Fabric Resource Loader v0 | https://www.curseforge.com/minecraft/mc-mods/fabric-api |
| Fabric Command API v1 | https://www.curseforge.com/minecraft/mc-mods/fabric-api |
| (Included) Cotton Client Commands | https://www.curseforge.com/minecraft/mc-mods/cotton-client-commands |
**1.14+ Dependencies:**
| Dependency | Download |
| ---------------------------------- | --------------------------------------------------------------------- |
| ViaVersion 3.0.2+ | dev builds at https://ci.viaversion.com/job/ViaVersion/ |
| Fabric Textures v0 | https://www.curseforge.com/minecraft/mc-mods/fabric-api |
| Fabric Resource Loader v0 | https://www.curseforge.com/minecraft/mc-mods/fabric-api |
| Fabric Command API v1 | https://www.curseforge.com/minecraft/mc-mods/fabric-api |
| (Included) Cotton Client Commands | https://www.curseforge.com/minecraft/mc-mods/cotton-client-commands |
**1.8.9 Dependencies:**
| Dependency | Download |
| -------------------------------------- | ------------------------------------------------------- |
| ViaVersion 3.0.2+ | dev builds at https://ci.viaversion.com/job/ViaVersion/ |
| Fabric Events Lifecycle v0 (mc 1.8.x) | unknown? (https://github.com/Legacy-Fabric/fabric) |
| Fabric Resource Loader v0 | unknown? (https://github.com/Legacy-Fabric/fabric) |
With ViaVersion:

View File

@ -1,4 +1,5 @@
import org.apache.tools.ant.filters.ReplaceTokens
import java.util.function.Function as JavaFunction
plugins {
id("java")
@ -8,12 +9,14 @@ plugins {
}
group = "com.github.creeper123123321.viafabric"
val gitVersion: groovy.lang.Closure<Any> by extra
version = "0.2.4-SNAPSHOT+" + try {
gitVersion()
val gitVersion: groovy.lang.Closure<String> by extra
val versionDetails: groovy.lang.Closure<com.palantir.gradle.gitversion.VersionDetails> by extra
version = "0.2.5-SNAPSHOT+" + try {
gitVersion() + "-" + versionDetails().branchName
} catch (e: Exception) {
e.printStackTrace()
"unknown"
} + "-mc-1.14-1.15"
}
extra.set("archivesBaseName", "ViaFabric")
description = "Client-side and server-side ViaVersion implementation for Fabric"
@ -33,6 +36,7 @@ repositories {
maven(url = "https://maven.fabricmc.net/")
maven(url = "https://server.bbkr.space/artifactory/libs-snapshot")
maven(url = "https://server.bbkr.space/artifactory/libs-release")
maven(url = "https://dl.bintray.com/legacy-fabric/Legacy-Fabric-Maven")
}
@ -49,19 +53,24 @@ dependencies {
// transitive = false because Guava is conflicting on runClient
implementation("us.myles:viaversion:3.0.2-SNAPSHOT") { isTransitive = false }
// Use 1.14.4 release, probably intermediary will make it work on snapshots
// https://modmuss50.me/fabric.html?&version=1.14.4
minecraft("com.mojang:minecraft:1.14.4")
mappings("net.fabricmc:yarn:1.14.4+build.16:v2")
modImplementation("net.fabricmc:fabric-loader:0.8.2+build.194")
// Use 1.8.9 Legacy Fabric https://github.com/Legacy-Fabric/fabric-example-mod/blob/master/gradle.properties
compile("com.google.guava:guava:23.5-jre")
minecraft("com.mojang:minecraft:1.8.9")
mappings("net.fabricmc:yarn:1.8.9+build.202007011615:v2")
modCompile("net.fabricmc:fabric-loader-1.8.9:0.8.2+build.202004131640") {
exclude(module = "guava")
}
modImplementation("net.fabricmc.fabric-api:fabric-api:0.13.1+build.257-1.14")
modImplementation("net.fabricmc.fabric-api:fabric-api:0.2.2-1.8.9")
modImplementation("io.github.cottonmc:cotton-client-commands:1.0.0+1.15.2")
include("io.github.cottonmc:cotton-client-commands:1.0.0+1.15.2")
//modImplementation("io.github.cottonmc:cotton-client-commands:1.0.0+1.15.2")
//include("io.github.cottonmc:cotton-client-commands:1.0.0+1.15.2")
}
minecraft {
this.intermediaryUrl = JavaFunction {
"https://dl.bintray.com/legacy-fabric/Legacy-Fabric-Maven/net/fabricmc/intermediary/" + it + "/intermediary-" + it + "-v2.jar";
}
}
license {

View File

@ -31,15 +31,13 @@ import com.github.creeper123123321.viafabric.platform.VRLoader;
import com.github.creeper123123321.viafabric.platform.VRPlatform;
import com.github.creeper123123321.viafabric.util.JLoggerToLog4j;
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 io.netty.channel.local.LocalEventLoopGroup;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
import net.fabricmc.fabric.api.event.server.ServerStartCallback;
import net.fabricmc.fabric.api.event.server.ServerStopCallback;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.server.command.CommandSource;
import net.minecraft.server.MinecraftServer;
import org.apache.logging.log4j.LogManager;
import us.myles.ViaVersion.ViaManager;
import us.myles.ViaVersion.api.Via;
@ -55,11 +53,12 @@ public class ViaFabric implements ModInitializer {
public static final ExecutorService ASYNC_EXECUTOR;
public static final EventLoop EVENT_LOOP;
public static VRConfig config;
public static MinecraftServer server;
static {
ThreadFactory factory = new ThreadFactoryBuilder().setNameFormat("ViaFabric-%d").build();
ASYNC_EXECUTOR = Executors.newFixedThreadPool(8, factory);
EVENT_LOOP = new DefaultEventLoop(factory);
EVENT_LOOP = new LocalEventLoopGroup(1, factory).next(); // ugly code
}
public static String getVersion() {
@ -67,17 +66,6 @@ public class ViaFabric implements ModInitializer {
.get().getMetadata().getVersion().getFriendlyString();
}
public static <S extends CommandSource> LiteralArgumentBuilder<S> command(String commandName) {
return LiteralArgumentBuilder.<S>literal(commandName)
.then(
RequiredArgumentBuilder
.<S, String>argument("args", StringArgumentType.greedyString())
.executes(((VRCommandHandler) Via.getManager().getCommandHandler())::execute)
.suggests(((VRCommandHandler) Via.getManager().getCommandHandler())::suggestion)
)
.executes(((VRCommandHandler) Via.getManager().getCommandHandler())::execute);
}
@Override
public void onInitialize() {
Via.init(ViaManager.builder()
@ -92,9 +80,11 @@ public class ViaFabric implements ModInitializer {
FabricLoader.getInstance().getEntrypoints("viafabric:via_api_initialized", Runnable.class).forEach(Runnable::run);
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")));
ServerStartCallback.EVENT.register(it -> server = it);
ServerStopCallback.EVENT.register(it -> server = it);
//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")));
config = new VRConfig(FabricLoader.getInstance().getConfigDirectory().toPath().resolve("ViaFabric")
.resolve("viafabric.yml").toFile());

View File

@ -24,14 +24,47 @@
package com.github.creeper123123321.viafabric.commands;
import com.github.creeper123123321.viafabric.ViaFabric;
import com.mojang.brigadier.CommandDispatcher;
import io.github.cottonmc.clientcommands.ClientCommandPlugin;
import io.github.cottonmc.clientcommands.CottonClientCommandSource;
import net.minecraft.command.AbstractCommand;
import net.minecraft.command.CommandSource;
import net.minecraft.util.math.BlockPos;
import java.util.Arrays;
import java.util.List;
public class NMSCommandImpl extends AbstractCommand {
private VRCommandHandler handler;
public NMSCommandImpl(VRCommandHandler handler) {
this.handler = handler;
}
public class VRClientCommands implements ClientCommandPlugin {
@Override
public void registerCommands(CommandDispatcher<CottonClientCommandSource> commandDispatcher) {
commandDispatcher.register(ViaFabric.command("viafabricclient"));
public String getName() {
return "viaversion";
}
@Override
public List<String> method_5887() {
return Arrays.asList("vvfabric", "viaver");
}
@Override
public String getUsageTranslationKey(CommandSource commandSource) {
return "/viaversion help";
}
@Override
public void method_5885(CommandSource commandSource, String[] strings) {
handler.onCommand(new NMSCommandSender(commandSource), strings);
}
@Override
public List<String> method_5886(CommandSource commandSource, String[] strings, BlockPos blockPos) {
return handler.onTabComplete(new NMSCommandSender(commandSource), strings);
}
@Override
public int getPermissionLevel() {
return 3;
}
}

View File

@ -24,11 +24,8 @@
package com.github.creeper123123321.viafabric.commands;
import io.github.cottonmc.clientcommands.CottonClientCommandSource;
import net.minecraft.client.MinecraftClient;
import net.minecraft.command.CommandSource;
import net.minecraft.entity.Entity;
import net.minecraft.server.command.CommandSource;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.text.Text;
import us.myles.ViaVersion.api.command.ViaCommandSender;
import us.myles.viaversion.libs.bungeecordchat.api.chat.TextComponent;
@ -46,16 +43,12 @@ public class NMSCommandSender implements ViaCommandSender {
@Override
public boolean hasPermission(String s) {
// https://gaming.stackexchange.com/questions/138602/what-does-op-permission-level-do
return source.hasPermissionLevel(3);
return source.method_6255(3, "viaversion.admin"); // the string seems to be the command
}
@Override
public void sendMessage(String s) {
if (source instanceof ServerCommandSource) {
((ServerCommandSource) source).sendFeedback(Text.Serializer.fromJson(legacyToJson(s)), false);
} else if (source instanceof CottonClientCommandSource) {
((CottonClientCommandSource) source).sendFeedback(Text.Serializer.fromJson(legacyToJson(s)), false);
}
source.sendMessage(Text.Serializer.deserialize(legacyToJson(s)));
}
private String legacyToJson(String legacy) {
@ -64,21 +57,16 @@ public class NMSCommandSender implements ViaCommandSender {
@Override
public UUID getUUID() {
if (source instanceof ServerCommandSource) {
Entity entity = ((ServerCommandSource) source).getEntity();
if (entity != null) return entity.getUuid();
} else if (source instanceof CottonClientCommandSource) {
return MinecraftClient.getInstance().player.getUuid();
if (source instanceof Entity) {
return ((Entity) source).getUuid();
}
return UUID.fromString(getName());
}
@Override
public String getName() {
if (source instanceof ServerCommandSource) {
return ((ServerCommandSource) source).getName();
} else if (source instanceof CottonClientCommandSource) {
return MinecraftClient.getInstance().player.getEntityName();
if (source instanceof Entity) {
return source.getName().asString();
}
return "?";
}

View File

@ -25,15 +25,8 @@
package com.github.creeper123123321.viafabric.commands;
import com.github.creeper123123321.viafabric.commands.subs.LeakDetectSubCommand;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import net.minecraft.server.command.CommandSource;
import us.myles.ViaVersion.commands.ViaCommandHandler;
import java.util.concurrent.CompletableFuture;
public class VRCommandHandler extends ViaCommandHandler {
{
try {
@ -42,38 +35,4 @@ public class VRCommandHandler extends ViaCommandHandler {
e.printStackTrace();
}
}
public int execute(CommandContext<? extends CommandSource> ctx) {
String[] args = new String[0];
try {
args = StringArgumentType.getString(ctx, "args").split(" ");
} catch (IllegalArgumentException ignored) {
}
onCommand(
new NMSCommandSender(ctx.getSource()),
args
);
return 1;
}
public CompletableFuture<Suggestions> suggestion(CommandContext<? extends CommandSource> ctx, SuggestionsBuilder builder) {
String[] args;
try {
args = StringArgumentType.getString(ctx, "args").split(" ", -1);
} catch (IllegalArgumentException ignored) {
args = new String[]{""};
}
String[] pref = args.clone();
pref[pref.length - 1] = "";
String prefix = String.join(" ", pref);
onTabComplete(new NMSCommandSender(ctx.getSource()), args)
.stream()
.map(it -> {
SuggestionsBuilder b = new SuggestionsBuilder(builder.getInput(), prefix.length() + builder.getStart());
b.suggest(it);
return b;
})
.forEach(builder::add);
return builder.buildFuture();
}
}

View File

@ -0,0 +1,75 @@
/*
* MIT License
*
* Copyright (c) 2018 creeper123123321 and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.github.creeper123123321.viafabric.gui;
import com.mojang.blaze3d.platform.GlStateManager;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.sound.SoundManager;
import net.minecraft.util.Identifier;
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;
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) {
super(id, x, y, width, height, altTxt);
this.startU = startU;
this.startV = startV;
this.offsetHoverV = offsetHoverV;
this.texturePath = texturePath;
assert textureSizeX == 256;
assert textureSizeY == 256;
this.onClick = onClick;
}
public void render(MinecraftClient client, int mouseX, int mouseY) {
// Modified copy-paste from LockButtonWidget
if (this.visible) {
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);
}
}
@Override
public void playDownSound(SoundManager soundManager) {
super.playDownSound(soundManager);
onClick.accept(this);
}
}

View File

@ -36,24 +36,23 @@ import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(ClientConnection.class)
public class MixinClientConnection {
@Redirect(
method = "exceptionCaught",
remap = false,
at = @At(
value = "INVOKE",
target = "Lorg/apache/logging/log4j/Logger;debug(Ljava/lang/String;Ljava/lang/Throwable;)V"
))
private void redirectDebug(Logger logger, String message, Throwable t) {
if ("Failed to sent packet".equals(message)) {
logger.info(message, t);
} else {
logger.debug(message, t);
}
}
//@Redirect(
// method = "exceptionCaught",
// remap = false,
// at = @At(
// value = "INVOKE",
// target = "Lorg/apache/logging/log4j/Logger;debug(Ljava/lang/String;Ljava/lang/Throwable;)V"
// ))
//private void redirectDebug(Logger logger, String message, Throwable t) {
// if ("Failed to sent packet".equals(message)) {
// logger.info(message, t);
// } else {
// logger.debug(message, t);
// }
//}
@Redirect(method = "setCompressionThreshold", at = @At(
value = "INVOKE",
remap = false,
target = "Lio/netty/channel/ChannelPipeline;addBefore(Ljava/lang/String;Ljava/lang/String;Lio/netty/channel/ChannelHandler;)Lio/netty/channel/ChannelPipeline;"
))
private ChannelPipeline decodeEncodePlacement(ChannelPipeline instance, String base, String newHandler, ChannelHandler handler) {

View File

@ -36,9 +36,9 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.protocol.ProtocolPipeline;
@Mixin(targets = "net.minecraft.server.ServerNetworkIo$1")
@Mixin(targets = "net.minecraft.server.ServerNetworkIo$4")
public class MixinServerNetworkIoChInit {
@Inject(method = "initChannel(Lio/netty/channel/Channel;)V", at = @At(value = "TAIL"), remap = false)
@Inject(method = "initChannel", at = @At(value = "TAIL"), remap = false)
private void onInitChannel(Channel channel, CallbackInfo ci) {
if (channel instanceof SocketChannel) {
UserConnection user = new UserConnection(channel);

View File

@ -37,9 +37,9 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.protocol.ProtocolPipeline;
@Mixin(targets = "net.minecraft.network.ClientConnection$1")
@Mixin(targets = "net.minecraft.network.ClientConnection$5")
public class MixinClientConnectionChInit {
@Inject(method = "initChannel(Lio/netty/channel/Channel;)V", at = @At(value = "TAIL"), remap = false)
@Inject(method = "initChannel", at = @At(value = "TAIL"), remap = false)
private void onInitChannel(Channel channel, CallbackInfo ci) {
if (channel instanceof SocketChannel) {
UserConnection user = new VRClientSideUserConnection(channel);

View File

@ -28,7 +28,7 @@ import com.github.creeper123123321.viafabric.handler.CommonTransformer;
import com.github.creeper123123321.viafabric.handler.clientside.VRDecodeHandler;
import io.netty.channel.ChannelHandler;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.hud.DebugHud;
import net.minecraft.client.gui.hud.OverlayDebug;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
@ -39,14 +39,14 @@ import us.myles.ViaVersion.protocols.base.ProtocolInfo;
import java.util.List;
@Mixin(DebugHud.class)
@Mixin(OverlayDebug.class)
public class MixinDebugHud {
@Inject(at = @At("RETURN"), method = "getLeftText")
@Inject(at = @At("RETURN"), method = "method_2505")
protected void getLeftText(CallbackInfoReturnable<List<String>> info) {
info.getReturnValue().add("[ViaFabric] Injected: " + Via.getManager().getConnections().size() + " ("
+ Via.getManager().getConnectedClients().size() + " frontend)");
@SuppressWarnings("ConstantConditions") ChannelHandler viaDecoder = ((MixinClientConnectionAccessor) MinecraftClient.getInstance().getNetworkHandler()
.getConnection()).getChannel().pipeline().get(CommonTransformer.HANDLER_DECODER_NAME);
.getClientConnection()).getChannel().pipeline().get(CommonTransformer.HANDLER_DECODER_NAME);
if (viaDecoder instanceof VRDecodeHandler) {
ProtocolInfo protocol = ((VRDecodeHandler) viaDecoder).getInfo().getProtocolInfo();
if (protocol != null) {

View File

@ -25,17 +25,16 @@
package com.github.creeper123123321.viafabric.mixin.client;
import com.github.creeper123123321.viafabric.ViaFabric;
import com.github.creeper123123321.viafabric.gui.ViaButton;
import com.github.creeper123123321.viafabric.util.VersionFormatFilter;
import net.minecraft.class_703;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.ConfirmScreen;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.multiplayer.MultiplayerScreen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.gui.widget.TextFieldWidget;
import net.minecraft.client.gui.widget.TexturedButtonWidget;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Identifier;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
@ -64,49 +63,29 @@ public abstract class MixinMultiplayerScreen extends Screen {
@Unique
private CompletableFuture<Void> latestProtocolSave;
protected MixinMultiplayerScreen(Text title, UnsupportedOperationException e) {
super(title);
protected MixinMultiplayerScreen(UnsupportedOperationException e) {
super();
throw e;
}
@Inject(method = "init", at = @At("TAIL"), remap = false)
@Inject(method = "init", at = @At("TAIL"))
private void onInit(CallbackInfo ci) {
protocolVersion = new TextFieldWidget(font, this.width / 2 + 88, 13, 65, 15, I18n.translate("gui.protocol_version_field.name"));
protocolVersion = new TextFieldWidget("viafabric client version".hashCode(),
textRenderer, this.width / 2 + 88, 13, 65, 15);
protocolVersion.setTextPredicate(new VersionFormatFilter());
protocolVersion.setChangedListener((text) -> {
protocolVersion.setSuggestion(null);
int newVersion = ViaFabric.config.getClientSideVersion();
validProtocol = true;
try {
newVersion = Integer.parseInt(text);
} catch (NumberFormatException e) {
ProtocolVersion closest = ProtocolVersion.getClosest(text);
if (closest != null) {
newVersion = closest.getId();
} else {
validProtocol = false;
List<String> completions = ProtocolVersion.getProtocols().stream()
.map(ProtocolVersion::getName)
.flatMap(str -> Stream.concat(
Arrays.stream(str.split("-")),
Arrays.stream(new String[]{str})
))
.distinct()
.filter(ver -> ver.startsWith(text))
.collect(Collectors.toList());
if (completions.size() == 1) {
protocolVersion.setSuggestion(completions.get(0).substring(text.length()));
}
}
protocolVersion.setListener(new class_703.WidgetListener() {
@Override
public void method_2596(int i, boolean bl) {
}
@Override
public void method_2594(int i, float f) {
}
@Override
public void textModified(int id, String text) {
MixinMultiplayerScreen.this.textModified(text);
}
supportedProtocol = isSupported(newVersion);
protocolVersion.setEditableColor(getTextColor());
int finalNewVersion = newVersion;
if (latestProtocolSave == null) latestProtocolSave = CompletableFuture.completedFuture(null);
latestProtocolSave = latestProtocolSave.thenRunAsync(() -> {
ViaFabric.config.setClientSideVersion(finalNewVersion);
ViaFabric.config.saveConfig();
}, ViaFabric.ASYNC_EXECUTOR);
});
int clientSideVersion = ViaFabric.config.getClientSideVersion();
@ -115,16 +94,17 @@ public abstract class MixinMultiplayerScreen extends Screen {
protocolVersion.setText(ProtocolVersion.isRegistered(clientSideVersion)
? ProtocolVersion.getProtocol(clientSideVersion).getName()
: Integer.toString(clientSideVersion));
this.children.add(protocolVersion);
textModified(protocolVersion.getText());
//this.children.add(protocolVersion);
enableClientSideViaVersion = new TexturedButtonWidget(this.width / 2 + 113, 10,
enableClientSideViaVersion = new ViaButton("via button".hashCode(),this.width / 2 + 113, 10,
40, 20, // Size
0, 0, // Start pos of texture
20, // v Hover offset
new Identifier("viafabric:textures/gui/via_button.png"),
64, 64, // Texture size
256, 256, // Texture size (1.8 is 256x256)
button -> MinecraftClient.getInstance().openScreen(new ConfirmScreen(
answer -> {
(answer, id) -> {
MinecraftClient.getInstance().openScreen(this);
if (answer) {
ViaFabric.config.setClientSideEnabled(true);
@ -133,29 +113,76 @@ public abstract class MixinMultiplayerScreen extends Screen {
enableClientSideViaVersion.visible = false;
}
},
new TranslatableText("gui.enable_client_side.question"),
new TranslatableText("gui.enable_client_side.warning"),
I18n.translate("gui.enable_client_side.question"),
I18n.translate("gui.enable_client_side.warning"),
I18n.translate("gui.enable_client_side.enable"),
I18n.translate("gui.cancel")
I18n.translate("gui.cancel"),
"via confirm".hashCode()
)),
I18n.translate("gui.enable_client_side_button"));
I18n.translate("gui.enable_client_side_button")
);
enableClientSideViaVersion.visible = !protocolVersion.isVisible();
addButton(enableClientSideViaVersion);
this.buttons.add(enableClientSideViaVersion);
}
private void textModified(String text) {
//protocolVersion.setSuggestion(null);
int newVersion = ViaFabric.config.getClientSideVersion();
validProtocol = true;
try {
newVersion = Integer.parseInt(text);
} catch (NumberFormatException e) {
ProtocolVersion closest = ProtocolVersion.getClosest(text);
if (closest != null) {
newVersion = closest.getId();
} else {
validProtocol = false;
List<String> completions = ProtocolVersion.getProtocols().stream()
.map(ProtocolVersion::getName)
.flatMap(str -> Stream.concat(
Arrays.stream(str.split("-")),
Arrays.stream(new String[]{str})
))
.distinct()
.filter(ver -> ver.startsWith(text))
.collect(Collectors.toList());
//if (completions.size() == 1) {
// protocolVersion.setSuggestion(completions.get(0).substring(text.length()));
//}
}
}
supportedProtocol = isSupported(newVersion);
protocolVersion.setEditableColor(getTextColor());
int finalNewVersion = newVersion;
if (latestProtocolSave == null) latestProtocolSave = CompletableFuture.completedFuture(null);
latestProtocolSave = latestProtocolSave.thenRunAsync(() -> {
ViaFabric.config.setClientSideVersion(finalNewVersion);
ViaFabric.config.saveConfig();
}, ViaFabric.ASYNC_EXECUTOR);
}
@Inject(method = "render", at = {
@At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/Screen;render(IIF)V"),
@At(value = "INVOKE", target = "Lnet/minecraft/class_437;render(IIF)V") // todo check if refmap was fixed
}, remap = false)
})
private void onRender(int int_1, int int_2, float float_1, CallbackInfo ci) {
protocolVersion.render(int_1, int_2, float_1);
protocolVersion.render();
}
@Inject(method = "tick", at = @At("TAIL"), remap = false)
@Inject(method = "keyPressed", at = {@At("TAIL")})
private void onKey(char character, int code, CallbackInfo ci) {
protocolVersion.keyPressed(character, code);
}
@Inject(method = "tick", at = @At("TAIL"))
private void onTick(CallbackInfo ci) {
protocolVersion.tick();
}
@Inject(method = "mouseClicked", at = @At("TAIL"))
private void onMouseClicked(int mouseX, int mouseY, int button, CallbackInfo ci) {
protocolVersion.mouseClicked(mouseX, mouseY, button);
}
@Unique
private int getTextColor() {
if (!validProtocol) {
@ -171,4 +198,5 @@ public abstract class MixinMultiplayerScreen extends Screen {
return ProtocolRegistry.getProtocolPath(ProtocolRegistry.SERVER_PROTOCOL, protocol) != null
|| ProtocolRegistry.SERVER_PROTOCOL == protocol;
}
}

View File

@ -26,8 +26,10 @@ package com.github.creeper123123321.viafabric.platform;
import com.github.creeper123123321.viafabric.handler.CommonTransformer;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.SharedConstants;
import net.minecraft.realms.RealmsSharedConstants;
import net.minecraft.server.MinecraftServer;
import us.myles.ViaVersion.api.platform.ViaInjector;
import us.myles.ViaVersion.util.GsonUtil;
import us.myles.viaversion.libs.gson.JsonObject;
@ -47,8 +49,16 @@ public class VRInjector implements ViaInjector {
}
@Override
public int getServerProtocolVersion() {
return SharedConstants.getGameVersion().getProtocolVersion();
public int getServerProtocolVersion() throws NoSuchFieldException, IllegalAccessException {
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
return getClientProtocol();
}
return MinecraftServer.getServer().getServerMetadata().getVersion().getProtocolVersion();
}
@Environment(EnvType.CLIENT)
private int getClientProtocol() throws NoSuchFieldException, IllegalAccessException {
return RealmsSharedConstants.class.getField("NETWORK_PROTOCOL_VERSION").getInt(null);
}
@Override

View File

@ -32,14 +32,10 @@ import com.github.creeper123123321.viafabric.util.JLoggerToLog4j;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GenericFutureListener;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.ModContainer;
import net.minecraft.client.MinecraftClient;
import net.minecraft.entity.Entity;
import net.minecraft.network.MessageType;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import org.apache.logging.log4j.LogManager;
import us.myles.ViaVersion.api.Via;
@ -62,6 +58,7 @@ import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.Callable;
import java.util.concurrent.CancellationException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
@ -86,15 +83,9 @@ public class VRPlatform implements ViaPlatform<UUID> {
}
public static MinecraftServer getServer() {
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
return getIntegratedServer();
}
return (MinecraftServer) FabricLoader.getInstance().getGameInstance();
}
@Environment(EnvType.CLIENT)
private static MinecraftServer getIntegratedServer() {
return MinecraftClient.getInstance().getServer();
// In 1.8.9 integrated server instance exists even if it's not running
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.SERVER) return MinecraftServer.getServer();
return ViaFabric.server;
}
@Override
@ -146,7 +137,10 @@ public class VRPlatform implements ViaPlatform<UUID> {
private TaskId runServerSync(Runnable runnable) {
// Kick task needs to be on main thread, it does already have error logger
return new FutureTaskId(CompletableFuture.runAsync(runnable, getServer()));
return new FutureTaskId(CompletableFuture.runAsync(runnable, it -> getServer().method_6444((Callable<Void>) () -> {
it.run();
return null;
})));
}
private TaskId runEventLoop(Runnable runnable) {
@ -204,8 +198,7 @@ public class VRPlatform implements ViaPlatform<UUID> {
}
private ViaCommandSender[] getServerPlayers() {
return getServer().getPlayerManager().getPlayerList().stream()
.map(Entity::getCommandSource)
return getServer().getPlayerManager().getPlayers().stream()
.map(NMSCommandSender::new)
.toArray(ViaCommandSender[]::new);
}
@ -221,7 +214,7 @@ public class VRPlatform implements ViaPlatform<UUID> {
runServerSync(() -> {
ServerPlayerEntity player = server.getPlayerManager().getPlayer(uuid);
if (player == null) return;
player.sendChatMessage(Text.Serializer.fromJson(legacyToJson(s)), MessageType.SYSTEM);
player.sendMessage(Text.Serializer.deserialize(legacyToJson(s)));
});
}
@ -236,7 +229,7 @@ public class VRPlatform implements ViaPlatform<UUID> {
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(s);
return true;
};
if (server.isOnThread()) {

View File

@ -24,15 +24,15 @@
package com.github.creeper123123321.viafabric.util;
import com.google.common.base.Predicate;
import us.myles.ViaVersion.api.protocol.ProtocolVersion;
import java.util.Arrays;
import java.util.function.Predicate;
import java.util.stream.Stream;
public class VersionFormatFilter implements Predicate<String> {
@Override
public boolean test(String s) {
public boolean apply(String s) {
try {
Integer.parseInt(s);
return true;

View File

@ -0,0 +1,5 @@
gui.protocol_version_field.name=Protokoll Version
gui.enable_client_side_button=ViaVersion aktivieren
gui.enable_client_side.question=Bist du dir sicher, dass du den clientseitigen Modus aktivieren möchtest?
gui.enable_client_side.warning=Ich kann nicht garantieren, dass diese Mod auf jedem (oder überhaupt einem) Server erlaubt ist. Diese Mod könnte eventuell Probleme mit Anti-Cheat Plugins hervorrufen. VERWENDUNG AUF EIGENE GEFAHR.
gui.enable_client_side.enable=Aktivieren

View File

@ -1,7 +0,0 @@
{
"gui.protocol_version_field.name": "Protokoll Version",
"gui.enable_client_side_button": "ViaVersion aktivieren",
"gui.enable_client_side.question": "Bist du dir sicher, dass du den clientseitigen Modus aktivieren möchtest?",
"gui.enable_client_side.warning": "Ich kann nicht garantieren, dass diese Mod auf jedem (oder überhaupt einem) Server erlaubt ist. Diese Mod könnte eventuell Probleme mit Anti-Cheat Plugins hervorrufen. VERWENDUNG AUF EIGENE GEFAHR.",
"gui.enable_client_side.enable": "Aktivieren"
}

View File

@ -0,0 +1,5 @@
gui.protocol_version_field.name=Protocol Version
gui.enable_client_side_button=Enable ViaVersion
gui.enable_client_side.question=Are you sure you want to enable client-side mode?
gui.enable_client_side.warning=I cannot guarantee that this mod is allowed on every (or even any) server. This mod may cause problems with anti-cheat plugins. USE AT OWN RISK.
gui.enable_client_side.enable=Enable

View File

@ -1,7 +0,0 @@
{
"gui.protocol_version_field.name": "Protocol Version",
"gui.enable_client_side_button": "Enable ViaVersion",
"gui.enable_client_side.question": "Are you sure you want to enable client-side mode?",
"gui.enable_client_side.warning": "I cannot guarantee that this mod is allowed on every (or even any) server. This mod may cause problems with anti-cheat plugins. USE AT OWN RISK.",
"gui.enable_client_side.enable": "Enable"
}

View File

@ -0,0 +1,5 @@
gui.protocol_version_field.name=Wersja protokołu
gui.enable_client_side_button=Włącz ViaVersion
gui.enable_client_side.question=Jesteś pewien, że chcesz włączyć tryb client-side?
gui.enable_client_side.warning=Nie możemy zagwarantować, że ten mod jest dozwolony na każdym (lub jakimkolwiek) serwerze. Ten mod może powodować problemy z anty-cheatami. UŻYWASZ NA WŁASNE RYZYKO!.
gui.enable_client_side.enable=Włącz"

View File

@ -1,7 +0,0 @@
{
"gui.protocol_version_field.name": "Wersja protokołu",
"gui.enable_client_side_button": "Włącz ViaVersion",
"gui.enable_client_side.question": "Jesteś pewien, że chcesz włączyć tryb client-side?",
"gui.enable_client_side.warning": "Nie możemy zagwarantować, że ten mod jest dozwolony na każdym (lub jakimkolwiek) serwerze. Ten mod może powodować problemy z anty-cheatami. UŻYWASZ NA WŁASNE RYZYKO!.",
"gui.enable_client_side.enable": "Włącz"
}

View File

@ -0,0 +1,5 @@
gui.protocol_version_field.name=Versão do protocolo
gui.enable_client_side_button=Habilitar ViaVersion
gui.enable_client_side.question=Você tem certeza de que deseja habilitar o modo client-side?
gui.enable_client_side.warning=Não posso garantir que este mod seja permitido em todos os (ou mesmo em quaisquer) servidores. Esse poderá causar problemas com plugins anti-trapaça. USE POR SUA PRÓPRIA CONTA E RISCO.
gui.enable_client_side.enable=Habilitar

View File

@ -1,7 +0,0 @@
{
"gui.protocol_version_field.name": "Versão do protocolo",
"gui.enable_client_side_button": "Habilitar ViaVersion",
"gui.enable_client_side.question": "Você tem certeza de que deseja habilitar o modo client-side?",
"gui.enable_client_side.warning": "Não posso garantir que este mod seja permitido em todos os (ou mesmo em quaisquer) servidores. Esse poderá causar problemas com plugins anti-trapaça. USE POR SUA PRÓPRIA CONTA E RISCO.",
"gui.enable_client_side.enable": "Habilitar"
}

View File

@ -0,0 +1,5 @@
gui.protocol_version_field.name=协议版本
gui.enable_client_side_button=启用 ViaVersion
gui.enable_client_side.question=您确定要启用客户端模式?
gui.enable_client_side.warning=我无法保证所有(甚至任何一个)服务器允许您使用这个 mod。这个 mod 可能被反作弊插件作出误判。使用后果自负。
gui.enable_client_side.enable=启用

View File

@ -1,7 +0,0 @@
{
"gui.protocol_version_field.name": "协议版本",
"gui.enable_client_side_button": "启用 ViaVersion",
"gui.enable_client_side.question": "您确定要启用客户端模式?",
"gui.enable_client_side.warning": "我无法保证所有(甚至任何一个)服务器允许您使用这个 mod。这个 mod 可能被反作弊插件作出误判。使用后果自负。",
"gui.enable_client_side.enable": "启用"
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.6 KiB

After

Width:  |  Height:  |  Size: 7.7 KiB

View File

@ -17,18 +17,13 @@
"entrypoints": {
"main": [
"com.github.creeper123123321.viafabric.ViaFabric"
],
"cotton-client-commands": [
"com.github.creeper123123321.viafabric.commands.VRClientCommands"
]
},
"depends": {
"cotton-client-commands": "*",
"fabricloader": ">=0.4.0",
"fabric-textures-v0": "*",
"fabric-events-lifecycle-v0": "*",
"fabric-resource-loader-v0": "*",
"fabric-command-api-v1": "*",
"minecraft": "<1.16",
"minecraft": "<1.13",
"viaversion": ">3.0.1"
},
"conflicts": {