Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- #深夜のComputerCrafting60分一本勝負
- -- お題: 「turtle.inspect()」または「turtle.getItemDetail()」を使ったプログラム
- -- 2015/01/27 23:00スタート by hevo2
- -- 23:44 終了
- -- turtle.getItemDetail(slot_num)
- -- nil or
- -- { count=1, name="minecraft:dirt", damage=0}
- -- ##############################################################
- -- turtle.getItemCounrt(slot_num)
- -- 発展→ turtle.getItemCountAll(item_name, damage) => 個数
- function getItemCountAll(item_name, damage)
- local count = 0
- for i=1,16 do
- local detail = turtle.getItemDetail(i)
- if detail then -- スロットになにかアイテムある
- if string.match(detail["name"],item_name) then -- アイテム名がマッチする
- if damage == nil or damage==detail["damage"] then -- ダメージ値の指定があり、それが一致する
- count = count + detail["count"]
- end
- else -- アイテム名がマッチしない
- end
- else -- スロットにアイテムない
- -- do nothing
- end
- end
- return count
- end
- -- 名前(ダメージ値も可)を指定して、インベントリ内に合計いくつそのアイテムが存在するか数える
- -- print(getItemCountAll("dirt",0))
- -- print(getItemCountAll("dirt"))
- -- print(getItemCountAll("stone"))
- -- print(getItemCountAll("stone",5))
- -- ##############################################################
- -- インベントリ内にバラバラに入っているアイテムをできるだけまとめる
- -- turtle.transferTo(slot [, quantity])
- function collectItem()
- local selected_slot = turtle.getSelectedSlot()
- for i=1,16 do
- local detail = turtle.getItemDetail(i)
- if detail then -- スロットになにかアイテムある
- for j=i,16 do
- local detail2 = turtle.getItemDetail(j)
- if detail2 and detail["name"]==detail2["name"] and detail["damage"]==detail2["damage"] then
- turtle.select(j)
- turtle.transferTo(i)
- end
- end
- else -- スロットにアイテムない
- end
- end
- turtle.select(selected_slot)
- end
- -- collectItem()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement