Skip to content

Commit

Permalink
Add warnings for certain redstone-control conditions (#8262)
Browse files Browse the repository at this point in the history
  • Loading branch information
bukowski912 authored Jan 30, 2025
1 parent c8693a0 commit caf4865
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 12 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -1189,6 +1189,10 @@ 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");
//Redstone Activation
add(MekanismLang.ISSUE_REDSTONE_SIGNAL_ABSENT, " - Redstone signal absent, provide one to activate.");
add(MekanismLang.ISSUE_REDSTONE_SIGNAL_PRESENT, " - Redstone signal present, remove it to activate.");
add(MekanismLang.ISSUE_REDSTONE_PULSE_REQUIRED, " - Redstone pulse required to activate.");
//Laser Amplifier
add(MekanismLang.ENTITY_DETECTION, "Entity Detection");
add(MekanismLang.ENERGY_CONTENTS, "Energy Contents");
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/mekanism/client/gui/GuiMekanismTile.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
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 mekanism.common.tile.interfaces.IRedstoneControl.RedstoneControl;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.player.Inventory;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -39,7 +41,10 @@ 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_SIGNAL_ABSENT, () -> tile.getControlType() == RedstoneControl.HIGH && !tile.isRedstoneActivated())
.warning(WarningType.REDSTONE_SIGNAL_PRESENT, () -> tile.getControlType() == RedstoneControl.LOW && !tile.isRedstoneActivated())
.warning(WarningType.REDSTONE_PULSE_REQUIRED, () -> tile.getControlType() == RedstoneControl.PULSE && !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) {
Expand Down
34 changes: 33 additions & 1 deletion src/main/java/mekanism/client/gui/element/GuiInsetElement.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
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 net.minecraft.client.gui.GuiGraphics;
import net.minecraft.resources.ResourceLocation;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public abstract class GuiInsetElement<DATA_SOURCE> extends GuiSideHolder {
public abstract class GuiInsetElement<DATA_SOURCE> extends GuiSideHolder implements ISupportsWarning<GuiInsetElement<DATA_SOURCE>> {

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;
Expand All @@ -25,6 +36,12 @@ public GuiInsetElement(ResourceLocation overlay, IGuiWrapper gui, DATA_SOURCE da
active = true;
}

@Override
public GuiInsetElement<DATA_SOURCE> 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
Expand Down Expand Up @@ -55,6 +72,21 @@ protected ResourceLocation getOverlay() {
return overlay;
}

@Override
protected void draw(@NotNull GuiGraphics guiGraphics) {
boolean warning = warningSupplier != null && warningSupplier.getAsBoolean();
if (warning) {
drawUncolored(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);
}
}

@Override
public void drawBackground(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) {
super.drawBackground(guiGraphics, mouseX, mouseY, partialTicks);
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/mekanism/client/gui/element/GuiSideHolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
drawUncolored(guiGraphics);
MekanismRenderer.resetColor(guiGraphics);
}

protected void drawUncolored(@NotNull GuiGraphics guiGraphics) {
GuiUtils.blitNineSlicedSized(guiGraphics, getResource(), relativeX, relativeY, width, height, 4, TEXTURE_WIDTH, TEXTURE_HEIGHT, 0, 0, TEXTURE_WIDTH, TEXTURE_HEIGHT);
}
}
4 changes: 4 additions & 0 deletions src/main/java/mekanism/common/MekanismLang.java
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,10 @@ 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"),
//Redstone Activation
ISSUE_REDSTONE_SIGNAL_ABSENT("gui", "issues.redstone_signal_absent"),
ISSUE_REDSTONE_SIGNAL_PRESENT("gui", "issues.redstone_signal_present"),
ISSUE_REDSTONE_PULSE_REQUIRED("gui", "issues.redstone_pulse_required"),
//Laser Amplifier
ENTITY_DETECTION("laser_amplifier", "entity_detection"),
ENERGY_CONTENTS("laser_amplifier", "energy_contents"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ 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_SIGNAL_ABSENT(MekanismLang.ISSUE_REDSTONE_SIGNAL_ABSENT),
REDSTONE_SIGNAL_PRESENT(MekanismLang.ISSUE_REDSTONE_SIGNAL_PRESENT),
REDSTONE_PULSE_REQUIRED(MekanismLang.ISSUE_REDSTONE_PULSE_REQUIRED),
;

private final ILangEntry langEntry;
Expand Down
15 changes: 10 additions & 5 deletions src/main/java/mekanism/common/tile/base/TileEntityMekanism.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -908,6 +909,8 @@ 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));
container.track(SyncableBoolean.create(this::wasPowered, value -> redstoneLastTick = value));
}
boolean isClient = isRemote();
if (canHandleChemicals() && syncs(ContainerType.CHEMICAL)) {
Expand Down Expand Up @@ -1094,16 +1097,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

Expand Down

0 comments on commit caf4865

Please sign in to comment.