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