Clean Up
EnergonRelics/pipeline/head This commit looks good Details

This commit is contained in:
TheBrokenRail 2020-07-24 17:32:45 -04:00
parent 94a4364826
commit ae32d77f23
1 changed files with 28 additions and 18 deletions

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,12 +63,9 @@ public class ForcefieldBlock extends SimpleBlock {
return false; return false;
} }
@Override public ForcefieldProjectorBlockEntity findProjector(BlockView world, BlockPos pos, BlockState state) {
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(); Direction facing = state.get(FACING).getOpposite();
if (direction.equals(facing)) { ForcefieldProjectorBlockEntity found = null;
boolean found = false;
for (int i = 0; i < HardcodedConfig.FORCEFIELD_MAX_SIZE + 1; i++) { for (int i = 0; i < HardcodedConfig.FORCEFIELD_MAX_SIZE + 1; i++) {
BlockPos targetPos = pos.offset(facing, i); BlockPos targetPos = pos.offset(facing, i);
BlockState targetState = world.getBlockState(targetPos); BlockState targetState = world.getBlockState(targetPos);
@ -76,14 +75,25 @@ public class ForcefieldBlock extends SimpleBlock {
} }
} else if (targetState.getBlock() == EnergonRelics.FORCEFIELD_PROJECTOR_BLOCK) { } else if (targetState.getBlock() == EnergonRelics.FORCEFIELD_PROJECTOR_BLOCK) {
if (facing.equals(targetState.get(FACING).getOpposite()) && targetState.get(ForcefieldProjectorBlock.POWERED)) { 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; break;
} else { } else {
break; 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 { } else {
return defaultState; return defaultState;
} }