Add NeoForge support in 1.20.6+ versions (#153)

This commit is contained in:
Howard ZHY 2025-01-20 16:33:33 +08:00 committed by GitHub
parent 2ccd4e3133
commit b7dfb38927
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 202 additions and 2 deletions

View File

@ -46,6 +46,9 @@ allprojects {
maven {
url = "https://repo.spongepowered.org/repository/maven-public"
}
maven {
url = "https://maven.neoforged.net/"
}
maven {
url = "https://repo.viaversion.com"
metadataSources {
@ -130,14 +133,19 @@ subprojects {
dependencies {
minecraft "net.minecraftforge:forge:${forge_version}"
library "org.slf4j:slf4j-api:2.0.16"
if (versionId < 1_20_6) {
// Always include for refmap in versions that don't have official mappings at runtime,
// later exclude classes to prevent loading conflicts...
library "org.spongepowered:mixin:${mixin_version}"
annotationProcessor "org.spongepowered:mixin:${mixin_version}:processor"
} else {
compileOnly("net.neoforged.fancymodloader:loader:2.0.20") {
transitive = false
}
compileOnly("net.neoforged:bus:7.2.0") {
transitive = false
}
}
library project(":") // Include the base project
}

View File

@ -0,0 +1,79 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2025 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.minecraft.network.HandlerNames;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.fml.common.Mod;
import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent;
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 ViaNeoForge1206 implements VFPlatform {
public ViaNeoForge1206(IEventBus modEventBus) {
modEventBus.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();
}
@Override
public String getDecodeHandlerName() {
return HandlerNames.INBOUND_CONFIG;
}
}

View File

@ -0,0 +1,17 @@
modLoader="javafml" #mandatory
loaderVersion="[2,)" #mandatory
license="GPL-3.0 license"
issueTrackerURL="https://github.com/ViaVersion/ViaForge/issues"
showAsResourcePack=false
[[mods]]
modId="viaforge"
version="1.20.6"
displayName="ViaForge"
displayURL="https://github.com/FlorianMichael"
logoFile="icon.png"
credits="Github contributors"
authors="FlorianMichael/EnZaXD"
description="description"

View File

@ -0,0 +1,79 @@
/*
* This file is part of ViaForge - https://github.com/FlorianMichael/ViaForge
* Copyright (C) 2021-2025 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.minecraft.network.HandlerNames;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.fml.common.Mod;
import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent;
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 ViaNeoForge1214 implements VFPlatform {
public ViaNeoForge1214(IEventBus modEventBus) {
modEventBus.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();
}
@Override
public String getDecodeHandlerName() {
return HandlerNames.INBOUND_CONFIG;
}
}

View File

@ -0,0 +1,17 @@
modLoader="javafml" #mandatory
loaderVersion="[2,)" #mandatory
license="GPL-3.0 license"
issueTrackerURL="https://github.com/ViaVersion/ViaForge/issues"
showAsResourcePack=false
[[mods]]
modId="viaforge"
version="1.21.4"
displayName="ViaForge"
displayURL="https://github.com/FlorianMichael"
logoFile="icon.png"
credits="Github contributors"
authors="FlorianMichael/EnZaXD"
description="description"