From 84d6179967a5d627d399cc241c056672ba7184aa Mon Sep 17 00:00:00 2001 From: bukowski912 Date: Sat, 23 Nov 2024 00:40:40 +1100 Subject: [PATCH 1/2] Add a warning for redstone conditions not being met - Make GuiInsetElement able to track warnings through a supplier - Use a separate texture for GuiInsetElement during a warning - Track the activation warning under GuiRedstoneControlTab - Add the corresponding lang entry to MekanismLangProvider - Synchronize activation (redstone) state of TileEntityMekanism --- .../c10fcd8abbb6a520fc3ac2cf14b627d36958dd55 | 6 ++-- .../mekanism/assets/mekanism/lang/en_ud.json | 1 + .../mekanism/assets/mekanism/lang/en_us.json | 1 + .../client/lang/MekanismLangProvider.java | 1 + .../mekanism/client/gui/GuiMekanismTile.java | 3 +- .../client/gui/element/GuiInsetElement.java | 29 +++++++++++++++++- .../client/gui/element/GuiSideHolder.java | 8 +++-- .../java/mekanism/common/MekanismLang.java | 1 + .../inventory/warning/WarningTracker.java | 1 + .../common/tile/base/TileEntityMekanism.java | 14 ++++++--- .../assets/mekanism/gui/warning_left.png | Bin 0 -> 206 bytes .../assets/mekanism/gui/warning_right.png | Bin 0 -> 207 bytes 12 files changed, 53 insertions(+), 12 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/.cache/c10fcd8abbb6a520fc3ac2cf14b627d36958dd55 b/src/datagen/generated/mekanism/.cache/c10fcd8abbb6a520fc3ac2cf14b627d36958dd55 index 00b567bbc28..f3a5d8e79c5 100644 --- a/src/datagen/generated/mekanism/.cache/c10fcd8abbb6a520fc3ac2cf14b627d36958dd55 +++ b/src/datagen/generated/mekanism/.cache/c10fcd8abbb6a520fc3ac2cf14b627d36958dd55 @@ -1,5 +1,5 @@ -// 1.21.1 2024-09-28T11:00:15.3042814 Languages: en_us for mod: mekanism +// 1.21.1 2024-11-23T20:13:21.6073479 Languages: en_us for mod: mekanism 8d915354d84b3a4d60c65f9280fdd7ceca016c35 assets/mekanism/lang/en_au.json 8d915354d84b3a4d60c65f9280fdd7ceca016c35 assets/mekanism/lang/en_gb.json -2cd403d1dc72293441a4c86b1b1ddc05978130e8 assets/mekanism/lang/en_ud.json -525157cafd0048a56223755ff5b66a357d3008b4 assets/mekanism/lang/en_us.json +7e84d49fa4f68936a43bca5f7a4dfb071e735e27 assets/mekanism/lang/en_ud.json +85cdcefae92079d12d07e68a3561964f4d4d9552 assets/mekanism/lang/en_us.json diff --git a/src/datagen/generated/mekanism/assets/mekanism/lang/en_ud.json b/src/datagen/generated/mekanism/assets/mekanism/lang/en_ud.json index 0d8f56e1208..9d000521a90 100644 --- a/src/datagen/generated/mekanism/assets/mekanism/lang/en_ud.json +++ b/src/datagen/generated/mekanism/assets/mekanism/lang/en_ud.json @@ -2294,6 +2294,7 @@ "gui.mekanism.issues.no_recipe": "ʇnduᴉ ɥᵷnouǝ ʇou ɹo ǝdᴉɔǝɹ ᵷuᴉɥɔʇɐɯ oN - ", "gui.mekanism.issues.no_space": "ʇndʇno uᴉ ɯooɹ ɥᵷnouǝ ʇoN - ", "gui.mekanism.issues.no_space.overflow": "ɹǝɟɟnq ꞁɐuɹǝʇuᴉ uᴉ pǝɹoʇs ʍoꞁɟɹǝʌo 'ʇndʇno uᴉ ɯooɹ ɥᵷnouǝ ʇoN - ", + "gui.mekanism.issues.redstone_prevents_activation": "ʇǝɯ ʇou suoᴉʇᴉpuoɔ ǝuoʇspǝᴚ - ", "gui.mekanism.jitter": "%%%s :ɹǝʇʇᴉՐ", "gui.mekanism.liquid": "%s :pᴉnbᴉꞀ", "gui.mekanism.max": "%s :xɐW", 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..3629b1f0937 100644 --- a/src/datagen/generated/mekanism/assets/mekanism/lang/en_us.json +++ b/src/datagen/generated/mekanism/assets/mekanism/lang/en_us.json @@ -2297,6 +2297,7 @@ "gui.mekanism.issues.no_recipe": " - No matching recipe or not enough input", "gui.mekanism.issues.no_space": " - Not enough room in output", "gui.mekanism.issues.no_space.overflow": " - Not enough room in output, overflow stored in internal buffer", + "gui.mekanism.issues.redstone_prevents_activation": " - Redstone conditions not met", "gui.mekanism.jitter": "Jitter: %1$s%%", "gui.mekanism.liquid": "Liquid: %1$s", "gui.mekanism.max": "Max: %1$s", diff --git a/src/datagen/main/java/mekanism/client/lang/MekanismLangProvider.java b/src/datagen/main/java/mekanism/client/lang/MekanismLangProvider.java index 4cec72f0704..61732f0df8b 100644 --- a/src/datagen/main/java/mekanism/client/lang/MekanismLangProvider.java +++ b/src/datagen/main/java/mekanism/client/lang/MekanismLangProvider.java @@ -1182,6 +1182,7 @@ private void addMisc() { add(MekanismLang.ISSUE_INPUT_DOESNT_PRODUCE_OUTPUT, " - Input does not produce output"); add(MekanismLang.ISSUE_INVALID_OREDICTIONIFICATOR_FILTER, " - Filter is no longer valid or supported"); add(MekanismLang.ISSUE_FILTER_HAS_BLACKLISTED_ELEMENT, " - Filter contains at least one element that is blacklisted"); + add(MekanismLang.ISSUE_REDSTONE_PREVENTS_ACTIVATION, " - Redstone conditions not met"); //Laser Amplifier add(MekanismLang.ENTITY_DETECTION, "Entity Detection"); add(MekanismLang.ENERGY_CONTENTS, "Energy Contents"); diff --git a/src/main/java/mekanism/client/gui/GuiMekanismTile.java b/src/main/java/mekanism/client/gui/GuiMekanismTile.java index 5a5dbd877e5..0696e892d33 100644 --- a/src/main/java/mekanism/client/gui/GuiMekanismTile.java +++ b/src/main/java/mekanism/client/gui/GuiMekanismTile.java @@ -5,6 +5,7 @@ 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 +40,7 @@ protected void addGenericTabs() { upgradeWindowTab = addRenderableWidget(new GuiUpgradeWindowTab(this, tile, () -> upgradeWindowTab)); } if (tile.supportsRedstone()) { - addRenderableWidget(new GuiRedstoneControlTab(this, tile)); + addRenderableWidget(new GuiRedstoneControlTab(this, tile).warning(WarningType.REDSTONE_PREVENTS_ACTIVATION, () -> !tile.isRedstoneActivated())); } //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..96c44da9662 100644 --- a/src/main/java/mekanism/client/gui/element/GuiInsetElement.java +++ b/src/main/java/mekanism/client/gui/element/GuiInsetElement.java @@ -1,11 +1,19 @@ package mekanism.client.gui.element; +import java.util.function.BooleanSupplier; import mekanism.client.gui.IGuiWrapper; +import mekanism.common.inventory.warning.ISupportsWarning; +import mekanism.common.inventory.warning.WarningTracker.WarningType; +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 { +public abstract class GuiInsetElement extends GuiSideHolder implements ISupportsWarning> { + + 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; @@ -13,6 +21,9 @@ public abstract class GuiInsetElement extends GuiSideHolder { 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 +36,12 @@ public GuiInsetElement(ResourceLocation overlay, IGuiWrapper gui, DATA_SOURCE da active = true; } + @Override + public GuiInsetElement warning(@NotNull WarningType type, @NotNull BooleanSupplier warningSupplier) { + this.warningSupplier = ISupportsWarning.compound(this.warningSupplier, gui().trackWarning(type, warningSupplier)); + return this; + } + @Override public boolean isMouseOver(double xAxis, double yAxis) { //TODO: override isHovered @@ -55,6 +72,16 @@ protected ResourceLocation getOverlay() { return overlay; } + @Override + protected void draw(@NotNull GuiGraphics guiGraphics) { + boolean warning = warningSupplier != null && warningSupplier.getAsBoolean(); + if (warning) { + innerDraw(guiGraphics, left ? WARNING_LEFT : WARNING_RIGHT); + } 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..f9703b3792b 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_PREVENTS_ACTIVATION("gui", "issues.redstone_prevents_activation"), //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..2dd3c9ab43f 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_PREVENTS_ACTIVATION(MekanismLang.ISSUE_REDSTONE_PREVENTS_ACTIVATION), ; 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..3c53e969c75 100644 --- a/src/main/java/mekanism/common/tile/base/TileEntityMekanism.java +++ b/src/main/java/mekanism/common/tile/base/TileEntityMekanism.java @@ -82,6 +82,7 @@ import mekanism.common.integration.computer.annotation.ComputerMethod; import mekanism.common.inventory.container.ITrackableContainer; import mekanism.common.inventory.container.MekanismContainer; +import mekanism.common.inventory.container.sync.SyncableBoolean; import mekanism.common.inventory.container.sync.SyncableDouble; import mekanism.common.inventory.container.sync.SyncableEnum; import mekanism.common.inventory.container.sync.SyncableFluidStack; @@ -901,6 +902,7 @@ public void addContainerTrackers(MekanismContainer container) { } if (supportsRedstone()) { container.track(SyncableEnum.create(RedstoneControl.BY_ID, RedstoneControl.DISABLED, () -> controlType, value -> controlType = value)); + container.track(SyncableBoolean.create(this::isPowered, value -> redstone = value)); } boolean isClient = isRemote(); if (canHandleChemicals() && syncs(ContainerType.CHEMICAL)) { @@ -1087,16 +1089,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 From 7f8bbffef73c269e316ed2cc04e533e3416efb81 Mon Sep 17 00:00:00 2001 From: bukowski912 Date: Mon, 2 Dec 2024 10:24:51 +1100 Subject: [PATCH 2/2] Properly blend the slot-holder warning overlay & fixup GuiSlotHolder --- .../client/gui/element/GuiInsetElement.java | 19 ++++++++++++------- .../client/gui/element/GuiSideHolder.java | 12 ++++++------ 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/main/java/mekanism/client/gui/element/GuiInsetElement.java b/src/main/java/mekanism/client/gui/element/GuiInsetElement.java index 96c44da9662..9ced4c3f60f 100644 --- a/src/main/java/mekanism/client/gui/element/GuiInsetElement.java +++ b/src/main/java/mekanism/client/gui/element/GuiInsetElement.java @@ -1,10 +1,13 @@ package mekanism.client.gui.element; import java.util.function.BooleanSupplier; + +import com.mojang.blaze3d.platform.GlStateManager.DestFactor; +import com.mojang.blaze3d.platform.GlStateManager.SourceFactor; +import com.mojang.blaze3d.systems.RenderSystem; import mekanism.client.gui.IGuiWrapper; import mekanism.common.inventory.warning.ISupportsWarning; import mekanism.common.inventory.warning.WarningTracker.WarningType; -import mekanism.common.util.MekanismUtils; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.resources.ResourceLocation; import org.jetbrains.annotations.NotNull; @@ -12,9 +15,6 @@ public abstract class GuiInsetElement extends GuiSideHolder implements ISupportsWarning> { - 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; @@ -73,12 +73,17 @@ protected ResourceLocation getOverlay() { } @Override - protected void draw(@NotNull GuiGraphics guiGraphics) { + protected void drawHolder(@NotNull GuiGraphics guiGraphics) { boolean warning = warningSupplier != null && warningSupplier.getAsBoolean(); if (warning) { - innerDraw(guiGraphics, left ? WARNING_LEFT : WARNING_RIGHT); + drawHolderUncolored(guiGraphics); + //Draw the warning overlay (multiply-blended) + RenderSystem.enableBlend(); + RenderSystem.blendFunc(SourceFactor.DST_COLOR, DestFactor.ZERO); + guiGraphics.blit(WARNING_TEXTURE, relativeX, relativeY, 0, 0, width, height, 256, 256); + RenderSystem.disableBlend(); } else { - super.draw(guiGraphics); + super.drawHolder(guiGraphics); } } diff --git a/src/main/java/mekanism/client/gui/element/GuiSideHolder.java b/src/main/java/mekanism/client/gui/element/GuiSideHolder.java index 1017542c848..a2458269473 100644 --- a/src/main/java/mekanism/client/gui/element/GuiSideHolder.java +++ b/src/main/java/mekanism/client/gui/element/GuiSideHolder.java @@ -51,7 +51,7 @@ public void renderWidget(@NotNull GuiGraphics guiGraphics, int mouseX, int mouse super.renderWidget(guiGraphics, mouseX, mouseY, partialTicks); if (this.slotHolder) { //Slot holders need to draw here to render behind the slots instead of in front of them - draw(guiGraphics); + drawHolder(guiGraphics); } } @@ -59,17 +59,17 @@ public void renderWidget(@NotNull GuiGraphics guiGraphics, int mouseX, int mouse public void drawBackground(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) { super.drawBackground(guiGraphics, mouseX, mouseY, partialTicks); if (!this.slotHolder) { - draw(guiGraphics); + drawHolder(guiGraphics); } } - protected void draw(@NotNull GuiGraphics guiGraphics) { + protected void drawHolder(@NotNull GuiGraphics guiGraphics) { colorTab(guiGraphics); - innerDraw(guiGraphics, getResource()); + drawHolderUncolored(guiGraphics); 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); + protected void drawHolderUncolored(@NotNull GuiGraphics guiGraphics) { + GuiUtils.blitNineSlicedSized(guiGraphics, getResource(), relativeX, relativeY, width, height, 4, TEXTURE_WIDTH, TEXTURE_HEIGHT, 0, 0, TEXTURE_WIDTH, TEXTURE_HEIGHT); } } \ No newline at end of file