Skip to content

Commit

Permalink
Use cross-platform mixin to render HUD overlay
Browse files Browse the repository at this point in the history
Turns out this *can* work after all, if I don't use MixinExtras?
  • Loading branch information
LostLuma committed Feb 17, 2024
1 parent 4ffe7c7 commit b6ca2e7
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 67 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package dynamic_fps.impl.mixin;

import dynamic_fps.impl.util.HudInfoRenderer;
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;
import net.minecraft.client.gui.GuiGraphics;

@Mixin(Gui.class)
public class GuiMixin {
Expand All @@ -19,4 +21,18 @@ private void shouldRender(CallbackInfo callbackInfo) {
callbackInfo.cancel();
}
}

/**
* Render info on whether Dynamic FPS is disabled or always reducing the user's FPS.
*/
@Inject(
method = "render",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/gui/Gui;renderSavingIndicator(Lnet/minecraft/client/gui/GuiGraphics;)V"
)
)
private void render(GuiGraphics guiGraphics, float f, CallbackInfo callbackInfo) {
HudInfoRenderer.renderInfo(guiGraphics);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"compatibilityLevel": "JAVA_17",
"minVersion": "0.8",
"client": [
"GuiMixin",
"OptionsMixin"
],
"mixins": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,9 @@ public DynamicFPSForgeMod() {
);

MinecraftForge.EVENT_BUS.addListener(this::onClientTick);
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()) {
event.register(handler.keyMapping());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,8 @@ public DynamicFPSNeoForgeMod(IEventBus modEventBus) {
);

modEventBus.addListener(this::registerKeyMappings);
NeoForge.EVENT_BUS.addListener(this::renderGuiOverlay);
}

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

public void registerKeyMappings(RegisterKeyMappingsEvent event) {
for (KeyMappingHandler handler : KeyMappingHandler.getHandlers()) {
event.register(handler.keyMapping());
Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion platforms/quilt/src/main/resources/dynamic_fps.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"compatibilityLevel": "JAVA_17",
"minVersion": "0.8",
"client": [
"GuiMixin",
"OptionsMixin"
],
"mixins": [],
Expand Down

0 comments on commit b6ca2e7

Please sign in to comment.