Provide an api to keep track of named items, and make sure you never throw away the last one.
local ItemSet = dofile('itemset')
local items = ItemSet.new {charcoal = 1, sapling = 2, bonemeal = 3, dirt = 4, log = 5, cobble = 16}
if items:blockUpIs('dirt') then
print("You're not going to space today")
elseif items:blockIs('charcoal') then
print("That's not even possible")
else
print(("I'm on a %s"):format(items:blockDown() or "unknown thing")
end
Builds a cobblestone pillar, using as many stacks of cobble as there are in the inventory (leaving one behind). Then drops 100 cobble, and all the saplings.
repeat
turtle.up()
print("What a lovely pillar this will be")
until not items:placeDown('cobble')
items:drop('log', 100)
items:drop('sapling')
items:refuelWith('charcoal', 20)
assert(items:count('sapling') == 0)
:slot(name)
- return the slot used to define the named item:count(name)
- the number of usable items remaining (all but one):block()
,:blockUp()
,blockDown()
- the identity of the block next to the turtle, if known:blockIs(name)
,:blockUpIs(name)
,blockDownIs(name)
- check the block next to the turtle is the named item:place(name)
,:placeUp(name)
,placeDown(name)
- place a block, picking from the highest-numbered slot containing that item:drop(name[, n])
,:dropUp(name[, n])
,dropDown(name[, n])
- dropsn
(or all) blocks of a certain type, always holding onto one:refuelWith(name[, n])
- refuel withn
(or all) blocks of a certain type, always holding onto one