Skip to content

Commit

Permalink
Merge pull request #164 from LostLuma/multi-platform
Browse files Browse the repository at this point in the history
Add Forge and NeoForge support
  • Loading branch information
LostLuma authored Feb 17, 2024
2 parents 0eb4df9 + 5fc6bef commit 2eede57
Show file tree
Hide file tree
Showing 126 changed files with 1,792 additions and 408 deletions.
9 changes: 4 additions & 5 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ root = true
tab_width = 4
charset = utf-8

indent_size = 4
indent_style = space

insert_final_newline = true
trim_trailing_whitespace = true

[*.{gradle,java,json,toml}]
[*.{gradle,java}]
indent_style = tab

[*.{properties,yaml}]
indent_size = 2
indent_style = space

[*.md]
trim_trailing_whitespace = false
5 changes: 4 additions & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,8 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: dynamic-fps-artifacts
path: build/libs
path: |
platforms/**/build/libs
!platforms/**/build/libs/*-all.jar
!platforms/**/build/libs/*-transformProduction*.jar
if-no-files-found: error
108 changes: 47 additions & 61 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,86 +1,72 @@
plugins {
id "maven-publish"
alias libs.plugins.fabric.loom
alias libs.plugins.architectury
alias libs.plugins.architectury.loom apply false
}

group = project.maven_group
version = "${generateVersion()}+minecraft-${libs.versions.minecraft.get()}"

base {
archivesName = project.archives_base_name
}

repositories {
maven { url = "https://maven.shedaniel.me/" } // cloth config
maven { url = "https://maven.terraformersmc.com/releases/" } // modmenu
architectury {
minecraft = libs.versions.minecraft.get()
}

dependencies {
minecraft libs.minecraft
mappings loom.officialMojangMappings()
subprojects {
if (project.name == "platforms") {
return
}

modImplementation libs.fabric.api
modImplementation libs.fabric.loader
apply plugin: "dev.architectury.loom"

modApi libs.modmenu
modApi libs.cloth.config
}
loom {
silentMojangMappingsLicense()
}

loom {
accessWidenerPath = file("src/main/resources/dynamic_fps.accesswidener")
dependencies {
minecraft libs.minecraft
mappings loom.officialMojangMappings()
}
}

processResources {
inputs.property "version", generateVersion()

filesMatching("fabric.mod.json") {
expand "version": generateVersion()
allprojects {
if (project.name == "platforms") {
return
}
}

java {
withSourcesJar()
apply plugin: "java"
apply plugin: "architectury-plugin"
apply plugin: "maven-publish"

toolchain {
languageVersion = JavaLanguageVersion.of(17)
base {
archivesName = rootProject.archives_base_name
}
}

tasks.withType(JavaCompile).configureEach {
it.options.encoding = "UTF-8"
group = rootProject.maven_group

javaCompiler = javaToolchains.compilerFor {
languageVersion = JavaLanguageVersion.of(17)
if (!project.hasProperty("loom.platform")) {
version = rootProject.mod_version
} else {
var platform = project.property("loom.platform")
version = "${rootProject.mod_version}+minecraft-${libs.versions.minecraft.get()}-${platform}"
}

it.options.compilerArgs += ["-Xlint:deprecation", "-Xlint:unchecked"]
}

tasks.withType(org.gradle.jvm.tasks.Jar).configureEach {
it.from(".") {
include("LICENSE")
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.
}
}

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

toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}

// 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.
}
}
tasks.withType(JavaCompile).configureEach {
it.options.encoding = "UTF-8"

def generateVersion() {
var version = project.mod_version;
// NOTE: To create a release jar run `./gradlew build -Prelease=true`
return project.hasProperty("release") ? version : version + "-alpha";
javaCompiler = javaToolchains.compilerFor {
languageVersion = JavaLanguageVersion.of(17)
}
}
}
6 changes: 4 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Gradle
# Gradle Properties
org.gradle.parallel = true
org.gradle.jvmargs = -Xmx1G
org.gradle.jvmargs = -Xmx3G

# Mod Properties
mod_version = 3.3.3
maven_group = juliand665
archives_base_name = dynamic-fps

enabled_platforms=fabric,forge,neoforge,quilt
46 changes: 38 additions & 8 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,22 +1,52 @@
[versions]
minecraft = "1.20"
fabric_loader = "0.15.3"
minecraft = "1.20.4"

modmenu = "7.0.1"
fabric_api = "0.83.0+1.20"
# Platform libraries

cloth_config = "11.0.99"
fabric_loader = "0.15.6"
fabric_api = "0.96.1+1.20.4"

forge = "1.20.4-49.0.30"

neoforge = "20.4.160-beta"

quilt_loader = "0.23.1"
quilt_standard_libraries = "7.0.0-alpha.10+1.20.2"

# Third-party libraries

modmenu = "9.0.0"
cloth_config = "13.0.121"

mixinextras = "0.3.5"

[libraries]
minecraft = { module = "com.mojang:minecraft", version.ref = "minecraft" }

# Platform libraries

fabric_loader = { module = "net.fabricmc:fabric-loader", version.ref = "fabric_loader" }
# fabric_api = { module = "net.fabricmc.fabric-api:fabric-api", version.ref = "fabric_api" }

forge = { module = "net.minecraftforge:forge", version.ref = "forge" }

neoforge = { module = "net.neoforged:neoforge", version.ref = "neoforge" }

quilt_loader = { module = "org.quiltmc:quilt-loader", version.ref = "quilt_loader" }
qsl_lifecycle_events = { module = "org.quiltmc.qsl.core:lifecycle_events", version.ref = "quilt_standard_libraries" }

# Third-party libraries

modmenu = { module = "com.terraformersmc:modmenu", version.ref = "modmenu" }
fabric_api = { module = "net.fabricmc.fabric-api:fabric-api", version.ref = "fabric_api" }
cloth_config = { module = "me.shedaniel.cloth:cloth-config", version.ref = "cloth_config" }

cloth_config = { module = "me.shedaniel.cloth:cloth-config-fabric", version.ref = "cloth_config" }
mixinextras_common = { module = "io.github.llamalad7:mixinextras-common", version.ref = "mixinextras" }
mixinextras_forge = { module = "io.github.llamalad7:mixinextras-forge", version.ref = "mixinextras" }

[bundles]

[plugins]
fabric_loom = { id = "fabric-loom", version = "1.5.7" }
shadow = { id = "com.github.johnrengelman.shadow", version = "8.1.1" }

architectury = { id = "architectury-plugin", version = "3.4.151" }
architectury_loom = { id = "dev.architectury.loom", version = "1.5.388" }
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
28 changes: 28 additions & 0 deletions platforms/common/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
architectury {
common(rootProject.enabled_platforms.split(","))
}

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

dependencies {
// We depend on fabric loader here to use the fabric @Environment annotations and get the mixin dependencies
// Do NOT use other classes from fabric loader
modImplementation libs.fabric.loader
modImplementation libs.cloth.config
}

publishing {
publications {
mavenCommon(MavenPublication) {
artifactId = rootProject.archives_base_name
from components.java
}
}

// 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.
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package dynamic_fps.impl;

import dynamic_fps.impl.compat.FREX;
import dynamic_fps.impl.compat.GLFW;
import dynamic_fps.impl.config.Config;
import dynamic_fps.impl.config.DynamicFPSConfig;
import dynamic_fps.impl.service.ModCompat;
import dynamic_fps.impl.util.Logging;
import dynamic_fps.impl.util.ModCompatibility;
import dynamic_fps.impl.util.OptionsHolder;
import dynamic_fps.impl.util.duck.DuckScreen;
import dynamic_fps.impl.util.duck.DuckLoadingOverlay;
import dynamic_fps.impl.util.duck.DuckSoundEngine;
import dynamic_fps.impl.util.event.InputObserver;
import dynamic_fps.impl.util.event.WindowObserver;
import dynamic_fps.impl.service.Platform;
Expand All @@ -23,8 +25,8 @@ public class DynamicFPSMod {

public static DynamicFPSConfig modConfig = DynamicFPSConfig.load();

private static boolean isDisabled = false;
private static boolean isForcingLowFPS = false;
private static boolean isDisabled = false;

private static final Minecraft minecraft = Minecraft.getInstance();

Expand All @@ -42,10 +44,15 @@ public class DynamicFPSMod {
// inactive.
private static boolean hasRenderedLastFrame = false;

private static final boolean OVERLAY_OPTIMIZATION_ACTIVE = !ModCompatibility.disableOverlayOptimization();
private static final boolean OVERLAY_OPTIMIZATION_ACTIVE = !ModCompat.getInstance().disableOverlayOptimization();

// Internal "API" for Dynamic FPS itself

public static void init() {
Platform platform = Platform.getInstance();
Logging.getLogger().info("Dynamic FPS {} active on {}!", platform.modVersion(), platform.getName());
}

public static boolean isDisabled() {
return isDisabled;
}
Expand Down Expand Up @@ -124,11 +131,11 @@ public static boolean shouldShowLevels() {
// Internal logic

private static boolean isDisabledInternal() {
return isDisabled || FREX.isFlawlessFramesActive();
return isDisabled || ModCompat.getInstance().isDisabled();
}

private static boolean isLevelCoveredByScreen() {
return minecraft.screen != null && minecraft.screen.dynamic_fps$rendersBackground();
return minecraft.screen != null && ((DuckScreen) minecraft.screen).dynamic_fps$rendersBackground();
}

private static boolean isIdle() {
Expand All @@ -142,7 +149,7 @@ private static boolean isIdle() {
}

private static boolean isLevelCoveredByOverlay() {
return OVERLAY_OPTIMIZATION_ACTIVE && minecraft.getOverlay() instanceof LoadingOverlay && ((LoadingOverlay)minecraft.getOverlay()).dynamic_fps$isReloadComplete();
return OVERLAY_OPTIMIZATION_ACTIVE && minecraft.getOverlay() instanceof LoadingOverlay && ((DuckLoadingOverlay)minecraft.getOverlay()).dynamic_fps$isReloadComplete();
}

private static void initializeIdleCheck() {
Expand Down Expand Up @@ -199,7 +206,7 @@ public static void handleStateChange(PowerState previous, PowerState current) {

for (SoundSource source : SoundSource.values()) {
if (before.volumeMultiplier(source) != config.volumeMultiplier(source)) {
minecraft.getSoundManager().soundEngine.dynamic_fps$updateVolume(source);
((DuckSoundEngine) minecraft.getSoundManager().soundEngine).dynamic_fps$updateVolume(source);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package dynamic_fps.impl.compat;

import dynamic_fps.impl.DynamicFPSMod;
import dynamic_fps.impl.GraphicsState;
import dynamic_fps.impl.PowerState;
import dynamic_fps.impl.config.Config;
import me.shedaniel.clothconfig2.api.ConfigBuilder;
import me.shedaniel.clothconfig2.api.ConfigCategory;
Expand All @@ -10,17 +13,12 @@
import net.minecraft.network.chat.Component;
import net.minecraft.sounds.SoundSource;

import static dynamic_fps.impl.util.Localization.localized;

import java.util.Locale;
import java.util.Optional;

import dynamic_fps.impl.DynamicFPSMod;
import dynamic_fps.impl.GraphicsState;
import dynamic_fps.impl.PowerState;
import static dynamic_fps.impl.util.Localization.localized;

public final class ClothConfig {
@SuppressWarnings("unchecked")
public static Screen genConfigScreen(Screen parent) {
ConfigBuilder builder = ConfigBuilder.create()
.setParentScreen(parent)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package dynamic_fps.impl.mixin;

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;

import dynamic_fps.impl.DynamicFPSMod;
import net.minecraft.client.gui.Gui;

@Mixin(Gui.class)
public class GuiMixin {
/**
* Cancels rendering the GUI if it is determined to currently not be visible.
*/
@Inject(method = "render", at = @At("HEAD"), cancellable = true)
private void shouldRender(CallbackInfo callbackInfo) {
if (!DynamicFPSMod.shouldShowLevels()) {
callbackInfo.cancel();
}
}
}
Loading

0 comments on commit 2eede57

Please sign in to comment.