Skip to content

Commit

Permalink
Copy forge to neoforge directory
Browse files Browse the repository at this point in the history
This allows changes made to neoforge to be seen more clearly.
  • Loading branch information
stewi1014 committed Nov 20, 2024
1 parent 9176242 commit a01ae15
Show file tree
Hide file tree
Showing 11 changed files with 719 additions and 0 deletions.
137 changes: 137 additions & 0 deletions neoforge/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
plugins {
id "com.github.johnrengelman.shadow" version "8.1.1"
id "com.modrinth.minotaur" version "2.8.7"
id "com.matthewprenger.cursegradle" version "1.4.0"
}

architectury {
platformSetupLoomIde()
forge()
}

shadowJar {
//https://stackoverflow.com/questions/73286776/grpc-unsupportedaddresstypeexception-but-only-when-packaged-with-shadowjar
// This does in fact make service discovery work when packaged; still doesn't work in the IDE. see SshHacks.
mergeServiceFiles()
}

configurations {
common
shadowCommon
compileClasspath.extendsFrom common
runtimeClasspath.extendsFrom common
developmentForge.extendsFrom common
}

archivesBaseName = "${project.archives_base_name}"
version = "${project.mod_version}-forge"
group = project.maven_group

dependencies {
forge("net.minecraftforge:forge:${project.forge_version}") { transitive false }

// note to self: implementation, NOT include. include does implicit jarjar

common(project(path: ":common", configuration: "namedElements")) { transitive false }
shadowCommon(project(path: ":common", configuration: "transformProductionForge")) { transitive = false }

// FIXME? I still don't understand if I need to declare all of these things as forgeRuntimeLibrary. It sort
// of seems like I do.

forgeRuntimeLibrary implementation("org.eclipse.jgit:org.eclipse.jgit:${project.jgit_version}") { transitive = false }
shadowCommon("org.eclipse.jgit:org.eclipse.jgit:${project.jgit_version}") { transitive = false }

forgeRuntimeLibrary runtimeOnly("org.eclipse.jgit:org.eclipse.jgit.ssh.jsch:${project.jgit_version}") { transitive = false; }
shadowCommon("org.eclipse.jgit:org.eclipse.jgit.ssh.jsch:${project.jgit_version}") { transitive = false }

forgeRuntimeLibrary runtimeOnly('com.jcraft:jsch:0.1.55')
shadowCommon('com.jcraft:jsch:0.1.55')

forgeRuntimeLibrary runtimeOnly("com.googlecode.javaewah:JavaEWAH:${project.JavaEWAH_version}") { transitive = false }
shadowCommon("com.googlecode.javaewah:JavaEWAH:${project.JavaEWAH_version}") { transitive = false }
}

processResources {
inputs.property "version", project.version

filesMatching("META-INF/mods.toml") {
expand "version": project.version
}
}

shadowJar {
configurations = [project.configurations.shadowCommon]
exclude('META-INF/maven/**')

// https://stackoverflow.com/questions/36659980/java-jar-classnotfoundexception-even-though-dependent-library-exists
// Forge has full control over loading the classes of a mod and it specifically checks the package information
// of every class it loads against a set of restricted package paths to protect its own dependencies from
// accidentally being overwritten by loading a different version of a similar dependency. In this case, Forge
// uses a few Apache libs, so it prevents the loading of classes from the org.apache package namespace.

relocate 'org/eclipse', 'net/pcal/fastback/shaded/org/eclipse'
relocate 'com/jcraft', 'net/pcal/fastback/shaded/com/jcraft'
archiveClassifier = 'dev-shadow'
}

remapJar {
inputFile.set shadowJar.archiveFile
dependsOn shadowJar
archiveClassifier = null
}

jar {

archiveClassifier = 'dev'
}

sourcesJar {
def commonSources = project(":common").sourcesJar
dependsOn commonSources
from commonSources.archiveFile.map { zipTree(it) }
}

processResources {
inputs.property "version", project.version
filesMatching("META-INF/mods.toml") {
expand "version": project.version
}
}


// https://github.com/modrinth/minotaur
modrinth {
token = System.getenv("MODRINTH_TOKEN") ?: 'MODRINTH_TOKEN_NOT_SET'
projectId = "fastback"
versionNumber = "${project.version}"
versionType = "alpha"
uploadFile = remapJar
changelog = "<p><a href='https://github.com/pcal43/fastback/releases/tag/${project.mod_version}'>https://github.com/pcal43/fastback/releases/tag/${project.mod_version}</a></p>"
gameVersions = ["${project.minecraft_version}"]
loaders = ["forge"]
dependencies {}
}


// https://github.com/matthewprenger/CurseGradle
curseforge {
apiKey = System.getenv("CURSEFORGE_TOKEN") ?: 'CURSEFORGE_TOKEN_NOT_SET'

project {
id = "667417"
releaseType = "alpha"
changelog = "https://github.com/pcal43/fastback/releases/tag/${project.mod_version}"
changelogType = "markdown"
mod_version = "${project.version}"
addGameVersion((String) project.minecraft_version)
addGameVersion "Forge"
mainArtifact(remapJar)
afterEvaluate {
uploadTask.dependsOn("remapJar")
}
}

options {
forgeGradleIntegration = false
}
}
1 change: 1 addition & 0 deletions neoforge/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
loom.platform=forge
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package net.pcal.fastback.mod.forge;

import net.minecraftforge.client.event.CustomizeGuiOverlayEvent;
import net.minecraftforge.client.event.ScreenEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.pcal.fastback.logging.UserMessage;

import static java.util.Objects.requireNonNull;
import static net.pcal.fastback.logging.SystemLogger.syslog;
import static net.pcal.fastback.mod.MinecraftProvider.messageToText;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;

/**
* Handles client-specific tasks.
*
* @author pcal
* @since 0.16.0
*/
final class ForgeClientProvider extends ForgeCommonProvider {

// ======================================================================
// Constants

private static final long TEXT_TIMEOUT = 10 * 1000;

// ======================================================================
// Fields

//private MinecraftClient client = null;
private Component hudText;
private long hudTextTime;
private final Minecraft client;

public ForgeClientProvider() {
final IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
modEventBus.addListener(this::onClientStartupEvent);
MinecraftForge.EVENT_BUS.addListener(this::onGuiOverlayEvent);
MinecraftForge.EVENT_BUS.addListener(this::onScreenRenderEvent);
this.client = requireNonNull(Minecraft.getInstance(), "MinecraftClient.getInstance() returned null");
}

// ======================================================================
// Forge Event handlers

private void onClientStartupEvent(FMLClientSetupEvent event) {
this.onInitialize();
}

private void onGuiOverlayEvent(CustomizeGuiOverlayEvent event) {
this.renderOverlayText(event.getGuiGraphics());
}

private void onScreenRenderEvent(ScreenEvent.Render.Post event) {
this.renderOverlayText(event.getGuiGraphics());
}

// ======================================================================
// MinecraftProvider implementation

@Override
public boolean isClient() {
return true;
}

@Override
public void setHudText(UserMessage userMessage) {
if (userMessage == null) {
clearHudText();
} else {
this.hudText = messageToText(userMessage); // so the hud renderer can find it
this.hudTextTime = System.currentTimeMillis();
}
}

@Override
public void clearHudText() {
this.hudText = null;
// TODO someday it might be nice to bring back the fading text effect. But getting to it properly
// clean up 100% of the time is more than I want to deal with right now.
}

@Override
public void setMessageScreenText(UserMessage userMessage) {
final Component text = messageToText(userMessage);
this.hudText = text;
final Screen screen = client.screen;
if (screen != null) screen.title = text;
}

@Override
void renderOverlayText(final GuiGraphics drawContext) {
if (this.hudText == null) return;
// if (!this.client.options.getShowAutosaveIndicator().getValue()) return; FIXME
if (System.currentTimeMillis() - this.hudTextTime > TEXT_TIMEOUT) {
// Don't leave it sitting up there forever if we fail to call clearHudText()
this.hudText = null;
syslog().debug("hud text timed out. somebody forgot to clean up");
return;
}
if (client != null) {
drawContext.drawString(this.client.font, this.hudText, 2, 2, 1);
}
}
}
Loading

0 comments on commit a01ae15

Please sign in to comment.