Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance Wireless Detectors with toggle-able sided redstone manipulation #3617

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
ca4c644
include toggle logic for detector covers
Sanduhr32 Dec 8, 2024
6c733e1
include gui button & hint for toggling behavior
Sanduhr32 Dec 8, 2024
09a7e06
document meaning & behavior of variable named "physical"
Sanduhr32 Dec 8, 2024
9e96648
adjust gui to use "checkmark" button
Sanduhr32 Dec 8, 2024
226741d
Merge branch 'master' into enhancement/toggle-detector-redstone-behavior
Sanduhr32 Dec 8, 2024
d692de0
apply spotless java guidelines
Sanduhr32 Dec 8, 2024
f164471
Merge branch 'master' into enhancement/toggle-detector-redstone-behavior
Sanduhr32 Dec 12, 2024
fbca40c
Merge branch 'master' into enhancement/toggle-detector-redstone-behavior
Dream-Master Dec 14, 2024
e38112f
Merge branch 'master' into enhancement/toggle-detector-redstone-behavior
Sanduhr32 Dec 18, 2024
a42dd45
Merge branch 'master' into enhancement/toggle-detector-redstone-behavior
Dream-Master Dec 18, 2024
d57d542
make physical mode true by default
Sanduhr32 Dec 19, 2024
cc0b453
add explicit `false` for missing physical nbt tags
Sanduhr32 Dec 19, 2024
b2de26e
Merge branch 'master' into enhancement/toggle-detector-redstone-behavior
Dream-Master Dec 19, 2024
d8eac9b
Merge branch 'master' into enhancement/toggle-detector-redstone-behavior
Dream-Master Dec 20, 2024
a62a588
Merge branch 'master' into enhancement/toggle-detector-redstone-behavior
Dream-Master Dec 21, 2024
be871db
Merge branch 'master' into enhancement/toggle-detector-redstone-behavior
Dream-Master Dec 26, 2024
fc10946
Merge branch 'master' into enhancement/toggle-detector-redstone-behavior
Dream-Master Dec 31, 2024
d3e7088
Merge branch 'master' into enhancement/toggle-detector-redstone-behavior
Dream-Master Jan 3, 2025
ac978eb
Merge branch 'master' into enhancement/toggle-detector-redstone-behavior
Dream-Master Jan 3, 2025
8dabeba
Merge branch 'master' into enhancement/toggle-detector-redstone-behavior
Dream-Master Jan 4, 2025
4c45f8c
Merge branch 'master' into enhancement/toggle-detector-redstone-behavior
Dream-Master Jan 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.StatCollector;
import net.minecraftforge.common.util.ForgeDirection;

import com.google.common.io.ByteArrayDataInput;
import com.gtnewhorizons.modularui.api.math.Alignment;
import com.gtnewhorizons.modularui.api.screen.ModularWindow;
import com.gtnewhorizons.modularui.common.widget.TextWidget;

Expand Down Expand Up @@ -76,7 +78,11 @@ public ActivityTransmitterData doCoverThingsImpl(ForgeDirection side, byte aInpu
final long hash = hashCoverCoords(aTileEntity, side);
setSignalAt(aCoverVariable.getUuid(), aCoverVariable.getFrequency(), hash, signal);

aTileEntity.setOutputRedstoneSignal(side, signal);
if (aCoverVariable.physical) {
aTileEntity.setOutputRedstoneSignal(side, signal);
} else {
aTileEntity.setOutputRedstoneSignal(side, (byte) 0);
}

return aCoverVariable;
}
Expand Down Expand Up @@ -114,28 +120,33 @@ public enum ActivityMode {
public static class ActivityTransmitterData extends CoverAdvancedRedstoneTransmitterBase.TransmitterData {

private ActivityMode mode;
/** Whether the wireless detector cover also sets the tiles sided Redstone output */
private boolean physical;

public ActivityTransmitterData(int frequency, UUID uuid, boolean invert, ActivityMode mode) {
public ActivityTransmitterData(int frequency, UUID uuid, boolean invert, ActivityMode mode, boolean physical) {
super(frequency, uuid, invert);
this.mode = mode;
this.physical = physical;
}

public ActivityTransmitterData() {
super();
this.mode = ActivityMode.MACHINE_IDLE;
this.physical = true;
}

@Nonnull
@Override
public ISerializableObject copy() {
return new ActivityTransmitterData(frequency, uuid, invert, mode);
return new ActivityTransmitterData(frequency, uuid, invert, mode, physical);
}

@Nonnull
@Override
public NBTBase saveDataToNBT() {
NBTTagCompound tag = (NBTTagCompound) super.saveDataToNBT();
tag.setInteger("mode", mode.ordinal());
tag.setBoolean("physical", physical);

return tag;
}
Expand All @@ -144,6 +155,7 @@ public NBTBase saveDataToNBT() {
public void writeToByteBuf(ByteBuf aBuf) {
super.writeToByteBuf(aBuf);
aBuf.writeInt(mode.ordinal());
aBuf.writeBoolean(physical);
}

@Override
Expand All @@ -152,13 +164,19 @@ public void loadDataFromNBT(NBTBase aNBT) {

NBTTagCompound tag = (NBTTagCompound) aNBT;
mode = ActivityMode.values()[tag.getInteger("mode")];
if (tag.hasKey("physical")) {
physical = tag.getBoolean("physical");
} else {
physical = false;
}
}

@Nonnull
@Override
public ISerializableObject readFromPacket(ByteArrayDataInput aBuf, EntityPlayerMP aPlayer) {
super.readFromPacket(aBuf, aPlayer);
mode = ActivityMode.values()[aBuf.readInt()];
physical = aBuf.readBoolean();

return this;
}
Expand All @@ -177,7 +195,7 @@ public WirelessActivityDetectorUIFactory(CoverUIBuildContext buildContext) {

@Override
protected int getGUIHeight() {
return 107;
return 123;
}

@Override
Expand Down Expand Up @@ -208,7 +226,22 @@ protected void addUIWidgets(ModularWindow.Builder builder) {
})
.setSynced(false)
.setDefaultColor(COLOR_TEXT_GRAY.get())
.setPos(startX + spaceX * 3, 4 + startY + spaceY * 2));
.setPos(startX + spaceX * 3, 4 + startY + spaceY * 2))
.widget(TextWidget.dynamicString(() -> {
ActivityTransmitterData coverData = getCoverData();
if (coverData != null) {
return getCoverData().physical
? StatCollector.translateToLocal("gt.cover.wirelessdetector.redstone.1")
: StatCollector.translateToLocal("gt.cover.wirelessdetector.redstone.0");
} else {
return "";
}
})
.setSynced(false)
.setDefaultColor(COLOR_TEXT_GRAY.get())
.setTextAlignment(Alignment.CenterLeft)
.setPos(startX + spaceX, 4 + startY + spaceY * 3)
.setSize(spaceX * 10, 12));
}

@Override
Expand Down Expand Up @@ -244,7 +277,17 @@ protected void addUIForDataController(CoverDataControllerWidget<ActivityTransmit
},
widget -> widget.setStaticTexture(GTUITextures.OVERLAY_BUTTON_POWER_SWITCH_ON)
.addTooltip(GTUtility.trans("271", "Machine enabled"))
.setPos(spaceX * 2, spaceY * 2));
.setPos(spaceX * 2, spaceY * 2))
.addFollower(
CoverDataFollowerToggleButtonWidget.ofDisableable(),
coverData -> coverData.physical,
(coverData, state) -> {
coverData.physical = state;
return coverData;
},
widget -> widget
.addTooltip(StatCollector.translateToLocal("gt.cover.wirelessdetector.redstone.tooltip"))
.setPos(0, 1 + spaceY * 3));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.StatCollector;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler;

import com.google.common.io.ByteArrayDataInput;
import com.gtnewhorizons.modularui.api.math.Alignment;
import com.gtnewhorizons.modularui.api.screen.ModularWindow;
import com.gtnewhorizons.modularui.common.widget.TextWidget;

Expand All @@ -24,6 +26,7 @@
import gregtech.common.covers.CoverLiquidMeter;
import gregtech.common.gui.modularui.widget.CoverDataControllerWidget;
import gregtech.common.gui.modularui.widget.CoverDataFollowerNumericWidget;
import gregtech.common.gui.modularui.widget.CoverDataFollowerToggleButtonWidget;
import io.netty.buffer.ByteBuf;

public class CoverWirelessFluidDetector
Expand Down Expand Up @@ -51,7 +54,11 @@ public FluidTransmitterData doCoverThingsImpl(ForgeDirection side, byte aInputRe
final long hash = hashCoverCoords(aTileEntity, side);
setSignalAt(aCoverVariable.getUuid(), aCoverVariable.getFrequency(), hash, signal);

aTileEntity.setOutputRedstoneSignal(side, signal);
if (aCoverVariable.physical) {
aTileEntity.setOutputRedstoneSignal(side, signal);
} else {
aTileEntity.setOutputRedstoneSignal(side, (byte) 0);
}

return aCoverVariable;
}
Expand All @@ -72,28 +79,33 @@ public static class FluidTransmitterData extends CoverAdvancedRedstoneTransmitte

/** The special value {@code 0} means threshold check is disabled. */
private int threshold;
/** Whether the wireless detector cover also sets the tiles sided Redstone output */
private boolean physical;

public FluidTransmitterData(int frequency, UUID uuid, boolean invert, int threshold) {
public FluidTransmitterData(int frequency, UUID uuid, boolean invert, int threshold, boolean physical) {
super(frequency, uuid, invert);
this.threshold = threshold;
this.physical = physical;
}

public FluidTransmitterData() {
super();
this.threshold = 0;
this.physical = true;
}

@Nonnull
@Override
public ISerializableObject copy() {
return new FluidTransmitterData(frequency, uuid, invert, threshold);
return new FluidTransmitterData(frequency, uuid, invert, threshold, physical);
}

@Nonnull
@Override
public NBTBase saveDataToNBT() {
NBTTagCompound tag = (NBTTagCompound) super.saveDataToNBT();
tag.setInteger("threshold", threshold);
tag.setBoolean("physical", physical);

return tag;
}
Expand All @@ -102,6 +114,7 @@ public NBTBase saveDataToNBT() {
public void writeToByteBuf(ByteBuf aBuf) {
super.writeToByteBuf(aBuf);
aBuf.writeInt(threshold);
aBuf.writeBoolean(physical);
}

@Override
Expand All @@ -110,13 +123,19 @@ public void loadDataFromNBT(NBTBase aNBT) {

NBTTagCompound tag = (NBTTagCompound) aNBT;
threshold = tag.getInteger("threshold");
if (tag.hasKey("physical")) {
physical = tag.getBoolean("physical");
} else {
physical = false;
}
}

@Nonnull
@Override
public ISerializableObject readFromPacket(ByteArrayDataInput aBuf, EntityPlayerMP aPlayer) {
super.readFromPacket(aBuf, aPlayer);
threshold = aBuf.readInt();
physical = aBuf.readBoolean();

return this;
}
Expand All @@ -137,6 +156,11 @@ public WirelessFluidDetectorUIFactory(CoverUIBuildContext buildContext) {
super(buildContext);
}

@Override
protected int getGUIHeight() {
return 123;
}

@Override
protected int getFrequencyRow() {
return 0;
Expand All @@ -151,9 +175,25 @@ protected int getButtonRow() {
protected void addUIWidgets(ModularWindow.Builder builder) {
setMaxCapacity();
super.addUIWidgets(builder);
builder.widget(
new TextWidget(GTUtility.trans("222", "Fluid threshold")).setDefaultColor(COLOR_TEXT_GRAY.get())
.setPos(startX + spaceX * 5, 4 + startY + spaceY * 2));
builder
.widget(
new TextWidget(GTUtility.trans("222", "Fluid threshold")).setDefaultColor(COLOR_TEXT_GRAY.get())
.setPos(startX + spaceX * 5, 4 + startY + spaceY * 2))
.widget(TextWidget.dynamicString(() -> {
FluidTransmitterData coverData = getCoverData();
if (coverData != null) {
return getCoverData().physical
? StatCollector.translateToLocal("gt.cover.wirelessdetector.redstone.1")
: StatCollector.translateToLocal("gt.cover.wirelessdetector.redstone.0");
} else {
return "";
}
})
.setSynced(false)
.setDefaultColor(COLOR_TEXT_GRAY.get())
.setTextAlignment(Alignment.CenterLeft)
.setPos(startX + spaceX, 4 + startY + spaceY * 3)
.setSize(spaceX * 10, 12));
}

@Override
Expand All @@ -170,7 +210,17 @@ protected void addUIForDataController(CoverDataControllerWidget<FluidTransmitter
.setScrollValues(1000, 144, 100000)
.setFocusOnGuiOpen(true)
.setPos(1, 2 + spaceY * 2)
.setSize(spaceX * 5 - 4, 12));
.setSize(spaceX * 5 - 4, 12))
.addFollower(
CoverDataFollowerToggleButtonWidget.ofDisableable(),
coverData -> coverData.physical,
(coverData, state) -> {
coverData.physical = state;
return coverData;
},
widget -> widget
.addTooltip(StatCollector.translateToLocal("gt.cover.wirelessdetector.redstone.tooltip"))
.setPos(0, 1 + spaceY * 3));
}

private void setMaxCapacity() {
Expand Down
Loading
Loading