Skip to content

Commit ae0b671

Browse files
committed
fix item rendering interference
1 parent 9451c42 commit ae0b671

File tree

8 files changed

+51
-11
lines changed

8 files changed

+51
-11
lines changed

src/main/java/com/cleanroommc/modularui/api/widget/IWidget.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ default void draw(ModularGuiContext context) {
9090
void drawForeground(ModularGuiContext context);
9191

9292
default void transform(IViewportStack stack) {
93-
stack.translate(getArea().rx, getArea().ry);
93+
stack.translate(getArea().rx, getArea().ry, getArea().getPanelLayer() * 20);
9494
}
9595

9696
default WidgetTheme getWidgetTheme(ITheme theme) {

src/main/java/com/cleanroommc/modularui/drawable/GuiDraw.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,15 +337,15 @@ public static void drawTiledTexture(float x, float y, float w, float h, float u0
337337
tessellator.draw();
338338
}
339339

340-
public static void drawItem(ItemStack item, int x, int y, float width, float height) {
340+
public static void drawItem(ItemStack item, int x, int y, float width, float height, int z) {
341341
if (item.isEmpty()) return;
342342
GlStateManager.pushMatrix();
343343
RenderHelper.enableGUIStandardItemLighting();
344344
GlStateManager.enableDepth();
345345
GlStateManager.translate(x, y, 0);
346346
GlStateManager.scale(width / 16f, height / 16f, 1);
347347
RenderItem renderItem = Minecraft.getMinecraft().getRenderItem();
348-
renderItem.zLevel = 200;
348+
renderItem.zLevel = z + 100;
349349
renderItem.renderItemAndEffectIntoGUI(Minecraft.getMinecraft().player, item, 0, 0);
350350
renderItem.zLevel = 0;
351351
GlStateManager.disableDepth();

src/main/java/com/cleanroommc/modularui/drawable/IngredientDrawable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public void draw(GuiContext context, int x, int y, int width, int height, Widget
2929
if (this.items.length == 0) return;
3030
ItemStack item = this.items[(int) (Minecraft.getSystemTime() % (1000 * this.items.length)) / 1000];
3131
if (item != null) {
32-
GuiDraw.drawItem(item, x, y, width, height);
32+
GuiDraw.drawItem(item, x, y, width, height, context.getCurrentDrawingZ());
3333
}
3434
}
3535

src/main/java/com/cleanroommc/modularui/drawable/ItemDrawable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public ItemDrawable(@NotNull Block item, int meta, int amount) {
6666
@SideOnly(Side.CLIENT)
6767
@Override
6868
public void draw(GuiContext context, int x, int y, int width, int height, WidgetTheme widgetTheme) {
69-
GuiDraw.drawItem(this.item, x, y, width, height);
69+
GuiDraw.drawItem(this.item, x, y, width, height, context.getCurrentDrawingZ());
7070
}
7171

7272
@Override

src/main/java/com/cleanroommc/modularui/screen/ModularScreen.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,13 @@ public void drawScreen(int mouseX, int mouseY, float partialTicks) {
246246
this.context.reset();
247247
this.context.pushViewport(null, this.context.getScreenArea());
248248
for (ModularPanel panel : this.panelManager.getReverseOpenPanels()) {
249+
this.context.updateZ(panel.getArea().getPanelLayer() * 20);
249250
if (panel.disablePanelsBelow()) {
250251
GuiDraw.drawRect(0, 0, this.context.getScreenArea().w(), this.context.getScreenArea().h(), Color.argb(16, 16, 16, (int) (125 * panel.getAlpha())));
251252
}
252253
WidgetTree.drawTree(panel, this.context);
253254
}
255+
this.context.updateZ(0);
254256
this.context.popViewport(null);
255257

256258
this.context.postRenderCallbacks.forEach(element -> element.accept(this.context));

src/main/java/com/cleanroommc/modularui/screen/viewport/GuiContext.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public static GuiContext getDefault() {
4444
/* Render states */
4545
private float partialTicks;
4646
private long tick = 0;
47+
private int currentDrawingZ = 0;
4748

4849
public boolean isAbove(IGuiElement widget) {
4950
return isMouseAbove(widget.getArea());
@@ -85,6 +86,10 @@ public void updateScreenArea(int w, int h) {
8586
this.screenArea.ry = 0;
8687
}
8788

89+
public void updateZ(int z) {
90+
this.currentDrawingZ = z;
91+
}
92+
8893
@SideOnly(Side.CLIENT)
8994
public Minecraft getMC() {
9095
return Minecraft.getMinecraft();
@@ -161,6 +166,10 @@ public float getPartialTicks() {
161166
return this.partialTicks;
162167
}
163168

169+
public int getCurrentDrawingZ() {
170+
return currentDrawingZ;
171+
}
172+
164173
public boolean isMuiContext() {
165174
return false;
166175
}

src/main/java/com/cleanroommc/modularui/test/TestTile2.java

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
package com.cleanroommc.modularui.test;
22

33
import com.cleanroommc.modularui.api.IGuiHolder;
4+
import com.cleanroommc.modularui.api.IPanelHandler;
5+
import com.cleanroommc.modularui.drawable.GuiTextures;
6+
import com.cleanroommc.modularui.drawable.ItemDrawable;
47
import com.cleanroommc.modularui.factory.PosGuiData;
58
import com.cleanroommc.modularui.screen.ModularPanel;
69
import com.cleanroommc.modularui.screen.UISettings;
710
import com.cleanroommc.modularui.value.sync.PanelSyncManager;
811
import com.cleanroommc.modularui.widget.ScrollWidget;
912
import com.cleanroommc.modularui.widget.scroll.VerticalScrollData;
13+
import com.cleanroommc.modularui.widgets.ButtonWidget;
14+
import com.cleanroommc.modularui.widgets.Dialog;
15+
import com.cleanroommc.modularui.widgets.SlotGroupWidget;
1016
import com.cleanroommc.modularui.widgets.slot.ItemSlot;
1117
import com.cleanroommc.modularui.widgets.slot.ModularSlot;
1218

@@ -22,7 +28,7 @@
2228

2329
public class TestTile2 extends TileEntity implements IGuiHolder<PosGuiData>, ITickable {
2430

25-
private static final int SLOT_COUNT = 9999;
31+
private static final int SLOT_COUNT = 81;
2632

2733
private final IItemHandlerModifiable itemHandler = new ItemStackHandler(SLOT_COUNT);
2834

@@ -39,17 +45,38 @@ public TestTile2() {
3945

4046
@Override
4147
public ModularPanel buildUI(PosGuiData data, PanelSyncManager syncManager, UISettings settings) {
42-
ScrollWidget<?> sw = new ScrollWidget<>(new VerticalScrollData()).size(9 * 18).margin(7);
48+
ScrollWidget<?> sw = new ScrollWidget<>(new VerticalScrollData()).size(9 * 18).margin(7).top(20);
4349
sw.getScrollArea().getScrollY().setScrollSize(18 * (SLOT_COUNT / 9));
4450
for (int i = 0; i < SLOT_COUNT; i++) {
4551
int x = i % 9;
4652
int y = i / 9;
4753
sw.child(new ItemSlot().pos(x * 18, y * 18)
4854
.slot(new ModularSlot(this.itemHandler, i)));
4955
}
50-
return ModularPanel.defaultPanel("test_tile_2", 176, 13 * 18 + 14 + 10)
56+
ModularPanel panel = ModularPanel.defaultPanel("test_tile_2", 176, 13 * 18 + 14 + 10 + 20);
57+
IPanelHandler otherPanel = syncManager.panel("2nd panel", (syncManager1, syncHandler) -> {
58+
ModularPanel panel1 = new Dialog<>("Option Selection").setDisablePanelsBelow(false).setDraggable(true).size(4 * 18 + 8, 4 * 18 + 8);
59+
return panel1
60+
.child(SlotGroupWidget.builder()
61+
.row("IIII")
62+
.row("IIII")
63+
.row("IIII")
64+
.row("IIII")
65+
.key('I', i -> new ItemDrawable(this.itemHandler.getStackInSlot(i + 23)).asIcon().asWidget().size(18)/*new ItemSlot().slot(new ModularSlot(this.itemHandler, i + 23))*/)
66+
.build()
67+
.pos(4, 4)
68+
);
69+
}, true);
70+
return panel
5171
.bindPlayerInventory()
52-
.child(sw);
72+
.child(sw)
73+
.child(new ButtonWidget<>()
74+
.top(5).size(12, 12).leftRel(0.5f)
75+
.overlay(GuiTextures.ADD)
76+
.onMouseTapped(mouseButton -> {
77+
otherPanel.openPanel();
78+
return true;
79+
}));
5380
}
5481

5582
@Override

src/main/java/com/cleanroommc/modularui/widgets/slot/ItemSlot.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,10 @@ private void drawSlot(Slot slotIn) {
214214
}
215215
}
216216

217-
((GuiAccessor) guiScreen).setZLevel(100f);
218-
renderItem.zLevel = 100.0F;
217+
// makes sure items of different layers don't interfere with each other visually
218+
float z = getContext().getCurrentDrawingZ() + 100;
219+
((GuiAccessor) guiScreen).setZLevel(z);
220+
renderItem.zLevel = z;
219221

220222
if (!flag1) {
221223
if (isDragPreview) {

0 commit comments

Comments
 (0)