TheBrokenRail
87d9e17919
All checks were successful
EnergonRelics/pipeline/head This commit looks good
74 lines
2.7 KiB
Java
74 lines
2.7 KiB
Java
package com.thebrokenrail.energonrelics.block.entity.portal;
|
|
|
|
import com.thebrokenrail.energonrelics.EnergonRelics;
|
|
import com.thebrokenrail.energonrelics.block.entity.forcefield.FieldProjectorBlockEntity;
|
|
import com.thebrokenrail.energonrelics.block.portal.EnergyPortalBlock;
|
|
import com.thebrokenrail.energonrelics.block.portal.EnergyProjectorBlock;
|
|
import com.thebrokenrail.energonrelics.config.HardcodedConfig;
|
|
import net.minecraft.block.BlockState;
|
|
import net.minecraft.block.Blocks;
|
|
import net.minecraft.block.entity.BlockEntityType;
|
|
import net.minecraft.util.math.BlockPos;
|
|
import net.minecraft.util.math.Direction;
|
|
|
|
import java.util.Objects;
|
|
|
|
public class EnergyProjectorBlockEntity extends FieldProjectorBlockEntity {
|
|
private BlockPos targetPos;
|
|
private BlockState targetState;
|
|
|
|
public EnergyProjectorBlockEntity(BlockEntityType<?> type) {
|
|
super(type, state -> EnergonRelics.ENERGY_BEAM_BLOCK);
|
|
}
|
|
|
|
@Override
|
|
protected long getCost() {
|
|
return HardcodedConfig.ENERGY_PROJECTOR_ENERGY_REQUIRED;
|
|
}
|
|
|
|
@Override
|
|
protected void setLastBlock(BlockPos newPos, BlockState newState) {
|
|
if (!Objects.equals(newPos, targetPos) || targetState != newState) {
|
|
targetPos = newPos;
|
|
targetState = newState;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
protected void energyTick() {
|
|
super.energyTick();
|
|
|
|
assert getWorld() != null;
|
|
|
|
if (getCachedState().get(EnergyProjectorBlock.POWERED) && targetState != null && targetPos != null) {
|
|
boolean isObsidian;
|
|
if (targetState.getBlock() == Blocks.OBSIDIAN) {
|
|
isObsidian = true;
|
|
targetState = EnergonRelics.ENERGIZED_OBSIDIAN_BLOCK.getDefaultState();
|
|
getWorld().setBlockState(targetPos, targetState);
|
|
} else {
|
|
isObsidian = targetState.getBlock() == EnergonRelics.ENERGIZED_OBSIDIAN_BLOCK;
|
|
}
|
|
|
|
if (isObsidian) {
|
|
Direction facing = getCachedState().get(EnergyProjectorBlock.FACING);
|
|
|
|
BlockPos centerPos = null;
|
|
for (Direction side : Direction.values()) {
|
|
if (EnergyPortalBlock.isValidDirection(side) && side != facing.getOpposite()) {
|
|
BlockPos newCenterPos = targetPos.offset(side, 2);
|
|
if (EnergyPortalBlock.isValidFrame(getWorld(), newCenterPos)) {
|
|
centerPos = newCenterPos;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (centerPos != null) {
|
|
EnergyPortalBlock.fillFrame(getWorld(), centerPos);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|