Skip to content

Commit

Permalink
Port 1/3 done
Browse files Browse the repository at this point in the history
  • Loading branch information
Deftu committed Nov 24, 2024
1 parent 56c8785 commit 7d3b39c
Show file tree
Hide file tree
Showing 14 changed files with 188 additions and 307 deletions.
179 changes: 23 additions & 156 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,75 +1,37 @@
@file:Suppress("UnstableApiUsage", "PropertyName")

import org.polyfrost.gradle.util.noServerRunConfigs
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import dev.deftu.gradle.utils.GameSide

// 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
kotlin("jvm")
id("dev.deftu.gradle.multiversion")
id("dev.deftu.gradle.tools")
id("dev.deftu.gradle.tools.resources")
id("dev.deftu.gradle.tools.bloom")
id("dev.deftu.gradle.tools.shadow")
id("dev.deftu.gradle.tools.minecraft.loom")
}

// 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.<your username> or com.<your domain>
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 `build` directory.
base {
archivesName.set("$mod_archives_name-$platform")
}
toolkitLoomHelper {
// Adds OneConfig to our project
useOneConfig(mcData, "commands", "config", "config-impl", "events", "internal", "ui")
useDevAuth()

// Configures the Polyfrost Loom, our plugin fork to easily set up the programming environment.
loom {
// Removes the server configs from IntelliJ IDEA, leaving only client runs.
// If you're developing a server-side mod, you can remove this line.
noServerRunConfigs()
disableRunConfigs(GameSide.SERVER)

// 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")
}
}
}
// Configures the mixins if we are building for forge, useful for when we are dealing with cross-platform projects.
if (project.platform.isForge) {
forge {
mixinConfig("mixins.${mod_id}.json")
}
// Sets up our Mixin refmap naming
if (!mcData.isNeoForge) {
useMixinRefMap(modData.id)
}
// Configures the name of the mixin "refmap" using an experimental loom api.
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)
// Adds the tweak class if we are building legacy version of forge as per the documentation (https://docs.polyfrost.org)
if (mcData.isLegacyForge) {
useTweaker("org.polyfrost.oneconfig.loader.stage0.LaunchWrapperTweaker", GameSide.CLIENT)
useForgeMixin(modData.id) // Configures the mixins if we are building for forge, useful for when we are dealing with cross-platform projects.
}
}

// Configures the output directory for when building from the `src/resources` directory.
Expand All @@ -84,109 +46,14 @@ sourceSets {

// Adds the Polyfrost maven repository so that we can get the libraries necessary to develop the mod.
repositories {
mavenLocal()
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+")

modRuntimeOnly("me.djtheredstoner:DevAuth-${if (platform.isFabric) "fabric" else if (platform.isLegacyForge) "forge-legacy" else "forge-latest"}:1.1.2")

// If we are building for legacy forge, includes the launch wrapper with `shade` as we configured earlier.
if (platform.isLegacyForge) {
if (mcData.isLegacyForge) {
compileOnly("org.spongepowered:mixin:0.7.11-SNAPSHOT")
shade("cc.polyfrost:oneconfig-wrapper-launchwrapper:1.0.0-beta17")
}
}

tasks {
// Processes the `src/resources/mcmod.info or fabric.mod.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>("shadowJar") {
archiveClassifier.set("dev") // TODO: machete gets confused by the `dev` prefix.
configurations = listOf(shade)
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, so this is fine.
"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
}
}
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# gradle.properties file -- CHANGE THE VALUES STARTING WITH `mod_*` AND REMOVE THIS COMMENT.
# gradle.properties file -- CHANGE THE VALUES STARTING WITH `mod.*` AND REMOVE THIS COMMENT.

# Sets the name of your mod.
mod_name=PolyCrosshair
mod.name=PolyCrosshair
# Sets the id of your mod that mod loaders use to recognize it.
mod_id=polycrosshair
mod.id=polycrosshair
# Sets the version of your mod. Make sure to update this when you make changes according to semver.
mod_version=1.0.3
mod.version=1.0.3
# Sets the name of the jar file that you put in your 'mods' folder.
mod_archives_name=PolyCrosshair
mod.group=org.polyfrost

# Gradle Configuration -- DO NOT TOUCH THESE VALUES.
polyfrost.defaults.loom=3
Expand Down
8 changes: 2 additions & 6 deletions root.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
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
id("dev.deftu.gradle.multiversion-root")
}

preprocess {
"1.12.2-forge"(11202, "srg") {
"1.8.9-forge"(10809, "srg")
}
"1.8.9-forge"(10809, "srg")
}
31 changes: 22 additions & 9 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,21 +1,34 @@
@file:Suppress("PropertyName")
import groovy.lang.MissingPropertyException

pluginManagement {
repositories {
// Repositories
maven("https://maven.deftu.dev/releases")
maven("https://maven.fabricmc.net")
maven("https://maven.architectury.dev/")
maven("https://maven.minecraftforge.net")
maven("https://repo.essential.gg/repository/maven-public")
maven("https://server.bbkr.space/artifactory/libs-release/")
maven("https://jitpack.io/")

// Snapshots
maven("https://maven.deftu.dev/snapshots")
mavenLocal()

// Default 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
kotlin("jvm") version("2.0.0")
id("dev.deftu.gradle.multiversion-root") version("2.11.2")
}
}

val mod_name: String by settings

// Configures the root project Gradle name based on the value in `gradle.properties`
rootProject.name = mod_name
val projectName: String = extra["mod.name"]?.toString()
?: throw MissingPropertyException("mod.name has not been set.")
rootProject.name = projectName
rootProject.buildFileName = "root.gradle.kts"

// Adds all of our build target versions to the classpath if we need to add version-specific code.
Expand All @@ -27,4 +40,4 @@ listOf(
projectDir = file("versions/$version")
buildFileName = "../../build.gradle.kts"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiIngame;
import org.polyfrost.crosshair.config.ModConfig;
import org.polyfrost.crosshair.config.PolyCrosshairConfig;
import org.polyfrost.crosshair.config.RenderConfig;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.*;
Expand All @@ -12,9 +12,9 @@
public class GuiIngameMixin {
@Inject(method = "showCrosshair", at = @At("HEAD"), cancellable = true)
private void check(CallbackInfoReturnable<Boolean> cir) {
RenderConfig cfg = ModConfig.INSTANCE.getRenderConfig();
RenderConfig cfg = PolyCrosshairConfig.INSTANCE.getRenderConfig();
Minecraft mc = Minecraft.getMinecraft();
if (!ModConfig.INSTANCE.enabled) return;
if (!PolyCrosshairConfig.INSTANCE.enabled) return;
if ((!cfg.getShowInGuis() && mc.currentScreen != null) || (!cfg.getShowInThirdPerson() && mc.gameSettings.thirdPersonView != 0)) {
cir.setReturnValue(false);
}
Expand Down
19 changes: 9 additions & 10 deletions src/main/kotlin/org/polyfrost/crosshair/PolyCrosshair.kt
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
package org.polyfrost.crosshair

import cc.polyfrost.oneconfig.config.core.ConfigUtils
import cc.polyfrost.oneconfig.events.EventManager
import cc.polyfrost.oneconfig.events.event.ShutdownEvent
import cc.polyfrost.oneconfig.libs.eventbus.Subscribe
import net.minecraftforge.common.MinecraftForge
import net.minecraftforge.fml.common.Mod
import net.minecraftforge.fml.common.event.FMLInitializationEvent
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent
import org.polyfrost.crosshair.config.ModConfig
import org.polyfrost.crosshair.config.PolyCrosshairConfig
import org.polyfrost.crosshair.render.CrosshairRenderer
import org.polyfrost.oneconfig.api.event.v1.EventManager
import org.polyfrost.oneconfig.api.event.v1.events.ShutdownEvent
import org.polyfrost.oneconfig.api.event.v1.invoke.impl.Subscribe
import java.io.File

@Mod(
modid = PolyCrosshair.MODID,
name = PolyCrosshair.NAME,
version = PolyCrosshair.VERSION,
modLanguageAdapter = "cc.polyfrost.oneconfig.utils.KotlinLanguageAdapter"
modLanguageAdapter = "org.polyfrost.oneconfig.utils.v1.forge.KotlinLanguageAdapter"
)
object PolyCrosshair {
const val MODID = "@ID@"
const val NAME = "@NAME@"
const val VERSION = "@VER@"
const val MODID = "@MOD_ID@"
const val NAME = "@MOD_NAME@"
const val VERSION = "@MOD_VERSION@"

val path = "${ConfigUtils.getProfileDir().absolutePath}/${MODID}/caches/"

Expand All @@ -31,7 +30,7 @@ object PolyCrosshair {
fun onFMLInitialization(event: FMLInitializationEvent) {
clearCaches()
dir.mkdirs()
ModConfig
PolyCrosshairConfig
MinecraftForge.EVENT_BUS.register(CrosshairRenderer)
EventManager.INSTANCE.register(this)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ class CrosshairEntry(
@Button(name = "Transform", text = "Reset", size = 1)
var transformReset = Runnable {
runAsync {
val img = ModConfig.newCurrentCrosshair.img
ModConfig.newCurrentCrosshair.loadFrom(CrosshairEntry())
ModConfig.newCurrentCrosshair.img = img
val img = PolyCrosshairConfig.newCurrentCrosshair.img
PolyCrosshairConfig.newCurrentCrosshair.loadFrom(CrosshairEntry())
PolyCrosshairConfig.newCurrentCrosshair.img = img
save(Drawer.saveFromDrawer(false))
}
}
Expand Down
Loading

0 comments on commit 7d3b39c

Please sign in to comment.