Skip to content

Commit

Permalink
Ported to NeoForge
Browse files Browse the repository at this point in the history
  • Loading branch information
Stereowalker committed Nov 23, 2024
1 parent c46cf6e commit e07654c
Show file tree
Hide file tree
Showing 17 changed files with 127 additions and 78 deletions.
21 changes: 5 additions & 16 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,35 +1,24 @@
plugins {
id 'eclipse'
id 'java-library'
id 'eclipse'
id 'idea'
id 'maven-publish'
id 'net.minecraftforge.gradle' version '[6.0.24,6.2)'
id 'org.parchmentmc.librarian.forgegradle' version '1.+'
id 'org.spongepowered.mixin' version '0.7.+'
id 'net.neoforged.gradle.userdev' version '7.0.145'
id "me.modmuss50.mod-publish-plugin" version "0.7.4"
id "com.modrinth.minotaur" version "2.+"
}
apply from: "main.gradle"
apply plugin: 'net.minecraftforge.gradle'
// Only edit below this line, the above code adds and enables the necessary things for Forge to be setup.
apply plugin: 'eclipse'
apply plugin: 'maven-publish'
apply plugin: 'org.parchmentmc.librarian.forgegradle'
apply plugin: 'org.spongepowered.mixin'

// Should exist on all loaders and is loader specific
repositories {
maven {url "https://modmaven.dev/" }// UnionLib
maven {url "https://girafi.dk/maven/"}
maven {url "https://www.cursemaven.com"} //CurseForge
maven {url = "https://repo.spongepowered.org/maven"} // mixin
maven {url "https://girafi.dk/maven/"}
}

dependencies {
minecraft "net.minecraftforge:forge:${_minecraft_version}-" + _loader_version
annotationProcessor "org.spongepowered:mixin:"+modMixinVersion+":processor"
implementation('net.sf.jopt-simple:jopt-simple:5.0.4') { version { strictly '5.0.4' } }
implementation ("net.neoforged:neoforge:${_loader_version}")

implementation ("com.stereowalker.unionlib:UnionLib:${_minecraft_version}-${_unionlib_version}-${_loader}")
}

// These aren't loader specific and should exist on all loaders
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ _modrinth_id = x
_minecraft_version = 1.21.1
_minecraft_version_min = 1.21
_minecraft_version_max = 1.22
_loader = Forge
_loader_file = META-INF/mods.toml
_loader_version = 52.0.1
_loader_version_min = 51
_loader_version_max = 53
_loader = NeoForge
_loader_file = META-INF/neoforge.mods.toml
_loader_version = 21.1.1
_loader_version_min = 4
_loader_version_max = 5
_unionlib_version = 12.0.7
_unionlib_version_min = 12.0.3
_unionlib_version_max = 12.1.0
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
27 changes: 17 additions & 10 deletions gradlew
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#

##############################################################################
#
Expand Down Expand Up @@ -55,7 +57,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand Down Expand Up @@ -83,7 +85,9 @@ done
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
' "$PWD" ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -130,26 +134,29 @@ location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi

# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -198,11 +205,11 @@ fi
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.
# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.

set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
Expand Down
22 changes: 12 additions & 10 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem

@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
Expand Down Expand Up @@ -43,11 +45,11 @@ set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand All @@ -57,11 +59,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto execute

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand Down
51 changes: 51 additions & 0 deletions neoforge.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
project.ext._mod_jar = jar

java.toolchain.languageVersion = JavaLanguageVersion.of(21)

tasks.named('wrapper', Wrapper).configure {
distributionType = Wrapper.DistributionType.BIN
}

minecraft {
accessTransformers {
file('src/main/resources/META-INF/accesstransformer.cfg')
}
}

runs {
configureEach {
systemProperty 'forge.logging.markers', 'REGISTRIES'
systemProperty 'forge.logging.console.level', 'debug'
modSource project.sourceSets.main
}
client {
systemProperty 'forge.enabledGameTestNamespaces', project._mod_id
workingDirectory project.file("run/${project._loader}-Client")
}
server {
systemProperty 'forge.enabledGameTestNamespaces', project._mod_id
workingDirectory project.file("run/${project._loader}-Server")
//programArgument '--nogui'
}
}

sourceSets.main.resources { srcDir 'src/generated/resources' }

configurations {
runtimeClasspath.extendsFrom localRuntime
}

// Example for how to get properties into the manifest for reading by the runtime..
jar {
manifest {
attributes([
"Specification-Title": _mod_name,
"Specification-Vendor": "Stereowalker",
"Specification-Version": "1", // We are version 1 of ourselves
"Implementation-Title": project.name,
"Implementation-Version": "${version}",
"Implementation-Vendor" :"Stereowalker",
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
])
}
}
5 changes: 2 additions & 3 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
pluginManagement {
repositories {
gradlePluginPortal()
maven { url = 'https://maven.minecraftforge.net/' }
maven { url = 'https://repo.spongepowered.org/repository/maven-public/' }
maven { url = 'https://maven.neoforged.net/releases' }
maven { url = 'https://maven.parchmentmc.org' }
}
resolutionStrategy {
Expand All @@ -18,5 +17,5 @@ pluginManagement {
}

plugins {
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.7.0'
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.8.0'
}
13 changes: 7 additions & 6 deletions src/main/java/net/rpgz/forge/RegistryEvents.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package net.rpgz.forge;

import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegisterEvent;
import net.minecraft.core.registries.Registries;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.fml.common.EventBusSubscriber.Bus;
import net.neoforged.neoforge.registries.RegisterEvent;
import net.rpgz.init.SoundInit;

@Mod.EventBusSubscriber(bus=Mod.EventBusSubscriber.Bus.MOD, modid = Rpgz.MOD_ID)
@EventBusSubscriber(bus=Bus.MOD, modid = Rpgz.MOD_ID)
public class RegistryEvents
{
@SubscribeEvent
public static void registerSoundEvents(final RegisterEvent event) {
event.register(ForgeRegistries.Keys.SOUND_EVENTS,
event.register(Registries.SOUND_EVENT,
helper -> {
SoundInit.registerAll(helper);
});
Expand Down
17 changes: 7 additions & 10 deletions src/main/java/net/rpgz/forge/Rpgz.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@
import com.stereowalker.unionlib.util.VersionHelper;

import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.neoforged.fml.common.Mod;
import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent;
import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent;
import net.neoforged.neoforge.common.NeoForge;
import net.rpgz.RpgzClientSegment;
import net.rpgz.init.ConfigInit;
import net.rpgz.init.TagInit;
Expand Down Expand Up @@ -52,11 +50,10 @@ public Rpgz()
{
super("rpgz", () -> new RpgzClientSegment(), () -> new ServerSegment());
instance = this;
final IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
TagInit.init();
modEventBus.addListener(this::setup);
modEventBus.addListener(this::clientSetup);
MinecraftForge.EVENT_BUS.register(this);
eventBus().addListener(this::setup);
eventBus().addListener(this::clientSetup);
// NeoForge.EVENT_BUS.register(this);
// NetRegistry.registerMessages();
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/rpgz/init/SoundInit.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvent;
import net.minecraftforge.registries.RegisterEvent.RegisterHelper;
import net.neoforged.neoforge.registries.RegisterEvent.RegisterHelper;

public class SoundInit {

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/rpgz/mixin/ClientWorldMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.Mob;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.api.distmarker.OnlyIn;

@Mixin(ClientLevel.class)
@OnlyIn(Dist.CLIENT)
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/rpgz/mixin/EntityRendererMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.phys.AABB;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.api.distmarker.OnlyIn;

@OnlyIn(Dist.CLIENT)
@Mixin(EntityRenderer.class)
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/rpgz/mixin/GameRendererMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import net.minecraft.world.phys.EntityHitResult;
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.api.distmarker.OnlyIn;

@Mixin(GameRenderer.class)
@OnlyIn(Dist.CLIENT)
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/net/rpgz/mixin/InGameHudMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,18 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import com.mojang.blaze3d.systems.RenderSystem;
import com.stereowalker.unionlib.util.VersionHelper;

import net.minecraft.client.DeltaTracker;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.phys.EntityHitResult;
import net.minecraft.world.phys.HitResult;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.api.distmarker.OnlyIn;

@OnlyIn(Dist.CLIENT)
@Mixin(Gui.class)
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/rpgz/mixin/LivingEntityRendererMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.Mob;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.api.distmarker.OnlyIn;

@OnlyIn(Dist.CLIENT)
@Mixin(LivingEntityRenderer.class)
Expand Down
Loading

0 comments on commit e07654c

Please sign in to comment.