Search in sources :

Example 1 with IChargeBlock

use of mods.railcraft.api.charge.IChargeBlock in project Railcraft by Railcraft.

the class BlockWire method getActualState.

@SuppressWarnings("deprecation")
@Override
public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) {
    state = super.getActualState(state, worldIn, pos);
    Connection[] connections = new Connection[6];
    Arrays.fill(connections, Connection.NONE);
    for (EnumFacing side : EnumFacing.VALUES) {
        BlockPos neighborPos = pos.offset(side);
        IBlockState neighborState = WorldPlugin.getBlockState(worldIn, pos.offset(side));
        Block neighborBlock = neighborState.getBlock();
        if (neighborBlock instanceof IChargeBlock) {
            ChargeSpec chargeSpec = ((IChargeBlock) neighborBlock).getChargeSpecs(neighborState, worldIn, neighborPos).get(Charge.distribution);
            if (chargeSpec != null) {
                IChargeBlock.ConnectType connectType = chargeSpec.getConnectType();
                if (connectionMatcher.get(side).contains(connectType)) {
                    connections[side.ordinal()] = connectType == IChargeBlock.ConnectType.WIRE ? Connection.WIRE : Connection.PLUG;
                }
            }
        } else if (side.getAxis() == EnumFacing.Axis.Y && neighborBlock instanceof BlockPostBase) {
            connections[side.ordinal()] = Connection.PLUG;
        }
    }
    for (EnumFacing side : EnumFacing.VALUES) {
        state = state.withProperty(connectionProperties[side.ordinal()], connections[side.ordinal()]);
    }
    return state;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing) IPostConnection(mods.railcraft.api.core.IPostConnection) Block(net.minecraft.block.Block) IChargeBlock(mods.railcraft.api.charge.IChargeBlock) BlockPos(net.minecraft.util.math.BlockPos) BlockPostBase(mods.railcraft.common.blocks.aesthetics.post.BlockPostBase) IChargeBlock(mods.railcraft.api.charge.IChargeBlock)

Aggregations

IChargeBlock (mods.railcraft.api.charge.IChargeBlock)1 IPostConnection (mods.railcraft.api.core.IPostConnection)1 BlockPostBase (mods.railcraft.common.blocks.aesthetics.post.BlockPostBase)1 Block (net.minecraft.block.Block)1 IBlockState (net.minecraft.block.state.IBlockState)1 EnumFacing (net.minecraft.util.EnumFacing)1 BlockPos (net.minecraft.util.math.BlockPos)1