Skip to content

Commit

Permalink
added zoom scroll and fixed #2
Browse files Browse the repository at this point in the history
  • Loading branch information
slushie0 committed Jan 9, 2023
1 parent ff71333 commit a8b3377
Show file tree
Hide file tree
Showing 12 changed files with 182 additions and 20 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ Right now qolify is in its infancy and doesn't have many features, but that shou

-Fullbright (With toggle)

-Status effect timers

## Planned Features
-ModMenu compatibility

-Zoom customizability

-Item stitching fix

-Food value info (In tooltips and on food names)
Expand All @@ -32,12 +38,14 @@ Right now qolify is in its infancy and doesn't have many features, but that shou

-Whatever is popular request!

## Alternate Mods
## Alternate Mods (These were used to design this one)
Zoom: https://modrinth.com/mod/zoomify *or* https://modrinth.com/mod/logical-zoom

Hotkeys: https://modrinth.com/mod/cheesy_slot

Fullbright: https://modrinth.com/mod/boosted-brightness

Status Effect Timer: https://github.com/magicus/statuseffecttimer

## License
MIT License
6 changes: 4 additions & 2 deletions src/main/java/net/slushie/qolify/Qolify.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import net.fabricmc.api.ModInitializer;
import net.slushie.qolify.event.KeyInputHandler;
import net.slushie.qolify.text.DrawText;
import net.slushie.qolify.text.DrawHotkeys;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -12,10 +12,12 @@ public class Qolify implements ModInitializer {
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;

@Override
public void onInitialize() {
KeyInputHandler.register();
DrawText.EVENT.register(new DrawText());
DrawHotkeys.EVENT.register(new DrawHotkeys());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static void register() {
zoomKey = KeyBindingHelper.registerKeyBinding(new KeyBinding(
KEY_ZOOM,
InputUtil.Type.KEYSYM,
GLFW.GLFW_KEY_O,
GLFW.GLFW_KEY_C,
KEY_CATEGORY_TUTORIAL
));
fullbrightKey = KeyBindingHelper.registerKeyBinding(new KeyBinding(
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/net/slushie/qolify/mixin/CreateWorldMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package net.slushie.qolify.mixin;

public class CreateWorldMixin {
}
33 changes: 33 additions & 0 deletions src/main/java/net/slushie/qolify/mixin/MouseMixin.java
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;
}
}
}
91 changes: 91 additions & 0 deletions src/main/java/net/slushie/qolify/mixin/PotionTimerMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
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.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 PotionTimerMixin 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);
int durationLength = client.textRenderer.getWidth(duration);
drawStringWithShadow(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);
drawStringWithShadow(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);
}
}
}
15 changes: 10 additions & 5 deletions src/main/java/net/slushie/qolify/mixin/ZoomMixin.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package net.slushie.qolify.mixin;


import net.slushie.qolify.Qolify;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -15,11 +14,17 @@
@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) {
if(Qolify.isZooming) {
double fov = callbackInfo.getReturnValue();
callbackInfo.setReturnValue(fov * 0.23);
}
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,12 @@
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.player.PlayerEntity;

public class DrawText implements HudRenderCallback {
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;
Expand All @@ -26,9 +22,14 @@ public void onHudRender(MatrixStack matrixStack, float tickDelta) {
matrixStack.push();
matrixStack.translate(0, 0, 200);

if (playerEntity.isSpectator()) {
return;
}

for (int i = 0; i < 9; i++) {
textRenderer.drawWithShadow(matrixStack, list[i].getBoundKeyLocalizedText(), width/2 - 87 + (i * 20), height - 19, 0xFFFFFFFF);
}

matrixStack.pop();
}
}
Binary file added src/main/resources/assets/qolify/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion src/main/resources/assets/qolify/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"key.category.qolify.qolify": "Qolify",
"key.qolify.zoom": "Zoom"
"key.qolify.zoom": "Zoom",
"key.qolify.fullbright": "Fullbright",
"qolify.github": "GitHub",
"qolify.modrinth": "Modrinth"
}
21 changes: 17 additions & 4 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
"version": "${version}",

"name": "Qolify",
"description": "Some quality of life mods, more to be added! (Zoom, Hotkey labels)",
"description": "Some quality of life mods, more to be added! (Zoom, Hotkey labels, Fullbright, Status effect timer)",
"authors": [
"Slushie"
],
"contact": {
"homepage": "https://fabricmc.net/",
"sources": "https://github.com/FabricMC/fabric-example-mod"
"homepage": "https://modrinth.com/mod/qolify",
"sources": "https://github.com/slushie0/qolify",
"issues": "https://github.com/slushie0/qolify/issues"
},

"license": "MIT License",
Expand All @@ -33,6 +34,18 @@
"java": ">=17"
},
"suggests": {
"another-mod": "*"
"modmenu": "*"
},
"custom": {
"modmenu": {
"links": {
"qolify.github": "https://github.com/slushie0/qolify",
"qolify.modrinth": "https://modrinth.com/mod/qolify"
},
"id": "qolify",
"name": "Qolify",
"description": "Qolify is a small Fabric QOL mod with zoom, hotkey labels, status effect timers, and fullbright",
"icon": "assets/qolify/icon.png"
}
}
}
4 changes: 3 additions & 1 deletion src/main/resources/qolify.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
],
"client": [
"ZoomMixin",
"FullbrightMixin"
"MouseMixin",
"FullbrightMixin",
"PotionTimerMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down

0 comments on commit a8b3377

Please sign in to comment.