Skip to content

Commit

Permalink
Minecraft 1.20.6, Java 21
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianMichael committed Aug 21, 2024
1 parent 45aa445 commit 7073457
Show file tree
Hide file tree
Showing 22 changed files with 1,065 additions and 6 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ jobs:
uses: actions/checkout@v4
- name: Validate Gradle Wrapper
uses: gradle/actions/wrapper-validation@v4
- name: Set up JDK 17
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: 17
java-version: 21
distribution: 'temurin'
check-latest: true
- name: Cache Dependencies
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ See [this project](https://github.com/ViaVersionMCP/ViaMCP) for a copy-paste sol
2. Run `./gradlew build` in the root directory of the repository.
3. The compiled jar files can be found in `viaforge-mc<version>/build/libs`.

Note: Build scripts are made to be run using Java 17.
Note: Build scripts are made to be run using Java 21.

## Other ViaVersion Mods / Platforms

Expand All @@ -52,4 +52,4 @@ ViaForge - https://modrinth.com/mod/viaforge/ <br>
ViaProxy (App) - https://github.com/ViaVersion/ViaProxy/#readme <br>
ViaaaS (Proxy) - https://github.com/ViaVersion/ViaaaS#readme <br>

For a more detailed summary see https://viaversion.com/suite
For a more detailed summary see https://viaversion.com
5 changes: 3 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ allprojects {
apply plugin: "xyz.wagyourtail.jvmdowngrader"

java {
// Minecraft 1.17+ required Java 16/17 to compile
toolchain.languageVersion = JavaLanguageVersion.of(17)
// Minecraft 1.17+ required Java 17 to compile,
// Minecraft 1.20.5+ required Java 21 to compile
toolchain.languageVersion = JavaLanguageVersion.of(21)
}

// We define the configuration here so we can use it across all conventions and platforms
Expand Down
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ include "viaforge-mc1182"
include "viaforge-mc1192"
include "viaforge-mc1194"
include "viaforge-mc1204"
include "viaforge-mc1206"
1 change: 1 addition & 0 deletions viaforge-mc1206/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
forge_version=1.20.6-50.1.12
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2024 FlorianMichael/EnZaXD <florian.michael07@gmail.com> 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.common.ViaForgeCommon;
import de.florianmichael.viaforge.common.platform.VFPlatform;
import de.florianmichael.viaforge.provider.ViaForgeGameProfileFetcher;
import net.minecraft.SharedConstants;
import net.minecraft.client.Minecraft;
import net.minecraft.client.User;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.raphimc.vialegacy.protocol.release.r1_7_6_10tor1_8.provider.GameProfileFetcher;

import java.io.File;
import java.util.function.Supplier;

@Mod("viaforge")
public class ViaForge1206 implements VFPlatform {

public ViaForge1206() {
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::onInit);
}

private void onInit(FMLCommonSetupEvent event) {
ViaForgeCommon.init(this);
}

@Override
public int getGameVersion() {
return SharedConstants.getProtocolVersion();
}

@Override
public Supplier<Boolean> isSingleplayer() {
return () -> Minecraft.getInstance().isSingleplayer();
}

@Override
public File getLeadingDirectory() {
return Minecraft.getInstance().gameDirectory;
}

@Override
public void joinServer(String serverId) throws Throwable {
final User session = Minecraft.getInstance().getUser();

Minecraft.getInstance().getMinecraftSessionService().joinServer(session.getProfileId(), session.getAccessToken(), serverId);
}

@Override
public GameProfileFetcher getGameProfileFetcher() {
return new ViaForgeGameProfileFetcher();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2024 FlorianMichael/EnZaXD <florian.michael07@gmail.com> 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.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.util.DumpUtil;
import de.florianmichael.viaforge.common.ViaForgeCommon;
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 com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import net.raphimc.vialoader.util.ProtocolVersionList;
import org.lwjgl.glfw.GLFW;

import java.util.UUID;
import java.util.concurrent.ExecutionException;

public class GuiProtocolSelector extends Screen {

public final Screen parent;
public final boolean simple;
public final FinishedCallback finishedCallback;

private String status;
private long time;

public static void open(final Minecraft minecraft) { // Bypass for some weird bytecode instructions errors in Forge
minecraft.setScreen(new GuiProtocolSelector(minecraft.screen));
}

public GuiProtocolSelector(final Screen parent) {
this(parent, false, (version, unused) -> {
// Default action is to set the target version and go back to the parent screen.
ViaForgeCommon.getManager().setTargetVersion(version);
});
}

public GuiProtocolSelector(final Screen parent, final boolean simple, final FinishedCallback finishedCallback) {
super(Component.literal("ViaForge Protocol Selector"));
this.parent = parent;
this.simple = simple;
this.finishedCallback = finishedCallback;
}

@Override
public void init() {
super.init();
addRenderableWidget(Button.builder(Component.literal("<-"), b -> minecraft.setScreen(parent)).bounds(5, height - 25, 20, 20).build());
if (!this.simple) {
addRenderableWidget(Button.builder(Component.literal("Create dump"), b -> {
try {
minecraft.keyboardHandler.setClipboard(DumpUtil.postDump(UUID.randomUUID()).get());
setStatus(ChatFormatting.GREEN + "Dump created and copied to clipboard");
} catch (InterruptedException | ExecutionException e) {
setStatus(ChatFormatting.RED + "Failed to create dump: " + e.getMessage());
}
}).bounds(width - 105, 5, 100, 20).build());
addRenderableWidget(Button.builder(Component.literal("Reload configs"), b -> Via.getManager().getConfigurationProvider().reloadConfigs()).bounds(width - 105, height - 25, 100, 20).build());
}

addRenderableWidget(new SlotList(minecraft, width, height, 3 + 3 /* start offset */ + (font.lineHeight + 2) * 3 /* title is 2 */, 30, font.lineHeight + 2));
}

public void setStatus(final String status) {
this.status = status;
this.time = System.currentTimeMillis();
}

@Override
public boolean keyPressed(int keyCode, int scanCode, int actions) {
if (keyCode == GLFW.GLFW_KEY_ESCAPE) {
minecraft.setScreen(parent);
}
return super.keyPressed(keyCode, scanCode, actions);
}

@Override
public void render(GuiGraphics graphics, int p_230430_2_, int p_230430_3_, float p_230430_4_) {
if (System.currentTimeMillis() - this.time >= 10_000) {
this.status = null;
}

super.render(graphics, p_230430_2_, p_230430_3_, p_230430_4_);

final var pose = graphics.pose();

pose.pushPose();
pose.scale(2.0F, 2.0F, 2.0F);
graphics.drawCenteredString(font, ChatFormatting.GOLD + "ViaForge", width / 4, 3, 16777215);
pose.popPose();

graphics.drawCenteredString(font, "https://github.com/ViaVersion/ViaForge", width / 2, (font.lineHeight + 2) * 2 + 3, -1);
graphics.drawString(font, status != null ? status : "Discord: florianmichael", 3, 3, -1);
}

class SlotList extends ObjectSelectionList<SlotList.SlotEntry> {

public SlotList(Minecraft client, int width, int height, int top, int bottom, int slotHeight) {
super(client, width, height - top - bottom, top, slotHeight);

for (ProtocolVersion version : ProtocolVersionList.getProtocolsNewToOld()) {
addEntry(new SlotEntry(version));
}
}

public class SlotEntry extends Entry<SlotEntry> {

private final ProtocolVersion ProtocolVersion;

public SlotEntry(ProtocolVersion ProtocolVersion) {
this.ProtocolVersion = ProtocolVersion;
}

@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
GuiProtocolSelector.this.finishedCallback.finished(ProtocolVersion, GuiProtocolSelector.this.parent);
return super.mouseClicked(mouseX, mouseY, button);
}

@Override
public Component getNarration() {
return Component.literal(ProtocolVersion.getName());
}

@Override
public void render(GuiGraphics graphics, int p_93524_, int y, int p_93526_, int p_93527_, int p_93528_, int p_93529_, int p_93530_, boolean p_93531_, float p_93532_) {
final ProtocolVersion targetVersion = ViaForgeCommon.getManager().getTargetVersion();

String color;
if (targetVersion == ProtocolVersion) {
color = GuiProtocolSelector.this.simple ? ChatFormatting.GOLD.toString() : ChatFormatting.GREEN.toString();
} else {
color = GuiProtocolSelector.this.simple ? ChatFormatting.WHITE.toString() : ChatFormatting.DARK_RED.toString();
}

graphics.drawCenteredString(Minecraft.getInstance().font, color + ProtocolVersion.getName(), width / 2, y, -1);
}
}
}

public interface FinishedCallback {

void finished(final ProtocolVersion version, final Screen parent);

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2024 FlorianMichael/EnZaXD <florian.michael07@gmail.com> 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.common.ViaForgeCommon;
import net.minecraft.client.gui.components.DebugScreenOverlay;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.List;

@Mixin(DebugScreenOverlay.class)
public class MixinDebugScreenOverlay {

@Inject(method = "getSystemInformation", at = @At(value = "TAIL"))
public void addViaForgeVersion(CallbackInfoReturnable<List<String>> cir) {
final ViaForgeCommon common = ViaForgeCommon.getManager();
final ProtocolVersion version = ViaForgeCommon.getManager().getTargetVersion();

if (common.getConfig().isShowProtocolVersionInF3() && version != common.getNativeVersion() && !common.getPlatform().isSingleplayer().get()) {
cir.getReturnValue().add("");
cir.getReturnValue().add("ViaForge: " + version.toString());
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2024 FlorianMichael/EnZaXD <florian.michael07@gmail.com> 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.util.Pair;
import de.florianmichael.viaforge.common.ViaForgeCommon;
import de.florianmichael.viaforge.common.platform.ViaForgeConfig;
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 {

public MixinDirectJoinServerScreen(Component title) {
super(title);
}

@Inject(method = "init", at = @At("RETURN"))
public void hookViaForgeButton(CallbackInfo ci) {
final ViaForgeConfig config = ViaForgeCommon.getManager().getConfig();
if (config.isShowDirectConnectButton()) {
final Pair<Integer, Integer> pos = config.getViaForgeButtonPosition().getPosition(this.width, this.height);

addRenderableWidget(Button.builder(Component.literal("ViaForge"), b -> GuiProtocolSelector.open(minecraft)).bounds(pos.key(), pos.value(), 100, 20).build());
}
}

}
Loading

0 comments on commit 7073457

Please sign in to comment.