Skip to content

Commit

Permalink
Add customizable night vision strength feature (#1078)
Browse files Browse the repository at this point in the history
* Add customizable night vision strength feature

Introduced a `nightVision` subcommand to adjust night vision strength with options for `full` (= 100), `off` (= 0), and any other value between 0 and 100. Integrated the setting into the configuration menu and game rendering, with default strength set to 100. Updated localization to include feedback for strength changes.

* Update GameRendererMixin.java

Clamped the applied value to ensure it's not overflowing.
Although you can't put an invalid value in-game, it's still possible to do so directly via the config file.

* Update en_us.json

Added the missing translation for the night vision strength option.

* Add description tooltip for night vision strength option

A tooltip was added to the "Night Vision Strength" option to improve user understanding of its functionality. Unused import(s) were also removed, following the requested changes.

* Use clamp

* Apply suggestions from code review

---------

Co-authored-by: Manchick0 <endercreep109@gmail.com>
Co-authored-by: Kevin <92656833+kevinthegreat1@users.noreply.github.com>
  • Loading branch information
3 people authored Dec 21, 2024
1 parent 070c7bc commit bcfade2
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,17 @@
public class UIAndVisualsCategory {
public static ConfigCategory create(SkyblockerConfig defaults, SkyblockerConfig config) {
return ConfigCategory.createBuilder()
.name(Text.translatable("skyblocker.config.uiAndVisuals"))
.name(Text.translatable("skyblocker.config.uiAndVisuals"))

//Ungrouped Options
.option(Option.<Integer>createBuilder()
.name(Text.translatable("skyblocker.config.uiAndVisuals.nightVisionStrength"))
.description(OptionDescription.of(Text.translatable("skyblocker.config.uiAndVisuals.nightVisionStrength.@Tooltip")))
.binding(defaults.uiAndVisuals.nightVisionStrength,
() -> config.uiAndVisuals.nightVisionStrength,
newValue -> config.uiAndVisuals.nightVisionStrength = newValue)
.controller(opt -> IntegerSliderControllerBuilder.create(opt).range(0, 100).step(1))
.build())
.option(Option.<Boolean>createBuilder()
.name(Text.translatable("skyblocker.config.uiAndVisuals.compactorDeletorPreview"))
.binding(defaults.uiAndVisuals.compactorDeletorPreview,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
import java.util.List;

public class UIAndVisualsConfig {
@SerialEntry
public int nightVisionStrength = 100;

@SerialEntry
public boolean compactorDeletorPreview = true;

Expand Down
21 changes: 21 additions & 0 deletions src/main/java/de/hysky/skyblocker/mixins/GameRendererMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package de.hysky.skyblocker.mixins;

import com.llamalad7.mixinextras.injector.ModifyReturnValue;
import de.hysky.skyblocker.config.SkyblockerConfigManager;
import de.hysky.skyblocker.utils.Utils;
import net.minecraft.client.render.GameRenderer;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;

@Mixin(GameRenderer.class)
public class GameRendererMixin {

@ModifyReturnValue(method = "getNightVisionStrength", at = @At("RETURN"))
private static float onGetNightVisionStrength(float original) {
if (original == 1.0F && Utils.isOnSkyblock()) {
var strength = SkyblockerConfigManager.get().uiAndVisuals.nightVisionStrength;
return Math.clamp(strength / 100.0F, 0, 100);
}
return original;
}
}
40 changes: 40 additions & 0 deletions src/main/java/de/hysky/skyblocker/skyblock/NightVisionCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package de.hysky.skyblocker.skyblock;

import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.IntegerArgumentType;
import com.mojang.brigadier.context.CommandContext;
import de.hysky.skyblocker.SkyblockerMod;
import de.hysky.skyblocker.annotations.Init;
import de.hysky.skyblocker.config.SkyblockerConfig;
import de.hysky.skyblocker.config.SkyblockerConfigManager;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.minecraft.command.CommandRegistryAccess;
import net.minecraft.text.Text;

import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument;
import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal;

public class NightVisionCommand {

@Init
public static void init() {
ClientCommandRegistrationCallback.EVENT.register(NightVisionCommand::register);
}

private static void register(CommandDispatcher<FabricClientCommandSource> dispatcher, CommandRegistryAccess access) {
dispatcher.register(literal(SkyblockerMod.NAMESPACE)
.then(literal("nightVision")
.then(argument("strength", IntegerArgumentType.integer(0, 100))
.executes(context -> NightVisionCommand.writeStrength(context, IntegerArgumentType.getInteger(context, "strength"))))
.then(literal("off").executes(context -> NightVisionCommand.writeStrength(context, 0)))
.then(literal("full").executes(context -> NightVisionCommand.writeStrength(context, 100)))));
}

private static int writeStrength(CommandContext<FabricClientCommandSource> context, int strength) {
SkyblockerConfigManager.get().uiAndVisuals.nightVisionStrength = strength;
context.getSource().sendFeedback(Text.translatable("skyblocker.nightVision.success", strength));
SkyblockerConfigManager.save();
return 1;
}
}
5 changes: 5 additions & 0 deletions src/main/resources/assets/skyblocker/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,9 @@

"skyblocker.config.uiAndVisuals": "UI & Visuals",

"skyblocker.config.uiAndVisuals.nightVisionStrength": "Night Vision Strength",
"skyblocker.config.uiAndVisuals.nightVisionStrength.@Tooltip": "Determines the strength of the Night Vision effect.",

"skyblocker.config.uiAndVisuals.backpackPreviewWithoutShift": "View backpack preview without holding Shift",

"skyblocker.config.uiAndVisuals.hideStatusEffectOverlay": "Hide Status Effect Overlay",
Expand Down Expand Up @@ -991,6 +994,8 @@
"skyblocker.waypoints.deleteQuestion": "Are you sure you want to remove this waypoint?",
"skyblocker.waypoints.deleteWarning": "Waypoint '%s' will be lost forever! (A long time!)",

"skyblocker.nightVision.success": "Changed the strength of night vision to %d.",

"skyblocker.customItemNames.removed": "§fRemoved this item's custom name.",
"skyblocker.customItemNames.neverHad": "§fThis item doesn't have a custom name set, but why not add one? ;)",
"skyblocker.customItemNames.added": "§fSet a custom name for your currently held item!",
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/skyblocker.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"EntityMixin",
"EntityRenderDispatcherMixin",
"FarmlandBlockMixin",
"GameRendererMixin",
"GenericContainerScreenHandlerMixin",
"HandledScreenMixin",
"HandledScreenProviderMixin",
Expand Down

0 comments on commit bcfade2

Please sign in to comment.