TheBrokenRail
9e0edf763a
All checks were successful
EnergonRelics/pipeline/head This commit looks good
45 lines
1.5 KiB
Java
45 lines
1.5 KiB
Java
package com.thebrokenrail.energonrelics.block.entity;
|
|
|
|
import com.thebrokenrail.energonrelics.api.block.entity.core.EnergyReceiverBlockEntity;
|
|
import com.thebrokenrail.energonrelics.api.energy.Action;
|
|
import com.thebrokenrail.energonrelics.block.SwitchBlock;
|
|
import com.thebrokenrail.energonrelics.config.HardcodedConfig;
|
|
import net.minecraft.block.entity.BlockEntityType;
|
|
|
|
import java.util.Objects;
|
|
|
|
public class SwitchBlockEntity extends EnergyReceiverBlockEntity {
|
|
public SwitchBlockEntity(BlockEntityType<?> type) {
|
|
super(type);
|
|
}
|
|
|
|
@Override
|
|
protected void energyTick() {
|
|
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));
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public boolean isEnergyProvider() {
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
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() {
|
|
return getCachedState().get(SwitchBlock.ACTIVE) && getCachedState().get(SwitchBlock.POWERED);
|
|
}
|
|
}
|