G2A Many GEOs
SHARE
TWEET

selfRefuel

kssr3951 May 7th, 2017 (edited) 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- ----------------------------------------------
  2. -- Utilities
  3. -- ----------------------------------------------
  4. function doSelfRefuel(inspectFunc, placeFunc)
  5.     local function findOne(name, metadata)
  6.         for i = 1, 16 do
  7.             if 1 == turtle.getItemCount(i) then
  8.                 local detail = turtle.getItemDetail(i)
  9.                 if nil ~= detail and detail.name == name and detail.damage == metadata then
  10.                     return i
  11.                 end
  12.             end
  13.         end
  14.         return -1
  15.     end
  16.     local selected = turtle.getSelectedSlot()
  17.     local rslt, inspect = inspectFunc()
  18.     if true == rslt and inspect.name == "minecraft:flowing_lava" and inspect.metadata == 0 then
  19.         local bucketSlot = findOne("minecraft:bucket", 0) -- とりあえず空バケツ1個の場合だけ実装する
  20.         if -1 ~= bucketSlot then
  21.             turtle.select(bucketSlot)
  22.             placeFunc() -- 溶岩を汲む
  23.             local lavaBucketSlot = findOne("minecraft:lava_bucket", 0)
  24.             if -1 ~= lavaBucketSlot then
  25.                 turtle.select(lavaBucketSlot)
  26.                 turtle.refuel()
  27.             end
  28.         end
  29.     end
  30.     turtle.select(selected)
  31. end
  32. function selfRefuelUp()
  33.     return doSelfRefuel(turtle.inspectUp, turtle.placeUp)
  34. end
  35. function selfRefuel()
  36.     return doSelfRefuel(turtle.inspect, turtle.place)
  37. end
  38. function selfRefuelDown()
  39.     return doSelfRefuel(turtle.inspectDown, turtle.placeDown)
  40. end
  41. -- ----------------------------------------------
  42. -- Utilities
  43. -- ----------------------------------------------
  44. local args = { ... }
  45. if 0 == #args then
  46.     print("bad argument")
  47. elseif "forward" == args[1] then
  48.     print("selfRefuel()")
  49.     print("before : " .. tostring(turtle.getFuelLevel()))
  50.     selfRefuel()
  51.     print("after  : " .. tostring(turtle.getFuelLevel()))
  52. elseif "up" == args[1] then
  53.     print("selfRefuelUp()")
  54.     print("before : " .. tostring(turtle.getFuelLevel()))
  55.     selfRefuelUp()
  56.     print("after  : " .. tostring(turtle.getFuelLevel()))
  57. elseif "down" == args[1] then
  58.     print("selfRefuelDown()")
  59.     print("before : " .. tostring(turtle.getFuelLevel()))
  60.     selfRefuelDown()
  61.     print("after  : " .. tostring(turtle.getFuelLevel()))
  62. else
  63.     print("bad argument")
  64. end
RAW Paste Data
Ledger Nano X - The secure hardware wallet
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top