Added Support for Minecraft 1.17, 1.18, 1.19, 1.20

This commit is contained in:
FlorianMichael 2023-10-21 01:27:37 +02:00
parent 48dea35519
commit fe045d01ac
No known key found for this signature in database
GPG Key ID: C2FB87E71C425126
61 changed files with 2226 additions and 1 deletions

View File

@ -24,3 +24,7 @@ jobs:
path: |
viaforge-mc112/build/libs/
viaforge-mc116/build/libs/
viaforge-mc117/build/libs/
viaforge-mc118/build/libs/
viaforge-mc119/build/libs/
viaforge-mc120/build/libs/

View File

@ -23,7 +23,10 @@ GitHub Releases: https://github.com/ViaVersion/ViaForge
All ViaForge versions from Minecraft version 1.12 onwards are on the `master` branch. <br>
The names of the submodules indicate the version, they are always given in the format `mc-<version name without .>`. <br>
`Minecraft 1.12.2` - `mc112` <br>
`Minecraft 1.16.4/5` - `mc116`
`Minecraft 1.16.4/5` - `mc116` <br>
`Minecraft 1.17.2` - `mc117` <br>
`Minecraft 1.18.2` - `mc118` <br>
`Minecraft 1.19.4` - `mc119` <br>
### ViaForge for Minecraft 1.8
Since ForgeGradle for Minecraft 1.8 is too old, it has its own branch called `legacy-1.8`

View File

@ -20,4 +20,7 @@ rootProject.name = "ViaForge"
include "viaforge-mc112"
include "viaforge-mc116"
include "viaforge-mc117"
include "viaforge-mc118"
include "viaforge-mc119"
include "viaforge-mc120"

View File

@ -0,0 +1,42 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viaforge;
import de.florianmichael.viaforge.protocolhack.ViaForgeVLInjector;
import de.florianmichael.viaforge.protocolhack.ViaForgeVLLoader;
import net.minecraftforge.fml.common.Mod;
import net.raphimc.vialoader.ViaLoader;
import net.raphimc.vialoader.impl.platform.ViaBackwardsPlatformImpl;
import net.raphimc.vialoader.impl.platform.ViaRewindPlatformImpl;
import net.raphimc.vialoader.util.VersionEnum;
@Mod("viaforge")
public class ViaForge {
public final static VersionEnum NATIVE_VERSION = VersionEnum.r1_17_1;
public static VersionEnum targetVersion = VersionEnum.r1_17_1;
private static boolean loaded;
public static void initViaVersion() {
if (loaded) return;
ViaLoader.init(null, new ViaForgeVLLoader(), new ViaForgeVLInjector(), null, ViaBackwardsPlatformImpl::new, ViaRewindPlatformImpl::new);
loaded = true;
}
}

View File

@ -0,0 +1,107 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viaforge.gui;
import com.mojang.blaze3d.vertex.PoseStack;
import de.florianmichael.viaforge.ViaForge;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.components.ObjectSelectionList;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
import net.raphimc.vialoader.util.VersionEnum;
import org.lwjgl.opengl.GL11;
public class GuiProtocolSelector extends Screen {
private final Screen parent;
public static void open(final Minecraft minecraft) { // Bypass for some weird bytecode instructions errors in Forge
minecraft.setScreen(new GuiProtocolSelector(minecraft.screen));
}
private SlotList slotList;
public GuiProtocolSelector(Screen parent) {
super(new TextComponent("ViaForge Protocol Selector"));
this.parent = parent;
}
@Override
protected void init() {
super.init();
addWidget(slotList = new SlotList(minecraft, width, height, 32, height - 32, 10));
addRenderableWidget(new Button(width / 2 - 100, height - 27, 200, 20, new TextComponent("Back"), b -> minecraft.setScreen(parent)));
}
@Override
public void render(PoseStack p_230430_1_, int p_230430_2_, int p_230430_3_, float p_230430_4_) {
renderBackground(p_230430_1_);
this.slotList.render(p_230430_1_, p_230430_2_, p_230430_3_, p_230430_4_);
super.render(p_230430_1_, p_230430_2_, p_230430_3_, p_230430_4_);
GL11.glPushMatrix();
GL11.glScalef(2.0F, 2.0F, 2.0F);
drawCenteredString(p_230430_1_, this.font, new TextComponent(ChatFormatting.GOLD + "ViaForge"), this.width / 4, 6, 16777215);
GL11.glPopMatrix();
drawString(p_230430_1_, this.font, "by https://github.com/ViaVersion/ViaForge", 1, 1, -1);
drawString(p_230430_1_, this.font, "Discord: florianmichael", 1, 11, -1);
}
static class SlotList extends ObjectSelectionList<SlotList.SlotEntry> {
public SlotList(Minecraft p_i51146_1_, int p_i51146_2_, int p_i51146_3_, int p_i51146_4_, int p_i51146_5_, int p_i51146_6_) {
super(p_i51146_1_, p_i51146_2_, p_i51146_3_, p_i51146_4_, p_i51146_5_, p_i51146_6_);
for (VersionEnum version : VersionEnum.SORTED_VERSIONS) {
addEntry(new SlotEntry(version));
}
}
public class SlotEntry extends ObjectSelectionList.Entry<SlotEntry> {
private final VersionEnum versionEnum;
public SlotEntry(VersionEnum versionEnum) {
this.versionEnum = versionEnum;
}
@Override
public boolean mouseClicked(double p_231044_1_, double p_231044_3_, int p_231044_5_) {
ViaForge.targetVersion = versionEnum;
return super.mouseClicked(p_231044_1_, p_231044_3_, p_231044_5_);
}
@Override
public void render(PoseStack p_230432_1_, int p_230432_2_, int p_230432_3_, int p_230432_4_, int p_230432_5_, int p_230432_6_, int p_230432_7_, int p_230432_8_, boolean p_230432_9_, float p_230432_10_) {
drawCenteredString(p_230432_1_, Minecraft.getInstance().font,
(ViaForge.targetVersion.getVersion() == versionEnum.getVersion() ? ChatFormatting.GREEN.toString() : ChatFormatting.DARK_RED.toString()) + versionEnum.getName(), width / 2, p_230432_3_, -1);
}
@Override
public Component getNarration() {
return new TextComponent(versionEnum.getName());
}
}
}
}

View File

@ -0,0 +1,38 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viaforge.mixin;
import io.netty.channel.Channel;
import net.minecraft.network.Connection;
import net.raphimc.vialoader.netty.CompressionReorderEvent;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(Connection.class)
public class MixinConnection {
@Shadow private Channel channel;
@Inject(method = "setupCompression", at = @At("RETURN"))
public void reorderPipeline(int p_129485_, boolean p_182682_, CallbackInfo ci) {
channel.pipeline().fireUserEventTriggered(CompressionReorderEvent.INSTANCE);
}
}

View File

@ -0,0 +1,45 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viaforge.mixin;
import de.florianmichael.viaforge.ViaForge;
import de.florianmichael.viaforge.gui.GuiProtocolSelector;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.screens.DirectJoinServerScreen;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
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(DirectJoinServerScreen.class)
public class MixinDirectJoinServerScreen extends Screen {
protected MixinDirectJoinServerScreen(Component p_96550_) {
super(p_96550_);
}
@Inject(method = "init", at = @At("RETURN"))
public void hookViaForgeButton(CallbackInfo ci) {
addRenderableWidget(new Button(5, 6, 98, 20, new TextComponent("ViaForge"), b -> minecraft.setScreen(new GuiProtocolSelector(this))));
ViaForge.initViaVersion();
}
}

View File

@ -0,0 +1,45 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viaforge.mixin;
import de.florianmichael.viaforge.ViaForge;
import de.florianmichael.viaforge.gui.GuiProtocolSelector;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.multiplayer.JoinMultiplayerScreen;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
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(JoinMultiplayerScreen.class)
public class MixinJoinMultiplayerScreen extends Screen {
protected MixinJoinMultiplayerScreen(Component p_96550_) {
super(p_96550_);
}
@Inject(method = "init", at = @At("RETURN"))
public void hookViaForgeButton(CallbackInfo ci) {
addRenderableWidget(new Button(5, 6, 98, 20, new TextComponent("ViaForge"), b -> minecraft.setScreen(new GuiProtocolSelector(this))));
ViaForge.initViaVersion();
}
}

View File

@ -0,0 +1,44 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viaforge.mixin;
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.viaforge.protocolhack.ViaForgeVLLegacyPipeline;
import io.netty.channel.Channel;
import io.netty.channel.socket.SocketChannel;
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(targets = "net.minecraft.network.Connection$1", remap = false)
public class MixinNetworkManager_1 {
@Inject(method = "initChannel", at = @At(value = "TAIL"), remap = false)
private void onInitChannel(Channel channel, CallbackInfo ci) {
if (channel instanceof SocketChannel && ViaForge.targetVersion != ViaForge.NATIVE_VERSION) {
final UserConnection user = new UserConnectionImpl(channel, true);
new ProtocolPipelineImpl(user);
channel.pipeline().addLast(new ViaForgeVLLegacyPipeline(user, ViaForge.targetVersion));
}
}
}

View File

@ -0,0 +1,45 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viaforge.mixin;
import de.florianmichael.viaforge.ViaForge;
import de.florianmichael.viaforge.gui.GuiProtocolSelector;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.TitleScreen;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
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(TitleScreen.class)
public class MixinTitleScreen extends Screen {
protected MixinTitleScreen(Component p_96550_) {
super(p_96550_);
}
@Inject(method = "init", at = @At("HEAD"))
public void hookViaForgeButton(CallbackInfo ci) {
addRenderableWidget(new Button(5, 6, 98, 20, new TextComponent("ViaForge"), b -> GuiProtocolSelector.open(minecraft)));
ViaForge.initViaVersion();
}
}

View File

@ -0,0 +1,34 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viaforge.protocolhack;
import net.raphimc.vialoader.impl.viaversion.VLInjector;
import net.raphimc.vialoader.netty.VLLegacyPipeline;
public class ViaForgeVLInjector extends VLInjector {
@Override
public String getDecoderName() {
return VLLegacyPipeline.VIA_DECODER_NAME;
}
@Override
public String getEncoderName() {
return VLLegacyPipeline.VIA_ENCODER_NAME;
}
}

View File

@ -0,0 +1,59 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viaforge.protocolhack;
import com.viaversion.viaversion.api.connection.UserConnection;
import net.raphimc.vialoader.netty.VLLegacyPipeline;
import net.raphimc.vialoader.util.VersionEnum;
public class ViaForgeVLLegacyPipeline extends VLLegacyPipeline {
public ViaForgeVLLegacyPipeline(UserConnection user, VersionEnum version) {
super(user, version);
}
@Override
protected String decompressName() {
return "decompress";
}
@Override
protected String compressName() {
return "compress";
}
@Override
protected String packetDecoderName() {
return "decoder";
}
@Override
protected String packetEncoderName() {
return "encoder";
}
@Override
protected String lengthSplitterName() {
return "splitter";
}
@Override
protected String lengthPrependerName() {
return "prepender";
}
}

View File

@ -0,0 +1,45 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viaforge.protocolhack;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.version.VersionProvider;
import com.viaversion.viaversion.protocols.base.BaseVersionProvider;
import de.florianmichael.viaforge.ViaForge;
import net.minecraft.client.Minecraft;
import net.raphimc.vialoader.impl.viaversion.VLLoader;
public class ViaForgeVLLoader extends VLLoader {
@Override
public void load() {
super.load();
Via.getManager().getProviders().use(VersionProvider.class, new BaseVersionProvider() {
@Override
public int getClosestServerProtocol(UserConnection connection) throws Exception {
if (connection.isClientSide() && !Minecraft.getInstance().hasSingleplayerServer()) {
return ViaForge.targetVersion.getVersion();
}
return super.getClosestServerProtocol(connection);
}
});
}
}

View File

@ -0,0 +1,17 @@
modLoader="javafml"
loaderVersion="[1,)"
license="GPL-3.0 license"
issueTrackerURL="https://github.com/ViaVersion/ViaForge/issues"
showAsResourcePack=false
[[mods]]
modId="viaforge"
version="${version}"
displayName="ViaForge"
displayURL="https://github.com/FlorianMichael"
credits="FlorianMichael/EnZaXD and all ViaVersion/ViaForge contributors"
authors="FlorianMichael/EnZaXD"
description='''
Client-side Implementation of ViaVersion, ViaBackwards and ViaRewind for Legacy Minecraft Forge
'''

View File

@ -0,0 +1,17 @@
{
"required": true,
"minVersion": "0.7.5",
"compatibilityLevel": "JAVA_8",
"package": "de.florianmichael.viaforge.mixin",
"mixins": [
"MixinConnection",
"MixinNetworkManager_1",
"MixinTitleScreen",
"MixinJoinMultiplayerScreen",
"MixinDirectJoinServerScreen"
],
"injectors": {
"defaultRequire": 1
},
"refmap": "mixins.viaforge-mc117.refmap.json"
}

View File

@ -0,0 +1,6 @@
{
"pack": {
"description": "ViaForge",
"pack_format": 6
}
}

View File

@ -0,0 +1,14 @@
plugins {
id "florianmichael.viaforge.base-conventions"
id "florianmichael.viaforge.forge-conventions"
}
java.toolchain.languageVersion = JavaLanguageVersion.of(17)
minecraft {
mappings channel: "official", version: "1.18.2"
}
dependencies {
minecraft "net.minecraftforge:forge:1.18.2-40.2.0"
}

View File

@ -0,0 +1,2 @@
maven_name=viaforge-mc118
mc_version=1.18.2

View File

@ -0,0 +1,42 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viaforge;
import de.florianmichael.viaforge.protocolhack.ViaForgeVLInjector;
import de.florianmichael.viaforge.protocolhack.ViaForgeVLLoader;
import net.minecraftforge.fml.common.Mod;
import net.raphimc.vialoader.ViaLoader;
import net.raphimc.vialoader.impl.platform.ViaBackwardsPlatformImpl;
import net.raphimc.vialoader.impl.platform.ViaRewindPlatformImpl;
import net.raphimc.vialoader.util.VersionEnum;
@Mod("viaforge")
public class ViaForge {
public final static VersionEnum NATIVE_VERSION = VersionEnum.r1_18_2;
public static VersionEnum targetVersion = VersionEnum.r1_18_2;
private static boolean loaded;
public static void initViaVersion() {
if (loaded) return;
ViaLoader.init(null, new ViaForgeVLLoader(), new ViaForgeVLInjector(), null, ViaBackwardsPlatformImpl::new, ViaRewindPlatformImpl::new);
loaded = true;
}
}

View File

@ -0,0 +1,107 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viaforge.gui;
import com.mojang.blaze3d.vertex.PoseStack;
import de.florianmichael.viaforge.ViaForge;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.components.ObjectSelectionList;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
import net.raphimc.vialoader.util.VersionEnum;
import org.lwjgl.opengl.GL11;
public class GuiProtocolSelector extends Screen {
private final Screen parent;
public static void open(final Minecraft minecraft) { // Bypass for some weird bytecode instructions errors in Forge
minecraft.setScreen(new GuiProtocolSelector(minecraft.screen));
}
private SlotList slotList;
public GuiProtocolSelector(Screen parent) {
super(new TextComponent("ViaForge Protocol Selector"));
this.parent = parent;
}
@Override
protected void init() {
super.init();
addWidget(slotList = new SlotList(minecraft, width, height, 32, height - 32, 10));
addRenderableWidget(new Button(width / 2 - 100, height - 27, 200, 20, new TextComponent("Back"), b -> minecraft.setScreen(parent)));
}
@Override
public void render(PoseStack p_230430_1_, int p_230430_2_, int p_230430_3_, float p_230430_4_) {
renderBackground(p_230430_1_);
this.slotList.render(p_230430_1_, p_230430_2_, p_230430_3_, p_230430_4_);
super.render(p_230430_1_, p_230430_2_, p_230430_3_, p_230430_4_);
GL11.glPushMatrix();
GL11.glScalef(2.0F, 2.0F, 2.0F);
drawCenteredString(p_230430_1_, this.font, new TextComponent(ChatFormatting.GOLD + "ViaForge"), this.width / 4, 6, 16777215);
GL11.glPopMatrix();
drawString(p_230430_1_, this.font, "by https://github.com/ViaVersion/ViaForge", 1, 1, -1);
drawString(p_230430_1_, this.font, "Discord: florianmichael", 1, 11, -1);
}
static class SlotList extends ObjectSelectionList<SlotList.SlotEntry> {
public SlotList(Minecraft p_i51146_1_, int p_i51146_2_, int p_i51146_3_, int p_i51146_4_, int p_i51146_5_, int p_i51146_6_) {
super(p_i51146_1_, p_i51146_2_, p_i51146_3_, p_i51146_4_, p_i51146_5_, p_i51146_6_);
for (VersionEnum version : VersionEnum.SORTED_VERSIONS) {
addEntry(new SlotEntry(version));
}
}
public class SlotEntry extends ObjectSelectionList.Entry<SlotEntry> {
private final VersionEnum versionEnum;
public SlotEntry(VersionEnum versionEnum) {
this.versionEnum = versionEnum;
}
@Override
public boolean mouseClicked(double p_231044_1_, double p_231044_3_, int p_231044_5_) {
ViaForge.targetVersion = versionEnum;
return super.mouseClicked(p_231044_1_, p_231044_3_, p_231044_5_);
}
@Override
public void render(PoseStack p_230432_1_, int p_230432_2_, int p_230432_3_, int p_230432_4_, int p_230432_5_, int p_230432_6_, int p_230432_7_, int p_230432_8_, boolean p_230432_9_, float p_230432_10_) {
drawCenteredString(p_230432_1_, Minecraft.getInstance().font,
(ViaForge.targetVersion.getVersion() == versionEnum.getVersion() ? ChatFormatting.GREEN.toString() : ChatFormatting.DARK_RED.toString()) + versionEnum.getName(), width / 2, p_230432_3_, -1);
}
@Override
public Component getNarration() {
return new TextComponent(versionEnum.getName());
}
}
}
}

View File

@ -0,0 +1,38 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viaforge.mixin;
import io.netty.channel.Channel;
import net.minecraft.network.Connection;
import net.raphimc.vialoader.netty.CompressionReorderEvent;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(Connection.class)
public class MixinConnection {
@Shadow private Channel channel;
@Inject(method = "setupCompression", at = @At("RETURN"))
public void reorderPipeline(int p_129485_, boolean p_182682_, CallbackInfo ci) {
channel.pipeline().fireUserEventTriggered(CompressionReorderEvent.INSTANCE);
}
}

View File

@ -0,0 +1,45 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viaforge.mixin;
import de.florianmichael.viaforge.ViaForge;
import de.florianmichael.viaforge.gui.GuiProtocolSelector;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.screens.DirectJoinServerScreen;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
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(DirectJoinServerScreen.class)
public class MixinDirectJoinServerScreen extends Screen {
protected MixinDirectJoinServerScreen(Component p_96550_) {
super(p_96550_);
}
@Inject(method = "init", at = @At("RETURN"))
public void hookViaForgeButton(CallbackInfo ci) {
addRenderableWidget(new Button(5, 6, 98, 20, new TextComponent("ViaForge"), b -> minecraft.setScreen(new GuiProtocolSelector(this))));
ViaForge.initViaVersion();
}
}

View File

@ -0,0 +1,45 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viaforge.mixin;
import de.florianmichael.viaforge.ViaForge;
import de.florianmichael.viaforge.gui.GuiProtocolSelector;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.multiplayer.JoinMultiplayerScreen;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
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(JoinMultiplayerScreen.class)
public class MixinJoinMultiplayerScreen extends Screen {
protected MixinJoinMultiplayerScreen(Component p_96550_) {
super(p_96550_);
}
@Inject(method = "init", at = @At("RETURN"))
public void hookViaForgeButton(CallbackInfo ci) {
addRenderableWidget(new Button(5, 6, 98, 20, new TextComponent("ViaForge"), b -> minecraft.setScreen(new GuiProtocolSelector(this))));
ViaForge.initViaVersion();
}
}

View File

@ -0,0 +1,44 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viaforge.mixin;
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.viaforge.protocolhack.ViaForgeVLLegacyPipeline;
import io.netty.channel.Channel;
import io.netty.channel.socket.SocketChannel;
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(targets = "net.minecraft.network.Connection$1", remap = false)
public class MixinNetworkManager_1 {
@Inject(method = "initChannel", at = @At(value = "TAIL"), remap = false)
private void onInitChannel(Channel channel, CallbackInfo ci) {
if (channel instanceof SocketChannel && ViaForge.targetVersion != ViaForge.NATIVE_VERSION) {
final UserConnection user = new UserConnectionImpl(channel, true);
new ProtocolPipelineImpl(user);
channel.pipeline().addLast(new ViaForgeVLLegacyPipeline(user, ViaForge.targetVersion));
}
}
}

View File

@ -0,0 +1,45 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viaforge.mixin;
import de.florianmichael.viaforge.ViaForge;
import de.florianmichael.viaforge.gui.GuiProtocolSelector;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.TitleScreen;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
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(TitleScreen.class)
public class MixinTitleScreen extends Screen {
protected MixinTitleScreen(Component p_96550_) {
super(p_96550_);
}
@Inject(method = "init", at = @At("HEAD"))
public void hookViaForgeButton(CallbackInfo ci) {
addRenderableWidget(new Button(5, 6, 98, 20, new TextComponent("ViaForge"), b -> GuiProtocolSelector.open(minecraft)));
ViaForge.initViaVersion();
}
}

View File

@ -0,0 +1,34 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viaforge.protocolhack;
import net.raphimc.vialoader.impl.viaversion.VLInjector;
import net.raphimc.vialoader.netty.VLLegacyPipeline;
public class ViaForgeVLInjector extends VLInjector {
@Override
public String getDecoderName() {
return VLLegacyPipeline.VIA_DECODER_NAME;
}
@Override
public String getEncoderName() {
return VLLegacyPipeline.VIA_ENCODER_NAME;
}
}

View File

@ -0,0 +1,59 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viaforge.protocolhack;
import com.viaversion.viaversion.api.connection.UserConnection;
import net.raphimc.vialoader.netty.VLLegacyPipeline;
import net.raphimc.vialoader.util.VersionEnum;
public class ViaForgeVLLegacyPipeline extends VLLegacyPipeline {
public ViaForgeVLLegacyPipeline(UserConnection user, VersionEnum version) {
super(user, version);
}
@Override
protected String decompressName() {
return "decompress";
}
@Override
protected String compressName() {
return "compress";
}
@Override
protected String packetDecoderName() {
return "decoder";
}
@Override
protected String packetEncoderName() {
return "encoder";
}
@Override
protected String lengthSplitterName() {
return "splitter";
}
@Override
protected String lengthPrependerName() {
return "prepender";
}
}

View File

@ -0,0 +1,45 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viaforge.protocolhack;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.version.VersionProvider;
import com.viaversion.viaversion.protocols.base.BaseVersionProvider;
import de.florianmichael.viaforge.ViaForge;
import net.minecraft.client.Minecraft;
import net.raphimc.vialoader.impl.viaversion.VLLoader;
public class ViaForgeVLLoader extends VLLoader {
@Override
public void load() {
super.load();
Via.getManager().getProviders().use(VersionProvider.class, new BaseVersionProvider() {
@Override
public int getClosestServerProtocol(UserConnection connection) throws Exception {
if (connection.isClientSide() && !Minecraft.getInstance().hasSingleplayerServer()) {
return ViaForge.targetVersion.getVersion();
}
return super.getClosestServerProtocol(connection);
}
});
}
}

View File

@ -0,0 +1,17 @@
modLoader="javafml"
loaderVersion="[1,)"
license="GPL-3.0 license"
issueTrackerURL="https://github.com/ViaVersion/ViaForge/issues"
showAsResourcePack=false
[[mods]]
modId="viaforge"
version="${version}"
displayName="ViaForge"
displayURL="https://github.com/FlorianMichael"
credits="FlorianMichael/EnZaXD and all ViaVersion/ViaForge contributors"
authors="FlorianMichael/EnZaXD"
description='''
Client-side Implementation of ViaVersion, ViaBackwards and ViaRewind for Legacy Minecraft Forge
'''

View File

@ -0,0 +1,17 @@
{
"required": true,
"minVersion": "0.7.5",
"compatibilityLevel": "JAVA_8",
"package": "de.florianmichael.viaforge.mixin",
"mixins": [
"MixinConnection",
"MixinNetworkManager_1",
"MixinTitleScreen",
"MixinJoinMultiplayerScreen",
"MixinDirectJoinServerScreen"
],
"injectors": {
"defaultRequire": 1
},
"refmap": "mixins.viaforge-mc118.refmap.json"
}

View File

@ -0,0 +1,6 @@
{
"pack": {
"description": "ViaForge",
"pack_format": 6
}
}

View File

@ -0,0 +1,14 @@
plugins {
id "florianmichael.viaforge.base-conventions"
id "florianmichael.viaforge.forge-conventions"
}
java.toolchain.languageVersion = JavaLanguageVersion.of(17)
minecraft {
mappings channel: "official", version: "1.19.4"
}
dependencies {
minecraft "net.minecraftforge:forge:1.19.4-45.2.0"
}

View File

@ -0,0 +1,2 @@
maven_name=viaforge-mc119
mc_version=1.19.4

View File

@ -0,0 +1,42 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viaforge;
import de.florianmichael.viaforge.protocolhack.ViaForgeVLInjector;
import de.florianmichael.viaforge.protocolhack.ViaForgeVLLoader;
import net.minecraftforge.fml.common.Mod;
import net.raphimc.vialoader.ViaLoader;
import net.raphimc.vialoader.impl.platform.ViaBackwardsPlatformImpl;
import net.raphimc.vialoader.impl.platform.ViaRewindPlatformImpl;
import net.raphimc.vialoader.util.VersionEnum;
@Mod("viaforge")
public class ViaForge {
public final static VersionEnum NATIVE_VERSION = VersionEnum.r1_19_4;
public static VersionEnum targetVersion = VersionEnum.r1_19_4;
private static boolean loaded;
public static void initViaVersion() {
if (loaded) return;
ViaLoader.init(null, new ViaForgeVLLoader(), new ViaForgeVLInjector(), null, ViaBackwardsPlatformImpl::new, ViaRewindPlatformImpl::new);
loaded = true;
}
}

View File

@ -0,0 +1,106 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viaforge.gui;
import com.mojang.blaze3d.vertex.PoseStack;
import de.florianmichael.viaforge.ViaForge;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.components.ObjectSelectionList;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;
import net.raphimc.vialoader.util.VersionEnum;
import org.lwjgl.opengl.GL11;
public class GuiProtocolSelector extends Screen {
private final Screen parent;
public static void open(final Minecraft minecraft) { // Bypass for some weird bytecode instructions errors in Forge
minecraft.setScreen(new GuiProtocolSelector(minecraft.screen));
}
private SlotList slotList;
public GuiProtocolSelector(Screen parent) {
super(Component.literal("ViaForge Protocol Selector"));
this.parent = parent;
}
@Override
protected void init() {
super.init();
addWidget(slotList = new SlotList(minecraft, width, height, 32, height - 32, 10));
addRenderableWidget(new Button.Builder(Component.literal("Back"), b -> minecraft.setScreen(parent)).bounds(width / 2 - 100, height - 27, 200, 20).build());
}
@Override
public void render(PoseStack p_230430_1_, int p_230430_2_, int p_230430_3_, float p_230430_4_) {
renderBackground(p_230430_1_);
this.slotList.render(p_230430_1_, p_230430_2_, p_230430_3_, p_230430_4_);
super.render(p_230430_1_, p_230430_2_, p_230430_3_, p_230430_4_);
GL11.glPushMatrix();
GL11.glScalef(2.0F, 2.0F, 2.0F);
drawCenteredString(p_230430_1_, this.font, Component.literal(ChatFormatting.GOLD + "ViaForge"), this.width / 4, 6, 16777215);
GL11.glPopMatrix();
drawString(p_230430_1_, this.font, "by https://github.com/ViaVersion/ViaForge", 1, 1, -1);
drawString(p_230430_1_, this.font, "Discord: florianmichael", 1, 11, -1);
}
static class SlotList extends ObjectSelectionList<SlotList.SlotEntry> {
public SlotList(Minecraft p_i51146_1_, int p_i51146_2_, int p_i51146_3_, int p_i51146_4_, int p_i51146_5_, int p_i51146_6_) {
super(p_i51146_1_, p_i51146_2_, p_i51146_3_, p_i51146_4_, p_i51146_5_, p_i51146_6_);
for (VersionEnum version : VersionEnum.SORTED_VERSIONS) {
addEntry(new SlotEntry(version));
}
}
public class SlotEntry extends ObjectSelectionList.Entry<SlotEntry> {
private final VersionEnum versionEnum;
public SlotEntry(VersionEnum versionEnum) {
this.versionEnum = versionEnum;
}
@Override
public boolean mouseClicked(double p_231044_1_, double p_231044_3_, int p_231044_5_) {
ViaForge.targetVersion = versionEnum;
return super.mouseClicked(p_231044_1_, p_231044_3_, p_231044_5_);
}
@Override
public void render(PoseStack p_230432_1_, int p_230432_2_, int p_230432_3_, int p_230432_4_, int p_230432_5_, int p_230432_6_, int p_230432_7_, int p_230432_8_, boolean p_230432_9_, float p_230432_10_) {
drawCenteredString(p_230432_1_, Minecraft.getInstance().font,
(ViaForge.targetVersion.getVersion() == versionEnum.getVersion() ? ChatFormatting.GREEN.toString() : ChatFormatting.DARK_RED.toString()) + versionEnum.getName(), width / 2, p_230432_3_, -1);
}
@Override
public Component getNarration() {
return Component.literal(versionEnum.getName());
}
}
}
}

View File

@ -0,0 +1,38 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viaforge.mixin;
import io.netty.channel.Channel;
import net.minecraft.network.Connection;
import net.raphimc.vialoader.netty.CompressionReorderEvent;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(Connection.class)
public class MixinConnection {
@Shadow private Channel channel;
@Inject(method = "setupCompression", at = @At("RETURN"))
public void reorderPipeline(int p_129485_, boolean p_182682_, CallbackInfo ci) {
channel.pipeline().fireUserEventTriggered(CompressionReorderEvent.INSTANCE);
}
}

View File

@ -0,0 +1,44 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viaforge.mixin;
import de.florianmichael.viaforge.ViaForge;
import de.florianmichael.viaforge.gui.GuiProtocolSelector;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.screens.DirectJoinServerScreen;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;
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(DirectJoinServerScreen.class)
public class MixinDirectJoinServerScreen extends Screen {
protected MixinDirectJoinServerScreen(Component p_96550_) {
super(p_96550_);
}
@Inject(method = "init", at = @At("RETURN"))
public void hookViaForgeButton(CallbackInfo ci) {
addRenderableWidget(new Button.Builder(Component.literal("ViaForge"), b -> minecraft.setScreen(new GuiProtocolSelector(this))).bounds(5, 6, 98, 20).build());
ViaForge.initViaVersion();
}
}

View File

@ -0,0 +1,44 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viaforge.mixin;
import de.florianmichael.viaforge.ViaForge;
import de.florianmichael.viaforge.gui.GuiProtocolSelector;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.multiplayer.JoinMultiplayerScreen;
import net.minecraft.network.chat.Component;
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(JoinMultiplayerScreen.class)
public class MixinJoinMultiplayerScreen extends Screen {
protected MixinJoinMultiplayerScreen(Component p_96550_) {
super(p_96550_);
}
@Inject(method = "init", at = @At("RETURN"))
public void hookViaForgeButton(CallbackInfo ci) {
addRenderableWidget(new Button.Builder(Component.literal("ViaForge"), b -> minecraft.setScreen(new GuiProtocolSelector(this))).bounds(5, 6, 98, 20).build());
ViaForge.initViaVersion();
}
}

View File

@ -0,0 +1,44 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viaforge.mixin;
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.viaforge.protocolhack.ViaForgeVLLegacyPipeline;
import io.netty.channel.Channel;
import io.netty.channel.socket.SocketChannel;
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(targets = "net.minecraft.network.Connection$1", remap = false)
public class MixinNetworkManager_1 {
@Inject(method = "initChannel", at = @At(value = "TAIL"), remap = false)
private void onInitChannel(Channel channel, CallbackInfo ci) {
if (channel instanceof SocketChannel && ViaForge.targetVersion != ViaForge.NATIVE_VERSION) {
final UserConnection user = new UserConnectionImpl(channel, true);
new ProtocolPipelineImpl(user);
channel.pipeline().addLast(new ViaForgeVLLegacyPipeline(user, ViaForge.targetVersion));
}
}
}

View File

@ -0,0 +1,44 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viaforge.mixin;
import de.florianmichael.viaforge.ViaForge;
import de.florianmichael.viaforge.gui.GuiProtocolSelector;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.TitleScreen;
import net.minecraft.network.chat.Component;
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(TitleScreen.class)
public class MixinTitleScreen extends Screen {
protected MixinTitleScreen(Component p_96550_) {
super(p_96550_);
}
@Inject(method = "init", at = @At("HEAD"))
public void hookViaForgeButton(CallbackInfo ci) {
addRenderableWidget(new Button.Builder(Component.literal("ViaForge"), b -> minecraft.setScreen(new GuiProtocolSelector(this))).bounds(5, 6, 98, 20).build());
ViaForge.initViaVersion();
}
}

View File

@ -0,0 +1,34 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viaforge.protocolhack;
import net.raphimc.vialoader.impl.viaversion.VLInjector;
import net.raphimc.vialoader.netty.VLLegacyPipeline;
public class ViaForgeVLInjector extends VLInjector {
@Override
public String getDecoderName() {
return VLLegacyPipeline.VIA_DECODER_NAME;
}
@Override
public String getEncoderName() {
return VLLegacyPipeline.VIA_ENCODER_NAME;
}
}

View File

@ -0,0 +1,59 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viaforge.protocolhack;
import com.viaversion.viaversion.api.connection.UserConnection;
import net.raphimc.vialoader.netty.VLLegacyPipeline;
import net.raphimc.vialoader.util.VersionEnum;
public class ViaForgeVLLegacyPipeline extends VLLegacyPipeline {
public ViaForgeVLLegacyPipeline(UserConnection user, VersionEnum version) {
super(user, version);
}
@Override
protected String decompressName() {
return "decompress";
}
@Override
protected String compressName() {
return "compress";
}
@Override
protected String packetDecoderName() {
return "decoder";
}
@Override
protected String packetEncoderName() {
return "encoder";
}
@Override
protected String lengthSplitterName() {
return "splitter";
}
@Override
protected String lengthPrependerName() {
return "prepender";
}
}

View File

@ -0,0 +1,45 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viaforge.protocolhack;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.version.VersionProvider;
import com.viaversion.viaversion.protocols.base.BaseVersionProvider;
import de.florianmichael.viaforge.ViaForge;
import net.minecraft.client.Minecraft;
import net.raphimc.vialoader.impl.viaversion.VLLoader;
public class ViaForgeVLLoader extends VLLoader {
@Override
public void load() {
super.load();
Via.getManager().getProviders().use(VersionProvider.class, new BaseVersionProvider() {
@Override
public int getClosestServerProtocol(UserConnection connection) throws Exception {
if (connection.isClientSide() && !Minecraft.getInstance().hasSingleplayerServer()) {
return ViaForge.targetVersion.getVersion();
}
return super.getClosestServerProtocol(connection);
}
});
}
}

View File

@ -0,0 +1,17 @@
modLoader="javafml"
loaderVersion="[1,)"
license="GPL-3.0 license"
issueTrackerURL="https://github.com/ViaVersion/ViaForge/issues"
showAsResourcePack=false
[[mods]]
modId="viaforge"
version="${version}"
displayName="ViaForge"
displayURL="https://github.com/FlorianMichael"
credits="FlorianMichael/EnZaXD and all ViaVersion/ViaForge contributors"
authors="FlorianMichael/EnZaXD"
description='''
Client-side Implementation of ViaVersion, ViaBackwards and ViaRewind for Legacy Minecraft Forge
'''

View File

@ -0,0 +1,17 @@
{
"required": true,
"minVersion": "0.7.5",
"compatibilityLevel": "JAVA_8",
"package": "de.florianmichael.viaforge.mixin",
"mixins": [
"MixinConnection",
"MixinNetworkManager_1",
"MixinTitleScreen",
"MixinJoinMultiplayerScreen",
"MixinDirectJoinServerScreen"
],
"injectors": {
"defaultRequire": 1
},
"refmap": "mixins.viaforge-mc119.refmap.json"
}

View File

@ -0,0 +1,6 @@
{
"pack": {
"description": "ViaForge",
"pack_format": 6
}
}

View File

@ -0,0 +1,14 @@
plugins {
id "florianmichael.viaforge.base-conventions"
id "florianmichael.viaforge.forge-conventions"
}
java.toolchain.languageVersion = JavaLanguageVersion.of(17)
minecraft {
mappings channel: "official", version: "1.20.2"
}
dependencies {
minecraft "net.minecraftforge:forge:1.20.2-48.0.30"
}

View File

@ -0,0 +1,2 @@
maven_name=viaforge-mc120
mc_version=1.20.2

View File

@ -0,0 +1,42 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viaforge;
import de.florianmichael.viaforge.protocolhack.ViaForgeVLInjector;
import de.florianmichael.viaforge.protocolhack.ViaForgeVLLoader;
import net.minecraftforge.fml.common.Mod;
import net.raphimc.vialoader.ViaLoader;
import net.raphimc.vialoader.impl.platform.ViaBackwardsPlatformImpl;
import net.raphimc.vialoader.impl.platform.ViaRewindPlatformImpl;
import net.raphimc.vialoader.util.VersionEnum;
@Mod("viaforge")
public class ViaForge {
public final static VersionEnum NATIVE_VERSION = VersionEnum.r1_20_2;
public static VersionEnum targetVersion = VersionEnum.r1_20_2;
private static boolean loaded;
public static void initViaVersion() {
if (loaded) return;
ViaLoader.init(null, new ViaForgeVLLoader(), new ViaForgeVLInjector(), null, ViaBackwardsPlatformImpl::new, ViaRewindPlatformImpl::new);
loaded = true;
}
}

View File

@ -0,0 +1,105 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viaforge.gui;
import de.florianmichael.viaforge.ViaForge;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.components.ObjectSelectionList;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;
import net.raphimc.vialoader.util.VersionEnum;
import org.lwjgl.opengl.GL11;
public class GuiProtocolSelector extends Screen {
private final Screen parent;
public static void open(final Minecraft minecraft) { // Bypass for some weird bytecode instructions errors in Forge
minecraft.setScreen(new GuiProtocolSelector(minecraft.screen));
}
private SlotList slotList;
public GuiProtocolSelector(Screen parent) {
super(Component.literal("ViaForge Protocol Selector"));
this.parent = parent;
}
@Override
protected void init() {
super.init();
addWidget(slotList = new SlotList(minecraft, width, height, 32, height - 32, 10));
addRenderableWidget(new Button.Builder(Component.literal("Back"), b -> minecraft.setScreen(parent)).bounds(width / 2 - 100, height - 27, 200, 20).build());
}
@Override
public void render(GuiGraphics p_230430_1_, int p_230430_2_, int p_230430_3_, float p_230430_4_) {
this.slotList.render(p_230430_1_, p_230430_2_, p_230430_3_, p_230430_4_);
super.render(p_230430_1_, p_230430_2_, p_230430_3_, p_230430_4_);
GL11.glPushMatrix();
GL11.glScalef(2.0F, 2.0F, 2.0F);
p_230430_1_.drawCenteredString(this.font, Component.literal(ChatFormatting.GOLD + "ViaForge"), this.width / 4, 6, 16777215);
GL11.glPopMatrix();
p_230430_1_.drawString(this.font, "by https://github.com/ViaVersion/ViaForge", 1, 1, -1);
p_230430_1_.drawString(this.font, "Discord: florianmichael", 1, 11, -1);
}
static class SlotList extends ObjectSelectionList<SlotList.SlotEntry> {
public SlotList(Minecraft p_i51146_1_, int p_i51146_2_, int p_i51146_3_, int p_i51146_4_, int p_i51146_5_, int p_i51146_6_) {
super(p_i51146_1_, p_i51146_2_, p_i51146_3_, p_i51146_4_, p_i51146_5_, p_i51146_6_);
for (VersionEnum version : VersionEnum.SORTED_VERSIONS) {
addEntry(new SlotEntry(version));
}
}
public class SlotEntry extends ObjectSelectionList.Entry<SlotEntry> {
private final VersionEnum versionEnum;
public SlotEntry(VersionEnum versionEnum) {
this.versionEnum = versionEnum;
}
@Override
public boolean mouseClicked(double p_231044_1_, double p_231044_3_, int p_231044_5_) {
ViaForge.targetVersion = versionEnum;
return super.mouseClicked(p_231044_1_, p_231044_3_, p_231044_5_);
}
@Override
public void render(GuiGraphics p_230432_1_, int p_230432_2_, int p_230432_3_, int p_230432_4_, int p_230432_5_, int p_230432_6_, int p_230432_7_, int p_230432_8_, boolean p_230432_9_, float p_230432_10_) {
p_230432_1_.drawCenteredString(Minecraft.getInstance().font,
(ViaForge.targetVersion.getVersion() == versionEnum.getVersion() ? ChatFormatting.GREEN.toString() : ChatFormatting.DARK_RED.toString()) + versionEnum.getName(), width / 2, p_230432_3_, -1);
}
@Override
public Component getNarration() {
return Component.literal(versionEnum.getName());
}
}
}
}

View File

@ -0,0 +1,38 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viaforge.mixin;
import io.netty.channel.Channel;
import net.minecraft.network.Connection;
import net.raphimc.vialoader.netty.CompressionReorderEvent;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(Connection.class)
public class MixinConnection {
@Shadow private Channel channel;
@Inject(method = "setupCompression", at = @At("RETURN"))
public void reorderPipeline(int p_129485_, boolean p_182682_, CallbackInfo ci) {
channel.pipeline().fireUserEventTriggered(CompressionReorderEvent.INSTANCE);
}
}

View File

@ -0,0 +1,44 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viaforge.mixin;
import de.florianmichael.viaforge.ViaForge;
import de.florianmichael.viaforge.gui.GuiProtocolSelector;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.screens.DirectJoinServerScreen;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;
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(DirectJoinServerScreen.class)
public class MixinDirectJoinServerScreen extends Screen {
protected MixinDirectJoinServerScreen(Component p_96550_) {
super(p_96550_);
}
@Inject(method = "init", at = @At("RETURN"))
public void hookViaForgeButton(CallbackInfo ci) {
addRenderableWidget(new Button.Builder(Component.literal("ViaForge"), b -> minecraft.setScreen(new GuiProtocolSelector(this))).bounds(5, 6, 98, 20).build());
ViaForge.initViaVersion();
}
}

View File

@ -0,0 +1,44 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viaforge.mixin;
import de.florianmichael.viaforge.ViaForge;
import de.florianmichael.viaforge.gui.GuiProtocolSelector;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.multiplayer.JoinMultiplayerScreen;
import net.minecraft.network.chat.Component;
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(JoinMultiplayerScreen.class)
public class MixinJoinMultiplayerScreen extends Screen {
protected MixinJoinMultiplayerScreen(Component p_96550_) {
super(p_96550_);
}
@Inject(method = "init", at = @At("RETURN"))
public void hookViaForgeButton(CallbackInfo ci) {
addRenderableWidget(new Button.Builder(Component.literal("ViaForge"), b -> minecraft.setScreen(new GuiProtocolSelector(this))).bounds(5, 6, 98, 20).build());
ViaForge.initViaVersion();
}
}

View File

@ -0,0 +1,44 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viaforge.mixin;
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.viaforge.protocolhack.ViaForgeVLLegacyPipeline;
import io.netty.channel.Channel;
import io.netty.channel.socket.SocketChannel;
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(targets = "net.minecraft.network.Connection$1", remap = false)
public class MixinNetworkManager_1 {
@Inject(method = "initChannel", at = @At(value = "TAIL"), remap = false)
private void onInitChannel(Channel channel, CallbackInfo ci) {
if (channel instanceof SocketChannel && ViaForge.targetVersion != ViaForge.NATIVE_VERSION) {
final UserConnection user = new UserConnectionImpl(channel, true);
new ProtocolPipelineImpl(user);
channel.pipeline().addLast(new ViaForgeVLLegacyPipeline(user, ViaForge.targetVersion));
}
}
}

View File

@ -0,0 +1,44 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viaforge.mixin;
import de.florianmichael.viaforge.ViaForge;
import de.florianmichael.viaforge.gui.GuiProtocolSelector;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.TitleScreen;
import net.minecraft.network.chat.Component;
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(TitleScreen.class)
public class MixinTitleScreen extends Screen {
protected MixinTitleScreen(Component p_96550_) {
super(p_96550_);
}
@Inject(method = "init", at = @At("HEAD"))
public void hookViaForgeButton(CallbackInfo ci) {
addRenderableWidget(new Button.Builder(Component.literal("ViaForge"), b -> minecraft.setScreen(new GuiProtocolSelector(this))).bounds(5, 6, 98, 20).build());
ViaForge.initViaVersion();
}
}

View File

@ -0,0 +1,34 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viaforge.protocolhack;
import net.raphimc.vialoader.impl.viaversion.VLInjector;
import net.raphimc.vialoader.netty.VLLegacyPipeline;
public class ViaForgeVLInjector extends VLInjector {
@Override
public String getDecoderName() {
return VLLegacyPipeline.VIA_DECODER_NAME;
}
@Override
public String getEncoderName() {
return VLLegacyPipeline.VIA_ENCODER_NAME;
}
}

View File

@ -0,0 +1,59 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viaforge.protocolhack;
import com.viaversion.viaversion.api.connection.UserConnection;
import net.raphimc.vialoader.netty.VLLegacyPipeline;
import net.raphimc.vialoader.util.VersionEnum;
public class ViaForgeVLLegacyPipeline extends VLLegacyPipeline {
public ViaForgeVLLegacyPipeline(UserConnection user, VersionEnum version) {
super(user, version);
}
@Override
protected String decompressName() {
return "decompress";
}
@Override
protected String compressName() {
return "compress";
}
@Override
protected String packetDecoderName() {
return "decoder";
}
@Override
protected String packetEncoderName() {
return "encoder";
}
@Override
protected String lengthSplitterName() {
return "splitter";
}
@Override
protected String lengthPrependerName() {
return "prepender";
}
}

View File

@ -0,0 +1,45 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viaforge.protocolhack;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.version.VersionProvider;
import com.viaversion.viaversion.protocols.base.BaseVersionProvider;
import de.florianmichael.viaforge.ViaForge;
import net.minecraft.client.Minecraft;
import net.raphimc.vialoader.impl.viaversion.VLLoader;
public class ViaForgeVLLoader extends VLLoader {
@Override
public void load() {
super.load();
Via.getManager().getProviders().use(VersionProvider.class, new BaseVersionProvider() {
@Override
public int getClosestServerProtocol(UserConnection connection) throws Exception {
if (connection.isClientSide() && !Minecraft.getInstance().hasSingleplayerServer()) {
return ViaForge.targetVersion.getVersion();
}
return super.getClosestServerProtocol(connection);
}
});
}
}

View File

@ -0,0 +1,17 @@
modLoader="javafml"
loaderVersion="[1,)"
license="GPL-3.0 license"
issueTrackerURL="https://github.com/ViaVersion/ViaForge/issues"
showAsResourcePack=false
[[mods]]
modId="viaforge"
version="${version}"
displayName="ViaForge"
displayURL="https://github.com/FlorianMichael"
credits="FlorianMichael/EnZaXD and all ViaVersion/ViaForge contributors"
authors="FlorianMichael/EnZaXD"
description='''
Client-side Implementation of ViaVersion, ViaBackwards and ViaRewind for Legacy Minecraft Forge
'''

View File

@ -0,0 +1,17 @@
{
"required": true,
"minVersion": "0.7.5",
"compatibilityLevel": "JAVA_8",
"package": "de.florianmichael.viaforge.mixin",
"mixins": [
"MixinConnection",
"MixinNetworkManager_1",
"MixinTitleScreen",
"MixinJoinMultiplayerScreen",
"MixinDirectJoinServerScreen"
],
"injectors": {
"defaultRequire": 1
},
"refmap": "mixins.viaforge-mc120.refmap.json"
}

View File

@ -0,0 +1,6 @@
{
"pack": {
"description": "ViaForge",
"pack_format": 6
}
}