Skip to content

Commit

Permalink
port to forge
Browse files Browse the repository at this point in the history
  • Loading branch information
TexBlock committed Sep 7, 2023
1 parent b10591f commit 2194a36
Show file tree
Hide file tree
Showing 14 changed files with 128 additions and 466 deletions.
222 changes: 26 additions & 196 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
plugins {
id 'fabric-loom' version '1.2.+'
id 'io.github.juuxel.loom-quiltflower' version '1.8.+'
id 'org.quiltmc.gradle.licenser' version '2.0.+'
id 'dev.architectury.loom' version '1.2-SNAPSHOT'
id 'io.github.juuxel.loom-vineflower' version '1.+'
id 'java-library'
id 'maven-publish'
id 'com.github.johnrengelman.shadow' version '7.1.2'
Expand All @@ -18,114 +17,50 @@ archivesBaseName = project.archives_base_name
// This field defines the Java version your mod target.
def targetJavaVersion = 17

boolean isMCVersionNonRelease() {
return project.minecraft_version.matches('^\\d\\dw\\d\\d[a-z]$')
|| project.minecraft_version.matches('\\d+\\.\\d+-(pre|rc)(\\d+)')
}
loom {
accessWidenerPath = file("src/main/resources/lambdynlights.accesswidener")

String getMCVersionString() {
if (isMCVersionNonRelease()) {
return project.minecraft_version
}
def version = project.minecraft_version.split('\\.')
return version[0] + '.' + version[1]
}
forge {
convertAccessWideners = true
extraAccessWideners.add loom.accessWidenerPath.get().asFile.name

String getVersionType() {
if (isMCVersionNonRelease() || version.contains("-alpha.")) {
return "alpha"
} else if (version.contains("-beta.")) {
return "beta"
} else {
return "release"
mixinConfigs = [
"lambdynlights.mixins.json","lambdynlights.lightsource.mixins.json"
]
}
}

String parseReadme() {
def excludeRegex = /(?m)<!-- modrinth_exclude\.start -->(.|\n)*?<!-- modrinth_exclude\.end -->/
def linkRegex = /!\[([A-z_ ]+)]\((images\/[A-z.\/_]+)\)/

def readme = (String) file('README.md').text
readme = readme.replaceAll(excludeRegex, '')
readme = readme.replaceAll(linkRegex, '![$1](https://raw.githubusercontent.com/LambdAurora/LambDynamicLights/1.19/$2)')
return readme
}

String fetchChangelog() {
def changelogText = file('CHANGELOG.md').text
def regexVersion = ((String) project.mod_version).replaceAll('\\.', /\\./).replaceAll('\\+', '\\+')
def changelogRegex = ~"###? ${regexVersion}\\n\\n(( *- .+\\n)+)"
def matcher = changelogText =~ changelogRegex

if (matcher.find()) {
def changelogContent = matcher.group(1)

def changelogLines = changelogText.split('\n')
def linkRefRegex = ~'^\\[([A-z\\d _\\-/+.]+)]: '
for (int i = changelogLines.length - 1; i > 0; i--) {
def line = changelogLines[i]
if ((line =~ linkRefRegex).find())
changelogContent += '\n' + line
else break
}
return changelogContent
} else {
return null;
}
}

repositories {
mavenLocal()
mavenCentral()
maven {
name "Quilt"
url "https://maven.quiltmc.org/repository/release"
}
maven {
name 'Terraformers'
url 'https://maven.terraformersmc.com/releases/'
}
maven {
name 'Gegy'
url 'https://maven.gegy.dev'
}
maven {
name 'grondag'
url 'https://maven.dblsaiko.net/'
exclusiveContent {
forRepository {
maven {
name "Modrinth"
url "https://api.modrinth.com/maven"
}
}
filter {
includeGroup "maven.modrinth"
}
}
}

configurations {
shadow
api.extendsFrom shadow
}

loom {
accessWidenerPath = file("src/main/resources/lambdynlights.accesswidener")
}

dependencies {
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "org.quiltmc:quilt-mappings:${minecraft_version}+build.${project.quilt_mappings}:intermediary-v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
mappings "org.quiltmc:quilt-mappings:${project.quilt_mappings}:intermediary-v2"
forge "net.minecraftforge:forge:${project.forge_version}"

// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_api_version}"
modImplementation("dev.architectury:architectury-forge:${project.architectury_version}")

modImplementation include("dev.lambdaurora:spruceui:${project.spruceui_version}")
modImplementation include("io.github.queerbric:pridelib:${project.pridelib_version}")

modImplementation("com.terraformersmc:modmenu:${project.modmenu_version}") {
transitive = false
}

shadow 'com.electronwill.night-config:core:3.6.6'
shadow 'com.electronwill.night-config:toml:3.6.6'
modImplementation("maven.modrinth:obsidianui:${project.spruceui_version}")
}

java {
sourceCompatibility = JavaVersion.toVersion(targetJavaVersion)
targetCompatibility = JavaVersion.toVersion(targetJavaVersion)
sourceCompatibility = targetCompatibility = JavaVersion.toVersion(targetJavaVersion)

withSourcesJar()
}
Expand All @@ -139,7 +74,7 @@ tasks.withType(JavaCompile).configureEach {
processResources {
inputs.property 'version', project.version

filesMatching('fabric.mod.json') {
filesMatching('META-INF/mods.toml') {
expand 'version': project.version
}
}
Expand All @@ -150,120 +85,15 @@ jar {
}
}

license {
rule file('HEADER')
include '**/*.java'
}

shadowJar {
dependsOn jar
configurations = [project.configurations.shadow]
destinationDirectory.set(file("${project.buildDir}/devlibs"))
archiveClassifier.set('dev')

relocate 'com.electronwill.nightconfig', 'dev.lambdaurora.lambdynlights.shadow.nightconfig'
}
remapJar.dependsOn(shadowJar)

modrinth {
projectId = project.modrinth_id
versionName = "LambDynamicLights ${project.mod_version} (${getMCVersionString()})"
uploadFile = tasks.remapJar
loaders = ["fabric", "quilt"]
gameVersions = [project.minecraft_version]
versionType = isMCVersionNonRelease() ? "beta" : "release"
syncBodyFrom = parseReadme()
dependencies = [
new ModDependency("P7dR8mSH", "required")
]

// Changelog fetching
def changelogContent = fetchChangelog()

if (changelogContent) {
changelog = changelogContent
} else {
afterEvaluate {
tasks.modrinth.setEnabled(false)
}
}
}
tasks.modrinth.dependsOn(tasks.modrinthSyncBody)

curseforge {
if (System.getenv("CURSEFORGE_TOKEN")) {
apiKey = System.getenv("CURSEFORGE_TOKEN")
}

project {
id = project.curseforge_id
releaseType = this.getVersionType()
addGameVersion project.minecraft_version
addGameVersion "Fabric"
addGameVersion "Quilt"
addGameVersion "Java 17"
addGameVersion "Java 18"

// Changelog fetching
def changelogContent = fetchChangelog()

if (changelogContent) {
changelogType = "markdown"
changelog = "Changelog:\n\n${changelogContent}"
} else {
afterEvaluate {
uploadTask.setEnabled(false)
}
}

mainArtifact(remapJar) {
displayName = "LambDynamicLights ${project.mod_version} (${project.minecraft_version})"

relations {
requiredDependency "fabric-api"
optionalDependency "modmenu"
incompatible "optifabric"
}
}

afterEvaluate {
uploadTask.setGroup("publishing")
uploadTask.dependsOn("remapJar")
}
}
}
tasks.curseforge.setGroup("publishing")

// configure the maven publication
publishing {
publications {
mavenJava(MavenPublication) {
from components.java

pom {
name = "LambDynamicLights"
description = "Adds dynamic lights to the game."
}
}
}

repositories {
mavenLocal()
maven {
name = 'BuildDirLocal'
url = "$buildDir/repo"
}

def ldlMaven = System.getenv('LDL_MAVEN')
if (ldlMaven) {
maven {
name = 'LambDynamicLightsMaven'
url = uri(ldlMaven)
credentials {
username = project.findProperty('gpr.user') ?: System.getenv('MAVEN_USERNAME')
password = project.findProperty('gpr.key') ?: System.getenv('MAVEN_PASSWORD')
}
}
}
}
}
20 changes: 8 additions & 12 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
# Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx2G
loom.platform=forge

# Fabric Properties
# check these on https://fabricmc.net/use
# Base Properties
minecraft_version=1.19.4
quilt_mappings=5
loader_version=0.14.21
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
fabric_api_version=0.76.0+1.19.4
quilt_mappings=1.19.4+build.10
forge_version=1.19.4-45.1.19

# Mod Properties
mod_version = 2.3.1
mod_version = 0.1.0
maven_group = dev.lambdaurora
archives_base_name = lambdynamiclights
archives_base_name = Ryoamiclights
modrinth_id=yBW8D80W
curseforge_id=393442

# Dependencies
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
spruceui_version=4.2.0+1.19.4
pridelib_version=1.2.0+1.19.4
modmenu_version=6.2.3
architectury_version=8.2.89
spruceui_version=0.1.3+1.19.4
14 changes: 5 additions & 9 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
pluginManagement {
repositories {
maven {
name 'Quilt'
url 'https://maven.quiltmc.org/repository/release'
}
maven {
name 'Fabric'
url 'https://maven.fabricmc.net/'
}
maven { url "https://maven.quiltmc.org/repository/release" }
maven { url "https://maven.fabricmc.net/" }
maven { url "https://maven.architectury.dev/" }
maven { url "https://files.minecraftforge.net/maven/" }
gradlePluginPortal()
}
}

rootProject.name = 'lambdynamiclights'
rootProject.name = 'RyoamicLights'
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
package dev.lambdaurora.lambdynlights;

import com.electronwill.nightconfig.core.file.FileConfig;
import dev.architectury.platform.Platform;
import dev.lambdaurora.lambdynlights.config.BooleanSettingEntry;
import dev.lambdaurora.lambdynlights.config.SettingEntry;
import dev.lambdaurora.spruceui.option.SpruceCyclingOption;
import dev.lambdaurora.spruceui.option.SpruceOption;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.text.Text;
Expand All @@ -38,7 +38,7 @@ public class DynamicLightsConfig {
private static final ExplosiveLightingMode DEFAULT_CREEPER_LIGHTING_MODE = ExplosiveLightingMode.SIMPLE;
private static final ExplosiveLightingMode DEFAULT_TNT_LIGHTING_MODE = ExplosiveLightingMode.OFF;

public static final Path CONFIG_FILE_PATH = FabricLoader.getInstance().getConfigDir().resolve("lambdynlights.toml");
public static final Path CONFIG_FILE_PATH = Platform.getConfigFolder().resolve("lambdynlights.toml");
protected final FileConfig config;
private final LambDynLights mod;
private DynamicLightsMode dynamicLightsMode;
Expand All @@ -61,7 +61,8 @@ public class DynamicLightsConfig {
public DynamicLightsConfig(@NotNull LambDynLights mod) {
this.mod = mod;

this.config = FileConfig.builder(CONFIG_FILE_PATH).concurrent().defaultResource("/lambdynlights.toml").autosave().build();
//this.config = FileConfig.builder(CONFIG_FILE_PATH).concurrent().defaultResource("/lambdynlights.toml").autosave().build();
this.config = FileConfig.builder(CONFIG_FILE_PATH).concurrent().autosave().build();
this.entitiesLightSource = new BooleanSettingEntry("light_sources.entities", DEFAULT_ENTITIES_LIGHT_SOURCE, this.config,
Text.translatable("lambdynlights.tooltip.entities"))
.withOnSet(value -> {
Expand Down
Loading

0 comments on commit 2194a36

Please sign in to comment.