From e0633283f9be8f932537f3d589b706247ce7e0c1 Mon Sep 17 00:00:00 2001 From: trinsdar <30245301+Trinsdar@users.noreply.github.com> Date: Mon, 31 Jul 2023 09:27:43 -0400 Subject: [PATCH] added redstone machine controller cover --- .../gregtech/cover/CoverConveyor.java | 15 +- .../muramasa/gregtech/cover/CoverPump.java | 10 +- .../muramasa/gregtech/cover/RedstoneMode.java | 32 +++++ .../CoverRedstoneMachineController.java | 135 ++++++++++++++++++ .../muramasa/gregtech/data/GregTechData.java | 7 +- .../cover/redstone_machine_controller.png | Bin 0 -> 288 bytes .../basic/redstone_machine_controller.png | Bin 0 -> 280 bytes 7 files changed, 186 insertions(+), 13 deletions(-) create mode 100644 common/src/main/java/muramasa/gregtech/cover/RedstoneMode.java create mode 100644 common/src/main/java/muramasa/gregtech/cover/redstone/CoverRedstoneMachineController.java create mode 100644 common/src/main/resources/assets/gti/textures/block/cover/redstone_machine_controller.png create mode 100644 common/src/main/resources/assets/gti/textures/item/basic/redstone_machine_controller.png diff --git a/common/src/main/java/muramasa/gregtech/cover/CoverConveyor.java b/common/src/main/java/muramasa/gregtech/cover/CoverConveyor.java index 0549127f03..b2b85d358e 100644 --- a/common/src/main/java/muramasa/gregtech/cover/CoverConveyor.java +++ b/common/src/main/java/muramasa/gregtech/cover/CoverConveyor.java @@ -12,7 +12,9 @@ import muramasa.antimatter.gui.widget.TextWidget; import muramasa.antimatter.gui.widget.WidgetSupplier; import muramasa.antimatter.machine.Tier; +import muramasa.antimatter.util.AntimatterCapUtils; import muramasa.antimatter.util.Utils; +import muramasa.gregtech.cover.redstone.CoverRedstoneMachineController; import muramasa.gregtech.gui.widgets.ChangingButtonWidget; import net.minecraft.client.gui.screens.Screen; import net.minecraft.nbt.CompoundTag; @@ -32,10 +34,7 @@ import tesseract.api.item.PlatformItemHandler; import javax.annotation.Nullable; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; +import java.util.*; import java.util.function.BiFunction; import java.util.function.Consumer; @@ -136,12 +135,12 @@ public void onUpdate() { protected boolean canMove(Direction side){ String name = getCoverMode().getName(); - /*if (name.contains("Conditional")){ + if (name.contains("Conditional")){ boolean powered = AntimatterCapUtils.getCoverHandler(handler.getTile(), side).map(h -> { List list = new ArrayList<>(); for (Direction dir : Direction.values()){ - if (h.get(dir) instanceof CoverRedstoneMachineController){ - list.add((CoverRedstoneMachineController) h.get(dir)); + if (h.get(dir) instanceof CoverRedstoneMachineController machineController){ + list.add(machineController); } } int i = 0; @@ -155,7 +154,7 @@ protected boolean canMove(Direction side){ return i > 0 && i == j; }).orElse(false); return name.contains("Invert") != powered; - }*/ + } return true; } diff --git a/common/src/main/java/muramasa/gregtech/cover/CoverPump.java b/common/src/main/java/muramasa/gregtech/cover/CoverPump.java index a6c15344a9..6016c510a4 100644 --- a/common/src/main/java/muramasa/gregtech/cover/CoverPump.java +++ b/common/src/main/java/muramasa/gregtech/cover/CoverPump.java @@ -7,7 +7,9 @@ import muramasa.antimatter.cover.CoverFactory; import muramasa.antimatter.gui.ButtonBody; import muramasa.antimatter.machine.Tier; +import muramasa.antimatter.util.AntimatterCapUtils; import muramasa.antimatter.util.Utils; +import muramasa.gregtech.cover.redstone.CoverRedstoneMachineController; import net.minecraft.core.BlockPos; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.core.Direction; @@ -89,12 +91,12 @@ public void onUpdate() { } protected boolean canMove(Direction side){ String name = getCoverMode().getName(); - /*if (name.contains("Conditional")){ + if (name.contains("Conditional")){ boolean powered = AntimatterCapUtils.getCoverHandler(handler.getTile(), side).map(h -> { List list = new ArrayList<>(); for (Direction dir : Direction.values()){ - if (h.get(dir) instanceof CoverRedstoneMachineController){ - list.add((CoverRedstoneMachineController) h.get(dir)); + if (h.get(dir) instanceof CoverRedstoneMachineController machineController){ + list.add(machineController); } } int i = 0; @@ -108,7 +110,7 @@ protected boolean canMove(Direction side){ return i > 0 && i == j; }).orElse(false); return name.contains("Invert") != powered; - }*/ + } return true; } } diff --git a/common/src/main/java/muramasa/gregtech/cover/RedstoneMode.java b/common/src/main/java/muramasa/gregtech/cover/RedstoneMode.java new file mode 100644 index 0000000000..9f734ede3e --- /dev/null +++ b/common/src/main/java/muramasa/gregtech/cover/RedstoneMode.java @@ -0,0 +1,32 @@ +package muramasa.gregtech.cover; + +import muramasa.antimatter.cover.ICoverMode; + +public enum RedstoneMode implements ICoverMode { + NORMAL("Normal", 60, 33), + INVERTED("Inverted", 78, 33), + NO_WORK("No Work at all", 96, 33); + int x, y; + String name; + + RedstoneMode(String name, int x, int y){ + this.name = name; + this.x = x; + this.y = y; + } + + @Override + public int getX() { + return x; + } + + @Override + public int getY() { + return y; + } + + @Override + public String getName() { + return name; + } +} diff --git a/common/src/main/java/muramasa/gregtech/cover/redstone/CoverRedstoneMachineController.java b/common/src/main/java/muramasa/gregtech/cover/redstone/CoverRedstoneMachineController.java new file mode 100644 index 0000000000..1dbbea5297 --- /dev/null +++ b/common/src/main/java/muramasa/gregtech/cover/redstone/CoverRedstoneMachineController.java @@ -0,0 +1,135 @@ +package muramasa.gregtech.cover.redstone; + +import muramasa.antimatter.Ref; +import muramasa.antimatter.capability.ICoverHandler; +import muramasa.antimatter.cover.BaseCover; +import muramasa.antimatter.cover.CoverFactory; +import muramasa.antimatter.cover.ICoverMode; +import muramasa.antimatter.cover.ICoverModeHandler; +import muramasa.antimatter.gui.event.GuiEvents; +import muramasa.antimatter.gui.event.IGuiEvent; +import muramasa.antimatter.machine.MachineState; +import muramasa.antimatter.machine.Tier; +import muramasa.antimatter.tile.TileEntityMachine; +import muramasa.gregtech.cover.RedstoneMode; +import net.minecraft.core.Direction; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.player.Player; + +import javax.annotation.Nullable; + +import static muramasa.gregtech.gui.ButtonOverlays.*; + +public class CoverRedstoneMachineController extends BaseCover implements ICoverModeHandler { + + protected RedstoneMode coverMode; + protected int redstonePower; + + public CoverRedstoneMachineController(ICoverHandler source, @Nullable Tier tier, Direction side, CoverFactory factory) { + super(source, tier, side, factory); + this.coverMode = RedstoneMode.NORMAL; + addGuiCallback(t -> { + t.addButton(61, 34, 16, 16, TORCH_ON).addButton(79, 34, 16, 16, TORCH_OFF).addButton(97, 34, 16, 16, REDSTONE); + }); + } + + @Override + public String getDomain() { + return Ref.ID; + } + + @Override + public String getId() { + return "redstone_machine_controller"; + } + + @Override + public void onRemove() { + if (handler.getTile() instanceof TileEntityMachine){ + TileEntityMachine machine = (TileEntityMachine) handler.getTile(); + if (machine.getMachineState() == MachineState.DISABLED){ + machine.toggleMachine(); + } + } + } + + public boolean isPowered(){ + if (coverMode == RedstoneMode.NORMAL){ + return redstonePower > 0; + } + if (coverMode == RedstoneMode.INVERTED){ + return redstonePower == 0; + } + return false; + } + + @Override + public void onUpdate() { + if (handler.getTile() instanceof TileEntityMachine){ + TileEntityMachine machine = (TileEntityMachine) handler.getTile(); + if (machine.getMachineState() != MachineState.DISABLED){ + if (coverMode == RedstoneMode.NO_WORK){ + machine.toggleMachine(); + } else if (coverMode == RedstoneMode.NORMAL){ + if (redstonePower == 0){ + machine.toggleMachine(); + } + } else { + if (redstonePower > 0){ + machine.toggleMachine(); + } + } + } else { + if (coverMode == RedstoneMode.NORMAL){ + if (redstonePower > 0){ + machine.toggleMachine(); + } + } else if (coverMode == RedstoneMode.INVERTED){ + if (redstonePower == 0){ + machine.toggleMachine(); + } + } + } + + } + } + + @Override + public void onBlockUpdate() { + redstonePower = handler.getTile().getLevel().getSignal(handler.getTile().getBlockPos().relative(side), side); + } + + @Override + public void onGuiEvent(IGuiEvent event, Player playerEntity) { + if (event.getFactory() == GuiEvents.EXTRA_BUTTON){ + GuiEvents.GuiEvent ev = (GuiEvents.GuiEvent) event; + coverMode = RedstoneMode.values()[Math.min(ev.data[0], 2)]; + } + } + + @Override + public ICoverMode getCoverMode() { + return coverMode; + } + + @Override + public int coverModeToInt() { + return coverMode.ordinal(); + } + + @Override + public ICoverMode getCoverMode(int index) { + return RedstoneMode.values()[index]; + } + + @Override + public ResourceLocation getModel(String type, Direction dir) { + if (type.equals("pipe")) return PIPE_COVER_MODEL; + return getBasicModel(); + } + + @Override + public boolean hasGui() { + return true; + } +} diff --git a/common/src/main/java/muramasa/gregtech/data/GregTechData.java b/common/src/main/java/muramasa/gregtech/data/GregTechData.java index 909c1084fe..662c2e4b00 100644 --- a/common/src/main/java/muramasa/gregtech/data/GregTechData.java +++ b/common/src/main/java/muramasa/gregtech/data/GregTechData.java @@ -22,6 +22,7 @@ import muramasa.gregtech.block.*; import muramasa.gregtech.block.BlockCoil.CoilData; import muramasa.gregtech.cover.*; +import muramasa.gregtech.cover.redstone.CoverRedstoneMachineController; import net.minecraft.core.BlockPos; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.LevelAccessor; @@ -62,8 +63,12 @@ public static void init(Side side) { public static final CoverFactory COVER_DRAIN = CoverFactory.builder(CoverDrain::new).item((a, b) -> new ItemCover(GTIRef.ID, "drain").tip("Can be placed on machines as a cover")).addTextures(new Texture(GTIRef.ID, "block/cover/drain")).build(GTIRef.ID, "drain"); + public static final CoverFactory COVER_REDSTONE_MACHINE_CONTROLLER = CoverFactory.builder(CoverRedstoneMachineController::new).gui().item((a, b) -> { + return new ItemCover(GTIRef.ID, "redstone_machine_controller"); + }).addTextures(new Texture(GTIRef.ID, "block/cover/redstone_machine_controller")).build(GTIRef.ID, "redstone_machine_controller"); + public static final CoverFactory COVER_STEAM_VENT = CoverFactory.builder(CoverSteamVent::new) - .addTextures(new Texture(GTIRef.ID, "block/cover/output")).build(Ref.ID, "steam_vent");; + .addTextures(new Texture(GTIRef.ID, "block/cover/output")).build(Ref.ID, "steam_vent"); public static ItemBasic ComputerMonitor = new ItemBasic<>(GTIRef.ID, "computer_monitor").tip("Can be placed on machines as a cover"); public static ItemFluidCell CellTin = new ItemFluidCell(GTIRef.ID, Tin, 1000); diff --git a/common/src/main/resources/assets/gti/textures/block/cover/redstone_machine_controller.png b/common/src/main/resources/assets/gti/textures/block/cover/redstone_machine_controller.png new file mode 100644 index 0000000000000000000000000000000000000000..37c0e34da6d7b839104a5059b84a88efd0b0d92b GIT binary patch literal 288 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkE%y{W;-5;PJdx@v7EBie*E+Izo#&X8RK%upsE{-78H0fQxO5)u2^ zd+tj=-NrM;L6EnzUChOCm(uy^%Y+>SuibiL`aJBfpvu-=8eA!nVh69vJJ#rihPLjy zr=C8aF=_Sl$)U;;$6gB@#T-Gb8ealGq=x!BS)oqJ~HaLWXA1C zy+DS)7taqrUgo+Bml>XjwDB-)R7sv9a}?-+{guCrCIuw`?XocroHCb@tJh}s)~WMB PUS;rf^>bP0l+XkKRk>%! literal 0 HcmV?d00001