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.
added redstone machine controller cover
- Loading branch information
Showing
7 changed files
with
186 additions
and
13 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
32 changes: 32 additions & 0 deletions
32
common/src/main/java/muramasa/gregtech/cover/RedstoneMode.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,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; | ||
} | ||
} |
135 changes: 135 additions & 0 deletions
135
common/src/main/java/muramasa/gregtech/cover/redstone/CoverRedstoneMachineController.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,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; | ||
} | ||
} |
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
+288 Bytes
.../main/resources/assets/gti/textures/block/cover/redstone_machine_controller.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
+280 Bytes
...c/main/resources/assets/gti/textures/item/basic/redstone_machine_controller.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.