diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..db54b04 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,47 @@ +# Build Workflow + +name: Build with Gradle + +on: + pull_request: + workflow_dispatch: + push: + +concurrency: + group: ${{ github.head_ref || format('{0}-{1}', github.ref, github.run_number) }} + cancel-in-progress: true + +jobs: + build: + name: Build + + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 10 + + - name: Set up JDK 17 + uses: actions/setup-java@v2 + with: + java-version: 17 + distribution: temurin + + - uses: actions/cache@v2 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + **/loom-cache + **/prebundled-jars + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} + restore-keys: | + ${{ runner.os }}-gradle- + + - name: Chmod Gradle + run: chmod +x ./gradlew + + - name: Build + run: ./gradlew build --no-daemon \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6de7fc5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,393 @@ +# eclipse +bin +*.launch +.settings +.metadata +.classpath +.project + +# idea +out +*.ipr +*.iws +*.iml +.idea + +# gradle +build +.gradle + +# other +eclipse +run +build - Copy.gradle +.vscode +.devauth +.DS_STORE + + +# Created by https://www.toptal.com/developers/gitignore/api/java,gradle,forgegradle,kotlin,macos,intellij,intellij+all,eclipse,visualstudiocode +# Edit at https://www.toptal.com/developers/gitignore?templates=java,gradle,forgegradle,kotlin,macos,intellij,intellij+all,eclipse,visualstudiocode + +### Eclipse ### +.metadata +bin/ +tmp/ +*.tmp +*.bak +*.swp +*~.nib +local.properties +.settings/ +.loadpath +.recommenders + +# External tool builders +.externalToolBuilders/ + +# Locally stored "Eclipse launch configurations" +*.launch + +# PyDev specific (Python IDE for Eclipse) +*.pydevproject + +# CDT-specific (C/C++ Development Tooling) +.cproject + +# CDT- autotools +.autotools + +# Java annotation processor (APT) +.factorypath + +# PDT-specific (PHP Development Tools) +.buildpath + +# sbteclipse plugin +.target + +# Tern plugin +.tern-project + +# TeXlipse plugin +.texlipse + +# STS (Spring Tool Suite) +.springBeans + +# Code Recommenders +.recommenders/ + +# Annotation Processing +.apt_generated/ +.apt_generated_test/ + +# Scala IDE specific (Scala & Java development for Eclipse) +.cache-main +.scala_dependencies +.worksheet + +# Uncomment this line if you wish to ignore the project description file. +# Typically, this file would be tracked if it contains build/dependency configurations: +#.project + +### Eclipse Patch ### +# Spring Boot Tooling +.sts4-cache/ + +### ForgeGradle ### +# Minecraft client/server files +run/ + +### Intellij ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# AWS User-specific +.idea/**/aws.xml + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# SonarLint plugin +.idea/sonarlint/ + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### Intellij Patch ### +# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 + +# *.iml +# modules.xml +# .idea/misc.xml +# *.ipr + +# Sonarlint plugin +# https://plugins.jetbrains.com/plugin/7973-sonarlint +.idea/**/sonarlint/ + +# SonarQube Plugin +# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin +.idea/**/sonarIssues.xml + +# Markdown Navigator plugin +# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced +.idea/**/markdown-navigator.xml +.idea/**/markdown-navigator-enh.xml +.idea/**/markdown-navigator/ + +# Cache file creation bug +# See https://youtrack.jetbrains.com/issue/JBR-2257 +.idea/$CACHE_FILE$ + +# CodeStream plugin +# https://plugins.jetbrains.com/plugin/12206-codestream +.idea/codestream.xml + +# Azure Toolkit for IntelliJ plugin +# https://plugins.jetbrains.com/plugin/8053-azure-toolkit-for-intellij +.idea/**/azureSettings.xml + +### Intellij+all ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff + +# AWS User-specific + +# Generated files + +# Sensitive or high-churn files + +# Gradle + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake + +# Mongo Explorer plugin + +# File-based project format + +# IntelliJ + +# mpeltonen/sbt-idea plugin + +# JIRA plugin + +# Cursive Clojure plugin + +# SonarLint plugin + +# Crashlytics plugin (for Android Studio and IntelliJ) + +# Editor-based Rest Client + +# Android studio 3.1+ serialized cache file + +### Intellij+all Patch ### +# Ignore everything but code style settings and run configurations +# that are supposed to be shared within teams. + +.idea/* + +!.idea/codeStyles +!.idea/runConfigurations + +### Java ### +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* +replay_pid* + +### Kotlin ### +# Compiled class file + +# Log file + +# BlueJ files + +# Mobile Tools for Java (J2ME) + +# Package Files # + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml + +### macOS ### +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### macOS Patch ### +# iCloud generated files +*.icloud + +### VisualStudioCode ### +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +!.vscode/*.code-snippets + +# Local History for Visual Studio Code +.history/ + +# Built Visual Studio Code Extensions +*.vsix + +### VisualStudioCode Patch ### +# Ignore all local history of files +.history +.ionide + +# Support for Project snippet scope +.vscode/*.code-snippets + +# Ignore code-workspaces +*.code-workspace + +### Gradle ### +.gradle +**/build/ +!src/**/build/ + +# Ignore Gradle GUI config +gradle-app.setting + +# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) +!gradle-wrapper.jar + +# Avoid ignore Gradle wrappper properties +!gradle-wrapper.properties + +# Cache of project +.gradletasknamecache + +# Eclipse Gradle plugin generated files +# Eclipse Core +.project +# JDT-specific (Eclipse Java Development Tools) +.classpath + +# End of https://www.toptal.com/developers/gitignore/api/java,gradle,forgegradle,kotlin,macos,intellij,intellij+all,eclipse,visualstudiocode diff --git a/LICENSE-TEMPLATE b/LICENSE-TEMPLATE new file mode 100644 index 0000000..fdddb29 --- /dev/null +++ b/LICENSE-TEMPLATE @@ -0,0 +1,24 @@ +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or +distribute this software, either in source code form or as a compiled +binary, for any purpose, commercial or non-commercial, and by any +means. + +In jurisdictions that recognize copyright laws, the author or authors +of this software dedicate any and all copyright interest in the +software to the public domain. We make this dedication for the benefit +of the public at large and to the detriment of our heirs and +successors. We intend this dedication to be an overt act of +relinquishment in perpetuity of all present and future rights to this +software under copyright law. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +For more information, please refer to diff --git a/README.md b/README.md new file mode 100644 index 0000000..f6c34b0 --- /dev/null +++ b/README.md @@ -0,0 +1,21 @@ +# OneConfigExampleMod + +![Powered by OneConfig](https://polyfrost.org/media/branding/badges/badge_1.svg) +![Compact Powered by OneConfig](https://polyfrost.org/media/branding/badges/badge_2.svg) +![Minimal Powered by OneConfig](https://polyfrost.org/media/branding/badges/badge_3.svg) +![Minimal Compact Powered by OneConfig](https://polyfrost.org/media/branding/badges/badge_4.svg) + +Example mod implementing OneConfig. + +## How to use + +- Copy the template either by using GitHub's "Use this template" feature or downloading the repo manually. +- **Remove the license named "LICENSE-TEMPLATE" and choose a new one.** +- Refactor the template (specifically, the modid, version and name in the gradle.properties and most of the class names) + to a different name. +- Have fun modding! :D + +## Need to update to a newer commit of this template? + +Check out these update guides: +- [Updating to commit `301a6ca`](update-to-301a6ca.md) (most recent update) \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..09a5f02 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,192 @@ +@file:Suppress("UnstableApiUsage", "PropertyName") + +import org.polyfrost.gradle.util.noServerRunConfigs +import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar + +// Adds support for kotlin, and adds the Polyfrost Gradle Toolkit +// which we use to prepare the environment. +plugins { + kotlin("jvm") + id("org.polyfrost.multi-version") + id("org.polyfrost.defaults.repo") + id("org.polyfrost.defaults.java") + id("org.polyfrost.defaults.loom") + id("com.github.johnrengelman.shadow") + id("net.kyori.blossom") version "1.3.2" + id("signing") + java +} + +// Gets the mod name, version and id from the `gradle.properties` file. +val mod_name: String by project +val mod_version: String by project +val mod_id: String by project +val mod_archives_name: String by project + +// Replaces the variables in `ExampleMod.java` to the ones specified in `gradle.properties`. +blossom { + replaceToken("@VER@", mod_version) + replaceToken("@NAME@", mod_name) + replaceToken("@ID@", mod_id) +} + +// Sets the mod version to the one specified in `gradle.properties`. Make sure to change this following semver! +version = mod_version +// Sets the group, make sure to change this to your own. It can be a website you own backwards or your GitHub username. +// e.g. com.github. or com. +group = "org.polyfrost" + +// Sets the name of the output jar (the one you put in your mods folder and send to other people) +// It outputs all versions of the mod into the `versions/{mcVersion}/build` directory. +base { + archivesName.set("$mod_archives_name-$platform") +} + +// Configures Polyfrost Loom, our plugin fork to easily set up the programming environment. +loom { + // Removes the server configs from IntelliJ IDEA, leaving only client runs. + noServerRunConfigs() + + // Adds the tweak class if we are building legacy version of forge as per the documentation (https://docs.polyfrost.org) + if (project.platform.isLegacyForge) { + runConfigs { + "client" { + programArgs("--tweakClass", "cc.polyfrost.oneconfig.loader.stage0.LaunchWrapperTweaker") + property("mixin.debug.export", "true") // Outputs all mixin changes to `versions/{mcVersion}/run/.mixin.out/class` + } + } + } + // Configures the mixins if we are building for forge + if (project.platform.isForge) { + forge { + mixinConfig("mixins.${mod_id}.json") + } + } + // Configures the name of the mixin "refmap" + mixin.defaultRefmapName.set("mixins.${mod_id}.refmap.json") +} + +// Creates the shade/shadow configuration, so we can include libraries inside our mod, rather than having to add them separately. +val shade: Configuration by configurations.creating { + configurations.implementation.get().extendsFrom(this) +} +val modShade: Configuration by configurations.creating { + configurations.modImplementation.get().extendsFrom(this) +} + +// Configures the output directory for when building from the `src/resources` directory. +sourceSets { + main { + output.setResourcesDir(java.classesDirectory) + } +} + +// Adds the Polyfrost maven repository so that we can get the libraries necessary to develop the mod. +repositories { + maven("https://repo.polyfrost.org/releases") +} + +// Configures the libraries/dependencies for your mod. +dependencies { + // Adds the OneConfig library, so we can develop with it. + modCompileOnly("cc.polyfrost:oneconfig-$platform:0.2.2-alpha+") + + // Adds DevAuth, which we can use to log in to Minecraft in development. + modRuntimeOnly("me.djtheredstoner:DevAuth-${if (platform.isFabric) "fabric" else if (platform.isLegacyForge) "forge-legacy" else "forge-latest"}:1.2.0") + + // If we are building for legacy forge, includes the launch wrapper with `shade` as we configured earlier, as well as mixin 0.7.11 + if (platform.isLegacyForge) { + compileOnly("org.spongepowered:mixin:0.7.11-SNAPSHOT") + shade("cc.polyfrost:oneconfig-wrapper-launchwrapper:1.0.0-beta+") + } +} + +tasks { + // Processes the `src/resources/mcmod.info`, `fabric.mod.json`, or `mixins.${mod_id}.json` and replaces + // the mod id, name and version with the ones in `gradle.properties` + processResources { + inputs.property("id", mod_id) + inputs.property("name", mod_name) + val java = if (project.platform.mcMinor >= 18) { + 17 // If we are playing on version 1.18, set the java version to 17 + } else { + // Else if we are playing on version 1.17, use java 16. + if (project.platform.mcMinor == 17) + 16 + else + 8 // For all previous versions, we **need** java 8 (for Forge support). + } + val compatLevel = "JAVA_${java}" + inputs.property("java", java) + inputs.property("java_level", compatLevel) + inputs.property("version", mod_version) + inputs.property("mcVersionStr", project.platform.mcVersionStr) + filesMatching(listOf("mcmod.info", "mixins.${mod_id}.json", "mods.toml")) { + expand( + mapOf( + "id" to mod_id, + "name" to mod_name, + "java" to java, + "java_level" to compatLevel, + "version" to mod_version, + "mcVersionStr" to project.platform.mcVersionStr + ) + ) + } + filesMatching("fabric.mod.json") { + expand( + mapOf( + "id" to mod_id, + "name" to mod_name, + "java" to java, + "java_level" to compatLevel, + "version" to mod_version, + "mcVersionStr" to project.platform.mcVersionStr.substringBeforeLast(".") + ".x" + ) + ) + } + } + + // Configures the resources to include if we are building for forge or fabric. + withType(Jar::class.java) { + if (project.platform.isFabric) { + exclude("mcmod.info", "mods.toml") + } else { + exclude("fabric.mod.json") + if (project.platform.isLegacyForge) { + exclude("mods.toml") + } else { + exclude("mcmod.info") + } + } + } + + // Configures our shadow/shade configuration, so we can + // include some dependencies within our mod jar file. + named("shadowJar") { + archiveClassifier.set("dev") + configurations = listOf(shade, modShade) + duplicatesStrategy = DuplicatesStrategy.EXCLUDE + } + + remapJar { + inputFile.set(shadowJar.get().archiveFile) + archiveClassifier.set("") + } + + jar { + // Sets the jar manifest attributes. + if (platform.isLegacyForge) { + manifest.attributes += mapOf( + "ModSide" to "CLIENT", // We aren't developing a server-side mod + "ForceLoadAsMod" to true, // We want to load this jar as a mod, so we force Forge to do so. + "TweakOrder" to "0", // Makes sure that the OneConfig launch wrapper is loaded as soon as possible. + "MixinConfigs" to "mixins.${mod_id}.json", // We want to use our mixin configuration, so we specify it here. + "TweakClass" to "cc.polyfrost.oneconfig.loader.stage0.LaunchWrapperTweaker" // Loads the OneConfig launch wrapper. + ) + } + dependsOn(shadowJar) + archiveClassifier.set("") + enabled = false + } +} diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..f8f0b3b --- /dev/null +++ b/gradle.properties @@ -0,0 +1,18 @@ +# gradle.properties file -- CHANGE THE VALUES STARTING WITH `mod_*` AND REMOVE THIS COMMENT. + +# Sets the name of your mod. +mod_name=ExampleMod +# Sets the id of your mod that mod loaders use to recognize it. +mod_id=examplemod +# Sets the version of your mod. Make sure to update this when you make changes according to semver. +mod_version=1.0.0 +# Sets the name of the jar file that you put in your 'mods' folder. +mod_archives_name=ExampleMod + +# Gradle Configuration -- DO NOT TOUCH THESE VALUES. +polyfrost.defaults.loom=3 +org.gradle.daemon=true +org.gradle.parallel=true +org.gradle.configureoncommand=true +org.gradle.parallel.threads=4 +org.gradle.jvmargs=-Xmx2G \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..e644113 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..a441313 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100755 index 0000000..1aa94a4 --- /dev/null +++ b/gradlew @@ -0,0 +1,249 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# 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 +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + 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=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=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +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, 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" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..25da30d --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,92 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +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 + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +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 + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/root.gradle.kts b/root.gradle.kts new file mode 100644 index 0000000..5488cd7 --- /dev/null +++ b/root.gradle.kts @@ -0,0 +1,11 @@ +plugins { + kotlin("jvm") version "1.9.10" apply false + id("org.polyfrost.multi-version.root") + id("com.github.johnrengelman.shadow") version "8.1.1" apply false +} + +preprocess { + "1.12.2-forge"(11202, "srg") { + "1.8.9-forge"(10809, "srg") + } +} \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 0000000..54f119e --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,31 @@ +@file:Suppress("PropertyName") + +pluginManagement { + repositories { + gradlePluginPortal() + mavenCentral() + maven("https://repo.polyfrost.org/releases") // Adds the Polyfrost maven repository to get Polyfrost Gradle Toolkit + } + plugins { + val pgtVersion = "0.6.2" // Sets the default versions for Polyfrost Gradle Toolkit + id("org.polyfrost.multi-version.root") version pgtVersion + } +} + +val mod_name: String by settings + +// Configures the root project Gradle name based on the value in `gradle.properties` +rootProject.name = mod_name +rootProject.buildFileName = "root.gradle.kts" + +// Adds all of our build target versions to the classpath if we need to add version-specific code. +listOf( + "1.8.9-forge", // Update this if you want to remove/add a version, along with `build.gradle.kts` and `root.gradle.kts`. + //"1.12.2-forge" // uncomment if you want 1.12.2 support in your mod +).forEach { version -> + include(":$version") + project(":$version").apply { + projectDir = file("versions/$version") + buildFileName = "../../build.gradle.kts" + } +} diff --git a/src/main/java/org/polyfrost/example/ExampleMod.java b/src/main/java/org/polyfrost/example/ExampleMod.java new file mode 100644 index 0000000..043a208 --- /dev/null +++ b/src/main/java/org/polyfrost/example/ExampleMod.java @@ -0,0 +1,33 @@ +package org.polyfrost.example; + +import org.polyfrost.example.command.ExampleCommand; +import org.polyfrost.example.config.TestConfig; +import cc.polyfrost.oneconfig.events.event.InitializationEvent; +import net.minecraftforge.fml.common.Mod; +import cc.polyfrost.oneconfig.utils.commands.CommandManager; +import net.minecraftforge.fml.common.event.FMLInitializationEvent; + +/** + * The entrypoint of the Example Mod that initializes it. + * + * @see Mod + * @see InitializationEvent + */ +@Mod(modid = ExampleMod.MODID, name = ExampleMod.NAME, version = ExampleMod.VERSION) +public class ExampleMod { + + // Sets the variables from `gradle.properties`. See the `blossom` config in `build.gradle.kts`. + public static final String MODID = "@ID@"; + public static final String NAME = "@NAME@"; + public static final String VERSION = "@VER@"; + @Mod.Instance(MODID) + public static ExampleMod INSTANCE; // Adds the instance of the mod, so we can access other variables. + public static TestConfig config; + + // Register the config and commands. + @Mod.EventHandler + public void onInit(FMLInitializationEvent event) { + config = new TestConfig(); + CommandManager.INSTANCE.registerCommand(new ExampleCommand()); + } +} diff --git a/src/main/java/org/polyfrost/example/command/ExampleCommand.java b/src/main/java/org/polyfrost/example/command/ExampleCommand.java new file mode 100644 index 0000000..b4373a3 --- /dev/null +++ b/src/main/java/org/polyfrost/example/command/ExampleCommand.java @@ -0,0 +1,21 @@ +package org.polyfrost.example.command; + +import org.polyfrost.example.ExampleMod; +import cc.polyfrost.oneconfig.utils.commands.annotations.Command; +import cc.polyfrost.oneconfig.utils.commands.annotations.Main; + +/** + * An example command implementing the Command api of OneConfig. + * Registered in ExampleMod.java with `CommandManager.INSTANCE.registerCommand(new ExampleCommand());` + * + * @see Command + * @see Main + * @see ExampleMod + */ +@Command(value = ExampleMod.MODID, description = "Access the " + ExampleMod.NAME + " GUI.") +public class ExampleCommand { + @Main + private void handle() { + ExampleMod.INSTANCE.config.openGui(); + } +} \ No newline at end of file diff --git a/src/main/java/org/polyfrost/example/config/TestConfig.java b/src/main/java/org/polyfrost/example/config/TestConfig.java new file mode 100644 index 0000000..a4cc343 --- /dev/null +++ b/src/main/java/org/polyfrost/example/config/TestConfig.java @@ -0,0 +1,48 @@ +package org.polyfrost.example.config; + +import org.polyfrost.example.ExampleMod; +import org.polyfrost.example.hud.TestHud; +import cc.polyfrost.oneconfig.config.Config; +import cc.polyfrost.oneconfig.config.annotations.Dropdown; +import cc.polyfrost.oneconfig.config.annotations.HUD; +import cc.polyfrost.oneconfig.config.annotations.Slider; +import cc.polyfrost.oneconfig.config.annotations.Switch; +import cc.polyfrost.oneconfig.config.data.Mod; +import cc.polyfrost.oneconfig.config.data.ModType; +import cc.polyfrost.oneconfig.config.data.OptionSize; + +/** + * The main Config entrypoint that extends the Config type and inits the config options. + * See this link for more config Options + */ +public class TestConfig extends Config { + @HUD( + name = "Example HUD" + ) + public TestHud hud = new TestHud(); + + @Switch( + name = "Example Switch", + size = OptionSize.SINGLE // Optional + ) + public static boolean exampleSwitch = false; // The default value for the boolean Switch. + + @Slider( + name = "Example Slider", + min = 0f, max = 100f, // Minimum and maximum values for the slider. + step = 10 // The amount of steps that the slider should have. + ) + public static float exampleSlider = 50f; // The default value for the float Slider. + + @Dropdown( + name = "Example Dropdown", // Name of the Dropdown + options = {"Option 1", "Option 2", "Option 3", "Option 4"} // Options available. + ) + public static int exampleDropdown = 1; // Default option (in this case "Option 2") + + public TestConfig() { + super(new Mod(ExampleMod.NAME, ModType.UTIL_QOL), ExampleMod.MODID + ".json"); + initialize(); + } +} + diff --git a/src/main/java/org/polyfrost/example/hud/TestHud.java b/src/main/java/org/polyfrost/example/hud/TestHud.java new file mode 100644 index 0000000..cd0dfa7 --- /dev/null +++ b/src/main/java/org/polyfrost/example/hud/TestHud.java @@ -0,0 +1,20 @@ +package org.polyfrost.example.hud; + +import cc.polyfrost.oneconfig.hud.SingleTextHud; +import org.polyfrost.example.config.TestConfig; + +/** + * An example OneConfig HUD that is started in the config and displays text. + * + * @see TestConfig#hud + */ +public class TestHud extends SingleTextHud { + public TestHud() { + super("Test", true); + } + + @Override + public String getText(boolean example) { + return "I'm an example HUD"; + } +} diff --git a/src/main/java/org/polyfrost/example/mixin/MinecraftMixin.java b/src/main/java/org/polyfrost/example/mixin/MinecraftMixin.java new file mode 100644 index 0000000..cc1304c --- /dev/null +++ b/src/main/java/org/polyfrost/example/mixin/MinecraftMixin.java @@ -0,0 +1,21 @@ +package org.polyfrost.example.mixin; + +import net.minecraft.client.Minecraft; +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; + +/** + * An example mixin using SpongePowered's Mixin library + * + * @see Inject + * @see Mixin + */ +@Mixin(Minecraft.class) +public class MinecraftMixin { + @Inject(method = "startGame", at = @At(value = "HEAD")) + private void onStartGame(CallbackInfo ci) { + System.out.println("This is a message from an example mod!"); + } +} diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info new file mode 100644 index 0000000..9028106 --- /dev/null +++ b/src/main/resources/mcmod.info @@ -0,0 +1,18 @@ +[ + { + "modid": "${id}", + "name": "${name}", + "description": "", + "version": "${version}", + "mcversion": "${mcVersionStr}", + "url": "", + "updateUrl": "", + "authorList": [ + "Your Name" + ], + "credits": "", + "logoFile": "", + "screenshots": [], + "dependencies": [] + } +] \ No newline at end of file diff --git a/src/main/resources/mixins.examplemod.json b/src/main/resources/mixins.examplemod.json new file mode 100644 index 0000000..c5a6f21 --- /dev/null +++ b/src/main/resources/mixins.examplemod.json @@ -0,0 +1,13 @@ +{ + "compatibilityLevel": "JAVA_8", + "minVersion": "0.7", + "package": "org.polyfrost.example.mixin", + "refmap": "mixins.${id}.refmap.json", + "injectors": { + "maxShiftBy": 5 + }, + "client": [ + "MinecraftMixin" + ], + "verbose": true +} diff --git a/update-to-301a6ca.md b/update-to-301a6ca.md new file mode 100644 index 0000000..74f3894 --- /dev/null +++ b/update-to-301a6ca.md @@ -0,0 +1,51 @@ +# Updating to commit [`301a6ca`](https://github.com/Polyfrost/OneConfigExampleMod/commit/301a6cae2fc9b62d00e968b05eb689f3175c5f79) + +If you don't care to check the commit and manually apply everything, here are all the changes we made in that commit: + +## build.gradle.kts + +![Screenshot 2024-06-17 at 5 24 13 AM](https://github.com/Polyfrost/OneConfigExampleMod/assets/45589059/830faef9-bb86-4279-86d5-b9b7f837d1af) + +Updates blossom to 1.3.2 (what this template uses to automatically replace mentions of mod_id, mod_ver, etc. with the values in `gradle.properties`. unofficial Polyfrost update fixing Kotlin 1.9.x support), and removes unnecessary preprocessor variable (it's already included by PGT) + +## gradle.properties + +![Screenshot 2024-06-17 at 5 27 35 AM](https://github.com/Polyfrost/OneConfigExampleMod/assets/45589059/a170663b-2449-4043-9be3-865e982387c9) + +Updates `polyfrost.defaults.loom` (PGT's "loom revision," aka what mappings the mod uses) to `3`. This won't really affect anyone outside of modern version users, but this is just good practice. + +## gradle/wrapper/gradle-wrapper.properties + +![Screenshot 2024-06-17 at 5 29 02 AM](https://github.com/Polyfrost/OneConfigExampleMod/assets/45589059/ff423c15-1339-47bc-8435-e05d15181b32) + +Updates Gradle to 8.8. + +### IMPORTANT!! + +This Gradle update is why some other gradle-related files in this project (`gradle-wrapper.jar`, `gradlew` and `gradlew.bat`) changed. Obviously, it would be a bit inconvenient to apply the changes to those files manually, so here's what you do to properly apply the new changes: + +1. Apply the rest of the changes in this document +2. Temporarily change `gradle/wrapper/gradle-wrapper.properties` to gradle 8.6 or 8.7. This is necessary because in order for Loom to function, 8.6 or higher is required. +3. Reload the Gradle project +4. Run `gradle wrapper --gradle-version 8.8` in Terminal or through your IDE (IntelliJ users can run this through the following method:) +![Screenshot 2024-06-17 at 5 33 24 AM](https://github.com/Polyfrost/OneConfigExampleMod/assets/45589059/8df43b0f-485d-4f4b-a288-f4db2c4521fe) +![Screenshot 2024-06-17 at 5 34 05 AM](https://github.com/Polyfrost/OneConfigExampleMod/assets/45589059/0d7b0598-d486-4fa4-af07-f72b2ab77966) +5. Done! + +## root.gradle.kts + +![Screenshot 2024-06-17 at 5 35 02 AM](https://github.com/Polyfrost/OneConfigExampleMod/assets/45589059/b4622399-6548-47ef-9724-cfe5f2785243) + +Updates shadow (what Gradle uses to shade dependencies) to 8.1.1. + +## settings.gradle.kts + +![Screenshot 2024-06-17 at 5 36 43 AM](https://github.com/Polyfrost/OneConfigExampleMod/assets/45589059/88252eb9-3aeb-48c4-b7f0-ec1553d999a3) + +Updates PGT to 0.6.2 (which updates loom), and comments out 1.12.2 support in case people don't want it. + +## src/resources/mcmod.info + +![Screenshot 2024-06-17 at 5 38 49 AM](https://github.com/Polyfrost/OneConfigExampleMod/assets/45589059/bb721a82-edd8-4a2e-8678-3b53f3741671) + +Makes sure the `mcversion` field in `mcmod.info` is updated to the actual Minecraft version (in this case, either 1.8.9 or 1.12.2) diff --git a/versions/mainProject b/versions/mainProject new file mode 100644 index 0000000..dd1433e --- /dev/null +++ b/versions/mainProject @@ -0,0 +1 @@ +1.8.9-forge \ No newline at end of file