local args = { ... }
 
tx.state.x = 22
tx.state.z = -508
tx.state.y = 65
tx.state.o = tx.norm_direction('east')
tx.state.move_mode = 'stop'
crop_slot = nil

function plant()
    tx.select(1)
    tx.digDown()
    tx.select(crop_slot)
    tx.placeDown()
end

if args[1] == 'wheat' then
    tx.goto_placemark('farming_row')
    tx.goto_placemark('wheat_farm')
    crop_slot = 16
    tx.grid_move{gx=5,gy=5,hook=plant}
    tx.goto_placemark('farming_row')
    tx.goto_placemark('farming_station')
elseif args[1] == 'carrot' then
    tx.goto_placemark('farming_row')
    tx.goto_placemark('carrot_farm')
    crop_slot = 15
    tx.grid_move{gx=5,gy=5,hook=plant}
    tx.goto_placemark('farming_row')
    tx.goto_placemark('farming_station')
elseif args[1] == 'cane' then
    tx.goto_placemark('farming_row')
    tx.state.move_mode = 'dig'
    tx.goto_placemark('cane_farm')
    crop_slot = 14
    tx.grid_move{gx=5,gy=5,hook=tx.digDown}
    tx.goto_placemark('farming_row')
    tx.state.move_mode = 'stop'
    tx.goto_placemark('farming_station')
else
	print( "Usage: farm <wheat|carrot|cane>" )
	return
end
