Skip to content

Commit

Permalink
Properly blend the slot-holder warning overlay & fixup GuiSlotHolder
Browse files Browse the repository at this point in the history
  • Loading branch information
bukowski912 committed Dec 2, 2024
1 parent 84d6179 commit 7f8bbff
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
19 changes: 12 additions & 7 deletions src/main/java/mekanism/client/gui/element/GuiInsetElement.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package mekanism.client.gui.element;

import java.util.function.BooleanSupplier;

import com.mojang.blaze3d.platform.GlStateManager.DestFactor;
import com.mojang.blaze3d.platform.GlStateManager.SourceFactor;
import com.mojang.blaze3d.systems.RenderSystem;
import mekanism.client.gui.IGuiWrapper;
import mekanism.common.inventory.warning.ISupportsWarning;
import mekanism.common.inventory.warning.WarningTracker.WarningType;
import mekanism.common.util.MekanismUtils;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.resources.ResourceLocation;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public abstract class GuiInsetElement<DATA_SOURCE> extends GuiSideHolder implements ISupportsWarning<GuiInsetElement<DATA_SOURCE>> {

private static final ResourceLocation WARNING_LEFT = MekanismUtils.getResource(MekanismUtils.ResourceType.GUI, "warning_left.png");
private static final ResourceLocation WARNING_RIGHT = MekanismUtils.getResource(MekanismUtils.ResourceType.GUI, "warning_right.png");

protected final int border;
protected final int innerWidth;
protected final int innerHeight;
Expand Down Expand Up @@ -73,12 +73,17 @@ protected ResourceLocation getOverlay() {
}

@Override
protected void draw(@NotNull GuiGraphics guiGraphics) {
protected void drawHolder(@NotNull GuiGraphics guiGraphics) {
boolean warning = warningSupplier != null && warningSupplier.getAsBoolean();
if (warning) {
innerDraw(guiGraphics, left ? WARNING_LEFT : WARNING_RIGHT);
drawHolderUncolored(guiGraphics);
//Draw the warning overlay (multiply-blended)
RenderSystem.enableBlend();
RenderSystem.blendFunc(SourceFactor.DST_COLOR, DestFactor.ZERO);
guiGraphics.blit(WARNING_TEXTURE, relativeX, relativeY, 0, 0, width, height, 256, 256);
RenderSystem.disableBlend();
} else {
super.draw(guiGraphics);
super.drawHolder(guiGraphics);
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/main/java/mekanism/client/gui/element/GuiSideHolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,25 @@ public void renderWidget(@NotNull GuiGraphics guiGraphics, int mouseX, int mouse
super.renderWidget(guiGraphics, mouseX, mouseY, partialTicks);
if (this.slotHolder) {
//Slot holders need to draw here to render behind the slots instead of in front of them
draw(guiGraphics);
drawHolder(guiGraphics);
}
}

@Override
public void drawBackground(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) {
super.drawBackground(guiGraphics, mouseX, mouseY, partialTicks);
if (!this.slotHolder) {
draw(guiGraphics);
drawHolder(guiGraphics);
}
}

protected void draw(@NotNull GuiGraphics guiGraphics) {
protected void drawHolder(@NotNull GuiGraphics guiGraphics) {
colorTab(guiGraphics);
innerDraw(guiGraphics, getResource());
drawHolderUncolored(guiGraphics);
MekanismRenderer.resetColor(guiGraphics);
}

protected void innerDraw(@NotNull GuiGraphics guiGraphics, ResourceLocation texture) {
GuiUtils.blitNineSlicedSized(guiGraphics, texture, relativeX, relativeY, width, height, 4, TEXTURE_WIDTH, TEXTURE_HEIGHT, 0, 0, TEXTURE_WIDTH, TEXTURE_HEIGHT);
protected void drawHolderUncolored(@NotNull GuiGraphics guiGraphics) {
GuiUtils.blitNineSlicedSized(guiGraphics, getResource(), relativeX, relativeY, width, height, 4, TEXTURE_WIDTH, TEXTURE_HEIGHT, 0, 0, TEXTURE_WIDTH, TEXTURE_HEIGHT);
}
}

0 comments on commit 7f8bbff

Please sign in to comment.