Skip to content

Commit

Permalink
Fix scaling option
Browse files Browse the repository at this point in the history
  • Loading branch information
NotRyken committed Jun 18, 2024
1 parent 3e0e652 commit 91745e9
Showing 1 changed file with 43 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,14 @@
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.inventory.EffectRenderingInventoryScreen;
import net.minecraft.core.Holder;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.effect.MobEffectInstance;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.Collection;
Expand All @@ -34,98 +30,65 @@ public class MixinGui {
@Shadow
private Minecraft minecraft;

@Unique
private boolean effectTimerPlus$operate;

@Inject(method = "renderEffects", at = @At("HEAD"))
private void scaleGraphics(GuiGraphics graphics, DeltaTracker delta, CallbackInfo ci) {
effectTimerPlus$operate = false;
Collection effects;
label40:
{
effects = this.minecraft.player.getActiveEffects();
if (!effects.isEmpty()) {
Screen screen = this.minecraft.screen;
if (!(screen instanceof EffectRenderingInventoryScreen)) {
break label40;
}

EffectRenderingInventoryScreen invScreen = (EffectRenderingInventoryScreen) screen;
if (!invScreen.canSeeEffects()) {
break label40;
}
}
return;
}
float scale = (float) Config.get().scale;
effectTimerPlus$operate = true;
graphics.pose().pushPose();
graphics.pose().translate(graphics.guiWidth() * (1 - scale), 0.0F, 0.0F);
graphics.pose().scale(scale, scale, 0.0F);
// this.screenWidth = (int) (graphics.guiWidth() / scale);
}

@ModifyVariable(method = "renderEffects", at = @At("STORE"), ordinal = 2)
private int moveIcons(int original, GuiGraphics graphics) {
if (effectTimerPlus$operate) {
return (int) ((double)graphics.guiWidth() / Config.get().scale);
}
return original;
}

@Inject(method = "renderEffects", at = @At("RETURN"))
private void descaleGraphicsAndOverlay(GuiGraphics graphics, DeltaTracker delta, CallbackInfo ci) {
if (effectTimerPlus$operate) {
// Replicate vanilla placement algorithm to place labels correctly
Collection<MobEffectInstance> effects = this.minecraft.player.getActiveEffects();
if (!effects.isEmpty()) {
// Replicate vanilla placement algorithm to place labels correctly
Collection<MobEffectInstance> effects = this.minecraft.player.getActiveEffects();
if (!effects.isEmpty()) {

int beneficialCount = 0;
int nonBeneficialCount = 0;
int beneficialCount = 0;
int nonBeneficialCount = 0;

for (MobEffectInstance effectInstance : Ordering.natural().reverse().sortedCopy(effects)) {
Holder<MobEffect> effect = effectInstance.getEffect();
if (effectInstance.showIcon()) {
int x = (int) ((double)graphics.guiWidth() / Config.get().scale); // this.screenWidth
int y = 1;
if (this.minecraft.isDemo()) {
y += 15;
}
for (MobEffectInstance effectInstance : Ordering.natural().reverse().sortedCopy(effects)) {
Holder<MobEffect> effect = effectInstance.getEffect();
if (effectInstance.showIcon()) {
int x = graphics.guiWidth();
int y = 1;
if (this.minecraft.isDemo()) {
y += 15;
}

if (effect.value().isBeneficial()) {
++beneficialCount;
x -= 25 * beneficialCount;
} else {
++nonBeneficialCount;
x -= 25 * nonBeneficialCount;
y += 26;
}
if (effect.value().isBeneficial()) {
++beneficialCount;
x -= 25 * beneficialCount;
} else {
++nonBeneficialCount;
x -= 25 * nonBeneficialCount;
y += 26;
}

// Render potency overlay
if (Config.get().potencyEnabled && effectInstance.getAmplifier() > 0) {
String label = MiscUtil.getAmplifierAsString(effectInstance.getAmplifier());
int labelWidth = minecraft.font.width(label);
int posX = x + MiscUtil.getTextOffsetX(Config.get().getPotencyLocation(), labelWidth);
int posY = y + MiscUtil.getTextOffsetY(Config.get().getPotencyLocation());
graphics.fill(posX, posY, posX + labelWidth, posY + minecraft.font.lineHeight - 1,
Config.get().getPotencyBackColor());
graphics.drawString(minecraft.font, label, posX, posY, Config.get().getPotencyColor(), false);
}
// Render timer overlay
if (Config.get().timerEnabled && (Config.get().timerEnabledAmbient || !effectInstance.isAmbient())) {
String label = MiscUtil.getDurationAsString(effectInstance.getDuration());
int labelWidth = minecraft.font.width(label);
int posX = x + MiscUtil.getTextOffsetX(Config.get().getTimerLocation(), labelWidth);
int posY = y + MiscUtil.getTextOffsetY(Config.get().getTimerLocation());
graphics.fill(posX, posY, posX + labelWidth, posY + minecraft.font.lineHeight - 1,
Config.get().getTimerBackColor());
int color = MiscUtil.getTimerColor(effectInstance);
graphics.drawString(minecraft.font, label, posX, posY, color, false);
}
// Render potency overlay
if (Config.get().potencyEnabled && effectInstance.getAmplifier() > 0) {
String label = MiscUtil.getAmplifierAsString(effectInstance.getAmplifier());
int labelWidth = minecraft.font.width(label);
int posX = x + MiscUtil.getTextOffsetX(Config.get().getPotencyLocation(), labelWidth);
int posY = y + MiscUtil.getTextOffsetY(Config.get().getPotencyLocation());
graphics.fill(posX, posY, posX + labelWidth, posY + minecraft.font.lineHeight - 1,
Config.get().getPotencyBackColor());
graphics.drawString(minecraft.font, label, posX, posY, Config.get().getPotencyColor(), false);
}
// Render timer overlay
if (Config.get().timerEnabled && (Config.get().timerEnabledAmbient || !effectInstance.isAmbient())) {
String label = MiscUtil.getDurationAsString(effectInstance.getDuration());
int labelWidth = minecraft.font.width(label);
int posX = x + MiscUtil.getTextOffsetX(Config.get().getTimerLocation(), labelWidth);
int posY = y + MiscUtil.getTextOffsetY(Config.get().getTimerLocation());
graphics.fill(posX, posY, posX + labelWidth, posY + minecraft.font.lineHeight - 1,
Config.get().getTimerBackColor());
int color = MiscUtil.getTimerColor(effectInstance);
graphics.drawString(minecraft.font, label, posX, posY, color, false);
}
}
graphics.pose().popPose();
// this.screenWidth = graphics.guiWidth();
}
graphics.pose().popPose();
}
}
}

0 comments on commit 91745e9

Please sign in to comment.