Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ]]--
- --[[
- emptyInventory:
- Arguments:
- forceEmpty (Boolean) - If true, forces the turtle to empty its inventory
- Does:
- Empties Turtle's inventory except the first slot(seeds) and second slot(bonemeal)
- ]]--
- function emptyInventory(forceEmpty)
- -- Check if the turtle's inventory is full or the emptying should be forced
- if (turtle.getItemCount(16) > 0 or forceEmpty == true) then
- -- Refill seeds in slot#1
- refillSeeds(true)
- -- Loop to check each slot, 3 through 16, of the turtle's inventory
- for n = 3, 16, 1 do
- -- check if there's items in the slot
- if (turtle.getItemCount(n) > 0) then
- -- select the turtle's inventory slot, and 'dropUp()' (Place in the inventory above the turtle)
- turtle.select(n)
- turtle.dropUp()
- end
- end
- -- Otherwise, refillSeeds
- else
- refillSeeds(false)
- end
- end
- --[[
- refillSeeds:
- Arguments:
- forceRefill (boolean) - If true, forces the turtle to refill seeds
- Does:
- Refills the first slot of the turtle with seeds from else where in the turtle's inventory
- ]]--
- function refillSeeds(forceRefill)
- --[[ Variables:
- seedCount: number of seeds in slot#1
- refillCount: number of seeds required to refill slot#1 ]]
- local seedCount, refillCount = turtle.getItemCount(1), 0
- refillCount = 64 - seedCount
- -- Check if there's no seeds in slot #1
- if (seedCount == 0) then
- -- Print the turtle is out of seeds
- print("Out of seeds: place seeds in first slot to continue")
- -- Wait for seeds
- repeat
- sleep(1)
- until (turtle.getItemCount(1) > 0)
- -- Check if the turtle needs to refill seeds or the 'forceRefill' argument is true
- elseif (seedCount < 16) or (forceRefill == true and seedCount < 64) then
- -- select the first slot
- turtle.select(1)
- -- loop over slots #3 through #16
- for n = 3, 16, 1 do
- -- check if the slot looped over contains seeds
- if (turtle.compareTo(n) == true) then
- -- Select the looped over slot
- turtle.select(n)
- -- If there's not enough seeds to completely refill slot#1
- if (refillCount > turtle.getItemCount(n)) then
- -- transfer the seeds to slot one
- turtle.transferTo(1, turtle.getItemCount(n))
- -- Adjust refillCount
- refillCount = 64 - turtle.getItemCount(1)
- -- If there's more than enough seeds in the looped over slot to refill slot#1
- else
- -- transfer enough seeds to fill slot#1 then exit the loop
- turtle.transferTo(1, refillCount)
- break
- end
- -- select slot#1 for the next literation of the loop
- turtle.select(1)
- end
- end
- end
- end
- --[[
- getBoneMeal
- Arguments:
- none
- Usage:
- Refills slot#2 with bone meal from an inventory directly below the turtle
- ]]
- function getBoneMeal()
- -- select the turtle's second inventory slot
- turtle.select(2)
- -- Check to see if the turtle needs more bonemeal
- if (turtle.getItemCount(2) <= 8) then
- -- Attempt to retrieve bone meal from inventory below the turtle
- if (turtle.suckDown() == false) then
- -- Print the turtle is out of bone meal and waiting
- print("Out of bonemeal, waiting...")
- -- Wait for bone meal to be placed in inventory below the turtle
- repeat
- sleep(1)
- until (turtle.suckDown() == true)
- end
- -- loop over the turtle's inventory slots #3 through 16
- for n = 3, 16, 1 do
- -- if the slot has bone meal(extra) place it in the inventory above
- if (turtle.compareTo(n) == true) then
- turtle.select(n)
- turtle.dropUp()
- turtle.select(2)
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement