Skip to content

Commit

Permalink
fixed water fluid drawing in gem cleanser
Browse files Browse the repository at this point in the history
  • Loading branch information
drkhodakarami committed Nov 11, 2023
1 parent 4901968 commit 174c516
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package jiraiyah.allthatmatters.screen.custom;

import io.github.cottonmc.cotton.gui.client.CottonInventoryScreen;
import io.github.cottonmc.cotton.gui.client.ScreenDrawing;
import io.github.cottonmc.cotton.gui.widget.WPanel;
import jiraiyah.allthatmatters.block.entity.GemCleanserBE;
import jiraiyah.allthatmatters.screen.handler.GemCleanserScreenHandler;
Expand All @@ -25,40 +26,28 @@ public GemCleanserScreen(GemCleanserScreenHandler container, PlayerEntity player
super(container, player, title);
this.container = container;
this.fluidStackRenderer = new FluidStackRenderer(GemCleanserBE.FLUID_CAPACITY, true, 15, 61);
}

@Override
protected void handledScreenTick() {
super.handledScreenTick();
if (description!=null) {
WPanel root = description.getRootPanel();
if (root!=null) {
root.tick();
}
}
this.fluidStackRenderer.setzOrder(1);
}

@Override
protected void drawBackground(DrawContext context, float partialTicks, int mouseX, int mouseY)
{
fluidStackRenderer.drawFluid(context, container.fluidStack, x + 10, y + 0, 100, 200, GemCleanserBE.FLUID_CAPACITY);
super.drawBackground(context, partialTicks, mouseX, mouseY);
fluidStackRenderer.drawFluid(context, container.fluidStack, x + 10, y + 0, 100, 200, GemCleanserBE.FLUID_CAPACITY);
}

@Override
public void render(DrawContext context, int mouseX, int mouseY, float partialTicks)
{
fluidStackRenderer.drawFluid(context, container.fluidStack, x + 10, y + 0, 100, 200, GemCleanserBE.FLUID_CAPACITY);
super.render(context, mouseX, mouseY, partialTicks);
fluidStackRenderer.drawFluid(context, container.fluidStack, x + 10, y + 0, 100, 200, GemCleanserBE.FLUID_CAPACITY);

fluidStackRenderer.drawFluid(context, container.fluidStack, x + 93, y + 22, 16, 61, GemCleanserBE.FLUID_CAPACITY);
}

@Override
protected void drawForeground(DrawContext context, int mouseX, int mouseY)
{
super.drawForeground(context, mouseX, mouseY);
renderFLuidTooltip(context, mouseX, mouseY, x, y, container.fluidStack, 93, 21, fluidStackRenderer);
renderFLuidTooltip(context, mouseX, mouseY, x, y, container.fluidStack, 93, 22, fluidStackRenderer);
}

private void renderFLuidTooltip(DrawContext context, int mouseX, int mouseY, int x, int y, FluidStack fluidStack, int offsetX, int offsetY, FluidStackRenderer renderer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public GemCleanserScreenHandler(int syncId, PlayerInventory playerInventory, Scr
WPlainPanel root = new WPlainPanel ();
setRootPanel(root);

root.setSize(200, 168);
root.setSize(200, 178);
root.setInsets(Insets.ROOT_PANEL);

WItemSlot base_input_slot = WItemSlot.of(blockInventory, GemCleanserBE.BASE_INPUT_SLOT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class FluidStackRenderer implements IIngredientRenderer<FluidStack>
private final TooltipMode tooltipMode;
private final int width;
private final int height;
private int zOrder;

enum TooltipMode
{
Expand Down Expand Up @@ -65,6 +66,12 @@ private FluidStackRenderer(long capacityMb, TooltipMode tooltipMode, int width,
this.tooltipMode = tooltipMode;
this.width = width;
this.height = height;
this.zOrder = 0;
}

public void setzOrder(int index)
{
this.zOrder = index;
}

/*
Expand All @@ -91,7 +98,10 @@ public void drawFluid(DrawContext context, FluidStack fluid, int x, int y, int w
{
final int curHeight = offsetHeight < iconHeight ? offsetHeight : iconHeight;

context.getMatrices().push();
context.getMatrices().translate(0f, 0f, 0.01f * zOrder);
context.drawSprite(x, y - offsetHeight, 0, width, curHeight, sprite);
context.getMatrices().pop();
offsetHeight -= curHeight;
iteration++;
if (iteration > 50)
Expand Down

0 comments on commit 174c516

Please sign in to comment.