From a9e852a75e5fb15a8a0b614e15b79cabb2e51851 Mon Sep 17 00:00:00 2001 From: PhilipB Date: Thu, 23 Jul 2026 03:52:19 +0200 Subject: [PATCH] Port 1.21.11 to NeoForge Mirrors the same build/loader porting pattern already used for 26.1-neoforge and 26.2-neoforge: swaps Fabric Loom for the NeoForge moddev toolchain, replaces FabricLoader with FMLEnvironment/ModList in GeneralUtils and ServerPlaceholders, and converts the testmod entrypoint from ModInitializer/CommandRegistrationCallback to a @Mod class wired through RegisterCommandsEvent. No unrelated 26.x feature changes (LoaderUtil, client placeholder API, etc.) are pulled in. --- .github/workflows/build.yml | 66 +++-- .github/workflows/docs.yml | 30 --- .github/workflows/release.yml | 64 +++-- README.md | 25 +- build.gradle | 248 +++++++++--------- gradle.properties | 25 +- settings.gradle | 2 +- .../pb4/placeholders/impl/GeneralUtils.java | 4 +- .../builtin/ServerPlaceholders.java | 16 +- .../{ => placeholder-api-neoforge}/icon.png | Bin src/main/resources/fabric.mod.json | 27 -- .../java/eu/pb4/placeholderstest/TestMod.java | 16 +- .../resources/META-INF/neoforge.mods.toml | 7 + src/testmod/resources/fabric.mod.json | 26 -- 14 files changed, 269 insertions(+), 287 deletions(-) delete mode 100644 .github/workflows/docs.yml rename src/main/resources/assets/{ => placeholder-api-neoforge}/icon.png (100%) delete mode 100644 src/main/resources/fabric.mod.json create mode 100644 src/testmod/resources/META-INF/neoforge.mods.toml delete mode 100644 src/testmod/resources/fabric.mod.json diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1383022e..46502c7a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,39 +1,47 @@ -# Automatically build the project and run any configured tests for every push -# and submitted pull request. This can help catch issues that only occur on -# certain platforms or Java versions, and provides a first line of defence -# against bad commits. +name: Build -name: build -on: [pull_request, push] +on: + push: + branches: + - "*" jobs: build: - strategy: - matrix: - # Use these Java versions - java: [ 21 ] - distro: [ temurin ] - # and run on both Linux and Windows - os: [ ubuntu-latest ] - runs-on: ${{ matrix.os }} + runs-on: ubuntu-latest + steps: - - name: checkout repository - uses: actions/checkout@v4 - - name: validate gradle wrapper - uses: gradle/actions/wrapper-validation@v4 - - name: setup jdk ${{ matrix.java }} - uses: actions/setup-java@v4 + - uses: actions/checkout@v6 + + - name: Set up JDK 21 + uses: actions/setup-java@v5 + with: + java-version: '21' + distribution: 'temurin' + + - name: Set up Gradle + uses: gradle/actions/setup-gradle@v6 with: - distribution: ${{ matrix.distro }} - java-version: ${{ matrix.java }} - - name: make gradle wrapper executable - if: ${{ runner.os != 'Windows' }} - run: chmod +x ./gradlew - - name: build + cache-read-only: false + + - name: Store short commit hash + run: echo "short_commit_hash=$(git rev-parse --short "$GITHUB_SHA")" >> "$GITHUB_ENV" + + - name: Build with Gradle run: ./gradlew build - - name: capture build artifacts - if: ${{ runner.os == 'Linux' }} - uses: actions/upload-artifact@v4 + env: + PRESERVE_PRERELEASE_VERSION: true + VERSION_SUFFIX: ${{ env.short_commit_hash }} + + - name: Publish to Maven + run: ./gradlew publishMavenPublicationToOffsetMonkey538Repository + env: + PRESERVE_PRERELEASE_VERSION: true + VERSION_SUFFIX: ${{ env.short_commit_hash }} + MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }} + MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }} + + - name: Upload build artifacts + uses: actions/upload-artifact@v7 with: name: Artifacts path: build/libs/ diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml deleted file mode 100644 index 311226ab..00000000 --- a/.github/workflows/docs.yml +++ /dev/null @@ -1,30 +0,0 @@ -name: Update docs - -on: - release: - types: - - published - workflow_dispatch: - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - uses: actions/setup-python@v5 - with: - python-version: 3.x - - - uses: actions/cache@v4 - with: - key: ${{ github.ref }} - path: .cache - - - run: pip install mkdocs-material mkdocs-minify-plugin pillow cairosvg - - run: mkdocs gh-deploy --force - env: - SOCIAL_CARDS: true # Enable social cards building - SITE_URL: https://placeholders.pb4.eu # Set the site url for mkdocs diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 62cfb2da..7c3da78e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,46 +1,56 @@ -name: Release +name: Publish on: release: types: - published - workflow_dispatch: jobs: build: runs-on: ubuntu-latest + permissions: + contents: write + steps: - - uses: actions/cache@v4 + - uses: actions/checkout@v6 + + - name: Set up JDK 21 + uses: actions/setup-java@v5 with: - path: | - ~/.gradle/loom-cache - ~/.gradle/caches - ~/.gradle/wrapper - key: gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} - restore-keys: | - gradle- - - uses: actions/checkout@v4 - - name: Set up JDK - uses: actions/setup-java@v4 + java-version: '21' + distribution: 'temurin' + + - name: Set up Gradle + uses: gradle/actions/setup-gradle@v6 with: - java-version: 21 - distribution: 'microsoft' + cache-read-only: false - - name: Grant execute permission for gradlew - run: chmod +x gradlew + - name: Build with Gradle + run: ./gradlew build + env: + IS_RELEASE: true + VERSION_SUFFIX: "" - - name: Build and publish with Gradle - run: ./gradlew build publish + - name: Upload to Modrinth + run: ./gradlew modrinth env: - MAVEN_URL: ${{ secrets.MAVEN_URL }} + IS_RELEASE: true + VERSION_SUFFIX: "" + MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }} + VERSION_NAME: ${{ github.event.release.name }} + VERSION_IS_PRERELEASE: ${{ github.event.release.prerelease }} + VERSION_CHANGELOG: ${{ github.event.release.body }} + + - name: Publish to Maven + run: ./gradlew publishMavenPublicationToOffsetMonkey538Repository + env: + IS_RELEASE: true + VERSION_SUFFIX: "" MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }} MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }} - MODRINTH: ${{ secrets.MODRINTH }} - CURSEFORGE: ${{ secrets.CURSEFORGE }} - CHANGELOG: ${{ github.event.release.body }} - - name: Upload GitHub release - uses: AButler/upload-release-assets@v3.0 + + - name: Upload to GitHub + uses: softprops/action-gh-release@v2 with: - files: 'build/libs/*.jar;!build/libs/*-sources.jar;!build/libs/*-dev.jar' - repo-token: ${{ secrets.GITHUB_TOKEN }} + files: ./build/libs/*.jar diff --git a/README.md b/README.md index 60ef336b..5ba93e42 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,26 @@ -# About Placeholder API -It's a small, jij-able API that allows creation and parsing placeholders within strings and Minecraft Text Components. +# About Placeholder API NeoForge +This is an unofficial port of Placeholder API to NeoForge, check out the original by Patbox [here](https://modrinth.com/mod/placeholder-api) and a Paper port [here](https://modrinth.com/project/placeholder-api-paper). + +Placeholder API is a small, JIJ-able API that allows creation and parsing placeholders within strings and Minecraft Text Components. Placeholders use simple format of `%modid:type%` or `%modid:type/data%`. It also includes simple, general usage text format indented for simplifying user input in configs/chats/etc. -For information about usage (for developers and users) you can check official docs at https://placeholders.pb4.eu/! +For information about usage (for developers and users) you can check official docs of the original Fabric version at https://placeholders.pb4.eu/! + +## Developers +To depend on Placeholder API NeoForge, add the following to your buildscript: +```groovy +repositories { + // ... other repositories + maven("https://maven.offsetmonkey538.top/releases") { name = "OffsetMonkey538" } +} + +dependencies { + // ... other dependencies + implementation "eu.pb4:placeholder-api-neoforge:[VERSION]" +} +``` +This will allow you to use the library in your project, but requires users to manually download it. +If you want to JIJ the library, see the NeoForge documentation for how to do so [here](https://docs.neoforged.net/toolchain/docs/dependencies/jarinjar/). +Make sure to replace the `[VERSION]` with an actual valid version. For a list of available versions, check the maven [here](https://maven.offsetmonkey538.top/#/releases/eu/pb4/placeholder-api-neoforge). diff --git a/build.gradle b/build.gradle index 8ae81626..d89f856e 100644 --- a/build.gradle +++ b/build.gradle @@ -1,24 +1,72 @@ +import dex.plugins.outlet.v2.util.ReleaseType +import org.codehaus.groovy.runtime.GStringImpl + +import java.nio.file.Files + plugins { - id 'fabric-loom' version '1.13.+' id 'maven-publish' id "com.modrinth.minotaur" version "2.+" - id 'com.matthewprenger.cursegradle' version '1.4.0' + id 'net.neoforged.moddev' version "2.0.+" + id 'xyz.jpenilla.resource-factory-neoforge-convention' version "1.3.1" + id 'io.github.dexman545.outlet' version "1.8.0" +} + +ext { + neo_mod_id = project.mod_id.replace('-', '_'); + + var versionPrefixTemp = project.mod_version + if (!Boolean.parseBoolean(System.getenv("IS_RELEASE"))) { + String preReleaseVersion = System.currentTimeMillis() + + if (Boolean.parseBoolean(System.getenv("PRESERVE_PRERELEASE_VERSION"))) { + var preReleaseVersionFile = file("preReleaseVersion.txt").toPath() + if (Files.exists(preReleaseVersionFile)) preReleaseVersion = Files.readString(preReleaseVersionFile) + Files.writeString(preReleaseVersionFile, preReleaseVersion) + } + + var separator = "-" + if (versionPrefixTemp.contains("-")) separator = "." + versionPrefixTemp = "${versionPrefixTemp}${separator}${preReleaseVersion}" + } + final String versionSuffix = System.getenv("VERSION_SUFFIX") + versionPrefixTemp = "${versionPrefixTemp}${versionSuffix == null ? "+local" : versionSuffix.isBlank() ? "" : "+${versionSuffix}"}" + versionPrefixTemp = "${versionPrefixTemp}+${project.project_name.replaceFirst("-", "+")}" + + versionPrefix = versionPrefixTemp as GStringImpl + + System.out.println("Version: " + versionPrefix) } base { - archivesName = project.archives_base_name - version = project.mod_version - group = project.maven_group + archivesName = project.mod_id + version = project.versionPrefix } +outlet { + mcVersionRange = project.supported_minecraft_versions + allowedReleaseTypes = Set.of(ReleaseType.RELEASE) +} -repositories { - // Add repositories to retrieve artifacts from in here. - // You should only use this when depending on other mods because - // Loom adds the essential maven repositories to download Minecraft and libraries from automatically. - // See https://docs.gradle.org/current/userguide/declaring_repositories.html - // for more information about repositories. +neoForgeModsToml { + issueTrackerUrl = rootProject.mod_issues + mod(rootProject.neo_mod_id) { + setLicense("LGPLv3") + version = project.version + displayName = rootProject.mod_name + description = rootProject.mod_description + authors = "Patbox,OffsetMonkey538" + logoFile = "assets/${rootProject.mod_id}/icon.png" + logoBlur = false + features = ["javaVersion": "[21,)"] + modUrl = rootProject.mod_sources + displayUrl = rootProject.mod_website + dependencies { + required("minecraft", project.minecraft_version_range) + } + } +} +repositories { maven { url = "https://maven.nucleoid.xyz" } maven { url = "https://jitpack.io" } } @@ -30,72 +78,58 @@ sourceSets { } } -loom { +dependencies { + testmodImplementation sourceSets.main.output +} + +neoForge { + version = project.neoforge_version + + mods { + "${project.neo_mod_id}" { + sourceSet(sourceSets.main) + } + "testmod" { + sourceSet(sourceSets.testmod) + } + } + runs { testmodClient { client() - ideConfigGenerated project.rootProject == project - name = "Test Mod Client" - source = sourceSets.testmod + ideName = "Test Mod Client" + sourceSet = sourceSets.testmod } + testmodServer { server() - ideConfigGenerated project.rootProject == project - name = "Test Mod Server" - source = sourceSets.testmod + ideName = "Test Mod Server" + sourceSet = sourceSets.testmod } - } -} -dependencies { - // To change the versions see the gradle.properties file - minecraft "com.mojang:minecraft:${project.minecraft_version}" - mappings loom.officialMojangMappings() - modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" - - // Fabric API. This is technically optional, but you probably want it anyway. - //modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" - modCompileOnly("net.fabricmc.fabric-api:fabric-api:${project.fabric_version}") - modLocalRuntime("net.fabricmc.fabric-api:fabric-api:${project.fabric_version}") - - // PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs. - // You may need to force-disable transitiveness on them. - testmodImplementation sourceSets.main.output -} - -processResources { - inputs.property "version", project.version - - filesMatching("fabric.mod.json") { - expand "version": project.version + configureEach { + systemProperty 'forge.logging.markers', 'REGISTRIES' + logLevel = org.slf4j.event.Level.INFO + } } } tasks.withType(JavaCompile).configureEach { - // ensure that the encoding is set to UTF-8, no matter what the system default is - // this fixes some edge cases with special characters not displaying correctly - // see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html - // If Javadoc is generated, this must be specified in that task too. it.options.encoding = "UTF-8" - - // The Minecraft launcher currently installs Java 8 for users, so your mod probably wants to target Java 8 too - // JDK 9 introduced a new way of specifying this that will make sure no newer classes or methods are used. - // We'll use that if it's available, but otherwise we'll use the older option. it.options.release = 21 } java { + toolchain.languageVersion = JavaLanguageVersion.of(21) sourceCompatibility = JavaVersion.VERSION_21 targetCompatibility = JavaVersion.VERSION_21 - // Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task - // if it is present. - // If you remove this line, sources will not be generated. + withSourcesJar() } jar { from("LICENSE") { - rename { "${it}_${project.archivesBaseName}"} + rename { "${it}_${base.archivesName.get()}"} } } @@ -103,83 +137,61 @@ def env = System.getenv() // configure the maven publication publishing { - publications { - mavenJava(MavenPublication) { - //artifactId = base.archivesName.get() - // add all the jars that should be included when publishing to maven - artifact(remapJar) { - builtBy remapJar + repositories { + maven { + name = "OffsetMonkey538" + url = "https://maven.offsetmonkey538.top/releases" + credentials { + username = providers.gradleProperty("OffsetMonkey538Username").getOrElse(System.getenv("MAVEN_USERNAME")) + password = providers.gradleProperty("OffsetMonkey538Password").getOrElse(System.getenv("MAVEN_PASSWORD")) } - artifact(sourcesJar) { - builtBy remapSourcesJar + authentication { + basic(BasicAuthentication) } } } - - // See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing. - repositories { - // Add repositories to publish to here. - // Notice: This block does NOT have the same function as the block in the top level. - // The repositories here will be used for publishing your artifact, not for - // retrieving dependencies. - repositories { - if (env.MAVEN_URL) { - maven { - credentials { - username env.MAVEN_USERNAME - password env.MAVEN_PASSWORD - } - url env.MAVEN_URL - } - } else { - mavenLocal() + publications { + register("maven", MavenPublication) { + afterEvaluate { + artifactId base.archivesName.get() } + groupId "eu.pb4" + from components.java } } } -if (System.getenv("MODRINTH")) { - modrinth { - token = System.getenv("MODRINTH") - projectId = 'eXts2L7r'// The ID of your modrinth project, slugs will not work. - versionNumber = "" + version // The version of the mod to upload. - versionType = "release" - uploadFile = remapJar // This links to a task that builds your mod jar and sets "uploadFile" to the mod jar. - gameVersions = [((String) project.minecraft_version)] - changelog = System.getenv("CHANGELOG") - loaders = ["fabric", "quilt"] - } +modrinth { + debugMode = Boolean.parseBoolean(System.getenv("MODRINTH_DEBUG")) - remapJar { - finalizedBy project.tasks.modrinth - } -} + // Main properties + token = System.getenv("MODRINTH_TOKEN") + projectId = rootProject.mod_id + gameVersions = outlet.mcVersions() + loaders = ["neoforge"] -curseforge { - if (System.getenv("CURSEFORGE")) { - apiKey = System.getenv("CURSEFORGE") + // Version stuff + def customVersionName = System.getenv("VERSION_NAME") + if (customVersionName != null) versionName = customVersionName - project { - id = "1037459" - releaseType = "release" - changelog = System.getenv("CHANGELOG") - changelogType = "markdown" - addGameVersion((project.minecraft_version.contains("-") ? ((String) project.minecraft_version.split("-")[0] + "-snapshot") : project.minecraft_version)) - addGameVersion "Fabric" - addGameVersion "Quilt" - mainArtifact(remapJar) + versionNumber = "${project.version}" - afterEvaluate { - uploadTask.dependsOn("remapJar") - } - } - } + def isPreRelease = System.getenv("VERSION_IS_PRERELEASE") + versionType = Boolean.parseBoolean(isPreRelease) ? "beta" : "release" - options { - forgeGradleIntegration = false - } - remapJar { - finalizedBy project.tasks.curseforge - } -} \ No newline at end of file + if (project.mod_version.contains("beta")) versionType = "beta" + if (project.mod_version.contains("alpha")) versionType = "alpha" + + + // Files + uploadFile = jar + additionalFiles = [sourcesJar] + + + // Project info + def changelogEnv = System.getenv("VERSION_CHANGELOG") + if (changelogEnv != null) changelog = changelogEnv + + autoAddDependsOn = false +} diff --git a/gradle.properties b/gradle.properties index 0c9bff84..e446660c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,16 +1,19 @@ # Done to increase the memory available to gradle. org.gradle.jvmargs=-Xmx1G -# Fabric Properties - # check these on https://fabricmc.net/use -minecraft_version=1.21.11 -loader_version=0.18.2 -loom_version=1.13-SNAPSHOT +# Minecraft +minecraft_version = 1.21.11 +neoforge_version = 21.11.42 -# Fabric API -fabric_version=0.140.0+1.21.11 +supported_minecraft_versions = >=1.21.11 +minecraft_version_range = [1.21.11,) - # Mod Properties - mod_version = 2.9.0+1.21.11 - maven_group = eu.pb4 - archives_base_name = placeholder-api +# Mod Properties +project_name = 1.21.11+neoforge +mod_version = 2.9.0 +mod_name = Placeholder API NeoForge +mod_id = placeholder-api-neoforge +mod_description = NeoForge port of Patbox's Text Placeholder API +mod_website = https://modrinth.com/mod/placeholder-api-neoforge +mod_issues = https://github.com/OffsetMods538/TextPlaceholderAPI-NeoForge/issues +mod_sources = https://github.com/OffsetMods538/TextPlaceholderAPI-NeoForge diff --git a/settings.gradle b/settings.gradle index c284de3b..b5eb07ab 100644 --- a/settings.gradle +++ b/settings.gradle @@ -8,5 +8,5 @@ pluginManagement { } } -rootProject.name = 'placeholder-api' +rootProject.name = 'placeholder-api-neoforge' diff --git a/src/main/java/eu/pb4/placeholders/impl/GeneralUtils.java b/src/main/java/eu/pb4/placeholders/impl/GeneralUtils.java index dc15cab4..933c3ed7 100644 --- a/src/main/java/eu/pb4/placeholders/impl/GeneralUtils.java +++ b/src/main/java/eu/pb4/placeholders/impl/GeneralUtils.java @@ -2,7 +2,7 @@ import eu.pb4.placeholders.api.node.*; import eu.pb4.placeholders.api.node.parent.*; -import net.fabricmc.loader.api.FabricLoader; +import net.neoforged.fml.loading.FMLEnvironment; import net.minecraft.ChatFormatting; import net.minecraft.core.component.DataComponents; import net.minecraft.network.chat.*; @@ -22,7 +22,7 @@ @ApiStatus.Internal public class GeneralUtils { public static final Logger LOGGER = LoggerFactory.getLogger("Text Placeholder API"); - public static final boolean IS_DEV = FabricLoader.getInstance().isDevelopmentEnvironment(); + public static final boolean IS_DEV = !FMLEnvironment.isProduction(); public static final TextNode[] CASTER = new TextNode[0]; public static String durationToString(long x) { diff --git a/src/main/java/eu/pb4/placeholders/impl/placeholder/builtin/ServerPlaceholders.java b/src/main/java/eu/pb4/placeholders/impl/placeholder/builtin/ServerPlaceholders.java index dc69e14c..e95b2dbf 100644 --- a/src/main/java/eu/pb4/placeholders/impl/placeholder/builtin/ServerPlaceholders.java +++ b/src/main/java/eu/pb4/placeholders/impl/placeholder/builtin/ServerPlaceholders.java @@ -4,7 +4,7 @@ import eu.pb4.placeholders.api.Placeholders; import eu.pb4.placeholders.api.arguments.StringArgs; import eu.pb4.placeholders.impl.GeneralUtils; -import net.fabricmc.loader.api.FabricLoader; +import net.neoforged.fml.ModList; import net.minecraft.ChatFormatting; import net.minecraft.network.chat.Component; import net.minecraft.resources.Identifier; @@ -111,10 +111,10 @@ public static void register() { Placeholders.register(Identifier.fromNamespaceAndPath("server", "mod_version"), (ctx, arg) -> { if (arg != null) { - var container = FabricLoader.getInstance().getModContainer(arg); + var container = ModList.get().getModContainerById(arg); if (container.isPresent()) { - return PlaceholderResult.value(Component.literal(container.get().getMetadata().getVersion().getFriendlyString())); + return PlaceholderResult.value(Component.literal(container.get().getModInfo().getVersion().toString())); } } return PlaceholderResult.invalid("Invalid argument"); @@ -122,10 +122,10 @@ public static void register() { Placeholders.register(Identifier.fromNamespaceAndPath("server", "mod_name"), (ctx, arg) -> { if (arg != null) { - var container = FabricLoader.getInstance().getModContainer(arg); + var container = ModList.get().getModContainerById(arg); if (container.isPresent()) { - return PlaceholderResult.value(Component.literal(container.get().getMetadata().getName())); + return PlaceholderResult.value(Component.literal(container.get().getModInfo().getDisplayName())); } } return PlaceholderResult.invalid("Invalid argument"); @@ -136,15 +136,15 @@ public static void register() { }); Placeholders.register(Identifier.fromNamespaceAndPath("server", "mod_count"), (ctx, arg) -> { - return PlaceholderResult.value(Component.literal("" + FabricLoader.getInstance().getAllMods().size())); + return PlaceholderResult.value(Component.literal("" + ModList.get().size())); }); Placeholders.register(Identifier.fromNamespaceAndPath("server", "mod_description"), (ctx, arg) -> { if (arg != null) { - var container = FabricLoader.getInstance().getModContainer(arg); + var container = ModList.get().getModContainerById(arg); if (container.isPresent()) { - return PlaceholderResult.value(Component.literal(container.get().getMetadata().getDescription())); + return PlaceholderResult.value(Component.literal(container.get().getModInfo().getDescription())); } } return PlaceholderResult.invalid("Invalid argument"); diff --git a/src/main/resources/assets/icon.png b/src/main/resources/assets/placeholder-api-neoforge/icon.png similarity index 100% rename from src/main/resources/assets/icon.png rename to src/main/resources/assets/placeholder-api-neoforge/icon.png diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json deleted file mode 100644 index add0a19f..00000000 --- a/src/main/resources/fabric.mod.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "schemaVersion": 1, - "id": "placeholder-api", - "version": "${version}", - - "name": "Placeholder API", - "description": "Simple api for mods allowing for user friendly formatting and universal placeholders!", - "authors": [ - "Patbox" - ], - "contact": { - "homepage": "https://pb4.eu", - "sources": "https://github.com/Patbox/TextPlaceholderAPI" - }, - "license": "LGPLv3", - "icon": "assets/icon.png", - "environment": "*", - "depends": { - "fabricloader": ">=0.16.10", - "minecraft": ">=1.21.5-beta.3" - }, - "custom": { - "modmenu": { - "badges": [ "library" ] - } - } -} diff --git a/src/testmod/java/eu/pb4/placeholderstest/TestMod.java b/src/testmod/java/eu/pb4/placeholderstest/TestMod.java index 377ff1d6..54a39fb8 100644 --- a/src/testmod/java/eu/pb4/placeholderstest/TestMod.java +++ b/src/testmod/java/eu/pb4/placeholderstest/TestMod.java @@ -12,8 +12,6 @@ import eu.pb4.placeholders.api.node.TextNode; import eu.pb4.placeholders.api.parsers.*; import it.unimi.dsi.fastutil.Pair; -import net.fabricmc.api.ModInitializer; -import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.arguments.ComponentArgument; import net.minecraft.core.RegistryAccess; @@ -21,6 +19,11 @@ import net.minecraft.network.chat.ComponentSerialization; import net.minecraft.network.chat.ComponentUtils; import net.minecraft.server.level.ServerPlayer; +import net.neoforged.bus.api.IEventBus; +import net.neoforged.fml.ModContainer; +import net.neoforged.fml.common.Mod; +import net.neoforged.neoforge.common.NeoForge; +import net.neoforged.neoforge.event.RegisterCommandsEvent; import java.util.List; import java.util.Map; @@ -29,7 +32,8 @@ @SuppressWarnings("deprecation") -public class TestMod implements ModInitializer { +@Mod("testmod") +public class TestMod { private static int perf(CommandContext context) { var input = context.getArgument("text", String.class); ServerPlayer player = context.getSource().getPlayer(); @@ -305,8 +309,10 @@ private static int test8(CommandContext context) { return 0; } - public void onInitialize() { - CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, dedicated) -> { + public TestMod(IEventBus modEventBus, ModContainer modContainer) { + NeoForge.EVENT_BUS.addListener(RegisterCommandsEvent.class, event -> { + var dispatcher = event.getDispatcher(); + var registryAccess = event.getBuildContext(); dispatcher.register( literal("test").then(argument("text", ComponentArgument.textComponent(registryAccess)).executes(TestMod::test)) ); diff --git a/src/testmod/resources/META-INF/neoforge.mods.toml b/src/testmod/resources/META-INF/neoforge.mods.toml new file mode 100644 index 00000000..d3f5ab2c --- /dev/null +++ b/src/testmod/resources/META-INF/neoforge.mods.toml @@ -0,0 +1,7 @@ +license="LGPLv3" + +[[mods]] +modId="testmod" +version="1.0.0" +displayName="Test Mod" +description="" diff --git a/src/testmod/resources/fabric.mod.json b/src/testmod/resources/fabric.mod.json deleted file mode 100644 index 40459707..00000000 --- a/src/testmod/resources/fabric.mod.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "schemaVersion": 1, - "id": "testmod", - "version": "1.0.0", - - "name": "Test Mod", - "description": "", - "authors": [ - "Patbox" - ], - "contact": { - "homepage": "https://pb4.eu" - }, - - "license": "LGPLv3", - - "environment": "*", - "entrypoints": { - "main": [ - "eu.pb4.placeholderstest.TestMod" - ] - }, - - "depends": { - } -}