Clean Up
All checks were successful
EnergonRelics/pipeline/head This commit looks good

This commit is contained in:
TheBrokenRail 2020-07-24 17:32:45 -04:00
parent 94a4364826
commit ae32d77f23

View File

@ -1,6 +1,7 @@
package com.thebrokenrail.energonrelics.block.forcefield;
import com.thebrokenrail.energonrelics.EnergonRelics;
import com.thebrokenrail.energonrelics.block.entity.forcefield.ForcefieldProjectorBlockEntity;
import com.thebrokenrail.energonrelics.block.util.SimpleBlock;
import com.thebrokenrail.energonrelics.config.HardcodedConfig;
import net.fabricmc.api.EnvType;
@ -9,6 +10,7 @@ import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.piston.PistonBehavior;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.state.StateManager;
@ -61,12 +63,9 @@ public class ForcefieldBlock extends SimpleBlock {
return false;
}
@Override
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState newState, WorldAccess world, BlockPos pos, BlockPos posFrom) {
BlockState defaultState = super.getStateForNeighborUpdate(state, direction, newState, world, pos, posFrom);
public ForcefieldProjectorBlockEntity findProjector(BlockView world, BlockPos pos, BlockState state) {
Direction facing = state.get(FACING).getOpposite();
if (direction.equals(facing)) {
boolean found = false;
ForcefieldProjectorBlockEntity found = null;
for (int i = 0; i < HardcodedConfig.FORCEFIELD_MAX_SIZE + 1; i++) {
BlockPos targetPos = pos.offset(facing, i);
BlockState targetState = world.getBlockState(targetPos);
@ -76,14 +75,25 @@ public class ForcefieldBlock extends SimpleBlock {
}
} else if (targetState.getBlock() == EnergonRelics.FORCEFIELD_PROJECTOR_BLOCK) {
if (facing.equals(targetState.get(FACING).getOpposite()) && targetState.get(ForcefieldProjectorBlock.POWERED)) {
found = true;
BlockEntity entity = world.getBlockEntity(targetPos);
if (entity instanceof ForcefieldProjectorBlockEntity) {
found = (ForcefieldProjectorBlockEntity) entity;
}
}
break;
} else {
break;
}
}
return found ? defaultState : Blocks.AIR.getDefaultState();
return found;
}
@Override
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState newState, WorldAccess world, BlockPos pos, BlockPos posFrom) {
BlockState defaultState = super.getStateForNeighborUpdate(state, direction, newState, world, pos, posFrom);
Direction facing = state.get(FACING).getOpposite();
if (direction.equals(facing)) {
return findProjector(world, pos, state) != null ? defaultState : Blocks.AIR.getDefaultState();
} else {
return defaultState;
}