From c92f20ee6572d2542bf1540b0b430406dbcd7068 Mon Sep 17 00:00:00 2001 From: FlorianMichael <60033407+FlorianMichael@users.noreply.github.com> Date: Mon, 30 Jan 2023 21:04:47 +0100 Subject: [PATCH] updated to new API --- gradle.properties | 8 +-- mc1122/build.gradle | 2 +- .../viaforge/GuiProtocolSelector.java | 24 +++----- .../de/florianmichael/viaforge/ViaForge.java | 61 +++---------------- ...iServerList.java => MixinGuiMainMenu.java} | 6 +- .../mixin/impl/MixinGuiMultiplayer.java | 26 ++++++++ .../mixin/impl/MixinGuiScreenServerList.java | 26 ++++++++ .../mixin/impl/MixinNetworkManager.java | 2 +- .../mixin/impl/MixinNetworkManagerSub5.java | 10 +-- .../src/main/resources/mixins.viaforge.json | 10 +-- 10 files changed, 90 insertions(+), 85 deletions(-) rename mc1122/src/main/java/de/florianmichael/viaforge/mixin/impl/{MixinGuiMainMenuGuiMultiplayerGuiServerList.java => MixinGuiMainMenu.java} (82%) create mode 100644 mc1122/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinGuiMultiplayer.java create mode 100644 mc1122/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinGuiScreenServerList.java diff --git a/gradle.properties b/gradle.properties index 6866490..e15030f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,7 +12,7 @@ mod_base_package=de.enzaxd mixin_version=0.8.3 # via-version -viaprotocolhack_version=ba5dcf9ce6 -viaversion_version=4.5.2-SNAPSHOT -viabackwards_version=4.5.2-SNAPSHOT -viarewind_version=2.0.2-SNAPSHOT +vialoadingbase_version=ad5fd83ad1 +viaversion_version=4.6.0-23w04a-SNAPSHOT +viabackwards_version=4.6.0-23w03a-SNAPSHOT +viarewind_version=2.0.3-SNAPSHOT diff --git a/mc1122/build.gradle b/mc1122/build.gradle index 0076b6c..5512b7a 100644 --- a/mc1122/build.gradle +++ b/mc1122/build.gradle @@ -92,7 +92,7 @@ def viaLibs = [ "com.viaversion:viarewind-core:${project.viarewind_version}", "org.yaml:snakeyaml:1.29", - "com.github.RejectedVia:ViaProtocolHack:${project.viaprotocolhack_version}" + "com.github.FlorianMichael:ViaLoadingBase:${project.vialoadingbase_version}" ] dependencies { diff --git a/mc1122/src/main/java/de/florianmichael/viaforge/GuiProtocolSelector.java b/mc1122/src/main/java/de/florianmichael/viaforge/GuiProtocolSelector.java index 5aa7c2a..43d2767 100644 --- a/mc1122/src/main/java/de/florianmichael/viaforge/GuiProtocolSelector.java +++ b/mc1122/src/main/java/de/florianmichael/viaforge/GuiProtocolSelector.java @@ -2,7 +2,8 @@ package de.florianmichael.viaforge; import com.mojang.realmsclient.gui.ChatFormatting; import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; -import de.florianmichael.viaprotocolhack.util.VersionList; +import de.florianmichael.vialoadingbase.ViaLoadingBase; +import de.florianmichael.vialoadingbase.api.version.InternalProtocolList; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; @@ -13,9 +14,8 @@ import java.io.IOException; public class GuiProtocolSelector extends GuiScreen { - public SlotList list; - - private GuiScreen parent; + private final GuiScreen parent; + private SlotList list; public GuiProtocolSelector(GuiScreen parent) { this.parent = parent; @@ -24,9 +24,7 @@ public class GuiProtocolSelector extends GuiScreen { @Override public void initGui() { super.initGui(); - buttonList.add(new GuiButton(1, width / 2 - 100, height - 27, 200, - 20, "Back")); - + buttonList.add(new GuiButton(1, width / 2 - 100, height - 27, 200, 20, "Back")); list = new SlotList(mc, width, height, 32, height - 32, 10); } @@ -34,8 +32,7 @@ public class GuiProtocolSelector extends GuiScreen { protected void actionPerformed(GuiButton p_actionPerformed_1_) throws IOException { list.actionPerformed(p_actionPerformed_1_); - if (p_actionPerformed_1_.id == 1) - mc.displayGuiScreen(parent); + if (p_actionPerformed_1_.id == 1) mc.displayGuiScreen(parent); } @Override @@ -61,19 +58,18 @@ public class GuiProtocolSelector extends GuiScreen { class SlotList extends GuiSlot { - public SlotList(Minecraft p_i1052_1_, int p_i1052_2_, int p_i1052_3_, int p_i1052_4_, int p_i1052_5_, int p_i1052_6_) { super(p_i1052_1_, p_i1052_2_, p_i1052_3_, p_i1052_4_, p_i1052_5_, p_i1052_6_); } @Override protected int getSize() { - return VersionList.getProtocols().size(); + return InternalProtocolList.getProtocols().size(); } @Override protected void elementClicked(int i, boolean b, int i1, int i2) { - ViaForge.targetVersion = VersionList.getProtocols().get(i).getVersion(); + ViaLoadingBase.getClassWrapper().reload(InternalProtocolList.getProtocols().get(i)); } @Override @@ -88,9 +84,9 @@ public class GuiProtocolSelector extends GuiScreen { @Override protected void drawSlot(int i, int i1, int i2, int i3, int i4, int i5, float v) { - final ProtocolVersion version = VersionList.getProtocols().get(i); + final ProtocolVersion version = InternalProtocolList.getProtocols().get(i); - drawCenteredString(mc.fontRenderer,(ViaForge.targetVersion == version.getVersion() ? ChatFormatting.GREEN.toString() : ChatFormatting.DARK_RED.toString()) + version.getName(), width / 2, i2, -1); + drawCenteredString(mc.fontRenderer,(ViaLoadingBase.getTargetVersion().getVersion() == version.getVersion() ? ChatFormatting.GREEN.toString() : ChatFormatting.DARK_RED.toString()) + version.getName(), width / 2, i2, -1); } } } diff --git a/mc1122/src/main/java/de/florianmichael/viaforge/ViaForge.java b/mc1122/src/main/java/de/florianmichael/viaforge/ViaForge.java index 8a2a975..37eefab 100644 --- a/mc1122/src/main/java/de/florianmichael/viaforge/ViaForge.java +++ b/mc1122/src/main/java/de/florianmichael/viaforge/ViaForge.java @@ -1,64 +1,23 @@ package de.florianmichael.viaforge; -import com.viaversion.viaversion.libs.gson.JsonObject; -import de.florianmichael.viaprotocolhack.INativeProvider; -import de.florianmichael.viaprotocolhack.ViaProtocolHack; +import de.florianmichael.vialoadingbase.ViaLoadingBase; import io.netty.channel.DefaultEventLoop; -import io.netty.channel.EventLoop; import net.minecraft.client.Minecraft; import net.minecraft.realms.RealmsSharedConstants; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; -import java.io.File; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.ThreadFactory; - -@Mod(modid = "viaforge", name = "ViaForge", version = "1.0.0") -public class ViaForge implements INativeProvider { - - public static int targetVersion = RealmsSharedConstants.NETWORK_PROTOCOL_VERSION; +@Mod(modid = "viaforge", name = "ViaForge", version = "3.0.0") +public class ViaForge { @Mod.EventHandler public void init(FMLPreInitializationEvent event) throws Exception { - ViaProtocolHack.instance().init(this, () -> System.out.println("ViaProtocolHack loaded successfully")); - } - - @Override - public boolean isSinglePlayer() { - return Minecraft.getMinecraft().isSingleplayer(); - } - - @Override - public int nativeVersion() { - return RealmsSharedConstants.NETWORK_PROTOCOL_VERSION; - } - - @Override - public int targetVersion() { - return targetVersion; - } - - @Override - public String[] nettyOrder() { - return new String[] { - "decompress", - "compress" - }; - } - - @Override - public File run() { - return Minecraft.getMinecraft().gameDir; - } - - @Override - public JsonObject createDump() { - return new JsonObject(); - } - - @Override - public EventLoop eventLoop(ThreadFactory threadFactory, ExecutorService executorService) { - return new DefaultEventLoop(executorService); + ViaLoadingBase.ViaLoadingBaseBuilder. + create(). + runDirectory(Minecraft.getMinecraft().gameDir). + nativeVersion(RealmsSharedConstants.NETWORK_PROTOCOL_VERSION). + singlePlayerProvider(() -> Minecraft.getMinecraft().isSingleplayer()). + eventLoop(new DefaultEventLoop(ViaLoadingBase.EXECUTOR_SERVICE)). + build(); } } diff --git a/mc1122/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinGuiMainMenuGuiMultiplayerGuiServerList.java b/mc1122/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinGuiMainMenu.java similarity index 82% rename from mc1122/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinGuiMainMenuGuiMultiplayerGuiServerList.java rename to mc1122/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinGuiMainMenu.java index 22bdf39..d759a72 100644 --- a/mc1122/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinGuiMainMenuGuiMultiplayerGuiServerList.java +++ b/mc1122/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinGuiMainMenu.java @@ -7,10 +7,8 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -@Mixin(value = { - GuiMainMenu.class, GuiMultiplayer.class, GuiScreenServerList.class -}) -public class MixinGuiMainMenuGuiMultiplayerGuiServerList extends GuiScreen { +@Mixin(GuiMainMenu.class) +public class MixinGuiMainMenu extends GuiScreen { @Inject(method = "initGui", at = @At("RETURN")) public void hookCustomButton(CallbackInfo ci) { diff --git a/mc1122/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinGuiMultiplayer.java b/mc1122/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinGuiMultiplayer.java new file mode 100644 index 0000000..ddbdc68 --- /dev/null +++ b/mc1122/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinGuiMultiplayer.java @@ -0,0 +1,26 @@ +package de.florianmichael.viaforge.mixin.impl; + +import de.florianmichael.viaforge.GuiProtocolSelector; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiMultiplayer; +import net.minecraft.client.gui.GuiScreen; +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.CallbackInfo; + +@Mixin(GuiMultiplayer.class) +public class MixinGuiMultiplayer extends GuiScreen { + + @Inject(method = "initGui", at = @At("RETURN")) + public void hookCustomButton(CallbackInfo ci) { + buttonList.add(new GuiButton(1337, 5, 6, 98, 20, "ViaForge")); + } + + @Inject(method = "actionPerformed", at = @At("RETURN")) + public void handleCustomButtonAction(GuiButton p_actionPerformed_1_, CallbackInfo ci) { + if (p_actionPerformed_1_.id == 1337) { + mc.displayGuiScreen(new GuiProtocolSelector(this)); + } + } +} diff --git a/mc1122/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinGuiScreenServerList.java b/mc1122/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinGuiScreenServerList.java new file mode 100644 index 0000000..e8c4d3c --- /dev/null +++ b/mc1122/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinGuiScreenServerList.java @@ -0,0 +1,26 @@ +package de.florianmichael.viaforge.mixin.impl; + +import de.florianmichael.viaforge.GuiProtocolSelector; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.gui.GuiScreenServerList; +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.CallbackInfo; + +@Mixin(GuiScreenServerList.class) +public class MixinGuiScreenServerList extends GuiScreen { + + @Inject(method = "initGui", at = @At("RETURN")) + public void hookCustomButton(CallbackInfo ci) { + buttonList.add(new GuiButton(1337, 5, 6, 98, 20, "ViaForge")); + } + + @Inject(method = "actionPerformed", at = @At("RETURN")) + public void handleCustomButtonAction(GuiButton p_actionPerformed_1_, CallbackInfo ci) { + if (p_actionPerformed_1_.id == 1337) { + mc.displayGuiScreen(new GuiProtocolSelector(this)); + } + } +} diff --git a/mc1122/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinNetworkManager.java b/mc1122/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinNetworkManager.java index cc21fda..a19d0e4 100644 --- a/mc1122/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinNetworkManager.java +++ b/mc1122/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinNetworkManager.java @@ -1,6 +1,6 @@ package de.florianmichael.viaforge.mixin.impl; -import de.florianmichael.viaprotocolhack.event.PipelineReorderEvent; +import de.florianmichael.vialoadingbase.event.PipelineReorderEvent; import io.netty.channel.Channel; import net.minecraft.network.NetworkManager; import org.spongepowered.asm.mixin.Mixin; diff --git a/mc1122/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinNetworkManagerSub5.java b/mc1122/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinNetworkManagerSub5.java index 80c0dcc..904a7fc 100644 --- a/mc1122/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinNetworkManagerSub5.java +++ b/mc1122/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinNetworkManagerSub5.java @@ -3,10 +3,10 @@ package de.florianmichael.viaforge.mixin.impl; import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.connection.UserConnectionImpl; import com.viaversion.viaversion.protocol.ProtocolPipelineImpl; -import de.florianmichael.viaforge.ViaForge; -import de.florianmichael.viaprotocolhack.netty.CustomViaDecodeHandler; -import de.florianmichael.viaprotocolhack.netty.CustomViaEncodeHandler; -import de.florianmichael.viaprotocolhack.netty.NettyConstants; +import de.florianmichael.vialoadingbase.ViaLoadingBase; +import de.florianmichael.vialoadingbase.netty.CustomViaDecodeHandler; +import de.florianmichael.vialoadingbase.netty.CustomViaEncodeHandler; +import de.florianmichael.vialoadingbase.netty.NettyConstants; import io.netty.channel.Channel; import io.netty.channel.socket.SocketChannel; import net.minecraft.realms.RealmsSharedConstants; @@ -20,7 +20,7 @@ public class MixinNetworkManagerSub5 { @Inject(method = "initChannel", at = @At(value = "TAIL"), remap = false) private void onInitChannel(Channel channel, CallbackInfo ci) { - if (channel instanceof SocketChannel && ViaForge.targetVersion != RealmsSharedConstants.NETWORK_PROTOCOL_VERSION) { + if (channel instanceof SocketChannel && ViaLoadingBase.getTargetVersion().getVersion() != RealmsSharedConstants.NETWORK_PROTOCOL_VERSION) { UserConnection user = new UserConnectionImpl(channel, true); new ProtocolPipelineImpl(user); diff --git a/mc1122/src/main/resources/mixins.viaforge.json b/mc1122/src/main/resources/mixins.viaforge.json index 5e200e2..9ce6619 100644 --- a/mc1122/src/main/resources/mixins.viaforge.json +++ b/mc1122/src/main/resources/mixins.viaforge.json @@ -6,10 +6,10 @@ "refmap": "mixins.viaforge.refmap.json", "mixins": [ "MixinNetworkManager", - "MixinNetworkManagerSub5" + "MixinNetworkManagerSub5", + "MixinGuiMainMenu", + "MixinGuiMultiplayer", + "MixinGuiScreenServerList" ], - "verbose": true, - "client": [ - "MixinGuiMainMenuGuiMultiplayerGuiServerList" - ] + "verbose": true }