added farming builds
This commit is contained in:
		@@ -129,3 +129,68 @@ function build_room(length, width, height)
 | 
			
		||||
 | 
			
		||||
  return true
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
-- sweepField() moves acress the rows
 | 
			
		||||
-- and columns of an area in front and
 | 
			
		||||
-- to the right of the turtle, calling
 | 
			
		||||
-- the provided sweepFunc at each space
 | 
			
		||||
function sweepField(length, width, sweepFunc)
 | 
			
		||||
  local turnRightNext = true
 | 
			
		||||
 | 
			
		||||
  for x = 1, width do
 | 
			
		||||
    for y = 1, length do
 | 
			
		||||
      sweepFunc()
 | 
			
		||||
 | 
			
		||||
      -- don't move forward on the last row
 | 
			
		||||
      if y ~= width then
 | 
			
		||||
        turtle.forward()
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
  
 | 
			
		||||
    -- don't turn on the last column
 | 
			
		||||
    if x ~= width then
 | 
			
		||||
      -- turn to the next column
 | 
			
		||||
      if turnRightNext then
 | 
			
		||||
        turtle.turnRight()
 | 
			
		||||
        turtle.forward()
 | 
			
		||||
        turtle.turnRight()
 | 
			
		||||
      else
 | 
			
		||||
        turtle.turnLeft()
 | 
			
		||||
        turtle.forward()
 | 
			
		||||
        turtle.turnLeft()
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      turnRightNext = not turnRightNext
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
  -- move back to the start position
 | 
			
		||||
  if width % 2 == 0 then
 | 
			
		||||
    turtle.turnRight()
 | 
			
		||||
  else
 | 
			
		||||
    for y = 1, length -1 do
 | 
			
		||||
      turtle.back()
 | 
			
		||||
    end
 | 
			
		||||
    turtle.turnLeft()
 | 
			
		||||
  end
 | 
			
		||||
  turtle.turnRight()
 | 
			
		||||
 | 
			
		||||
  return true
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
--findBlock() spins around searching
 | 
			
		||||
--for the named block next to the turtle
 | 
			
		||||
function findBlock(name)
 | 
			
		||||
  local result, block
 | 
			
		||||
 | 
			
		||||
  for i = 1, 4 do
 | 
			
		||||
    result, block = turtle.inspect()
 | 
			
		||||
    if block ~= nil and block['name'] == name then
 | 
			
		||||
      return true
 | 
			
		||||
    end
 | 
			
		||||
    turtle.turnRight()
 | 
			
		||||
  end
 | 
			
		||||
  return false
 | 
			
		||||
end
 | 
			
		||||
 
 | 
			
		||||
@@ -1,49 +0,0 @@
 | 
			
		||||
--[[Stone Brick Factory program by Al Sweigart
 | 
			
		||||
Gets stone from furnace to craft stone bricks, turtle 2 of 2]]
 | 
			
		||||
 | 
			
		||||
print('Starting stone brick crafting program')
 | 
			
		||||
 | 
			
		||||
local NUM_FURNACES = 5
 | 
			
		||||
local brickCount = 0
 | 
			
		||||
while true do
 | 
			
		||||
    -- check turtle's fuel
 | 
			
		||||
    if turtle.getFuelLevel() < (2 * NUM_FURNACES) then
 | 
			
		||||
        error('Turtle needs more fuel!')
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    turtle.select(1) -- put stone in slot 1
 | 
			
		||||
 | 
			
		||||
    -- start collecting stone from furnaces
 | 
			
		||||
    for i = 1, NUM_FURNACES do
 | 
			
		||||
        turtle.suckUp(64 - turtle.getItemCount(1)) -- get stone from furnace
 | 
			
		||||
        if turtle.getItemCount(1) == 64 then
 | 
			
		||||
            break -- stop once there are 64 stone blocks
 | 
			
		||||
        end
 | 
			
		||||
        if i ~= NUM_FURNACES then
 | 
			
		||||
            turtle.back() -- move to next furnace
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    -- craft stone bricks
 | 
			
		||||
    if turtle.getItemCount(1) == 64 then
 | 
			
		||||
        turtle.transferTo(2, 16) -- put in slot 2
 | 
			
		||||
        turtle.transferTo(5, 16) -- put in slot 5
 | 
			
		||||
        turtle.transferTo(6, 16) -- put in slot 6
 | 
			
		||||
        turtle.select(16) -- stone brick to go in slot 16
 | 
			
		||||
        turtle.craft() -- craft stone bricks
 | 
			
		||||
        brick.Count = brickCount + 64
 | 
			
		||||
        print('Total stone bricks: ' .. brickCount)
 | 
			
		||||
    else
 | 
			
		||||
        print('Not enough stones yet. Sleeping...')
 | 
			
		||||
        os.sleep(120) -- wait for 2 minutes
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    -- move back to chest (by first furnace)
 | 
			
		||||
    for i = 1, NUM_FURNACES - 1 do
 | 
			
		||||
        turtle.forward()
 | 
			
		||||
    end
 | 
			
		||||
    turtle.turnLeft() -- face chest
 | 
			
		||||
    turtle.select(16) -- select stone bricks
 | 
			
		||||
    turtle.drop() -- put stone bricks into chest
 | 
			
		||||
    turtle.turnRight() -- face generator again
 | 
			
		||||
end
 | 
			
		||||
							
								
								
									
										46
									
								
								cobminer.lua
									
									
									
									
									
								
							
							
						
						
									
										46
									
								
								cobminer.lua
									
									
									
									
									
								
							@@ -1,46 +0,0 @@
 | 
			
		||||
--[[Stone Brick Factory program by Al Sweigart
 | 
			
		||||
Mines cobblestone from a generator, trutle 1 of 2]]
 | 
			
		||||
 | 
			
		||||
os.loadAPI('hare') -- load the hare module
 | 
			
		||||
local numToDrop
 | 
			
		||||
local NUM_FURNACES = 5
 | 
			
		||||
 | 
			
		||||
print('Starting mining program...')
 | 
			
		||||
while true do
 | 
			
		||||
    -- mine cobblestone
 | 
			
		||||
    if turtle.detect() then
 | 
			
		||||
        print('Cobblestone detected. Mining...')
 | 
			
		||||
        turtle.dig() -- Mine cobblestone
 | 
			
		||||
    else
 | 
			
		||||
        print('No cobblestone detected. Sleeping...')
 | 
			
		||||
        os.sleep(0.5) -- half-second pause
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    -- check for a full stack of cobblestone
 | 
			
		||||
    hare.selectItem('minecraft:cobblestone')
 | 
			
		||||
    if turtle.getItemCount() == 64 then
 | 
			
		||||
        -- check turtle's fuel
 | 
			
		||||
        if turtle.getFuelLevel() < (2 * NUM_FURNACES) then
 | 
			
		||||
            error('Turtle needs more fuel!')
 | 
			
		||||
        end
 | 
			
		||||
 | 
			
		||||
        -- put cobblestone in furnaces
 | 
			
		||||
        print('Dropping off cobblestone...')
 | 
			
		||||
        for furnacesToFill = NUM_FURNACES, 1, -1 do
 | 
			
		||||
            turtle.back() -- move over furnace
 | 
			
		||||
            numToDrop = math.floor(turtle.getItemCount() / furnacesToFill)
 | 
			
		||||
            turtle.dropDown(numToDrop) -- put cobblestone in furnace
 | 
			
		||||
        end
 | 
			
		||||
 | 
			
		||||
        -- move back to cobblestone generator
 | 
			
		||||
        for moves = 1, NUM_FURNACES do
 | 
			
		||||
            turtle.forward()
 | 
			
		||||
        end
 | 
			
		||||
 | 
			
		||||
        if turtle.getItemCount() > 0 then
 | 
			
		||||
            print('All furnaces full. Sleeping...')
 | 
			
		||||
            os.sleep(300) -- wait for five minutes
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user