Skip to content

Commit 1156945

Browse files
committed
Let BackgroundRenderedSlots override the background atlas
1 parent a52a091 commit 1156945

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/client/java/aztech/modern_industrialization/machines/gui/MachineScreen.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,15 @@ protected void renderBg(GuiGraphics guiGraphics, float delta, int mouseX, int mo
211211

212212
private void renderConfigurableSlotBackgrounds(GuiGraphics guiGraphics) {
213213
for (Slot slot : this.menu.slots) {
214-
if (slot instanceof BackgroundRenderedSlot brs) {
214+
if (slot.isActive() && slot instanceof BackgroundRenderedSlot brs) {
215215
int px = leftPos + slot.x - 1;
216216
int py = topPos + slot.y - 1;
217-
guiGraphics.blit(SLOT_ATLAS, px, py, brs.getBackgroundU(), brs.getBackgroundV(), 18, 18);
217+
if (slot.getItem().isEmpty()) {
218+
var atlas = brs.getBackgroundAtlasLocation();
219+
guiGraphics.blit(atlas == null ? SLOT_ATLAS : atlas, px, py, brs.getBackgroundU(), brs.getBackgroundV(), 18, 18);
220+
} else {
221+
guiGraphics.blit(SLOT_ATLAS, px, py, 0, 0, 18, 18);
222+
}
218223
}
219224
}
220225
}

src/main/java/aztech/modern_industrialization/inventory/BackgroundRenderedSlot.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,21 @@
2323
*/
2424
package aztech.modern_industrialization.inventory;
2525

26+
import net.minecraft.resources.ResourceLocation;
27+
import org.jetbrains.annotations.Nullable;
28+
2629
/**
2730
* Implement this on a slot to render its background automatically.
2831
*/
2932
public interface BackgroundRenderedSlot {
33+
/**
34+
* @return the {@link ResourceLocation} of the slot atlas texture to use for the slot background. When null, uses the MI slot atlas
35+
*/
36+
@Nullable
37+
default ResourceLocation getBackgroundAtlasLocation() {
38+
return null;
39+
}
40+
3041
default int getBackgroundU() {
3142
return 0;
3243
}

0 commit comments

Comments
 (0)