From 4db03c998c57fa15ca2752ce0fa70472da198148 Mon Sep 17 00:00:00 2001 From: HenryLoenwind Date: Mon, 26 Oct 2015 18:38:38 +0100 Subject: [PATCH] Ghost slots can now be used to paint grayed out items everywhere e.g. as background images for real slots --- .../core/client/gui/GhostSlotHandler.java | 2 +- .../core/client/gui/GuiContainerBase.java | 4 +- .../gui/widget/GhostBackgroundItemSlot.java | 66 +++++++++++++++++++ .../core/client/gui/widget/GhostSlot.java | 12 +++- 4 files changed, 79 insertions(+), 5 deletions(-) create mode 100644 src/main/java/com/enderio/core/client/gui/widget/GhostBackgroundItemSlot.java diff --git a/src/main/java/com/enderio/core/client/gui/GhostSlotHandler.java b/src/main/java/com/enderio/core/client/gui/GhostSlotHandler.java index dfa486d..2e74a19 100644 --- a/src/main/java/com/enderio/core/client/gui/GhostSlotHandler.java +++ b/src/main/java/com/enderio/core/client/gui/GhostSlotHandler.java @@ -198,7 +198,7 @@ public class GhostSlotHandler { GL11.glDisable(GL11.GL_LIGHTING); GL11.glDisable(GL11.GL_DEPTH_TEST); GL11.glEnable(GL11.GL_BLEND); - GL11.glColor4f(1.0F, 1.0F, 1.0F, 0.5F); + GL11.glColor4f(1.0F, 1.0F, 1.0F, slot.getGrayOutLevel()); String guiTexture = gui.getGuiTexture(); if (guiTexture == null) { NEUTRAL_SLOT_BACKGROUND.getMap().render(NEUTRAL_SLOT_BACKGROUND, gui.getGuiLeft() + slot.x, gui.getGuiTop() + slot.y, gui.getZlevel(), true); diff --git a/src/main/java/com/enderio/core/client/gui/GuiContainerBase.java b/src/main/java/com/enderio/core/client/gui/GuiContainerBase.java index 44d18dc..5ba58d6 100644 --- a/src/main/java/com/enderio/core/client/gui/GuiContainerBase.java +++ b/src/main/java/com/enderio/core/client/gui/GuiContainerBase.java @@ -390,8 +390,8 @@ public abstract class GuiContainerBase extends GuiContainer implements ToolTipRe } protected void drawFakeItemsStart() { - zLevel = 100.0F; - itemRender.zLevel = 100.0F; + zLevel = 0.0F; + itemRender.zLevel = -25.0F; GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); GL11.glEnable(GL11.GL_LIGHTING); GL11.glEnable(GL12.GL_RESCALE_NORMAL); diff --git a/src/main/java/com/enderio/core/client/gui/widget/GhostBackgroundItemSlot.java b/src/main/java/com/enderio/core/client/gui/widget/GhostBackgroundItemSlot.java new file mode 100644 index 0000000..f55bffe --- /dev/null +++ b/src/main/java/com/enderio/core/client/gui/widget/GhostBackgroundItemSlot.java @@ -0,0 +1,66 @@ +package com.enderio.core.client.gui.widget; + +import net.minecraft.block.Block; +import net.minecraft.inventory.Slot; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; + +public class GhostBackgroundItemSlot extends GhostSlot { + + private final ItemStack stack; + private final Slot parent; + + public GhostBackgroundItemSlot(ItemStack stack, int x, int y) { + this.stack = stack; + this.parent = null; + this.x = x; + this.y = y; + this.grayOut = true; + this.grayOutLevel = .75f; + } + + public GhostBackgroundItemSlot(ItemStack stack, Slot parent) { + this.stack = stack; + this.parent = parent; + this.x = parent.xDisplayPosition; + this.y = parent.yDisplayPosition; + this.grayOut = true; + this.grayOutLevel = .75f; + } + + public GhostBackgroundItemSlot(Item item, int x, int y) { + this(new ItemStack(item), x, y); + } + + public GhostBackgroundItemSlot(Block block, int x, int y) { + this(new ItemStack(block), x, y); + } + + public GhostBackgroundItemSlot(Item item, Slot parent) { + this(new ItemStack(item), parent); + } + + public GhostBackgroundItemSlot(Block block, Slot parent) { + this(new ItemStack(block), parent); + } + + @Override + public boolean isMouseOver(int mx, int my) { + return false; + } + + @Override + public ItemStack getStack() { + return stack; + } + + @Override + public void putStack(ItemStack stack) { + } + + @Override + public boolean isVisible() { + return parent != null ? parent.xDisplayPosition >= 0 && parent.yDisplayPosition >= 0 : super.isVisible(); + } + +} \ No newline at end of file diff --git a/src/main/java/com/enderio/core/client/gui/widget/GhostSlot.java b/src/main/java/com/enderio/core/client/gui/widget/GhostSlot.java index 1463089..f3c4d88 100644 --- a/src/main/java/com/enderio/core/client/gui/widget/GhostSlot.java +++ b/src/main/java/com/enderio/core/client/gui/widget/GhostSlot.java @@ -1,11 +1,11 @@ package com.enderio.core.client.gui.widget; +import net.minecraft.item.ItemStack; + import com.enderio.core.common.TileEntityEnder; import com.enderio.core.common.network.EnderPacketHandler; import com.enderio.core.common.network.PacketGhostSlot; -import net.minecraft.item.ItemStack; - public abstract class GhostSlot { public TileEntityEnder te = null; @@ -15,6 +15,7 @@ public abstract class GhostSlot { public boolean visible = true; public boolean grayOut = true; + public float grayOutLevel = 0.5f; public boolean displayStdOverlay = false; public int stackSizeLimit = 1; @@ -44,6 +45,13 @@ public abstract class GhostSlot { return grayOut; } + /** + * If it should be grayed out, how far? (1=no graying, 0=fully invisible) + */ + public float getGrayOutLevel() { + return grayOutLevel; + } + /** * Should the items in the slot have their standard overlay (stacksize)? */