Skip to content

Commit

Permalink
Port to Legacy Fabric, update OneConfig, etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
Deftu committed Dec 13, 2024
1 parent 3800a82 commit bd71ad9
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 46 deletions.
4 changes: 3 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ preprocess {

toolkitLoomHelper {
// Adds OneConfig to our project
useOneConfig(mcData.version, mcData.loader, "commands", "config-impl", "events", "hud", "internal", "ui")
useOneConfig("1.1.0-alpha.34", "1.0.0-alpha.43", mcData, "commands", "config-impl", "events", "hud", "internal", "ui")
useDevAuth()

// Removes the server configs from IntelliJ IDEA, leaving only client runs.
Expand Down Expand Up @@ -59,5 +59,7 @@ dependencies {
// If we are building for legacy forge, includes the launch wrapper with `shade` as we configured earlier.
if (mcData.isLegacyForge) {
compileOnly("org.spongepowered:mixin:0.7.11-SNAPSHOT")
} else if (mcData.isFabric) {
modImplementation("net.fabricmc:fabric-language-kotlin:${mcData.dependencies.fabric.fabricLanguageKotlinVersion}")
}
}
4 changes: 3 additions & 1 deletion root.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ plugins {
}

preprocess {
"1.8.9-forge"(10809, "srg") {}
"1.8.9-forge"(10809, "srg") {
"1.8.9-fabric"(10809, "yarn")
}
}
5 changes: 3 additions & 2 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pluginManagement {

plugins {
kotlin("jvm") version("2.0.0")
id("dev.deftu.gradle.multiversion-root") version("2.11.2")
id("dev.deftu.gradle.multiversion-root") version("2.13.0")
}
}

Expand All @@ -33,7 +33,8 @@ 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"
"1.8.9-forge",
"1.8.9-fabric"
).forEach { version ->
include(":$version")
project(":$version").apply {
Expand Down
32 changes: 0 additions & 32 deletions src/main/java/org/polyfrost/colorsaturation/ColorSaturation.java

This file was deleted.

8 changes: 4 additions & 4 deletions src/main/java/org/polyfrost/colorsaturation/Saturation.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public class Saturation {
@Subscribe
private void onRenderTick(RenderEvent.End event) {
// Only update the shader if one is active
if (!isShaderActive() || lastEnabled != ColorSaturation.config.enabled) {
lastEnabled = ColorSaturation.config.enabled;
if (!isShaderActive() || lastEnabled != ColorSaturation.getConfig().enabled) {
lastEnabled = ColorSaturation.getConfig().enabled;
reloadShader();
}
}
Expand All @@ -33,7 +33,7 @@ public static void reloadShader() {
return;
}

if (!isShaderActive() && ColorSaturation.config.enabled) {
if (!isShaderActive() && ColorSaturation.getConfig().enabled) {
try {
final ShaderGroup saturationShader = new ShaderGroup(UMinecraft.getMinecraft().getTextureManager(), UMinecraft.getMinecraft().getResourceManager(), UMinecraft.getMinecraft().getFramebuffer(), phosphorBlur);
saturationShader.createBindFramebuffers(UResolution.getWindowWidth(), UResolution.getWindowHeight());
Expand All @@ -42,7 +42,7 @@ public static void reloadShader() {
} catch (IOException e) {
e.printStackTrace();
}
} else if (isShaderActive() && !ColorSaturation.config.enabled) {
} else if (isShaderActive() && !ColorSaturation.getConfig().enabled) {
final EntityRendererHook entityRenderer = (EntityRendererHook) UMinecraft.getMinecraft().entityRenderer;
if (entityRenderer.colorSaturation$getSaturationShader() != null) {
entityRenderer.colorSaturation$getSaturationShader().deleteShaderGroup();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

import org.polyfrost.colorsaturation.ColorSaturation;
import org.polyfrost.oneconfig.api.commands.v1.factories.annotated.Command;
import org.polyfrost.utils.v1.dsl.ScreensKt;
import org.polyfrost.oneconfig.utils.v1.dsl.ScreensKt;

@Command(value = ColorSaturation.MODID, description = "Access the " + ColorSaturation.NAME + " GUI.")
@Command(value = ColorSaturation.ID, description = "Access the " + ColorSaturation.NAME + " GUI.")
public class SaturationCommand {
@Command
private void main() {
// TODO Implement openGui
// ColorSaturation.config.openGui();
ScreensKt.openUI(ColorSaturation.config);
// ColorSaturation.getConfig().openGui();
ScreensKt.openUI(ColorSaturation.getConfig());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class SaturationConfig extends Config {
public static float saturation = 1;

public SaturationConfig() {
super(ColorSaturation.MODID + ".json", "/colorsaturation.svg", ColorSaturation.NAME, Category.QOL);
super(ColorSaturation.ID + ".json", "/colorsaturation.svg", ColorSaturation.NAME, Category.QOL);

addCallback("saturation", () -> {
if (enabled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class OptifineConfigMixin {
@Dynamic("OptiFine")
@Inject(method = "isFastRender", at = @At("HEAD"), cancellable = true)
private static void cancelFastRender(CallbackInfoReturnable<Boolean> cir) {
if (ColorSaturation.config != null && ColorSaturation.config.enabled && SaturationConfig.forceDisableFastRender) {
if (ColorSaturation.getConfig() != null && ColorSaturation.getConfig().enabled && SaturationConfig.forceDisableFastRender) {
cir.setReturnValue(false);
}
}
Expand Down
49 changes: 49 additions & 0 deletions src/main/kotlin/org/polyfrost/colorsaturation/ColorSaturation.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package org.polyfrost.colorsaturation

//#if FORGE
import net.minecraftforge.fml.common.Mod
import net.minecraftforge.fml.common.event.FMLInitializationEvent
//#else
//$$ import net.fabricmc.api.ClientModInitializer
//#endif

import org.polyfrost.colorsaturation.command.SaturationCommand
import org.polyfrost.colorsaturation.config.SaturationConfig
import org.polyfrost.oneconfig.api.commands.v1.CommandManager
import org.polyfrost.oneconfig.api.event.v1.EventManager

//#if FORGE
@Mod(modid = ColorSaturation.ID, version = ColorSaturation.VERSION, name = ColorSaturation.NAME, modLanguageAdapter = "org.polyfrost.oneconfig.utils.v1.forge.KotlinLanguageAdapter")
//#endif
object ColorSaturation
//#if FABRIC
//$$ : ClientModInitializer
//#endif
{

const val ID = "@MOD_ID@"
const val NAME = "@MOD_NAME@"
const val VERSION = "@MOD_VERSION@"

@JvmStatic
lateinit var config: SaturationConfig
private set

fun initialize() {
config = SaturationConfig()
CommandManager.registerCommand(SaturationCommand())
EventManager.INSTANCE.register(Saturation())
}

//#if FORGE
@Mod.EventHandler
fun onInit(e: FMLInitializationEvent) {
initialize()
}
//#else
//$$ override fun onInitializeClient() {
//$$ initialize()
//$$ }
//#endif

}
30 changes: 30 additions & 0 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"schemaVersion": 1,
"id": "${mod_id}",
"version": "${mod_version}",
"name": "${mod_name}",
"authors": [
"Polyfrost"
],
"contact": {
"issues": "https://github.com/Polyfrost/${mod_name}/issues",
"sources": "https://github.com/Polyfrost/${mod_name}"
},
"license": "GPL-3.0-or-later",
"environment": "*",
"entrypoints": {
"client": [
{
"adapter": "kotlin",
"value": "org.polyfrost.colorsaturation.ColorSaturation"
}
]
},
"mixins": [
"mixins.${mod_id}.json"
],
"depends": {
"fabricloader": ">=0.15.11",
"fabric-language-kotlin": "*"
}
}

0 comments on commit bd71ad9

Please sign in to comment.