Skip to content

Commit

Permalink
Convert more direct RenderSystem calls to GuiGraphics calls where app…
Browse files Browse the repository at this point in the history
…ropriate
  • Loading branch information
pupnewfster committed Jul 4, 2023
1 parent 3c0b01c commit dc7a212
Show file tree
Hide file tree
Showing 54 changed files with 164 additions and 153 deletions.
Expand Up @@ -57,9 +57,9 @@ private ReactorLogicButton(IGuiWrapper gui, int x, int y, int index, @NotNull IR
public void drawBackground(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) {
TYPE mode = modeSupplier.get();
if (mode != null) {
MekanismRenderer.color(mode.getColor());
MekanismRenderer.color(guiGraphics, mode.getColor());
guiGraphics.blit(TEXTURE, getButtonX(), getButtonY(), 0, mode == tile.getMode() ? 22 : 0, getButtonWidth(), getButtonHeight(), 128, 44);
MekanismRenderer.resetColor();
MekanismRenderer.resetColor(guiGraphics);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/mekanism/client/gui/GuiMekanism.java
Expand Up @@ -551,7 +551,7 @@ protected ItemStack checkValidity(int slotIndex) {
protected void renderBg(@NotNull GuiGraphics guiGraphics, float partialTick, int mouseX, int mouseY) {
//Ensure the GL color is white as mods adding an overlay (such as JEI for bookmarks), might have left
// it in an unexpected state.
MekanismRenderer.resetColor();
MekanismRenderer.resetColor(guiGraphics);
if (width < 8 || height < 8) {
Mekanism.logger.warn("Gui: {}, was too small to draw the background of. Unable to draw a background for a gui smaller than 8 by 8.", getClass().getSimpleName());
return;
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/mekanism/client/gui/GuiRadialSelector.java
Expand Up @@ -103,7 +103,7 @@ private <MODE extends IRadialMode> void render(@NotNull GuiGraphics guiGraphics,
// other bits may be drawn by hovering or current selection, it is not practical to do so due
// to floating point precision causing some values to have gaps in the torus, and also the light
// colors occasionally being harder to see without the added back layer torus
RenderSystem.setShaderColor(0.3F, 0.3F, 0.3F, 0.5F);
guiGraphics.setColor(0.3F, 0.3F, 0.3F, 0.5F);
drawTorus(guiGraphics, 0, 360);

MODE current = getCurrent(radialData);
Expand All @@ -119,9 +119,9 @@ private <MODE extends IRadialMode> void render(@NotNull GuiGraphics guiGraphics,
// draw current selected if any is selected
EnumColor color = current.color();
if (color == null) {
RenderSystem.setShaderColor(0.4F, 0.4F, 0.4F, 0.7F);
guiGraphics.setColor(0.4F, 0.4F, 0.4F, 0.7F);
} else {
MekanismRenderer.color(color, 0.3F);
MekanismRenderer.color(guiGraphics, color, 0.3F);
}
float startAngle = -90F + 360F * (-0.5F + section) / activeModes;
drawTorus(guiGraphics, startAngle, angleSize);
Expand All @@ -135,15 +135,15 @@ private <MODE extends IRadialMode> void render(@NotNull GuiGraphics guiGraphics,
// draw mouse selection highlight
float angle = (float) (Mth.RAD_TO_DEG * Mth.atan2(yDiff, xDiff));
float modeSize = 180F / activeModes;
RenderSystem.setShaderColor(0.8F, 0.8F, 0.8F, 0.3F);
guiGraphics.setColor(0.8F, 0.8F, 0.8F, 0.3F);
drawTorus(guiGraphics, angle - modeSize, angleSize);

float selectionAngle = StatUtils.wrapDegrees(angle + modeSize + 90F);
int selectionDrawnPos = (int) (selectionAngle * (activeModes / 360F));
selection = modes.get(selectionDrawnPos);

// draw hovered selection
RenderSystem.setShaderColor(0.6F, 0.6F, 0.6F, 0.7F);
guiGraphics.setColor(0.6F, 0.6F, 0.6F, 0.7F);
drawTorus(guiGraphics, -90F + 360F * (-0.5F + selectionDrawnPos) / activeModes, angleSize);
} else {
selection = null;
Expand All @@ -155,20 +155,20 @@ record PositionedText(float x, float y, Component text) {}
if (!parents.isEmpty()) {
overBackButton = distanceFromCenter <= SELECT_RADIUS_WITH_PARENT;
if (overBackButton) {
RenderSystem.setShaderColor(0.8F, 0.8F, 0.8F, 0.3F);
guiGraphics.setColor(0.8F, 0.8F, 0.8F, 0.3F);
} else {
RenderSystem.setShaderColor(0.3F, 0.3F, 0.3F, 0.5F);
guiGraphics.setColor(0.3F, 0.3F, 0.3F, 0.5F);
}
drawTorus(guiGraphics, 0, 360, 0, SELECT_RADIUS_WITH_PARENT);
MekanismRenderer.resetColor();
MekanismRenderer.resetColor(guiGraphics);
// draw icon
guiGraphics.blit(MekanismUtils.getResource(ResourceType.GUI_RADIAL, "back.png"), -12, -18, 24, 24, 0, 0, 18, 18, 18, 18);
textToDraw.add(new PositionedText(0, 0, MekanismLang.BACK.translate()));
} else {
overBackButton = false;
}

MekanismRenderer.resetColor();
MekanismRenderer.resetColor(guiGraphics);

// Icons
int position = 0;
Expand Down Expand Up @@ -197,7 +197,7 @@ record PositionedText(float x, float y, Component text) {}
pose.popPose();
}

MekanismRenderer.resetColor();
MekanismRenderer.resetColor(guiGraphics);
pose.popPose();
}

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/mekanism/client/gui/GuiUtils.java
Expand Up @@ -177,12 +177,12 @@ public static void drawBackdrop(GuiGraphics guiGraphics, Minecraft minecraft, in
}
}

public static void drawTiledSprite(PoseStack matrix, int xPosition, int yPosition, int yOffset, int desiredWidth, int desiredHeight, TextureAtlasSprite sprite,
public static void drawTiledSprite(GuiGraphics guiGraphics, int xPosition, int yPosition, int yOffset, int desiredWidth, int desiredHeight, TextureAtlasSprite sprite,
int textureWidth, int textureHeight, int zLevel, TilingDirection tilingDirection) {
drawTiledSprite(matrix, xPosition, yPosition, yOffset, desiredWidth, desiredHeight, sprite, textureWidth, textureHeight, zLevel, tilingDirection, true);
drawTiledSprite(guiGraphics, xPosition, yPosition, yOffset, desiredWidth, desiredHeight, sprite, textureWidth, textureHeight, zLevel, tilingDirection, true);
}

public static void drawTiledSprite(PoseStack matrix, int xPosition, int yPosition, int yOffset, int desiredWidth, int desiredHeight, TextureAtlasSprite sprite,
public static void drawTiledSprite(GuiGraphics guiGraphics, int xPosition, int yPosition, int yOffset, int desiredWidth, int desiredHeight, TextureAtlasSprite sprite,
int textureWidth, int textureHeight, int zLevel, TilingDirection tilingDirection, boolean blend) {
if (desiredWidth == 0 || desiredHeight == 0 || textureWidth == 0 || textureHeight == 0) {
return;
Expand All @@ -205,7 +205,7 @@ public static void drawTiledSprite(PoseStack matrix, int xPosition, int yPositio
}
BufferBuilder vertexBuffer = Tesselator.getInstance().getBuilder();
vertexBuffer.begin(Mode.QUADS, DefaultVertexFormat.POSITION_TEX);
Matrix4f matrix4f = matrix.last().pose();
Matrix4f matrix4f = guiGraphics.pose().last().pose();
for (int xTile = 0; xTile <= xTileCount; xTile++) {
int width = (xTile == xTileCount) ? xRemainder : textureWidth;
if (width == 0) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/mekanism/client/gui/element/GuiElement.java
Expand Up @@ -480,7 +480,7 @@ protected int getButtonTextureY(boolean hoveredOrFocused) {
protected void drawButton(GuiGraphics guiGraphics, int mouseX, int mouseY) {
if (resetColorBeforeRender()) {
//TODO: Support alpha like super? Is there a point
MekanismRenderer.resetColor();
MekanismRenderer.resetColor(guiGraphics);
}
//TODO: Convert this to being two different 16x48 images, one for with border and one for buttons without a black border?
// And then make it so that they can stretch out to be any size (make this make use of the renderExtendedTexture method
Expand Down Expand Up @@ -546,7 +546,7 @@ private static void playClickSound(@NotNull SoundManager soundHandler, @NotNull

protected void drawTiledSprite(GuiGraphics guiGraphics, int xPosition, int yPosition, int yOffset, int desiredWidth, int desiredHeight, TextureAtlasSprite sprite,
TilingDirection tilingDirection) {
GuiUtils.drawTiledSprite(guiGraphics.pose(), xPosition, yPosition, yOffset, desiredWidth, desiredHeight, sprite, 16, 16, 0, tilingDirection);
GuiUtils.drawTiledSprite(guiGraphics, xPosition, yPosition, yOffset, desiredWidth, desiredHeight, sprite, 16, 16, 0, tilingDirection);
}

@Override
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/mekanism/client/gui/element/GuiSideHolder.java
Expand Up @@ -19,8 +19,8 @@ public static GuiSideHolder armorHolder(IGuiWrapper gui) {
public static GuiSideHolder create(IGuiWrapper gui, int x, int y, int height, boolean left, boolean slotHolder, ColorRegistryObject tabColor) {
return new GuiSideHolder(gui, x, y, height, left, slotHolder) {
@Override
protected void colorTab() {
MekanismRenderer.color(tabColor);
protected void colorTab(GuiGraphics guiGraphics) {
MekanismRenderer.color(guiGraphics, tabColor);
}
};
}
Expand All @@ -43,7 +43,7 @@ protected GuiSideHolder(IGuiWrapper gui, int x, int y, int height, boolean left,
}
}

protected abstract void colorTab();
protected abstract void colorTab(GuiGraphics guiGraphics);

@Override
public void renderWidget(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) {
Expand All @@ -63,7 +63,7 @@ public void drawBackground(@NotNull GuiGraphics guiGraphics, int mouseX, int mou
}

private void draw(@NotNull GuiGraphics guiGraphics) {
colorTab();
colorTab(guiGraphics);
//Top
guiGraphics.blit(getResource(), relativeX, relativeY, 0, 0, width, 4, TEXTURE_WIDTH, TEXTURE_HEIGHT);
//Middle
Expand All @@ -73,6 +73,6 @@ private void draw(@NotNull GuiGraphics guiGraphics) {
}
//Bottom
guiGraphics.blit(getResource(), relativeX, relativeY + 4 + middleHeight, 0, 5, width, 4, TEXTURE_WIDTH, TEXTURE_HEIGHT);
MekanismRenderer.resetColor();
MekanismRenderer.resetColor(guiGraphics);
}
}
Expand Up @@ -15,6 +15,7 @@
import mekanism.common.util.ChemicalUtil;
import mekanism.common.util.text.TextUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.network.chat.Component;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -55,8 +56,8 @@ protected List<Component> getTooltip(STACK stack) {
}

@Override
protected void applyRenderColor(STACK stack) {
MekanismRenderer.color(stack);
protected void applyRenderColor(GuiGraphics guiGraphics, STACK stack) {
MekanismRenderer.color(guiGraphics, stack);
}

@Override
Expand Down
Expand Up @@ -32,7 +32,7 @@ protected void renderBarOverlay(GuiGraphics guiGraphics, int mouseX, int mouseY,
if (displayInt > 0) {
for (int i = 0; i < displayInt; i++) {
float level = i / (float) (width - 2);
MekanismRenderer.color(colorFunction.getColor(level));
MekanismRenderer.color(guiGraphics, colorFunction.getColor(level));
if (i == 0) {
guiGraphics.blit(getResource(), relativeX + 1, relativeY + 1, 0, 0, 1, texHeight, texWidth, texHeight);
} else if (i == displayInt - 1) {
Expand All @@ -41,7 +41,7 @@ protected void renderBarOverlay(GuiGraphics guiGraphics, int mouseX, int mouseY,
guiGraphics.blit(getResource(), relativeX + 1 + i, relativeY + 1, 1, 0, 1, texHeight, texWidth, texHeight);
}
}
MekanismRenderer.resetColor();
MekanismRenderer.resetColor(guiGraphics);
}
}
}
Expand Up @@ -8,6 +8,7 @@
import mekanism.common.MekanismLang;
import mekanism.common.network.to_server.PacketDropperUse.TankType;
import mekanism.common.util.text.TextUtils;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.network.chat.Component;
import net.minecraftforge.fluids.FluidStack;
Expand All @@ -30,8 +31,8 @@ protected TankType getType(FluidStack stack) {
}

@Override
protected void applyRenderColor(FluidStack stack) {
MekanismRenderer.color(stack);
protected void applyRenderColor(GuiGraphics guiGraphics, FluidStack stack) {
MekanismRenderer.color(guiGraphics, stack);
}

@Override
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/mekanism/client/gui/element/bar/GuiTankBar.java
Expand Up @@ -55,7 +55,7 @@ protected List<Component> getTooltip(STACK stack) {
return tooltips;
}

protected abstract void applyRenderColor(STACK stack);
protected abstract void applyRenderColor(GuiGraphics guiGraphics, STACK stack);

protected abstract TextureAtlasSprite getIcon(STACK stack);

Expand All @@ -65,14 +65,14 @@ protected void renderBarOverlay(GuiGraphics guiGraphics, int mouseX, int mouseY,
if (!isEmpty(stored)) {
int displayInt = (int) (handlerLevel * ((horizontal ? width : height) - 2));
if (displayInt > 0) {
applyRenderColor(stored);
applyRenderColor(guiGraphics, stored);
TextureAtlasSprite icon = getIcon(stored);
if (horizontal) {
drawTiledSprite(guiGraphics, relativeX + 1, relativeY + 1, height - 2, displayInt, height - 2, icon, TilingDirection.DOWN_RIGHT);
} else {
drawTiledSprite(guiGraphics, relativeX + 1, relativeY + 1, height - 2, width - 2, displayInt, icon, TilingDirection.DOWN_RIGHT);
}
MekanismRenderer.resetColor();
MekanismRenderer.resetColor(guiGraphics);
}
}
}
Expand Down
Expand Up @@ -41,13 +41,13 @@ public void drawBackground(@NotNull GuiGraphics guiGraphics, int mouseX, int mou
double[] hsv = c.hsvArray();
hsv[1] = Math.max(0, hsv[1] - 0.25F);
hsv[2] = Math.min(1, hsv[2] + 0.4F);
MekanismRenderer.color(Color.hsv(hsv[0], hsv[1], hsv[2]));
MekanismRenderer.color(guiGraphics, Color.hsv(hsv[0], hsv[1], hsv[2]));
} else {
MekanismRenderer.resetColor();
MekanismRenderer.resetColor(guiGraphics);
}
super.drawBackground(guiGraphics, mouseX, mouseY, partialTicks);
if (doColor) {
MekanismRenderer.resetColor();
MekanismRenderer.resetColor(guiGraphics);
}
}

Expand Down
Expand Up @@ -31,7 +31,7 @@ public void drawBackground(@NotNull GuiGraphics guiGraphics, int mouseX, int mou
EnumColor color = colorSupplier.get();
if (color != null) {
guiGraphics.fill(getButtonX(), getButtonY(), getButtonX() + getButtonWidth(), getButtonY() + getButtonHeight(), MekanismRenderer.getColorARGB(color, 1));
MekanismRenderer.resetColor();
MekanismRenderer.resetColor(guiGraphics);
}
}
}
Expand Up @@ -27,7 +27,7 @@ public FilterSelectButton(IGuiWrapper gui, int x, int y, boolean down, @NotNull
@Override
public void drawBackground(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) {
if (resetColorBeforeRender()) {
MekanismRenderer.resetColor();
MekanismRenderer.resetColor(guiGraphics);
}
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
Expand Down
Expand Up @@ -112,7 +112,7 @@ public void drawBackground(@NotNull GuiGraphics guiGraphics, int mouseX, int mou
}
if (color != null) {
GuiUtils.fill(guiGraphics, getButtonX(), getButtonY(), getButtonWidth(), getButtonHeight(), MekanismRenderer.getColorARGB(color, 0.5F));
MekanismRenderer.resetColor();
MekanismRenderer.resetColor(guiGraphics);
}
updateButtonVisibility();
//Render our sub buttons and our slot
Expand Down
Expand Up @@ -27,13 +27,13 @@ public TranslationButton(IGuiWrapper gui, int x, int y, int width, int height, I
@Override
public void drawBackground(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) {
if (colorSupplier == null) {
MekanismRenderer.resetColor();
MekanismRenderer.resetColor(guiGraphics);
super.drawBackground(guiGraphics, mouseX, mouseY, partialTicks);
return;
}
MekanismRenderer.color(colorSupplier.get());
MekanismRenderer.color(guiGraphics, colorSupplier.get());
super.drawBackground(guiGraphics, mouseX, mouseY, partialTicks);
MekanismRenderer.resetColor();
MekanismRenderer.resetColor(guiGraphics);
}

@Override
Expand Down
Expand Up @@ -74,13 +74,13 @@ public void drawBackground(@NotNull GuiGraphics guiGraphics, int mouseX, int mou
if (target instanceof ItemStack stack) {
gui().renderItem(guiGraphics, stack, relativeX, relativeY);
} else if (target instanceof FluidStack stack) {
MekanismRenderer.color(stack);
MekanismRenderer.color(guiGraphics, stack);
drawTiledSprite(guiGraphics, relativeX, relativeY, height, width, height, MekanismRenderer.getFluidTexture(stack, FluidTextureType.STILL), TilingDirection.DOWN_RIGHT);
MekanismRenderer.resetColor();
MekanismRenderer.resetColor(guiGraphics);
} else if (target instanceof ChemicalStack<?> stack) {
MekanismRenderer.color(stack);
MekanismRenderer.color(guiGraphics, stack);
drawTiledSprite(guiGraphics, relativeX, relativeY, height, width, height, MekanismRenderer.getChemicalTexture(stack.getType()), TilingDirection.DOWN_RIGHT);
MekanismRenderer.resetColor();
MekanismRenderer.resetColor(guiGraphics);
}
}

Expand Down
Expand Up @@ -66,8 +66,8 @@ public void onClick(double mouseX, double mouseY, int button) {
}

@Override
protected void colorTab() {
MekanismRenderer.color(SpecialColors.TAB_RESIZE_CONTROLS);
protected void colorTab(GuiGraphics guiGraphics) {
MekanismRenderer.color(guiGraphics, SpecialColors.TAB_RESIZE_CONTROLS);
}

private void handleResize(ResizeType type) {
Expand Down
Expand Up @@ -17,6 +17,7 @@
import mekanism.common.util.ChemicalUtil;
import mekanism.common.util.text.TextUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.renderer.Rect2i;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.network.chat.Component;
Expand Down Expand Up @@ -106,11 +107,11 @@ public List<Component> getTooltipText() {
}

@Override
protected void applyRenderColor() {
protected void applyRenderColor(GuiGraphics guiGraphics) {
if (dummy || getTank() == null) {
MekanismRenderer.color(dummyType);
MekanismRenderer.color(guiGraphics, dummyType);
} else {
MekanismRenderer.color(getTank().getStack());
MekanismRenderer.color(guiGraphics, getTank().getStack());
}
}

Expand Down
Expand Up @@ -13,6 +13,7 @@
import mekanism.common.lib.transmitter.TransmissionType;
import mekanism.common.network.to_server.PacketDropperUse.TankType;
import mekanism.common.util.text.TextUtils;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.renderer.Rect2i;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.network.chat.Component;
Expand Down Expand Up @@ -114,8 +115,8 @@ public List<Component> getTooltipText() {
}

@Override
protected void applyRenderColor() {
MekanismRenderer.color(dummy || getTank() == null ? dummyType : getTank().getFluid());
protected void applyRenderColor(GuiGraphics guiGraphics) {
MekanismRenderer.color(guiGraphics, dummy || getTank() == null ? dummyType : getTank().getFluid());
}

@Override
Expand Down

0 comments on commit dc7a212

Please sign in to comment.