Skip to content

Commit

Permalink
update to 1.20
Browse files Browse the repository at this point in the history
  • Loading branch information
slushie0 committed Jun 8, 2023
1 parent 5cb8c20 commit 5ec4a53
Show file tree
Hide file tree
Showing 15 changed files with 349 additions and 30 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ Right now qolify is in its infancy and doesn't have many features, but that shou

-Modmenu compatibility

-Clock and compass show up in HUD if in inventory

## Planned Features

-Move chat up 10px
Expand Down
12 changes: 6 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ org.gradle.parallel=true

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.19.4
yarn_mappings=1.19.4+build.2
loader_version=0.14.19
minecraft_version=1.20
yarn_mappings=1.20+build.1
loader_version=0.14.21

# Mod Properties
mod_version=1.2.2-1.19.4
mod_version=1.3.0-1.20
maven_group=net.slushie.qolify
archives_base_name=qolify

# Dependencies
fabric_version=0.78.0+1.19.4
modmenu_version=6.2.1
fabric_version=0.83.0+1.20
modmenu_version=7.0.0
27 changes: 27 additions & 0 deletions remappedSrc/net/slushie/qolify/Qolify.java
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());
}
}
51 changes: 51 additions & 0 deletions remappedSrc/net/slushie/qolify/event/KeyInputHandler.java
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();
}
}
34 changes: 34 additions & 0 deletions remappedSrc/net/slushie/qolify/hud/DrawHotkeys.java
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();
}
}
22 changes: 22 additions & 0 deletions remappedSrc/net/slushie/qolify/mixin/FullbrightMixin.java
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));
}
}
}

}
33 changes: 33 additions & 0 deletions remappedSrc/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;
}
}
}
95 changes: 95 additions & 0 deletions remappedSrc/net/slushie/qolify/mixin/StatusEffectTimerMixin.java
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);
}
}
}
33 changes: 33 additions & 0 deletions remappedSrc/net/slushie/qolify/mixin/TooltipMixin.java
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("")
}
30 changes: 30 additions & 0 deletions remappedSrc/net/slushie/qolify/mixin/ZoomMixin.java
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;
}
}
Loading

0 comments on commit 5ec4a53

Please sign in to comment.