2020-07-23 23:31:02 +00:00
|
|
|
package com.thebrokenrail.energonrelics.block.entity.forcefield;
|
|
|
|
|
2020-07-28 03:10:16 +00:00
|
|
|
import com.thebrokenrail.energonrelics.block.forcefield.util.AbstractFieldBlock;
|
|
|
|
import com.thebrokenrail.energonrelics.block.forcefield.util.FieldProjectorBlock;
|
2020-07-23 23:31:02 +00:00
|
|
|
import com.thebrokenrail.energonrelics.config.HardcodedConfig;
|
|
|
|
import com.thebrokenrail.energonrelics.energy.core.EnergyReceiverBlockEntity;
|
|
|
|
import com.thebrokenrail.energonrelics.energy.core.util.Action;
|
|
|
|
import net.minecraft.block.BlockState;
|
|
|
|
import net.minecraft.block.entity.BlockEntityType;
|
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraft.util.math.Direction;
|
|
|
|
|
2020-07-28 03:10:16 +00:00
|
|
|
import java.util.function.Function;
|
|
|
|
|
|
|
|
public class FieldProjectorBlockEntity extends EnergyReceiverBlockEntity {
|
|
|
|
private final Function<BlockState, AbstractFieldBlock> block;
|
|
|
|
|
|
|
|
public FieldProjectorBlockEntity(BlockEntityType<?> type, Function<BlockState, AbstractFieldBlock> block) {
|
2020-07-23 23:31:02 +00:00
|
|
|
super(type);
|
2020-07-28 03:10:16 +00:00
|
|
|
this.block = block;
|
2020-07-23 23:31:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-07-27 18:06:46 +00:00
|
|
|
protected void energyTick() {
|
2020-07-23 23:31:02 +00:00
|
|
|
assert getWorld() != null;
|
|
|
|
|
2020-07-28 15:53:33 +00:00
|
|
|
addAction(Action.createBlockStatePropertyAction(HardcodedConfig.FIELD_PROJECTOR_ENERGY_REQUIRED, FieldProjectorBlock.POWERED, true, false));
|
2020-07-28 03:10:16 +00:00
|
|
|
if (getCachedState().get(FieldProjectorBlock.POWERED)) {
|
|
|
|
Direction facing = getCachedState().get(FieldProjectorBlock.FACING);
|
|
|
|
BlockState state = block.apply(getCachedState()).getDefaultState().with(AbstractFieldBlock.FACING, facing);
|
2020-07-28 15:53:33 +00:00
|
|
|
for (int i = 1; i < HardcodedConfig.FIELD_MAX_SIZE + 1; i++) {
|
2020-07-23 23:31:02 +00:00
|
|
|
BlockPos targetPos = getPos().offset(facing, i);
|
|
|
|
BlockState targetState = getWorld().getBlockState(targetPos);
|
2020-07-28 03:10:16 +00:00
|
|
|
if (targetState.isAir() || (targetState != state && targetState.getBlock() instanceof AbstractFieldBlock && targetState.get(AbstractFieldBlock.FACING) == facing)) {
|
2020-07-23 23:31:02 +00:00
|
|
|
getWorld().setBlockState(targetPos, state);
|
2020-07-24 22:23:09 +00:00
|
|
|
} else if (targetState != state) {
|
2020-07-23 23:31:02 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|