This repository has been archived by the owner on Nov 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
208 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
common/src/main/java/muramasa/gregtech/cover/CoverRedstoneSensitive.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
160
common/src/main/java/muramasa/gregtech/cover/CoverShutter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+329 Bytes
common/src/main/resources/assets/gti/textures/block/cover/crafting_module.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+291 Bytes
common/src/main/resources/assets/gti/textures/block/cover/energy_detector.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+294 Bytes
common/src/main/resources/assets/gti/textures/block/cover/fluid_detector.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+272 Bytes
common/src/main/resources/assets/gti/textures/block/cover/fluid_filter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+272 Bytes
common/src/main/resources/assets/gti/textures/block/cover/shutter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.