diff --git a/README.md b/README.md index 15469af..0a14ffb 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Note: ViaVersion is not designed for modded Minecraft with registry synchronizat **Dependencies:** | Dependency | Download | | --------------------------------- | --------------------------------------------------------------------- | -| ViaVersion 3.0.0+ | https://viaversion.com/ | +| ViaVersion 3.0.2+ | dev build 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 | diff --git a/build.gradle.kts b/build.gradle.kts index da0804e..03304d8 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -9,7 +9,7 @@ plugins { group = "com.github.creeper123123321.viafabric" val gitVersion: groovy.lang.Closure by extra -version = "0.2.3-SNAPSHOT+" + try { +version = "0.2.4-SNAPSHOT+" + try { gitVersion() } catch (e: Exception) { "unknown" @@ -47,7 +47,7 @@ tasks.named("processResources") { dependencies { // transitive = false because Guava is conflicting on runClient - implementation("us.myles:viaversion:3.0.1-SNAPSHOT") { isTransitive = false } + implementation("us.myles:viaversion:3.0.2-SNAPSHOT") { isTransitive = false } // Use 1.16 snapshot, probably intermediary will make it work on further versions // https://modmuss50.me/fabric.html?&version=1.16 diff --git a/src/main/java/com/github/creeper123123321/viafabric/commands/UserCommandSender.java b/src/main/java/com/github/creeper123123321/viafabric/commands/UserCommandSender.java index c1ab190..d687344 100644 --- a/src/main/java/com/github/creeper123123321/viafabric/commands/UserCommandSender.java +++ b/src/main/java/com/github/creeper123123321/viafabric/commands/UserCommandSender.java @@ -27,7 +27,6 @@ package com.github.creeper123123321.viafabric.commands; import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.command.ViaCommandSender; import us.myles.ViaVersion.api.data.UserConnection; -import us.myles.ViaVersion.protocols.base.ProtocolInfo; import java.util.UUID; @@ -50,11 +49,11 @@ public class UserCommandSender implements ViaCommandSender { @Override public UUID getUUID() { - return con.get(ProtocolInfo.class).getUuid(); + return con.getProtocolInfo().getUuid(); } @Override public String getName() { - return con.get(ProtocolInfo.class).getUsername(); + return con.getProtocolInfo().getUsername(); } } diff --git a/src/main/java/com/github/creeper123123321/viafabric/handler/clientside/VRDecodeHandler.java b/src/main/java/com/github/creeper123123321/viafabric/handler/clientside/VRDecodeHandler.java index ab6c07f..2800d9b 100644 --- a/src/main/java/com/github/creeper123123321/viafabric/handler/clientside/VRDecodeHandler.java +++ b/src/main/java/com/github/creeper123123321/viafabric/handler/clientside/VRDecodeHandler.java @@ -62,4 +62,8 @@ public class VRDecodeHandler extends MessageToMessageDecoder { if (cause instanceof CancelCodecException) return; super.exceptionCaught(ctx, cause); } + + public UserConnection getInfo() { + return info; + } } diff --git a/src/main/java/com/github/creeper123123321/viafabric/mixin/client/MixinClientConnectionAccessor.java b/src/main/java/com/github/creeper123123321/viafabric/mixin/client/MixinClientConnectionAccessor.java new file mode 100644 index 0000000..cf11107 --- /dev/null +++ b/src/main/java/com/github/creeper123123321/viafabric/mixin/client/MixinClientConnectionAccessor.java @@ -0,0 +1,36 @@ +/* + * 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.mixin.client; + +import io.netty.channel.Channel; +import net.minecraft.network.ClientConnection; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +@Mixin(ClientConnection.class) +public interface MixinClientConnectionAccessor { + @Accessor + Channel getChannel(); +} diff --git a/src/main/java/com/github/creeper123123321/viafabric/mixin/client/MixinDebugHud.java b/src/main/java/com/github/creeper123123321/viafabric/mixin/client/MixinDebugHud.java new file mode 100644 index 0000000..cba0057 --- /dev/null +++ b/src/main/java/com/github/creeper123123321/viafabric/mixin/client/MixinDebugHud.java @@ -0,0 +1,62 @@ +/* + * 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.mixin.client; + +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 org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import us.myles.ViaVersion.api.Via; +import us.myles.ViaVersion.api.protocol.ProtocolVersion; +import us.myles.ViaVersion.protocols.base.ProtocolInfo; + +import java.util.List; + +@Mixin(DebugHud.class) +public class MixinDebugHud { + @Inject(at = @At("RETURN"), method = "getLeftText") + protected void getLeftText(CallbackInfoReturnable> info) { + info.getReturnValue().add("[ViaFabric] " + Via.getManager().getConnections().size() + " injected (" + + Via.getManager().getConnectedClients().size() + " frontend)"); + ChannelHandler viaDecoder = ((MixinClientConnectionAccessor) MinecraftClient.getInstance().getNetworkHandler() + .getConnection()).getChannel().pipeline().get(CommonTransformer.HANDLER_DECODER_NAME); + if (viaDecoder instanceof VRDecodeHandler) { + ProtocolInfo protocol = ((VRDecodeHandler) viaDecoder).getInfo().getProtocolInfo(); + if (protocol != null) { + ProtocolVersion serverVer = ProtocolVersion.getProtocol(protocol.getServerProtocolVersion()); + String inactive = ""; + if (!protocol.getUser().isActive()) { + inactive = " (inactive)"; + } + info.getReturnValue().add("[ViaFabric] Client injected" + inactive + ": server is " + serverVer); + } + } + } +} diff --git a/src/main/java/com/github/creeper123123321/viafabric/platform/VRConnectionManager.java b/src/main/java/com/github/creeper123123321/viafabric/platform/VRConnectionManager.java index 0fffbba..08e3a0b 100644 --- a/src/main/java/com/github/creeper123123321/viafabric/platform/VRConnectionManager.java +++ b/src/main/java/com/github/creeper123123321/viafabric/platform/VRConnectionManager.java @@ -29,20 +29,7 @@ import us.myles.ViaVersion.api.platform.ViaConnectionManager; public class VRConnectionManager extends ViaConnectionManager { @Override - public void onLoginSuccess(UserConnection connection) { - if (connection instanceof VRClientSideUserConnection) { - this.connections.add(connection); - } else { - super.onLoginSuccess(connection); - } - } - - @Override - public void onDisconnect(UserConnection connection) { - if (connection instanceof VRClientSideUserConnection) { - this.connections.remove(connection); - } else { - super.onDisconnect(connection); - } + public boolean isFrontEnd(UserConnection connection) { + return !(connection instanceof VRClientSideUserConnection); } } diff --git a/src/main/java/com/github/creeper123123321/viafabric/platform/VRViaAPI.java b/src/main/java/com/github/creeper123123321/viafabric/platform/VRViaAPI.java index 34759f0..64f1acc 100644 --- a/src/main/java/com/github/creeper123123321/viafabric/platform/VRViaAPI.java +++ b/src/main/java/com/github/creeper123123321/viafabric/platform/VRViaAPI.java @@ -32,7 +32,6 @@ import us.myles.ViaVersion.api.boss.BossColor; import us.myles.ViaVersion.api.boss.BossStyle; import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.protocol.ProtocolRegistry; -import us.myles.ViaVersion.protocols.base.ProtocolInfo; import java.util.SortedSet; import java.util.TreeSet; @@ -43,7 +42,7 @@ public class VRViaAPI implements ViaAPI { public int getPlayerVersion(UUID uuid) { UserConnection con = Via.getManager().getConnection(uuid); if (con != null) { - return con.get(ProtocolInfo.class).getProtocolVersion(); + return con.getProtocolInfo().getProtocolVersion(); } try { return Via.getManager().getInjector().getServerProtocolVersion(); diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 6bedf7c..0fa77b6 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -29,7 +29,7 @@ "fabric-resource-loader-v0": "*", "fabric-command-api-v1": "*", "minecraft": ">1.15.2", - "viaversion": ">=3.0.0-SNAPSHOT" + "viaversion": ">=3.0.2-SNAPSHOT" }, "conflicts": { "fabric-registry-sync": "*" diff --git a/src/main/resources/mixins.viafabric.json b/src/main/resources/mixins.viafabric.json index 7c47f6a..b104f0a 100644 --- a/src/main/resources/mixins.viafabric.json +++ b/src/main/resources/mixins.viafabric.json @@ -7,7 +7,9 @@ "MixinServerNetworkIoChInit" ], "client": [ + "client.MixinClientConnectionAccessor", "client.MixinClientConnectionChInit", + "client.MixinDebugHud", "client.MixinMultiplayerScreen" ], "injectors": {