From 1156945de2dc0c7b9672d1a4734095cd369a35e8 Mon Sep 17 00:00:00 2001 From: Swedz Date: Sun, 24 Nov 2024 20:12:29 -0500 Subject: [PATCH 1/5] Let BackgroundRenderedSlots override the background atlas --- .../machines/gui/MachineScreen.java | 9 +++++++-- .../inventory/BackgroundRenderedSlot.java | 11 +++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/client/java/aztech/modern_industrialization/machines/gui/MachineScreen.java b/src/client/java/aztech/modern_industrialization/machines/gui/MachineScreen.java index ab75a6164..27c1b334b 100644 --- a/src/client/java/aztech/modern_industrialization/machines/gui/MachineScreen.java +++ b/src/client/java/aztech/modern_industrialization/machines/gui/MachineScreen.java @@ -211,10 +211,15 @@ protected void renderBg(GuiGraphics guiGraphics, float delta, int mouseX, int mo private void renderConfigurableSlotBackgrounds(GuiGraphics guiGraphics) { for (Slot slot : this.menu.slots) { - if (slot instanceof BackgroundRenderedSlot brs) { + if (slot.isActive() && slot instanceof BackgroundRenderedSlot brs) { int px = leftPos + slot.x - 1; int py = topPos + slot.y - 1; - guiGraphics.blit(SLOT_ATLAS, px, py, brs.getBackgroundU(), brs.getBackgroundV(), 18, 18); + if (slot.getItem().isEmpty()) { + var atlas = brs.getBackgroundAtlasLocation(); + guiGraphics.blit(atlas == null ? SLOT_ATLAS : atlas, px, py, brs.getBackgroundU(), brs.getBackgroundV(), 18, 18); + } else { + guiGraphics.blit(SLOT_ATLAS, px, py, 0, 0, 18, 18); + } } } } diff --git a/src/main/java/aztech/modern_industrialization/inventory/BackgroundRenderedSlot.java b/src/main/java/aztech/modern_industrialization/inventory/BackgroundRenderedSlot.java index f0cb1f6a3..7a0af9d53 100644 --- a/src/main/java/aztech/modern_industrialization/inventory/BackgroundRenderedSlot.java +++ b/src/main/java/aztech/modern_industrialization/inventory/BackgroundRenderedSlot.java @@ -23,10 +23,21 @@ */ package aztech.modern_industrialization.inventory; +import net.minecraft.resources.ResourceLocation; +import org.jetbrains.annotations.Nullable; + /** * Implement this on a slot to render its background automatically. */ public interface BackgroundRenderedSlot { + /** + * @return the {@link ResourceLocation} of the slot atlas texture to use for the slot background. When null, uses the MI slot atlas + */ + @Nullable + default ResourceLocation getBackgroundAtlasLocation() { + return null; + } + default int getBackgroundU() { return 0; } From 563df3a3dbcaa02b8030ae57df9500d6736dd371 Mon Sep 17 00:00:00 2001 From: Swedz Date: Mon, 25 Nov 2024 21:18:22 -0500 Subject: [PATCH 2/5] Make getBackgroundAtlasLocation not nullable --- .../machines/gui/MachineScreen.java | 6 +++--- .../inventory/BackgroundRenderedSlot.java | 7 +++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/client/java/aztech/modern_industrialization/machines/gui/MachineScreen.java b/src/client/java/aztech/modern_industrialization/machines/gui/MachineScreen.java index 27c1b334b..15a54c654 100644 --- a/src/client/java/aztech/modern_industrialization/machines/gui/MachineScreen.java +++ b/src/client/java/aztech/modern_industrialization/machines/gui/MachineScreen.java @@ -212,13 +212,13 @@ protected void renderBg(GuiGraphics guiGraphics, float delta, int mouseX, int mo private void renderConfigurableSlotBackgrounds(GuiGraphics guiGraphics) { for (Slot slot : this.menu.slots) { if (slot.isActive() && slot instanceof BackgroundRenderedSlot brs) { + var atlas = brs.getBackgroundAtlasLocation(); int px = leftPos + slot.x - 1; int py = topPos + slot.y - 1; if (slot.getItem().isEmpty()) { - var atlas = brs.getBackgroundAtlasLocation(); - guiGraphics.blit(atlas == null ? SLOT_ATLAS : atlas, px, py, brs.getBackgroundU(), brs.getBackgroundV(), 18, 18); + guiGraphics.blit(atlas, px, py, brs.getBackgroundU(), brs.getBackgroundV(), 18, 18); } else { - guiGraphics.blit(SLOT_ATLAS, px, py, 0, 0, 18, 18); + guiGraphics.blit(atlas, px, py, 0, 0, 18, 18); } } } diff --git a/src/main/java/aztech/modern_industrialization/inventory/BackgroundRenderedSlot.java b/src/main/java/aztech/modern_industrialization/inventory/BackgroundRenderedSlot.java index 7a0af9d53..f824a0acd 100644 --- a/src/main/java/aztech/modern_industrialization/inventory/BackgroundRenderedSlot.java +++ b/src/main/java/aztech/modern_industrialization/inventory/BackgroundRenderedSlot.java @@ -23,19 +23,18 @@ */ package aztech.modern_industrialization.inventory; +import aztech.modern_industrialization.MI; import net.minecraft.resources.ResourceLocation; -import org.jetbrains.annotations.Nullable; /** * Implement this on a slot to render its background automatically. */ public interface BackgroundRenderedSlot { /** - * @return the {@link ResourceLocation} of the slot atlas texture to use for the slot background. When null, uses the MI slot atlas + * @return the {@link ResourceLocation} of the slot atlas texture to use for the slot background. */ - @Nullable default ResourceLocation getBackgroundAtlasLocation() { - return null; + return MI.id("textures/gui/container/slot_atlas.png"); } default int getBackgroundU() { From f6057836569cc2956876a1c0334e91b3cca280b9 Mon Sep 17 00:00:00 2001 From: Swedz Date: Tue, 26 Nov 2024 20:15:37 -0500 Subject: [PATCH 3/5] Use null atlas check instead of isActive --- .../modern_industrialization/machines/gui/MachineScreen.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/client/java/aztech/modern_industrialization/machines/gui/MachineScreen.java b/src/client/java/aztech/modern_industrialization/machines/gui/MachineScreen.java index 15a54c654..f0120f6b4 100644 --- a/src/client/java/aztech/modern_industrialization/machines/gui/MachineScreen.java +++ b/src/client/java/aztech/modern_industrialization/machines/gui/MachineScreen.java @@ -211,8 +211,11 @@ protected void renderBg(GuiGraphics guiGraphics, float delta, int mouseX, int mo private void renderConfigurableSlotBackgrounds(GuiGraphics guiGraphics) { for (Slot slot : this.menu.slots) { - if (slot.isActive() && slot instanceof BackgroundRenderedSlot brs) { + if (slot instanceof BackgroundRenderedSlot brs) { var atlas = brs.getBackgroundAtlasLocation(); + if (atlas == null) { + continue; + } int px = leftPos + slot.x - 1; int py = topPos + slot.y - 1; if (slot.getItem().isEmpty()) { From 654b0a900d9bcf02c4a576267034af17fcc1f5d3 Mon Sep 17 00:00:00 2001 From: Swedz Date: Tue, 26 Nov 2024 20:17:13 -0500 Subject: [PATCH 4/5] Remove isEmpty check --- .../machines/gui/MachineScreen.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/client/java/aztech/modern_industrialization/machines/gui/MachineScreen.java b/src/client/java/aztech/modern_industrialization/machines/gui/MachineScreen.java index f0120f6b4..46371153e 100644 --- a/src/client/java/aztech/modern_industrialization/machines/gui/MachineScreen.java +++ b/src/client/java/aztech/modern_industrialization/machines/gui/MachineScreen.java @@ -218,11 +218,7 @@ private void renderConfigurableSlotBackgrounds(GuiGraphics guiGraphics) { } int px = leftPos + slot.x - 1; int py = topPos + slot.y - 1; - if (slot.getItem().isEmpty()) { - guiGraphics.blit(atlas, px, py, brs.getBackgroundU(), brs.getBackgroundV(), 18, 18); - } else { - guiGraphics.blit(atlas, px, py, 0, 0, 18, 18); - } + guiGraphics.blit(atlas, px, py, brs.getBackgroundU(), brs.getBackgroundV(), 18, 18); } } } From b990b9180fd9daed9c7a96759eb73ec6cb12386e Mon Sep 17 00:00:00 2001 From: Swedz Date: Tue, 26 Nov 2024 20:20:02 -0500 Subject: [PATCH 5/5] Update comment to say that background atlas can be null --- .../inventory/BackgroundRenderedSlot.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/aztech/modern_industrialization/inventory/BackgroundRenderedSlot.java b/src/main/java/aztech/modern_industrialization/inventory/BackgroundRenderedSlot.java index f824a0acd..0586b0152 100644 --- a/src/main/java/aztech/modern_industrialization/inventory/BackgroundRenderedSlot.java +++ b/src/main/java/aztech/modern_industrialization/inventory/BackgroundRenderedSlot.java @@ -25,14 +25,16 @@ import aztech.modern_industrialization.MI; import net.minecraft.resources.ResourceLocation; +import org.jetbrains.annotations.Nullable; /** * Implement this on a slot to render its background automatically. */ public interface BackgroundRenderedSlot { /** - * @return the {@link ResourceLocation} of the slot atlas texture to use for the slot background. + * @return the {@link ResourceLocation} of the slot atlas texture to use for the slot background. Return null to render no background. */ + @Nullable default ResourceLocation getBackgroundAtlasLocation() { return MI.id("textures/gui/container/slot_atlas.png"); }