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

Commit

Permalink
added redstone conductor covers
Browse files Browse the repository at this point in the history
  • Loading branch information
Trinsdar committed Aug 3, 2024
1 parent 250a74a commit e665eee
Show file tree
Hide file tree
Showing 10 changed files with 160 additions and 58 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package muramasa.gregtech.cover.base;

import muramasa.antimatter.blockentity.BlockEntityMachine;
import muramasa.antimatter.capability.ICoverHandler;
import muramasa.antimatter.cover.BaseCover;
import muramasa.antimatter.cover.CoverFactory;
import muramasa.antimatter.data.AntimatterDefaultTools;
import muramasa.antimatter.machine.MachineState;
import muramasa.antimatter.machine.Tier;
import muramasa.antimatter.tool.AntimatterToolType;
import muramasa.antimatter.util.Utils;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import org.jetbrains.annotations.Nullable;


public class CoverBasicRedstoneInput extends BaseCover {
protected int redstonePower;
boolean inverted = false;

public CoverBasicRedstoneInput(ICoverHandler<?> source, @Nullable Tier tier, Direction side, CoverFactory factory) {
super(source, tier, side, factory);
}

public boolean isPowered(){
return inverted ? redstonePower == 0 : redstonePower > 0;
}

public int getRedstonePower() {
return redstonePower;
}

@Override
public void onBlockUpdate() {
redstonePower = handler.getTile().getLevel().getSignal(handler.getTile().getBlockPos().relative(side), side);
}

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

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

@Override
public InteractionResult onInteract(Player player, InteractionHand hand, Direction side, @Nullable AntimatterToolType type) {
if (type != null && type.getTag() == AntimatterDefaultTools.SCREWDRIVER.getTag()){
inverted = !inverted;
player.sendMessage(Utils.translatable("message.gti.redstone_mode." + (inverted ? "inverted" : "normal")), player.getUUID());
for (Direction dir : Direction.values()) {
if (dir == this.side) continue;
source().get(dir).onBlockUpdate();
}
return InteractionResult.SUCCESS;
}
return super.onInteract(player, hand, side, type);
}

@Override
public CompoundTag serialize() {
CompoundTag nbt = super.serialize();
nbt.putBoolean("inverted", inverted);
return nbt;
}

@Override
public void deserialize(CompoundTag nbt) {
super.deserialize(nbt);
inverted = nbt.getBoolean("inverted");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package muramasa.gregtech.cover.redstone;

import muramasa.antimatter.capability.ICoverHandler;
import muramasa.antimatter.cover.BaseCover;
import muramasa.antimatter.cover.CoverFactory;
import muramasa.antimatter.machine.Tier;
import muramasa.antimatter.tool.AntimatterToolType;
import muramasa.gregtech.cover.base.CoverBasicRedstoneInput;
import net.minecraft.core.Direction;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

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

@Override
public boolean isPowered() {
return redstonePower > 0;
}

@Override
public InteractionResult onInteract(Player player, InteractionHand hand, Direction side, @Nullable AntimatterToolType type) {
return InteractionResult.PASS;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package muramasa.gregtech.cover.redstone;

import muramasa.antimatter.capability.ICoverHandler;
import muramasa.antimatter.cover.CoverFactory;
import muramasa.antimatter.cover.ICover;
import muramasa.antimatter.machine.Tier;
import muramasa.antimatter.tool.AntimatterToolType;
import muramasa.gregtech.cover.base.CoverBasicRedstoneOutput;
import net.minecraft.core.Direction;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

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

@Override
public void onUpdate() {
int newPower = 0;
for (Direction direction : Direction.values()) {
if (direction == this.side) continue;
ICover cover = source().get(direction);
if (!(cover instanceof CoverRedstoneConductorAccept accept)) continue;
if (newPower < accept.getRedstonePower()){
newPower = accept.getRedstonePower();
}
}
setOutputRedstone(newPower);
}

@Override
public InteractionResult onInteract(Player player, InteractionHand hand, Direction side, @Nullable AntimatterToolType type) {
return InteractionResult.PASS;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import muramasa.antimatter.machine.Tier;
import muramasa.antimatter.tool.AntimatterToolType;
import muramasa.antimatter.util.Utils;
import muramasa.gregtech.cover.base.CoverBasicRedstoneInput;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation;
Expand All @@ -22,19 +23,12 @@
import org.jetbrains.annotations.Nullable;


public class CoverRedstoneMachineController extends BaseCover {
protected int redstonePower;
boolean inverted = false;
public class CoverRedstoneMachineController extends CoverBasicRedstoneInput {

public CoverRedstoneMachineController(ICoverHandler<?> source, @Nullable Tier tier, Direction side, CoverFactory factory) {
super(source, tier, side, factory);
}

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

@Override
public void onRemove() {
if (handler.getTile() instanceof BlockEntityMachine<?> machine){
Expand All @@ -46,10 +40,6 @@ public void onRemove() {
}
}

public boolean isPowered(){
return inverted ? redstonePower == 0 : redstonePower > 0;
}

@Override
public void onUpdate() {
if (handler.getTile() instanceof BlockEntityMachine<?> machine && machine.isServerSide()){
Expand All @@ -65,47 +55,4 @@ public void onUpdate() {

}
}

@Override
public void onBlockUpdate() {
redstonePower = handler.getTile().getLevel().getSignal(handler.getTile().getBlockPos().relative(side), side);
}

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

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

@Override
public InteractionResult onInteract(Player player, InteractionHand hand, Direction side, @Nullable AntimatterToolType type) {
if (type != null && type.getTag() == AntimatterDefaultTools.SCREWDRIVER.getTag()){
inverted = !inverted;
player.sendMessage(Utils.translatable("message.gti.redstone_mode." + (inverted ? "inverted" : "normal")), player.getUUID());
for (Direction dir : Direction.values()) {
if (dir == this.side) continue;
source().get(dir).onBlockUpdate();
}
return InteractionResult.SUCCESS;
}
return super.onInteract(player, hand, side, type);
}

@Override
public CompoundTag serialize() {
CompoundTag nbt = super.serialize();
nbt.putBoolean("inverted", inverted);
return nbt;
}

@Override
public void deserialize(CompoundTag nbt) {
super.deserialize(nbt);
inverted = nbt.getBoolean("inverted");
}
}
10 changes: 7 additions & 3 deletions common/src/main/java/muramasa/gregtech/data/GregTechCovers.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
import muramasa.antimatter.texture.Texture;
import muramasa.gregtech.GTIRef;
import muramasa.gregtech.cover.*;
import muramasa.gregtech.cover.redstone.CoverNeedsMaintenance;
import muramasa.gregtech.cover.redstone.CoverProgressSensor;
import muramasa.gregtech.cover.redstone.CoverRedstoneMachineController;
import muramasa.gregtech.cover.redstone.*;
import muramasa.gregtech.items.ItemCoverCustomTooltip;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
Expand Down Expand Up @@ -81,6 +79,12 @@ public class GregTechCovers {
public static final CoverFactory COVER_REDSTONE_MACHINE_CONTROLLER = CoverFactory.builder(CoverRedstoneMachineController::new).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_REDSTONE_CONDUCTOR_ACCEPT = CoverFactory.builder(CoverRedstoneConductorAccept::new).item((a, b) -> {
return new ItemCover(GTIRef.ID, "redstone_conductor_accept");
}).addTextures(new Texture(GTIRef.ID, "block/cover/redstone_conductor_accept")).build(GTIRef.ID, "redstone_conductor_accept");
public static final CoverFactory COVER_REDSTONE_CONDUCTOR_EMIT = CoverFactory.builder(CoverRedstoneConductorEmit::new).item((a, b) -> {
return new ItemCover(GTIRef.ID, "redstone_conductor_emit");
}).addTextures(new Texture(GTIRef.ID, "block/cover/redstone_conductor_emit")).build(GTIRef.ID, "redstone_conductor_emit");
public static final CoverFactory COVER_NEEDS_MAINTENANCE_COVER = CoverFactory.builder(CoverNeedsMaintenance::new).item((a, b) -> {
return new ItemCover(GTIRef.ID, "needs_maintenance_cover");
}).addTextures(new Texture(GTIRef.ID, "block/cover/needs_maintenance_cover")).build(GTIRef.ID, "needs_maintenance_cover");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import muramasa.gregtech.GTIRef;
import muramasa.gregtech.block.*;
import muramasa.gregtech.data.GregTechBlocks;
import muramasa.gregtech.data.GregTechCovers;
import muramasa.gregtech.data.GregTechItems;
import muramasa.gregtech.items.ItemDepletedRod;
import muramasa.gregtech.items.ItemNuclearFuelRod;
Expand Down Expand Up @@ -368,6 +369,8 @@ protected void english(String domain, String locale) {
add(GregTechBlocks.POWDER_BARREL, "Powder Barrel");
override(GregTechBlocks.CASING_BRONZE_PLATED_BRICK.getDescriptionId(), "Bronze Plated Bricks");
override("machine.hull", "%s " + HULL.getLang(locale));
override(GregTechCovers.COVER_REDSTONE_CONDUCTOR_ACCEPT.getItem().getDescriptionId(), "Redstone Conductor (Accept)");
override(GregTechCovers.COVER_REDSTONE_CONDUCTOR_EMIT.getItem().getDescriptionId(), "Redstone Conductor (Emit)");
HULL.getTiers().forEach(tier -> {
override(HULL, tier, tier.getId().toUpperCase() + " " + HULL.getLang(locale));
});
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.

0 comments on commit e665eee

Please sign in to comment.