Skip to content

Commit

Permalink
1.17.0
Browse files Browse the repository at this point in the history
NOTE: HUD overlay and debug overlay info doesn't render on Forge.
  • Loading branch information
LostLuma committed Feb 17, 2024
1 parent 8d35e0e commit 8a56e51
Show file tree
Hide file tree
Showing 23 changed files with 186 additions and 107 deletions.
22 changes: 11 additions & 11 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
[versions]
minecraft = "1.20.4"
minecraft = "1.17.1"

# Platform libraries

fabric_loader = "0.15.6"
fabric_api = "0.96.1+1.20.4"
fabric_api = "0.46.1+1.17"

forge = "1.20.4-49.0.30"
forge = "1.17.1-37.1.1"

neoforge = "20.4.160-beta"
# neoforge = "20.4.160-beta"

quilt_loader = "0.23.1"
quilt_standard_libraries = "7.0.0-alpha.10+1.20.2"
# quilt_loader = "0.23.1"
# quilt_standard_libraries = "1.1.0-beta.26+1.18.2"

# Third-party libraries

modmenu = "9.0.0"
cloth_config = "13.0.121"
modmenu = "2.0.17"
cloth_config = "5.3.63"

mixinextras = "0.3.5"

Expand All @@ -30,10 +30,10 @@ fabric_loader = { module = "net.fabricmc:fabric-loader", version.ref = "fabric_l

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

neoforge = { module = "net.neoforged:neoforge", version.ref = "neoforge" }
# 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" }
# 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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.CommonComponents;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.sounds.SoundSource;

import java.util.Locale;
Expand Down Expand Up @@ -43,7 +45,7 @@ public static Screen genConfigScreen(Screen parent) {
);

general.addEntry(
entryBuilder.startTextDescription(CommonComponents.SPACE).build()
entryBuilder.startTextDescription(new TextComponent(" ")).build()
);

general.addEntry(
Expand Down Expand Up @@ -101,7 +103,7 @@ public static Screen genConfigScreen(Screen parent) {

volumes.add(
entryBuilder.startIntSlider(
Component.translatable("soundCategory." + name),
new TranslatableComponent("soundCategory." + name),
(int) (config.rawVolumeMultiplier(source) * 100),
0, 100
)
Expand All @@ -123,7 +125,7 @@ public static Screen genConfigScreen(Screen parent) {
.setDefaultValue(standard.graphicsState())
.setSaveConsumer(config::setGraphicsState)
.setEnumNameProvider(ClothConfig::graphicsStateMessage)
.setTooltipSupplier(ClothConfig::graphicsStateTooltip)
.setTooltipSupplier((selected) -> ClothConfig.graphicsStateTooltip((GraphicsState) selected)) // what
.build()
);

Expand Down Expand Up @@ -173,14 +175,14 @@ private static int fromConfigFpsTarget(int value) {

private static Component fpsTargetMessage(int value) {
if (toConfigFpsTarget(value) != -1) {
return Component.translatable("options.framerate", value);
return new TranslatableComponent("options.framerate", value);
} else {
return Component.translatable("options.framerateLimit.max");
return new TranslatableComponent("options.framerateLimit.max");
}
}

private static Component volumeMultiplierMessage(int value) {
return Component.literal(Integer.toString(value) + "%");
return new TranslatableComponent(Integer.toString(value) + "%");
}

private static Component graphicsStateMessage(Enum<GraphicsState> graphicsState) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
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 @@ -21,18 +19,4 @@ 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private void getFramerateLimit(CallbackInfoReturnable<Integer> callbackInfo) {
callbackInfo.setReturnValue(limit);
}
} else if (DynamicFPSMod.uncapMenuFrameRate()) {
if (self.options.enableVsync().get()) {
if (self.options.enableVsync) {
// VSync will regulate to a non-infinite value
callbackInfo.setReturnValue(NO_FRAME_RATE_LIMIT);
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
package dynamic_fps.impl.mixin;

import java.util.Deque;

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.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.Redirect;

import dynamic_fps.impl.DynamicFPSMod;
import net.minecraft.client.gui.components.toasts.Toast;
import net.minecraft.client.gui.components.toasts.ToastComponent;

@Mixin(ToastComponent.class)
public class ToastComponentMixin {
@Inject(method = "freeSlots", at = @At("HEAD"), cancellable = true)
private void hasFreeSlots(CallbackInfoReturnable<Integer> callbackInfo) {
@Redirect(method = "render", at = @At(value = "INVOKE", target = "Ljava/util/Deque;isEmpty()Z"))
private boolean onQueueIsEmpty(Deque<Toast> queued) {
if (!DynamicFPSMod.shouldShowToasts()) {
callbackInfo.setReturnValue(0);
return true;
} else {
return queued.isEmpty();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dynamic_fps.impl.service;

import java.util.NoSuchElementException;
import java.util.Optional;
import java.util.ServiceLoader;

Expand All @@ -8,11 +9,9 @@ class Services {
static ModCompat MOD_COMPAT = loadService(ModCompat.class);

static <T> T loadService(Class<T> type) {
Optional<T> optional = ServiceLoader.load(type).findFirst();

if (optional.isPresent()) {
return optional.get();
} else {
try {
return ServiceLoader.load(type).iterator().next();
} catch (NoSuchElementException e) {
throw new RuntimeException("Failed to load Dynamic FPS " + type.getSimpleName() + " service!");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,37 @@

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.Font.DisplayMode;
import net.minecraft.network.chat.Component;

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

import org.joml.Matrix4f;
import com.mojang.blaze3d.vertex.PoseStack;

import dynamic_fps.impl.DynamicFPSMod;

public final class HudInfoRenderer {
private static final Minecraft minecraft = Minecraft.getInstance();

public static void renderInfo(GuiGraphics guiGraphics) {
public static void renderInfo(PoseStack poseStack) {
if (DynamicFPSMod.disabledByUser()) {
drawCenteredText(guiGraphics, localized("gui", "hud.disabled"), 32);
drawCenteredText(poseStack, localized("gui", "hud.disabled"), 32);
} else if (DynamicFPSMod.isForcingLowFPS()) {
drawCenteredText(guiGraphics, localized("gui", "hud.reducing"), 32);
drawCenteredText(poseStack, localized("gui", "hud.reducing"), 32);
}
}

private static void drawCenteredText(GuiGraphics guiGraphics, Component component, float y) {
private static void drawCenteredText(PoseStack poseStack, Component component, float y) {
Font fontRenderer = minecraft.gui.getFont();

int stringWidth = fontRenderer.width(component);
int windowWidth = minecraft.getWindow().getGuiScaledWidth();

fontRenderer.drawInBatch(
fontRenderer.drawShadow(
poseStack,
component,
(windowWidth - stringWidth) / 2f,
y,
0xFFFFFFFF,
true,
new Matrix4f(),
guiGraphics.bufferSource(),
DisplayMode.NORMAL,
0,
255
0xFFFFFFFF
);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package dynamic_fps.impl.util;

import dynamic_fps.impl.Constants;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.chat.TranslatableComponent;

public final class Localization {
/** e.g. keyString("title", "config") -> "title.dynamic_fps.config") */
Expand All @@ -11,7 +11,7 @@ public static String translationKey(String domain, String path) {
}

public static MutableComponent localized(String domain, String path, Object... args) {
return Component.translatable(translationKey(domain, path), args);
return new TranslatableComponent(translationKey(domain, path), args);
}

private Localization() {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package dynamic_fps.impl.util;

import dynamic_fps.impl.Constants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class Logging {
private static final Logger logger = LoggerFactory.getLogger(Constants.MOD_ID);
private static final Logger logger = LogManager.getLogger(Constants.MOD_ID);

public static Logger getLogger() {
return logger;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dynamic_fps.impl.util;

import dynamic_fps.impl.GraphicsState;
import net.minecraft.client.AmbientOcclusionStatus;
import net.minecraft.client.CloudStatus;
import net.minecraft.client.GraphicsStatus;
import net.minecraft.client.Options;
Expand All @@ -14,45 +15,45 @@
public class OptionsHolder {
private static CloudStatus cloudStatus;
private static GraphicsStatus graphicsStatus;
private static boolean ambientOcclusion;
private static AmbientOcclusionStatus ambientOcclusion;
private static ParticleStatus particlesStatus;
private static boolean entityShadows;
private static double entityDistance;
private static float entityDistance;

/*
* Create an in-memory copy of current vanilla graphics options.
*
* This MUST be called while graphics options have not been changed yet.
*/
public static void copyOptions(Options options) {
cloudStatus = options.getCloudsType();
graphicsStatus = options.graphicsMode().get();
ambientOcclusion = options.ambientOcclusion().get();
particlesStatus = options.particles().get();
entityShadows = options.entityShadows().get();
entityDistance = options.entityDistanceScaling().get();
cloudStatus = options.renderClouds;
graphicsStatus = options.graphicsMode;
ambientOcclusion = options.ambientOcclusion;
particlesStatus = options.particles;
entityShadows = options.entityShadows;
entityDistance = options.entityDistanceScaling;
}

/*
* Apply or revert the graphics options for the specified graphics state.
*/
public static void applyOptions(Options options, GraphicsState state) {
if (state == GraphicsState.DEFAULT) {
options.cloudStatus().set(cloudStatus);
options.graphicsMode().set(graphicsStatus);
options.ambientOcclusion().set(ambientOcclusion);
options.particles().set(particlesStatus);
options.entityShadows().set(entityShadows);
options.entityDistanceScaling().set(entityDistance);
options.renderClouds = cloudStatus;
options.graphicsMode = graphicsStatus;
options.ambientOcclusion = ambientOcclusion;
options.particles = particlesStatus;
options.entityShadows = entityShadows;
options.entityDistanceScaling = entityDistance;
} else { // state == GraphicsState.REDUCED
options.cloudStatus().set(CloudStatus.OFF);
options.particles().set(ParticleStatus.MINIMAL);
options.entityShadows().set(false);
options.entityDistanceScaling().set(0.5);
options.renderClouds = CloudStatus.OFF;
options.particles = ParticleStatus.MINIMAL;
options.entityShadows = false;
options.entityDistanceScaling = 0.5f;

if (state == GraphicsState.MINIMAL) {
options.graphicsMode().set(GraphicsStatus.FAST);
options.ambientOcclusion().set(false);
options.graphicsMode = GraphicsStatus.FAST;
options.ambientOcclusion = AmbientOcclusionStatus.OFF;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package net.lostluma.dynamic_fps.impl.fabric.mixin;

import com.llamalad7.mixinextras.sugar.Local;
import com.mojang.blaze3d.vertex.PoseStack;
import dynamic_fps.impl.util.HudInfoRenderer;
import net.minecraft.client.gui.Gui;
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 = "render",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/gui/Gui;renderHotbar(FLcom/mojang/blaze3d/vertex/PoseStack;)V"
)
)
private void render(CallbackInfo callbackInfo, @Local PoseStack poseStack) {
HudInfoRenderer.renderInfo(poseStack);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"compatibilityLevel": "JAVA_17",
"minVersion": "0.8",
"client": [
"GuiMixin",
"OptionsMixin"
],
"mixins": [],
Expand Down
Loading

0 comments on commit 8a56e51

Please sign in to comment.