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

Commit

Permalink
added shutter cover
Browse files Browse the repository at this point in the history
  • Loading branch information
Trinsdar committed Aug 9, 2023
1 parent 87b6d43 commit d16fbf1
Show file tree
Hide file tree
Showing 12 changed files with 208 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import static muramasa.gregtech.cover.ImportExportMode.EXPORT;
import static muramasa.gregtech.cover.ImportExportMode.IMPORT;

public abstract class CoverBasicTransport extends BaseCover implements ICoverModeHandler {
public abstract class CoverBasicTransport extends CoverRedstoneSensitive implements ICoverModeHandler {

protected ImportExportMode coverMode;
int coverModeInt;
Expand Down
18 changes: 1 addition & 17 deletions common/src/main/java/muramasa/gregtech/cover/CoverConveyor.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,23 +136,7 @@ public void onUpdate() {
protected boolean canMove(Direction side){
String name = getCoverMode().getName();
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 machineController){
list.add(machineController);
}
}
int i = 0;
int j = 0;
for (CoverRedstoneMachineController coverStack : list){
j++;
if (coverStack.isPowered()){
i++;
}
}
return i > 0 && i == j;
}).orElse(false);
boolean powered = isPowered(side);
return name.contains("Invert") != powered;
}
return true;
Expand Down
18 changes: 1 addition & 17 deletions common/src/main/java/muramasa/gregtech/cover/CoverPump.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,23 +92,7 @@ public void onUpdate() {
protected boolean canMove(Direction side){
String name = getCoverMode().getName();
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 machineController){
list.add(machineController);
}
}
int i = 0;
int j = 0;
for (CoverRedstoneMachineController coverStack : list){
j++;
if (coverStack.isPowered()){
i++;
}
}
return i > 0 && i == j;
}).orElse(false);
boolean powered = isPowered(side);
return name.contains("Invert") != powered;
}
return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package muramasa.gregtech.cover;

import muramasa.antimatter.capability.ICoverHandler;
import muramasa.antimatter.cover.BaseCover;
import muramasa.antimatter.cover.CoverFactory;
import muramasa.antimatter.machine.Tier;
import muramasa.antimatter.util.AntimatterCapUtils;
import muramasa.gregtech.cover.redstone.CoverRedstoneMachineController;
import net.minecraft.core.Direction;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.List;

public class CoverRedstoneSensitive extends BaseCover {
public CoverRedstoneSensitive(@NotNull ICoverHandler<?> source, @Nullable Tier tier, Direction side, CoverFactory factory) {
super(source, tier, side, factory);
}

protected boolean isPowered(Direction side){
return AntimatterCapUtils.getCoverHandler(handler.getTile(), side).map(h -> {
List<CoverRedstoneMachineController> list = new ArrayList<>();
for (Direction dir : Direction.values()){
if (h.get(dir) instanceof CoverRedstoneMachineController machineController){
list.add(machineController);
}
}
int i = 0;
int j = 0;
for (CoverRedstoneMachineController coverStack : list){
j++;
if (coverStack.isPowered()){
i++;
}
}
return i > 0 && i == j;
}).orElse(false);
}
}
160 changes: 160 additions & 0 deletions common/src/main/java/muramasa/gregtech/cover/CoverShutter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
package muramasa.gregtech.cover;

import muramasa.antimatter.capability.ICoverHandler;
import muramasa.antimatter.cover.BaseCover;
import muramasa.antimatter.cover.CoverFactory;
import muramasa.antimatter.data.AntimatterDefaultTools;
import muramasa.antimatter.machine.Tier;
import muramasa.antimatter.tile.pipe.TileEntityPipe;
import muramasa.antimatter.tool.AntimatterToolType;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.player.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class CoverShutter extends CoverRedstoneSensitive {
Mode mode = Mode.OPEN_REDSTONE;
boolean isPowered = false;
public CoverShutter(@NotNull ICoverHandler<?> source, @Nullable Tier tier, Direction side, CoverFactory factory) {
super(source, tier, side, factory);
}

@Override
public boolean canPlace() {
return handler.getTile() instanceof TileEntityPipe<?>;
}

@Override
public void onPlace() {
super.onPlace();
checkPipeConnection();
}

@Override
public <T> boolean blocksCapability(Class<T> cap, @Nullable Direction side) {
return (mode == Mode.OPEN_NO_REDSTONE && isPowered) || (mode == Mode.OPEN_REDSTONE && !isPowered);
}

@Override
public <T> boolean blocksInput(Class<T> cap, @Nullable Direction side) {
return mode == Mode.OUTPUT_ONLY;
}

@Override
public <T> boolean blocksOutput(Class<T> cap, @Nullable Direction side) {
return mode == Mode.INPUT_ONLY;
}

@Override
public boolean onInteract(Player player, InteractionHand hand, Direction side, @Nullable AntimatterToolType type) {
if (type != null && type.getTag() == AntimatterDefaultTools.SCREWDRIVER.getTag()){
mode = player.isShiftKeyDown() ? mode.cycleBackward() : mode.cycleForward();
switch (mode){
case OPEN_NO_REDSTONE -> {
if (handler.getTile() instanceof TileEntityPipe<?> pipe){
if (isPowered){
pipe.clearConnection(this.side);
} else {
pipe.setConnection(this.side);
}
}
player.sendMessage(new TextComponent("Open if work disabled"), player.getUUID());
}
case OUTPUT_ONLY -> {
if (handler.getTile() instanceof TileEntityPipe<?> pipe){
pipe.setConnection(this.side);
}
player.sendMessage(new TextComponent("Output only"), player.getUUID());
}
case INPUT_ONLY -> {
if (handler.getTile() instanceof TileEntityPipe<?> pipe){
pipe.setConnection(this.side);
}
player.sendMessage(new TextComponent("Input only"), player.getUUID());
}
case OPEN_REDSTONE -> {
if (handler.getTile() instanceof TileEntityPipe<?> pipe){
if (isPowered){
pipe.setConnection(this.side);
} else {
pipe.clearConnection(this.side);

}
}
player.sendMessage(new TextComponent("Open if work enabled"), player.getUUID());
}
}
}
return super.onInteract(player, hand, side, type);
}

@Override
public void onBlockUpdate() {
checkPipeConnection();
}

private void checkPipeConnection(){
TileEntityPipe<?> pipe = (TileEntityPipe<?>) handler.getTile();
isPowered = isPowered(this.side);
if (mode == Mode.OPEN_NO_REDSTONE || mode == Mode.OPEN_REDSTONE){
boolean remove = (mode == Mode.OPEN_NO_REDSTONE && isPowered) || (mode == Mode.OPEN_REDSTONE && !isPowered);
if (remove) pipe.clearConnection(this.side);
else pipe.setConnection(this.side);
}
}

@Override
protected String getRenderId() {
return "shutter";
}

@Override
public String getId() {
return "shutter";
}

@Override
public ResourceLocation getModel(String type, Direction dir) {
if (type.equals("pipe")) return PIPE_COVER_MODEL;
return getBasicModel();
}

enum Mode {
INPUT_ONLY, OUTPUT_ONLY, OPEN_REDSTONE, OPEN_NO_REDSTONE;

Mode cycleForward(){
return switch (this){
case OPEN_REDSTONE -> Mode.OPEN_NO_REDSTONE;
case OPEN_NO_REDSTONE -> Mode.OUTPUT_ONLY;
case OUTPUT_ONLY -> Mode.INPUT_ONLY;
case INPUT_ONLY -> Mode.OPEN_REDSTONE;
};
}

Mode cycleBackward(){
return switch (this){
case OPEN_REDSTONE -> Mode.INPUT_ONLY;
case OPEN_NO_REDSTONE -> Mode.OPEN_REDSTONE;
case OUTPUT_ONLY -> Mode.OPEN_NO_REDSTONE;
case INPUT_ONLY -> Mode.OUTPUT_ONLY;
};
}
}

@Override
public CompoundTag serialize() {
CompoundTag nbt = super.serialize();
nbt.putInt("mode", mode.ordinal());
return nbt;
}

@Override
public void deserialize(CompoundTag nbt) {
super.deserialize(nbt);
mode = Mode.values()[nbt.getInt("mode")];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import muramasa.antimatter.machine.MachineState;
import muramasa.antimatter.machine.Tier;
import muramasa.antimatter.tile.TileEntityMachine;
import muramasa.antimatter.tile.pipe.TileEntityPipe;
import muramasa.gregtech.cover.RedstoneMode;
import net.minecraft.core.Direction;
import net.minecraft.resources.ResourceLocation;
Expand Down Expand Up @@ -104,6 +105,8 @@ 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)];
if (handler.getTile() instanceof TileEntityPipe<?> pipe) pipe.onBlockUpdate(pipe.getBlockPos());
if (handler.getTile() instanceof TileEntityMachine<?> machine) machine.onBlockUpdate(machine.getBlockPos());
}
}

Expand Down
2 changes: 2 additions & 0 deletions common/src/main/java/muramasa/gregtech/data/GregTechData.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ public static void init(Side side) {
public static final CoverFactory COVER_FLUID_FILTER = CoverFactory.builder(CoverFluidFilter::new).item((a, b) ->
new ItemCover(GTIRef.ID, "fluid_filter").tip("Can be placed as cover")).addTextures(new Texture(GTIRef.ID, "block/cover/item_filter")).gui().build(GTIRef.ID, "fluid_filter");

public static CoverFactory COVER_SHUTTER = CoverFactory.builder(CoverShutter::new).item((a, b) ->
new ItemCover(GTIRef.ID, "shutter").tip("can be placed as a pipe cover")).addTextures(new Texture(GTIRef.ID, "block/cover/shutter")).build(GTIRef.ID, "shutter");
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");
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.
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.
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 d16fbf1

Please sign in to comment.