Skip to content

Commit

Permalink
Fullbright!
Browse files Browse the repository at this point in the history
  • Loading branch information
N-slash-A committed Jul 28, 2020
1 parent ad8c452 commit 3883614
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/main/java/io/github/simplycmd/quake/AntiGhost.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ public class AntiGhost implements ClientModInitializer
@Override
public void onInitializeClient()
{
final String category="key.categories.antighost";
final String category="key.categories.quake";
KeyBindingRegistry.INSTANCE.addCategory(category);
KeyBindingRegistry.INSTANCE.register(requestBlocks = FabricKeyBinding.Builder
.create(new Identifier("antighost:reveal"), InputUtil.Type.KEYSYM,
.create(new Identifier("quake:reveal"), InputUtil.Type.KEYSYM,
GLFW_KEY_G, category)
.build());
ClientTickCallback.EVENT.register(e->keyPressed());
Expand Down
68 changes: 68 additions & 0 deletions src/main/java/io/github/simplycmd/quake/Fullbright.java
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 src/main/java/io/github/simplycmd/quake/mixin/FullbrightMixin.java
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) + "%");
}
};
}
}
}
7 changes: 5 additions & 2 deletions src/main/resources/assets/quake/lang/en_us.json
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"
}
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"main": [
"io.github.simplycmd.quake.Quake"
],
"client": ["io.github.simplycmd.quake.AntiGhost"],
"client": ["io.github.simplycmd.quake.AntiGhost","io.github.simplycmd.quake.Fullbright"],
"server": []
},
"mixins": [
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/quake.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"package": "io.github.simplycmd.quake.mixin",
"compatibilityLevel": "JAVA_8",
"mixins": ["LegacyPvp"],
"client": ["TitleScreenDebrand","ClientDebrand"],
"client": ["TitleScreenDebrand","ClientDebrand","FullbrightMixin"],
"server": [],
"injectors": {
"defaultRequire": 1
Expand Down

0 comments on commit 3883614

Please sign in to comment.