This repository has been archived on 2023-11-26. You can view files and clone it, but cannot push or open issues or pull requests.
EnergonRelics/src/main/java/com/thebrokenrail/energonrelics/block/entity/SwitchBlockEntity.java

45 lines
1.5 KiB
Java
Raw Normal View History

2020-07-13 20:37:21 +00:00
package com.thebrokenrail.energonrelics.block.entity;
2020-08-04 17:06:11 +00:00
import com.thebrokenrail.energonrelics.api.block.entity.core.EnergyReceiverBlockEntity;
import com.thebrokenrail.energonrelics.api.energy.Action;
2020-07-13 20:37:21 +00:00
import com.thebrokenrail.energonrelics.block.SwitchBlock;
2020-08-16 03:01:24 +00:00
import com.thebrokenrail.energonrelics.config.HardcodedConfig;
2020-07-13 20:37:21 +00:00
import net.minecraft.block.entity.BlockEntityType;
2020-08-20 00:48:29 +00:00
import java.util.Objects;
2020-07-13 20:37:21 +00:00
public class SwitchBlockEntity extends EnergyReceiverBlockEntity {
public SwitchBlockEntity(BlockEntityType<?> type) {
super(type);
}
@Override
2020-07-27 18:06:46 +00:00
protected void energyTick() {
2020-08-20 00:48:29 +00:00
if (getCachedState().get(SwitchBlock.ACTIVE)) {
addAction(Action.createBlockStatePropertyAction(HardcodedConfig.SWITCH_ENERGY_REQUIRED, SwitchBlock.POWERED, true, false));
} else if (getCachedState().get(SwitchBlock.POWERED)) {
Objects.requireNonNull(getWorld()).setBlockState(getPos(), getCachedState().with(SwitchBlock.POWERED, false));
}
2020-07-13 20:37:21 +00:00
}
@Override
public boolean isEnergyProvider() {
return true;
}
@Override
2020-08-03 20:36:20 +00:00
protected void handlePropagatedAction(Action.PropagatedAction action) {
super.handlePropagatedAction(action);
// Propagate Action To Energy Providers
if (isActive() && !hasSent(action)) {
propagateAction(action);
} else {
action.pay(0);
}
}
private boolean isActive() {
2020-08-16 03:01:24 +00:00
return getCachedState().get(SwitchBlock.ACTIVE) && getCachedState().get(SwitchBlock.POWERED);
2020-07-13 20:37:21 +00:00
}
}