aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorJuuz <6596629+Juuxel@users.noreply.github.com>2023-11-26 17:24:52 +0200
committerJuuz <6596629+Juuxel@users.noreply.github.com>2023-11-26 17:24:52 +0200
commitc82111365b52fe4710a4192a16ca5df70510949d (patch)
tree34a410373b8b1be47e9d7b0eb0d075fddff54f89 /src/main
parentf5d46dea812f0019ce06e1512dff697bb811f739 (diff)
downloadLibGui-c82111365b52fe4710a4192a16ca5df70510949d.tar.gz
LibGui-c82111365b52fe4710a4192a16ca5df70510949d.tar.bz2
LibGui-c82111365b52fe4710a4192a16ca5df70510949d.zip
Add ghost item icons
Closes #228.
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/icon/ItemIcon.java33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/icon/ItemIcon.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/icon/ItemIcon.java
index 9da86ee..e6beeed 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/widget/icon/ItemIcon.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/icon/ItemIcon.java
@@ -3,6 +3,7 @@ package io.github.cottonmc.cotton.gui.widget.icon;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.gui.DrawContext;
+import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
@@ -15,7 +16,11 @@ import java.util.Objects;
* @since 2.2.0
*/
public class ItemIcon implements Icon {
+ // Matches the vanilla RecipeBookGhostSlots class (1.20.2).
+ private static final int GHOST_OVERLAY_COLOR = 0x30_FFFFFF;
+
private final ItemStack stack;
+ private boolean ghost = false;
/**
* Constructs an item icon.
@@ -47,6 +52,34 @@ public class ItemIcon implements Icon {
matrices.translate(x, y, 0);
matrices.scale(scale, scale, 1);
context.drawItemWithoutEntity(stack, 0, 0);
+
+ if (isGhost()) {
+ context.fill(RenderLayer.getGuiGhostRecipeOverlay(), 0, 0, 16, 16, GHOST_OVERLAY_COLOR);
+ }
+
matrices.pop();
}
+
+ /**
+ * Checks whether this icon is a ghost item.
+ * Ghost items are rendered with a pale overlay.
+ *
+ * @return {@code true} if this icon is a ghost item, {@code false} otherwise
+ * @since 9.2.0
+ */
+ public boolean isGhost() {
+ return ghost;
+ }
+
+ /**
+ * Marks this icon as a ghost or non-ghost icon.
+ *
+ * @param ghost {@code true} if this icon is a ghost item, {@code false} otherwise
+ * @return this icon
+ * @since 9.2.0
+ */
+ public ItemIcon setGhost(boolean ghost) {
+ this.ghost = ghost;
+ return this;
+ }
}