-
-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add customizable night vision strength feature (#1078)
* 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
1 parent
070c7bc
commit bcfade2
Showing
6 changed files
with
79 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/main/java/de/hysky/skyblocker/mixins/GameRendererMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
40
src/main/java/de/hysky/skyblocker/skyblock/NightVisionCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters