-
Notifications
You must be signed in to change notification settings - Fork 0
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
15 changed files
with
349 additions
and
30 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
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,27 @@ | ||
package net.slushie.qolify; | ||
|
||
import net.fabricmc.api.ModInitializer; | ||
|
||
import net.slushie.qolify.event.KeyInputHandler; | ||
import net.slushie.qolify.hud.DrawHotkeys; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class Qolify implements ModInitializer { | ||
|
||
public static final String MOD_ID = "qolify"; | ||
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID); | ||
public static boolean isZooming; | ||
public static boolean isFullbright; | ||
public static double zoomLevel; | ||
public static double globalFov; | ||
public static boolean renderHotbarHUD = true; | ||
public static boolean needItemToRenderHotbarHUD = true; | ||
public static boolean drawHotkeys; | ||
|
||
@Override | ||
public void onInitialize() { | ||
KeyInputHandler.register(); | ||
DrawHotkeys.EVENT.register(new DrawHotkeys()); | ||
} | ||
} |
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,51 @@ | ||
package net.slushie.qolify.event; | ||
|
||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; | ||
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; | ||
import net.minecraft.client.option.KeyBinding; | ||
import net.minecraft.client.util.InputUtil; | ||
import net.slushie.qolify.Qolify; | ||
import org.lwjgl.glfw.GLFW; | ||
|
||
public class KeyInputHandler { | ||
public static final String KEY_CATEGORY_TUTORIAL = "key.category.qolify.qolify"; | ||
public static final String KEY_ZOOM = "key.qolify.zoom"; | ||
public static final String KEY_FULLBRIGHT = "key.qolify.fullbright"; | ||
|
||
public static KeyBinding zoomKey; | ||
public static KeyBinding fullbrightKey; | ||
|
||
public static void registerKeyInputs() { | ||
ClientTickEvents.END_CLIENT_TICK.register(client -> { | ||
if(zoomKey.isPressed()) { | ||
Qolify.isZooming = true; | ||
} else { | ||
Qolify.isZooming = false; | ||
} | ||
if(fullbrightKey.wasPressed()) { | ||
Qolify.isFullbright = Qolify.isFullbright ? false : true; | ||
if (Qolify.isFullbright) { | ||
client.options.getGamma().setValue(69420.0); | ||
} else { | ||
client.options.getGamma().setValue(1.0); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
public static void register() { | ||
zoomKey = KeyBindingHelper.registerKeyBinding(new KeyBinding( | ||
KEY_ZOOM, | ||
InputUtil.Type.KEYSYM, | ||
GLFW.GLFW_KEY_C, | ||
KEY_CATEGORY_TUTORIAL | ||
)); | ||
fullbrightKey = KeyBindingHelper.registerKeyBinding(new KeyBinding( | ||
KEY_FULLBRIGHT, | ||
InputUtil.Type.KEYSYM, | ||
GLFW.GLFW_KEY_B, | ||
KEY_CATEGORY_TUTORIAL | ||
)); | ||
registerKeyInputs(); | ||
} | ||
} |
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,34 @@ | ||
package net.slushie.qolify.hud; | ||
|
||
import ; | ||
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.font.TextRenderer; | ||
import net.minecraft.client.util.math.MatrixStack; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
|
||
public class DrawHotkeys implements HudRenderCallback { | ||
@Override | ||
public void onHudRender(MatrixStack matrixStack, float tickDelta) { | ||
final MinecraftClient client = MinecraftClient.getInstance(); | ||
final PlayerEntity playerEntity = client.player; | ||
|
||
if (playerEntity.isSpectator()) { | ||
return; | ||
} | ||
|
||
final TextRenderer textRenderer = client.textRenderer; | ||
|
||
var list = client.options.hotbarKeys; | ||
|
||
int width = client.getWindow().getScaledWidth(); | ||
int height = client.getWindow().getScaledHeight(); | ||
|
||
matrixStack.push(); | ||
matrixStack.translate(0, 0, 200); | ||
for (int i = 0; i < 9; i++) { | ||
textRenderer.drawWithShadow(matrixStack, list[i].getBoundKeyLocalizedText(), width/2 - 87 + (i * 20), height - 19, 0xFFFFFFFF); | ||
} | ||
matrixStack.pop(); | ||
} | ||
} |
File renamed without changes.
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,22 @@ | ||
package net.slushie.qolify.mixin; | ||
|
||
import net.minecraft.client.option.SimpleOption; | ||
import net.slushie.qolify.Qolify; | ||
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 java.util.Optional; | ||
|
||
@Mixin(SimpleOption.DoubleSliderCallbacks.class) | ||
public class FullbrightMixin { | ||
@Inject(method = "validate(Ljava/lang/Double;)Ljava/util/Optional;", at = @At("RETURN"), cancellable = true) | ||
public void removeValidation(Double double_, CallbackInfoReturnable<Optional<Double>> cir) { | ||
if(Qolify.isFullbright) { | ||
if(double_ == 69420.0) { | ||
cir.setReturnValue(Optional.of(69420.0)); | ||
} | ||
} | ||
} | ||
|
||
} |
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,33 @@ | ||
package net.slushie.qolify.mixin; | ||
|
||
import net.minecraft.client.Mouse; | ||
import net.slushie.qolify.Qolify; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
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; | ||
|
||
@Mixin(Mouse.class) | ||
public class MouseMixin { | ||
@Shadow private double eventDeltaWheel; | ||
@Inject( | ||
method = "onMouseScroll", | ||
at = @At(value = "FIELD", target = "Lnet/minecraft/client/Mouse;eventDeltaWheel:D", ordinal = 7), | ||
cancellable = true | ||
) | ||
private void zoomScrollMixin(CallbackInfo info) { | ||
if (!Qolify.isZooming) return; | ||
info.cancel(); | ||
|
||
if (eventDeltaWheel < 0.0) { | ||
if (Qolify.globalFov * Qolify.zoomLevel*1.5 > Qolify.globalFov) return; | ||
Qolify.zoomLevel = Qolify.zoomLevel*1.5; | ||
} | ||
|
||
if (eventDeltaWheel > 0.0) { | ||
if (Qolify.zoomLevel/1.5 < 0.000001) return; | ||
Qolify.zoomLevel = Qolify.zoomLevel/1.5; | ||
} | ||
} | ||
} |
95 changes: 95 additions & 0 deletions
95
remappedSrc/net/slushie/qolify/mixin/StatusEffectTimerMixin.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,95 @@ | ||
package net.slushie.qolify.mixin; | ||
|
||
import com.google.common.collect.Ordering; | ||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.api.Environment; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.gui.DrawableHelper; | ||
import net.minecraft.client.gui.hud.InGameHud; | ||
import net.minecraft.client.resource.language.I18n; | ||
import net.minecraft.client.util.math.MatrixStack; | ||
import net.minecraft.entity.effect.StatusEffect; | ||
import net.minecraft.entity.effect.StatusEffectInstance; | ||
import net.minecraft.util.math.MathHelper; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
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 java.io.Console; | ||
import java.util.Collection; | ||
|
||
// Set priority to 500, to load before default at 1000. This is to better cooperate with HUDTweaks. | ||
@Environment(EnvType.CLIENT) | ||
@Mixin(value = InGameHud.class, priority = 500) | ||
public abstract class StatusEffectTimerMixin extends DrawableHelper { | ||
@Shadow @Final | ||
private MinecraftClient client; | ||
|
||
@Inject(method = "renderStatusEffectOverlay", at = @At("TAIL")) | ||
private void renderDurationOverlay(MatrixStack matrices, CallbackInfo c) { | ||
Collection<StatusEffectInstance> collection = this.client.player.getStatusEffects(); | ||
if (!collection.isEmpty()) { | ||
// Replicate vanilla placement algorithm to get the duration | ||
// labels to line up exactly right. | ||
|
||
int beneficialCount = 0; | ||
int nonBeneficialCount = 0; | ||
for (StatusEffectInstance statusEffectInstance : Ordering.natural().reverse().sortedCopy(collection)) { | ||
StatusEffect statusEffect = statusEffectInstance.getEffectType(); | ||
if (statusEffectInstance.shouldShowIcon()) { | ||
int x = this.client.getWindow().getScaledWidth(); | ||
int y = 1; | ||
|
||
if (this.client.isDemo()) { | ||
y += 15; | ||
} | ||
|
||
if (statusEffect.isBeneficial()) { | ||
beneficialCount++; | ||
x -= 25 * beneficialCount; | ||
} else { | ||
nonBeneficialCount++; | ||
x -= 25 * nonBeneficialCount; | ||
y += 26; | ||
} | ||
|
||
String duration = getDurationAsString(statusEffectInstance); | ||
if (statusEffectInstance.isInfinite()) { | ||
duration = "∞"; | ||
} | ||
int durationLength = client.textRenderer.getWidth(duration); | ||
drawTextWithShadow(matrices, client.textRenderer, duration, x + 13 - (durationLength / 2), y + 14, 0xFFFFFFFF); | ||
|
||
int amplifier = statusEffectInstance.getAmplifier(); | ||
if (amplifier > 0) { | ||
// Most langages has "translations" for amplifier 1-5, converting to roman numerals | ||
String amplifierString = (amplifier < 6) ? I18n.translate("potion.potency." + amplifier) : "**"; | ||
int amplifierLength = client.textRenderer.getWidth(amplifierString); | ||
drawTextWithShadow(matrices, client.textRenderer, amplifierString, x + 22 - amplifierLength, y + 3, 0xFFFFFFFF); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
@NotNull | ||
private String getDurationAsString(StatusEffectInstance statusEffectInstance) { | ||
int ticks = MathHelper.floor((float) statusEffectInstance.getDuration()); | ||
int seconds = ticks / 20; | ||
|
||
if (ticks > 32147) { | ||
// Vanilla considers everything above this to be infinite | ||
return "**"; | ||
} else if (seconds > 60 & seconds < 600) { | ||
return seconds / 60 + ":" + seconds % 60; | ||
} else if (seconds > 600 ) { | ||
return seconds / 60 + "m"; | ||
} else { | ||
return String.valueOf(seconds); | ||
} | ||
} | ||
} |
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,33 @@ | ||
package net.slushie.qolify.mixin; | ||
|
||
import net.minecraft.client.item.TooltipContext; | ||
import net.minecraft.client.option.SimpleOption; | ||
import net.minecraft.item.EnchantedBookItem; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.text.Text; | ||
import net.minecraft.util.Formatting; | ||
import net.minecraft.world.World; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
|
||
import java.util.List; | ||
|
||
@Mixin(EnchantedBookItem.class) | ||
public class TooltipMixin extends Item { | ||
public TooltipMixin(Settings settings) { | ||
super(settings); | ||
} | ||
|
||
@Override | ||
public void appendTooltip(ItemStack itemStack, World world, List<Text> tooltip, TooltipContext tooltipContext) { | ||
|
||
// default white text | ||
tooltip.add(Text.translatable("item.tutorial.custom_item.tooltip")); | ||
|
||
// formatted red text | ||
tooltip.add(Text.translatable("item.tutorial.custom_item.tooltip").formatted(Formatting.RED)); | ||
} | ||
|
||
//@Inject("") | ||
} |
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,30 @@ | ||
package net.slushie.qolify.mixin; | ||
|
||
import net.slushie.qolify.Qolify; | ||
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 net.fabricmc.api.EnvType; | ||
import net.fabricmc.api.Environment; | ||
|
||
import net.minecraft.client.render.GameRenderer; | ||
|
||
@Environment(EnvType.CLIENT) | ||
@Mixin(GameRenderer.class) | ||
public class ZoomMixin { | ||
boolean wasZooming = false; | ||
@Inject(method = "getFov(Lnet/minecraft/client/render/Camera;FZ)D", at = @At("RETURN"), cancellable = true) | ||
public void zoom(CallbackInfoReturnable<Double> callbackInfo) { | ||
double fov = callbackInfo.getReturnValue(); | ||
callbackInfo.setReturnValue(fov * Qolify.zoomLevel); | ||
Qolify.globalFov = fov; | ||
//0.23 | ||
if (!Qolify.isZooming) Qolify.zoomLevel = 1.0; | ||
else if (wasZooming) return; | ||
else if (Qolify.isZooming) Qolify.zoomLevel = 0.23; | ||
|
||
wasZooming = Qolify.isZooming; | ||
} | ||
} |
Oops, something went wrong.