Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

Commit

Permalink
added redstone machine controller cover
Browse files Browse the repository at this point in the history
  • Loading branch information
Trinsdar committed Jul 31, 2023
1 parent 27b30ef commit e063328
Show file tree
Hide file tree
Showing 7 changed files with 186 additions and 13 deletions.
15 changes: 7 additions & 8 deletions common/src/main/java/muramasa/gregtech/cover/CoverConveyor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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<CoverRedstoneMachineController> 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;
Expand All @@ -155,7 +154,7 @@ protected boolean canMove(Direction side){
return i > 0 && i == j;
}).orElse(false);
return name.contains("Invert") != powered;
}*/
}
return true;
}

Expand Down
10 changes: 6 additions & 4 deletions common/src/main/java/muramasa/gregtech/cover/CoverPump.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<CoverRedstoneMachineController> 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;
Expand All @@ -108,7 +110,7 @@ protected boolean canMove(Direction side){
return i > 0 && i == j;
}).orElse(false);
return name.contains("Invert") != powered;
}*/
}
return true;
}
}
32 changes: 32 additions & 0 deletions common/src/main/java/muramasa/gregtech/cover/RedstoneMode.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e063328

Please sign in to comment.