Skip to content

Commit

Permalink
Fix rendering on inventory screen
Browse files Browse the repository at this point in the history
  • Loading branch information
NotRyken committed Jul 18, 2024
1 parent e745482 commit c8f3ff4
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 45 deletions.
3 changes: 2 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
- Switch to YACL for configuration
- Switch to YACL for configuration
- Fix rendering when on inventory screen
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiGraphics;
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;
Expand Down Expand Up @@ -42,56 +43,59 @@ private void scaleGraphics(GuiGraphics graphics, DeltaTracker delta, CallbackInf
private void descaleGraphicsAndOverlay(GuiGraphics graphics, DeltaTracker delta, CallbackInfo ci) {
// Replicate vanilla placement algorithm to place labels correctly
Collection<MobEffectInstance> effects = this.minecraft.player.getActiveEffects();
if (!effects.isEmpty()) {

int beneficialCount = 0;
int nonBeneficialCount = 0;
if (effects.isEmpty() || this.minecraft.screen instanceof EffectRenderingInventoryScreen) {
graphics.pose().popPose();
return;
}

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;
}
int beneficialCount = 0;
int nonBeneficialCount = 0;

if (effect.value().isBeneficial()) {
++beneficialCount;
x -= 25 * beneficialCount;
} else {
++nonBeneficialCount;
x -= 25 * nonBeneficialCount;
y += 26;
}
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;
}

Config options = Config.get();
// Render potency overlay
if (options.potencyEnabled && effectInstance.getAmplifier() > 0) {
String label = IndicatorUtil.getAmplifierAsString(effectInstance.getAmplifier());
int labelWidth = minecraft.font.width(label);
int posX = x + IndicatorUtil.getTextOffsetX(options.potencyLocation, labelWidth);
int posY = y + IndicatorUtil.getTextOffsetY(options.potencyLocation);
graphics.fill(posX, posY, posX + labelWidth, posY + minecraft.font.lineHeight - 1,
options.potencyBackColor);
graphics.drawString(minecraft.font, label, posX, posY, options.potencyColor, false);
}
// Render timer overlay
if (options.timerEnabled && (options.timerEnabledAmbient || !effectInstance.isAmbient())) {
String label = IndicatorUtil.getDurationAsString(effectInstance.getDuration());
int labelWidth = minecraft.font.width(label);
int posX = x + IndicatorUtil.getTextOffsetX(options.timerLocation, labelWidth);
int posY = y + IndicatorUtil.getTextOffsetY(options.timerLocation);
graphics.fill(posX, posY, posX + labelWidth, posY + minecraft.font.lineHeight - 1,
options.timerBackColor);
int color = IndicatorUtil.getTimerColor(effectInstance, options.timerColor,
options.timerWarnEnabled, options.timerWarnTime,
options.timerWarnColor, options.timerFlashEnabled);
graphics.drawString(minecraft.font, label, posX, posY, color, false);
}
if (effect.value().isBeneficial()) {
++beneficialCount;
x -= 25 * beneficialCount;
} else {
++nonBeneficialCount;
x -= 25 * nonBeneficialCount;
y += 26;
}

Config options = Config.get();
// Render potency overlay
if (options.potencyEnabled && effectInstance.getAmplifier() > 0) {
String label = IndicatorUtil.getAmplifierAsString(effectInstance.getAmplifier());
int labelWidth = minecraft.font.width(label);
int posX = x + IndicatorUtil.getTextOffsetX(options.potencyLocation, labelWidth);
int posY = y + IndicatorUtil.getTextOffsetY(options.potencyLocation);
graphics.fill(posX, posY, posX + labelWidth, posY + minecraft.font.lineHeight - 1,
options.potencyBackColor);
graphics.drawString(minecraft.font, label, posX, posY, options.potencyColor, false);
}
// Render timer overlay
if (options.timerEnabled && (options.timerEnabledAmbient || !effectInstance.isAmbient())) {
String label = IndicatorUtil.getDurationAsString(effectInstance.getDuration());
int labelWidth = minecraft.font.width(label);
int posX = x + IndicatorUtil.getTextOffsetX(options.timerLocation, labelWidth);
int posY = y + IndicatorUtil.getTextOffsetY(options.timerLocation);
graphics.fill(posX, posY, posX + labelWidth, posY + minecraft.font.lineHeight - 1,
options.timerBackColor);
int color = IndicatorUtil.getTimerColor(effectInstance, options.timerColor,
options.timerWarnEnabled, options.timerWarnTime,
options.timerWarnColor, options.timerFlashEnabled);
graphics.drawString(minecraft.font, label, posX, posY, color, false);
}
}
graphics.pose().popPose();
}
graphics.pose().popPose();
}
}

0 comments on commit c8f3ff4

Please sign in to comment.