This commit is contained in:
parent
94a4364826
commit
ae32d77f23
@ -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,29 +63,37 @@ public class ForcefieldBlock extends SimpleBlock {
|
||||
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
|
||||
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)) {
|
||||
boolean found = false;
|
||||
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();
|
||||
return findProjector(world, pos, state) != null ? defaultState : Blocks.AIR.getDefaultState();
|
||||
} else {
|
||||
return defaultState;
|
||||
}
|
||||
|
Reference in New Issue
Block a user