updated to new API

This commit is contained in:
FlorianMichael 2023-01-30 21:04:47 +01:00
parent 1cffc9c3b9
commit c92f20ee65
10 changed files with 90 additions and 85 deletions

View File

@ -12,7 +12,7 @@ mod_base_package=de.enzaxd
mixin_version=0.8.3 mixin_version=0.8.3
# via-version # via-version
viaprotocolhack_version=ba5dcf9ce6 vialoadingbase_version=ad5fd83ad1
viaversion_version=4.5.2-SNAPSHOT viaversion_version=4.6.0-23w04a-SNAPSHOT
viabackwards_version=4.5.2-SNAPSHOT viabackwards_version=4.6.0-23w03a-SNAPSHOT
viarewind_version=2.0.2-SNAPSHOT viarewind_version=2.0.3-SNAPSHOT

View File

@ -92,7 +92,7 @@ def viaLibs = [
"com.viaversion:viarewind-core:${project.viarewind_version}", "com.viaversion:viarewind-core:${project.viarewind_version}",
"org.yaml:snakeyaml:1.29", "org.yaml:snakeyaml:1.29",
"com.github.RejectedVia:ViaProtocolHack:${project.viaprotocolhack_version}" "com.github.FlorianMichael:ViaLoadingBase:${project.vialoadingbase_version}"
] ]
dependencies { dependencies {

View File

@ -2,7 +2,8 @@ package de.florianmichael.viaforge;
import com.mojang.realmsclient.gui.ChatFormatting; import com.mojang.realmsclient.gui.ChatFormatting;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; 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.Minecraft;
import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.GuiScreen;
@ -13,9 +14,8 @@ import java.io.IOException;
public class GuiProtocolSelector extends GuiScreen { public class GuiProtocolSelector extends GuiScreen {
public SlotList list; private final GuiScreen parent;
private SlotList list;
private GuiScreen parent;
public GuiProtocolSelector(GuiScreen parent) { public GuiProtocolSelector(GuiScreen parent) {
this.parent = parent; this.parent = parent;
@ -24,9 +24,7 @@ public class GuiProtocolSelector extends GuiScreen {
@Override @Override
public void initGui() { public void initGui() {
super.initGui(); super.initGui();
buttonList.add(new GuiButton(1, width / 2 - 100, height - 27, 200, buttonList.add(new GuiButton(1, width / 2 - 100, height - 27, 200, 20, "Back"));
20, "Back"));
list = new SlotList(mc, width, height, 32, height - 32, 10); 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 { protected void actionPerformed(GuiButton p_actionPerformed_1_) throws IOException {
list.actionPerformed(p_actionPerformed_1_); list.actionPerformed(p_actionPerformed_1_);
if (p_actionPerformed_1_.id == 1) if (p_actionPerformed_1_.id == 1) mc.displayGuiScreen(parent);
mc.displayGuiScreen(parent);
} }
@Override @Override
@ -61,19 +58,18 @@ public class GuiProtocolSelector extends GuiScreen {
class SlotList extends GuiSlot { 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_) { 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_); super(p_i1052_1_, p_i1052_2_, p_i1052_3_, p_i1052_4_, p_i1052_5_, p_i1052_6_);
} }
@Override @Override
protected int getSize() { protected int getSize() {
return VersionList.getProtocols().size(); return InternalProtocolList.getProtocols().size();
} }
@Override @Override
protected void elementClicked(int i, boolean b, int i1, int i2) { 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 @Override
@ -88,9 +84,9 @@ public class GuiProtocolSelector extends GuiScreen {
@Override @Override
protected void drawSlot(int i, int i1, int i2, int i3, int i4, int i5, float v) { 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);
} }
} }
} }

View File

@ -1,64 +1,23 @@
package de.florianmichael.viaforge; package de.florianmichael.viaforge;
import com.viaversion.viaversion.libs.gson.JsonObject; import de.florianmichael.vialoadingbase.ViaLoadingBase;
import de.florianmichael.viaprotocolhack.INativeProvider;
import de.florianmichael.viaprotocolhack.ViaProtocolHack;
import io.netty.channel.DefaultEventLoop; import io.netty.channel.DefaultEventLoop;
import io.netty.channel.EventLoop;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.realms.RealmsSharedConstants; import net.minecraft.realms.RealmsSharedConstants;
import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import java.io.File; @Mod(modid = "viaforge", name = "ViaForge", version = "3.0.0")
import java.util.concurrent.ExecutorService; public class ViaForge {
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.EventHandler @Mod.EventHandler
public void init(FMLPreInitializationEvent event) throws Exception { public void init(FMLPreInitializationEvent event) throws Exception {
ViaProtocolHack.instance().init(this, () -> System.out.println("ViaProtocolHack loaded successfully")); ViaLoadingBase.ViaLoadingBaseBuilder.
} create().
runDirectory(Minecraft.getMinecraft().gameDir).
@Override nativeVersion(RealmsSharedConstants.NETWORK_PROTOCOL_VERSION).
public boolean isSinglePlayer() { singlePlayerProvider(() -> Minecraft.getMinecraft().isSingleplayer()).
return Minecraft.getMinecraft().isSingleplayer(); eventLoop(new DefaultEventLoop(ViaLoadingBase.EXECUTOR_SERVICE)).
} build();
@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);
} }
} }

View File

@ -7,10 +7,8 @@ import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(value = { @Mixin(GuiMainMenu.class)
GuiMainMenu.class, GuiMultiplayer.class, GuiScreenServerList.class public class MixinGuiMainMenu extends GuiScreen {
})
public class MixinGuiMainMenuGuiMultiplayerGuiServerList extends GuiScreen {
@Inject(method = "initGui", at = @At("RETURN")) @Inject(method = "initGui", at = @At("RETURN"))
public void hookCustomButton(CallbackInfo ci) { public void hookCustomButton(CallbackInfo ci) {

View File

@ -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));
}
}
}

View File

@ -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));
}
}
}

View File

@ -1,6 +1,6 @@
package de.florianmichael.viaforge.mixin.impl; package de.florianmichael.viaforge.mixin.impl;
import de.florianmichael.viaprotocolhack.event.PipelineReorderEvent; import de.florianmichael.vialoadingbase.event.PipelineReorderEvent;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import net.minecraft.network.NetworkManager; import net.minecraft.network.NetworkManager;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;

View File

@ -3,10 +3,10 @@ package de.florianmichael.viaforge.mixin.impl;
import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.connection.UserConnectionImpl; import com.viaversion.viaversion.connection.UserConnectionImpl;
import com.viaversion.viaversion.protocol.ProtocolPipelineImpl; import com.viaversion.viaversion.protocol.ProtocolPipelineImpl;
import de.florianmichael.viaforge.ViaForge; import de.florianmichael.vialoadingbase.ViaLoadingBase;
import de.florianmichael.viaprotocolhack.netty.CustomViaDecodeHandler; import de.florianmichael.vialoadingbase.netty.CustomViaDecodeHandler;
import de.florianmichael.viaprotocolhack.netty.CustomViaEncodeHandler; import de.florianmichael.vialoadingbase.netty.CustomViaEncodeHandler;
import de.florianmichael.viaprotocolhack.netty.NettyConstants; import de.florianmichael.vialoadingbase.netty.NettyConstants;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.SocketChannel;
import net.minecraft.realms.RealmsSharedConstants; import net.minecraft.realms.RealmsSharedConstants;
@ -20,7 +20,7 @@ public class MixinNetworkManagerSub5 {
@Inject(method = "initChannel", at = @At(value = "TAIL"), remap = false) @Inject(method = "initChannel", at = @At(value = "TAIL"), remap = false)
private void onInitChannel(Channel channel, CallbackInfo ci) { 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); UserConnection user = new UserConnectionImpl(channel, true);
new ProtocolPipelineImpl(user); new ProtocolPipelineImpl(user);

View File

@ -6,10 +6,10 @@
"refmap": "mixins.viaforge.refmap.json", "refmap": "mixins.viaforge.refmap.json",
"mixins": [ "mixins": [
"MixinNetworkManager", "MixinNetworkManager",
"MixinNetworkManagerSub5" "MixinNetworkManagerSub5",
"MixinGuiMainMenu",
"MixinGuiMultiplayer",
"MixinGuiScreenServerList"
], ],
"verbose": true, "verbose": true
"client": [
"MixinGuiMainMenuGuiMultiplayerGuiServerList"
]
} }