Skip to content

Commit

Permalink
Enable and fix up Forge module for 1.21.0
Browse files Browse the repository at this point in the history
  • Loading branch information
LostLuma committed Aug 13, 2024
1 parent 8ca36ab commit 7443875
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 23 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ minecraft_version = 1.21.0
minecraft_version_min = 1.21
minecraft_version_max = 1.21

enabled_platforms=fabric,neoforge,quilt
enabled_platforms=fabric,forge,neoforge,quilt
6 changes: 3 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ minecraft = "1.21"
fabric_loader = "0.15.10"
fabric_api = "0.100.1+1.21"

forge = "1.20.4-49.0.30"
forge = "1.21-51.0.33"

neoforge = "21.0.143"

Expand All @@ -23,8 +23,8 @@ cloth_config = "15.0.127"

mixinextras = "0.3.5"

architectury = "3.4.155"
architectury_loom = "1.7.410"
architectury = "3.4.159"
architectury_loom = "1.7.412"

mod_publish = "0.6.3"

Expand Down
2 changes: 2 additions & 0 deletions platforms/forge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ configurations {
dependencies {
forge libs.forge

include(libs.battery)

compileOnly(libs.mixinextras.common)
annotationProcessor(libs.mixinextras.common)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
import dynamic_fps.impl.Constants;
import dynamic_fps.impl.DynamicFPSMod;
import dynamic_fps.impl.service.Platform;
import dynamic_fps.impl.util.HudInfoRenderer;
import dynamic_fps.impl.util.KeyMappingHandler;
import net.minecraftforge.client.ConfigScreenHandler;
import net.minecraftforge.client.event.RegisterKeyMappingsEvent;
import net.minecraftforge.client.event.RenderGuiOverlayEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.fml.ModLoadingContext;
Expand Down Expand Up @@ -37,14 +35,16 @@ public DynamicFPSForgeMod() {
);

MinecraftForge.EVENT_BUS.addListener(this::onClientTick);
MinecraftForge.EVENT_BUS.addListener(this::renderGuiOverlay);
// MinecraftForge.EVENT_BUS.addListener(this::renderGuiOverlay);

FMLJavaModLoadingContext.get().getModEventBus().addListener(this::registerKeyMappings);
}

/*
public void renderGuiOverlay(RenderGuiOverlayEvent event) {
HudInfoRenderer.renderInfo(event.getGuiGraphics());
}
*/

public void registerKeyMappings(RegisterKeyMappingsEvent event) {
for (KeyMappingHandler handler : KeyMappingHandler.getHandlers()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package net.lostluma.dynamic_fps.impl.forge.mixin;

import com.llamalad7.mixinextras.sugar.Local;
import dynamic_fps.impl.util.HudInfoRenderer;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiGraphics;
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;

@Mixin(Gui.class)
public class GuiMixin {
/**
* Render info on whether Dynamic FPS is disabled or always reducing the user's FPS.
*/
@Inject(method = "renderSavingIndicator", at = @At("HEAD"))
private void renderSavingIndicator(CallbackInfo callbackInfo, @Local(argsOnly = true) GuiGraphics guiGraphics) {
HudInfoRenderer.renderInfo(guiGraphics);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import dynamic_fps.impl.Constants;
import dynamic_fps.impl.service.Platform;
import dynamic_fps.impl.util.Version;
import net.lostluma.dynamic_fps.impl.forge.DynamicFPSForgeMod;
import net.minecraftforge.fml.ModContainer;
import net.minecraftforge.fml.ModList;
Expand Down Expand Up @@ -41,9 +42,20 @@ public boolean isModLoaded(String modId) {
}

@Override
public Optional<String> getModVersion(String modId) {
public Optional<Version> getModVersion(String modId) {
Optional<? extends ModContainer> optional = ModList.get().getModContainerById(modId);
return optional.map(modContainer -> modContainer.getModInfo().getVersion().toString());

if (!optional.isPresent()) {
return Optional.empty();
}

String raw = optional.get().getModInfo().getVersion().toString();

try {
return Optional.of(Version.of(raw));
} catch (Version.VersionParseException e) {
throw new RuntimeException(e);
}
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion platforms/forge/src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,6 @@ file="META-INF/accesstransformer.cfg"
[[dependencies.dynamic_fps]]
modId = "minecraft"
mandatory = true
versionRange = "[1.20.0,1.20.4]"
versionRange = "[1.21.0,)"
ordering = "NONE"
side = "CLIENT"
26 changes: 14 additions & 12 deletions platforms/forge/src/main/resources/dynamic_fps.mixins.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
{
"required": true,
"package": "net.lostluma.dynamic_fps.impl.forge.mixin",
"minVersion": "0.8",
"client": [],
"mixins": [],
"server": [],
"injectors": {
"defaultRequire": 1
},
"overwrites": {
"conformVisibility": true,
"requireAnnotations": true
"required": true,
"package": "net.lostluma.dynamic_fps.impl.forge.mixin",
"minVersion": "0.8",
"client": [
"GuiMixin"
],
"mixins": [],
"server": [],
"injectors": {
"defaultRequire": 1
},
"overwrites": {
"conformVisibility": true,
"requireAnnotations": true
}
}
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ includeBuild("build-logic")

include(":platforms:common")
include(":platforms:fabric")
// include(":platforms:forge")
include(":platforms:forge")
include(":platforms:neoforge")
include(":platforms:quilt")
include(":platforms:textile")

0 comments on commit 7443875

Please sign in to comment.