From 34e0dd6e711fa01648b37cd53988157ef042c572 Mon Sep 17 00:00:00 2001 From: bukowski912 Date: Sat, 23 Nov 2024 00:40:40 +1100 Subject: [PATCH] Add a warning for machine inactivity due to redstone control - Make GuiInsetElement able to track warnings with a supplier - Use a separate texture for GuiInsetElement on a warning condition - Inject an activation supplier into the redstone control tab during its creation - Write a corresponding lang entry for "en_us" (we will need to support more langs in future) --- .../mekanism/assets/mekanism/lang/en_us.json | 1 + .../mekanism/client/gui/GuiMekanismTile.java | 5 +++- .../client/gui/element/GuiInsetElement.java | 26 ++++++++++++++++++ .../client/gui/element/GuiSideHolder.java | 8 ++++-- .../java/mekanism/common/MekanismLang.java | 1 + .../inventory/warning/WarningTracker.java | 1 + .../common/tile/base/TileEntityMekanism.java | 12 ++++---- .../assets/mekanism/gui/warning_left.png | Bin 0 -> 206 bytes .../assets/mekanism/gui/warning_right.png | Bin 0 -> 207 bytes 9 files changed, 46 insertions(+), 8 deletions(-) create mode 100644 src/main/resources/assets/mekanism/gui/warning_left.png create mode 100644 src/main/resources/assets/mekanism/gui/warning_right.png diff --git a/src/datagen/generated/mekanism/assets/mekanism/lang/en_us.json b/src/datagen/generated/mekanism/assets/mekanism/lang/en_us.json index d78477a49c4..3ba283fa8f2 100644 --- a/src/datagen/generated/mekanism/assets/mekanism/lang/en_us.json +++ b/src/datagen/generated/mekanism/assets/mekanism/lang/en_us.json @@ -2324,6 +2324,7 @@ "gui.mekanism.radiation_dose": "Radiation Dose: %1$s", "gui.mekanism.radiation_exposure": "Radiation Exposure: %1$s", "gui.mekanism.radiation_exposure.entity": "Entity Radiation Exposure: %1$s", + "gui.mekanism.issues.redstone_unactivated": "Machine is currently inactive due to its redstone control setting.", "gui.mekanism.rgb": "RGB:", "gui.mekanism.rgba": "RGBA:", "gui.mekanism.set": "Set:", diff --git a/src/main/java/mekanism/client/gui/GuiMekanismTile.java b/src/main/java/mekanism/client/gui/GuiMekanismTile.java index 5a5dbd877e5..d39f1b4a293 100644 --- a/src/main/java/mekanism/client/gui/GuiMekanismTile.java +++ b/src/main/java/mekanism/client/gui/GuiMekanismTile.java @@ -1,10 +1,12 @@ package mekanism.client.gui; +import java.util.function.BooleanSupplier; import mekanism.api.security.IBlockSecurityUtils; import mekanism.client.gui.element.tab.GuiRedstoneControlTab; import mekanism.client.gui.element.tab.GuiSecurityTab; import mekanism.client.gui.element.tab.window.GuiUpgradeWindowTab; import mekanism.common.inventory.container.tile.MekanismTileContainer; +import mekanism.common.inventory.warning.WarningTracker.WarningType; import mekanism.common.tile.base.TileEntityMekanism; import net.minecraft.network.chat.Component; import net.minecraft.world.entity.player.Inventory; @@ -39,7 +41,8 @@ protected void addGenericTabs() { upgradeWindowTab = addRenderableWidget(new GuiUpgradeWindowTab(this, tile, () -> upgradeWindowTab)); } if (tile.supportsRedstone()) { - addRenderableWidget(new GuiRedstoneControlTab(this, tile)); + BooleanSupplier supplier = trackWarning(WarningType.REDSTONE_UNACTIVATED, () -> !tile.isRedstoneActivated()); + addRenderableWidget(new GuiRedstoneControlTab(this, tile).warning(supplier)); } //Note: We check if the capability is present rather than calling hasSecurity so that we don't add the tab to the security desk if (tile.getLevel() != null && IBlockSecurityUtils.INSTANCE.securityCapability(tile.getLevel(), tile.getBlockPos(), tile) != null) { diff --git a/src/main/java/mekanism/client/gui/element/GuiInsetElement.java b/src/main/java/mekanism/client/gui/element/GuiInsetElement.java index cdec5578438..f9a17b9ef9d 100644 --- a/src/main/java/mekanism/client/gui/element/GuiInsetElement.java +++ b/src/main/java/mekanism/client/gui/element/GuiInsetElement.java @@ -1,18 +1,28 @@ package mekanism.client.gui.element; +import java.util.function.BooleanSupplier; import mekanism.client.gui.IGuiWrapper; +import mekanism.common.inventory.warning.ISupportsWarning; +import mekanism.common.util.MekanismUtils; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.resources.ResourceLocation; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; public abstract class GuiInsetElement extends GuiSideHolder { + private static final ResourceLocation WARNING_LEFT = MekanismUtils.getResource(MekanismUtils.ResourceType.GUI, "warning_left.png"); + private static final ResourceLocation WARNING_RIGHT = MekanismUtils.getResource(MekanismUtils.ResourceType.GUI, "warning_right.png"); + protected final int border; protected final int innerWidth; protected final int innerHeight; protected final DATA_SOURCE dataSource; protected final ResourceLocation overlay; + @Nullable + protected BooleanSupplier warningSupplier; + public GuiInsetElement(ResourceLocation overlay, IGuiWrapper gui, DATA_SOURCE dataSource, int x, int y, int height, int innerSize, boolean left) { super(gui, x, y, height, left, false); this.overlay = overlay; @@ -25,6 +35,11 @@ public GuiInsetElement(ResourceLocation overlay, IGuiWrapper gui, DATA_SOURCE da active = true; } + public GuiInsetElement warning(@NotNull BooleanSupplier warningSupplier) { + this.warningSupplier = ISupportsWarning.compound(this.warningSupplier, warningSupplier); + return this; + } + @Override public boolean isMouseOver(double xAxis, double yAxis) { //TODO: override isHovered @@ -55,6 +70,17 @@ protected ResourceLocation getOverlay() { return overlay; } + @Override + public void draw(@NotNull GuiGraphics guiGraphics) { + boolean warning = warningSupplier != null && warningSupplier.getAsBoolean(); + if (warning) { + ResourceLocation texture = (left ? WARNING_LEFT : WARNING_RIGHT); + innerDraw(guiGraphics, texture); + } else { + super.draw(guiGraphics); + } + } + @Override public void drawBackground(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) { super.drawBackground(guiGraphics, mouseX, mouseY, partialTicks); diff --git a/src/main/java/mekanism/client/gui/element/GuiSideHolder.java b/src/main/java/mekanism/client/gui/element/GuiSideHolder.java index 9427f278ad7..1017542c848 100644 --- a/src/main/java/mekanism/client/gui/element/GuiSideHolder.java +++ b/src/main/java/mekanism/client/gui/element/GuiSideHolder.java @@ -63,9 +63,13 @@ public void drawBackground(@NotNull GuiGraphics guiGraphics, int mouseX, int mou } } - private void draw(@NotNull GuiGraphics guiGraphics) { + protected void draw(@NotNull GuiGraphics guiGraphics) { colorTab(guiGraphics); - GuiUtils.blitNineSlicedSized(guiGraphics, getResource(), relativeX, relativeY, width, height, 4, TEXTURE_WIDTH, TEXTURE_HEIGHT, 0, 0, TEXTURE_WIDTH, TEXTURE_HEIGHT); + innerDraw(guiGraphics, getResource()); MekanismRenderer.resetColor(guiGraphics); } + + protected void innerDraw(@NotNull GuiGraphics guiGraphics, ResourceLocation texture) { + GuiUtils.blitNineSlicedSized(guiGraphics, texture, relativeX, relativeY, width, height, 4, TEXTURE_WIDTH, TEXTURE_HEIGHT, 0, 0, TEXTURE_WIDTH, TEXTURE_HEIGHT); + } } \ No newline at end of file diff --git a/src/main/java/mekanism/common/MekanismLang.java b/src/main/java/mekanism/common/MekanismLang.java index 63018a6699a..7723a44313f 100644 --- a/src/main/java/mekanism/common/MekanismLang.java +++ b/src/main/java/mekanism/common/MekanismLang.java @@ -294,6 +294,7 @@ public enum MekanismLang implements ILangEntry { ISSUE_INPUT_DOESNT_PRODUCE_OUTPUT("gui", "issues.input_doesnt_produce_output"), ISSUE_INVALID_OREDICTIONIFICATOR_FILTER("gui", "issues.invalid_oredictionificator_filter"), ISSUE_FILTER_HAS_BLACKLISTED_ELEMENT("gui", "issues.filter_has_blacklisted_element"), + ISSUE_REDSTONE_UNACTIVATED("gui", "issues.redstone_unactivated"), //Laser Amplifier ENTITY_DETECTION("laser_amplifier", "entity_detection"), ENERGY_CONTENTS("laser_amplifier", "energy_contents"), diff --git a/src/main/java/mekanism/common/inventory/warning/WarningTracker.java b/src/main/java/mekanism/common/inventory/warning/WarningTracker.java index 0b985d60063..0b55d394e73 100644 --- a/src/main/java/mekanism/common/inventory/warning/WarningTracker.java +++ b/src/main/java/mekanism/common/inventory/warning/WarningTracker.java @@ -75,6 +75,7 @@ public enum WarningType { NOT_ENOUGH_ENERGY_REDUCED_RATE(MekanismLang.ISSUE_NOT_ENOUGH_ENERGY_REDUCED_RATE), INVALID_OREDICTIONIFICATOR_FILTER(MekanismLang.ISSUE_INVALID_OREDICTIONIFICATOR_FILTER, 4), FILTER_HAS_BLACKLISTED_ELEMENT(MekanismLang.ISSUE_FILTER_HAS_BLACKLISTED_ELEMENT, 5), + REDSTONE_UNACTIVATED(MekanismLang.ISSUE_REDSTONE_UNACTIVATED), ; private final ILangEntry langEntry; diff --git a/src/main/java/mekanism/common/tile/base/TileEntityMekanism.java b/src/main/java/mekanism/common/tile/base/TileEntityMekanism.java index 009c2de6d44..91d2dac3db0 100644 --- a/src/main/java/mekanism/common/tile/base/TileEntityMekanism.java +++ b/src/main/java/mekanism/common/tile/base/TileEntityMekanism.java @@ -1087,16 +1087,18 @@ public final void updatePower() { } } - public boolean canFunction() { - if (supportsRedstone()) { - return switch (controlType) { + public final boolean isRedstoneActivated() { + return !supportsRedstone() || + switch (controlType) { case DISABLED -> true; case HIGH -> isPowered(); case LOW -> !isPowered(); case PULSE -> isPowered() && !redstoneLastTick; }; - } - return true; + } + + public boolean canFunction() { + return isRedstoneActivated(); } //End methods ITileRedstone diff --git a/src/main/resources/assets/mekanism/gui/warning_left.png b/src/main/resources/assets/mekanism/gui/warning_left.png new file mode 100644 index 0000000000000000000000000000000000000000..b62c6f422894bd5d15bb79da08d6edcaf98e9895 GIT binary patch literal 206 zcmeAS@N?(olHy`uVBq!ia0vp^Qb5ef!3HFCIBb4{I0YV&#S9GG!XV7ZFl&wkP_V(% z#W6(Vd~%9I!+#zVmL3D|IdkR&s66v~;`&hidA(Y+omQniv+|iq*Vo4%R`n|05nxj4 z|Fi9odZ^vv4_wT`yTn)KdVZhso(Bk4h+RA-#Kz{vCUz^bN#{TRBjqn0OV_FL@cgpU x=?F>BJa+s55EOhoCC}q}q9LZzt?H>V1GA6kl@)>P%YbfS@O1TaS?83{1OTSyMLYli literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/mekanism/gui/warning_right.png b/src/main/resources/assets/mekanism/gui/warning_right.png new file mode 100644 index 0000000000000000000000000000000000000000..86da5c5b032a64b2cda07340c08105fc4566c0e0 GIT binary patch literal 207 zcmeAS@N?(olHy`uVBq!ia0vp^Qb5ef!3HFCIBb4{I0YV&#S9GG!XV7ZFl&wkP_WU{ z#W6(Vd~!-c!jJO~(FaZ(0D_FnW8dp<#<;gV`Ey=lQ?dG|MITO14Zm_1EO`PX`~P%# zrHJcN%NUJ6?=3!Sf|%=*9hXHujbPf`n(r7cU8=RH{`)Fm3O+Htj&L u>^6f|##&i1Hm@i9Yk#wOmVP5>7(8A5T-G@yGywoXjZvxq literal 0 HcmV?d00001