-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
127 additions
and
6 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package io.github.simplycmd.quake; | ||
|
||
import org.lwjgl.glfw.GLFW; | ||
|
||
import net.fabricmc.api.ClientModInitializer; | ||
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; | ||
import net.fabricmc.fabric.api.event.client.ClientTickCallback; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.options.GameOptions; | ||
import net.minecraft.client.options.KeyBinding; | ||
import net.minecraft.client.util.InputUtil; | ||
|
||
public class Fullbright implements ClientModInitializer { | ||
|
||
public static boolean done = false; | ||
|
||
public final static double MAX_BRIGHTNESS = 12.0D; | ||
|
||
private GameOptions gameOptions; | ||
private boolean maxBrightToggled = false; | ||
private double prevBrightness; | ||
private boolean prevPressed; | ||
private KeyBinding brightnessBind; | ||
|
||
|
||
@Override | ||
public void onInitializeClient() { | ||
SetupKeybinds(); | ||
} | ||
|
||
|
||
private void SetupKeybinds() { | ||
|
||
// Create the max brightness toggle | ||
brightnessBind = new KeyBinding( | ||
"key.quake.fullbright", | ||
InputUtil.Type.KEYSYM, | ||
GLFW.GLFW_KEY_B, | ||
"key.categories.quake" | ||
); | ||
|
||
KeyBindingHelper.registerKeyBinding(brightnessBind); | ||
|
||
// Callback that toggles brightness between set value and maximum | ||
ClientTickCallback.EVENT.register(e -> { | ||
// When onInitializeClient is called, client.options is null, so we grab it here | ||
if (gameOptions == null) { | ||
MinecraftClient client = MinecraftClient.getInstance(); | ||
gameOptions = client.options; | ||
} | ||
|
||
if (brightnessBind.isPressed()) { | ||
if (!prevPressed) { | ||
if (!maxBrightToggled) { | ||
prevBrightness = gameOptions.gamma; | ||
gameOptions.gamma = MAX_BRIGHTNESS; | ||
} else { | ||
gameOptions.gamma = prevBrightness; | ||
} | ||
maxBrightToggled = !maxBrightToggled; | ||
prevPressed = true; | ||
} | ||
} else { | ||
prevPressed = false; | ||
} // The ClientTickCallback is called every tick, so this logic prevents rapid toggling when key is held >1 tick | ||
}); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
src/main/java/io/github/simplycmd/quake/mixin/FullbrightMixin.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,50 @@ | ||
package io.github.simplycmd.quake.mixin; | ||
|
||
import net.minecraft.text.MutableText; | ||
import net.minecraft.text.Text; | ||
import net.minecraft.text.TranslatableText; | ||
import net.minecraft.client.options.DoubleOption; | ||
import net.minecraft.client.options.GameOptions; | ||
|
||
import java.util.function.BiConsumer; | ||
import java.util.function.BiFunction; | ||
import java.util.function.Function; | ||
|
||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Mutable; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
import io.github.simplycmd.quake.Fullbright; | ||
|
||
@Mixin(DoubleOption.class) | ||
public class FullbrightMixin { | ||
@Shadow | ||
@Final | ||
@Mutable | ||
private BiFunction<GameOptions, DoubleOption, Text> displayStringGetter; | ||
@Shadow | ||
private double max; | ||
|
||
@Inject(at = @At("RETURN"), method = "<init>") | ||
private void init(String key, double min, double max, float step, Function<GameOptions, Double> getter, | ||
BiConsumer<GameOptions, Double> setter, BiFunction<GameOptions, DoubleOption, Text> displayStringGetter, | ||
CallbackInfo info) { | ||
// Modifies the max and displayStringGetter of the brightness slider | ||
if (key.equals("options.gamma")) { | ||
this.max = Fullbright.MAX_BRIGHTNESS; | ||
this.displayStringGetter = (gameOptions, doubleOption) -> { | ||
double d = doubleOption.getRatio(doubleOption.get(gameOptions)); | ||
MutableText mutableText = doubleOption.getDisplayPrefix(); | ||
if (d == 0.0D) { | ||
return mutableText.append((Text)(new TranslatableText("options.gamma.min"))); | ||
} else { | ||
return d == 1.0D ? mutableText.append((Text)(new TranslatableText("options.gamma.max"))) : mutableText.append("+" + (int)(d * Fullbright.MAX_BRIGHTNESS * 100.0D) + "%"); | ||
} | ||
}; | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,5 +1,8 @@ | ||
{ | ||
"key.categories.quake": "Quake Client", | ||
"key.quake.reveal": "Reveal ghost blocks", | ||
"msg.request": "Revealing glitched blocks (Don't spam this or else you will get kicked!)" | ||
|
||
"key.quake.reveal": "Reveal Ghost Blocks", | ||
"msg.request": "Revealing glitched blocks (Don't spam this or else you will get kicked!)", | ||
|
||
"key.quake.fullbright": "Toggle Fullbright" | ||
} |
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