Search in sources :

Example 1 with BlockLantern

use of mods.railcraft.common.blocks.aesthetics.materials.BlockLantern in project Railcraft by Railcraft.

the class PostConnectionHelper method connect.

public static ConnectStyle connect(IBlockAccess world, BlockPos pos, IBlockState state, EnumFacing side) {
    try {
        Block block = state.getBlock();
        if (block instanceof IPostConnection && ((IPostConnection) block).connectsToPost(world, pos, state, side) == ConnectStyle.NONE)
            return ConnectStyle.NONE;
    } catch (Error error) {
        Game.log().api(Railcraft.NAME, error, IPostConnection.class);
        return ConnectStyle.NONE;
    }
    BlockPos otherPos = pos.offset(side);
    if (world.isAirBlock(otherPos))
        return ConnectStyle.NONE;
    IBlockState otherState = WorldPlugin.getBlockState(world, otherPos);
    Block otherBlock = otherState.getBlock();
    EnumFacing oppositeSide = side.getOpposite();
    try {
        if (otherBlock instanceof IPostConnection)
            return ((IPostConnection) otherBlock).connectsToPost(world, otherPos, otherState, oppositeSide);
    } catch (Error error) {
        Game.log().api(Railcraft.NAME, error, IPostConnection.class);
    }
    if (otherBlock instanceof BlockPostBase)
        return ConnectStyle.TWO_THIN;
    if (noConnect.contains(otherBlock))
        return ConnectStyle.NONE;
    if (canConnect.contains(otherBlock))
        return ConnectStyle.TWO_THIN;
    if (otherBlock instanceof BlockFenceGate) {
        return otherState.getValue(BlockFenceGate.FACING).getAxis() != side.getAxis() ? ConnectStyle.TWO_THIN : ConnectStyle.NONE;
    }
    if (otherBlock instanceof BlockWallSign) {
        return otherState.getValue(BlockWallSign.FACING) == side ? ConnectStyle.SINGLE_THICK : ConnectStyle.NONE;
    }
    if (otherBlock instanceof BlockLantern)
        return ConnectStyle.SINGLE_THICK;
    if (world.isSideSolid(pos, oppositeSide, false))
        return ConnectStyle.TWO_THIN;
    return ConnectStyle.NONE;
}
Also used : BlockLantern(mods.railcraft.common.blocks.aesthetics.materials.BlockLantern) IPostConnection(mods.railcraft.api.core.IPostConnection) IBlockState(net.minecraft.block.state.IBlockState) BlockFenceGate(net.minecraft.block.BlockFenceGate) EnumFacing(net.minecraft.util.EnumFacing) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) BlockWallSign(net.minecraft.block.BlockWallSign)

Aggregations

IPostConnection (mods.railcraft.api.core.IPostConnection)1 BlockLantern (mods.railcraft.common.blocks.aesthetics.materials.BlockLantern)1 Block (net.minecraft.block.Block)1 BlockFenceGate (net.minecraft.block.BlockFenceGate)1 BlockWallSign (net.minecraft.block.BlockWallSign)1 IBlockState (net.minecraft.block.state.IBlockState)1 EnumFacing (net.minecraft.util.EnumFacing)1 BlockPos (net.minecraft.util.math.BlockPos)1