Advertisement
Inksaver

p.lua (Place block/bucket up/forward/down)

Dec 6th, 2020 (edited)
2,686
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.73 KB | None | 0 0
  1. version = 20230430.1200
  2. -- pastebin get D25pg0QQ p.lua
  3. -- Last edited: see version YYYYMMDD.HHMM
  4. local usage = [[usage:
  5. p   (place forward) or p 1
  6. p u (place up) or p 0
  7. p d (place down) or p 2
  8. ]]
  9. args = {...}
  10. local success = false
  11. local direction = "forward"
  12. local place = turtle.place
  13. local inspect = turtle.inspect
  14. local data = {}
  15. local text = ""
  16. local block = ""
  17. local message = ""
  18.  
  19. term.clear()
  20. term.setCursorPos(1,1)
  21. if args[1] ~= nil then
  22.     if args[1]:lower() == "h" then
  23.         print(usage)
  24.         print("Fuel Level: "..turtle.getFuelLevel())
  25.         error()
  26.     elseif args[1]:lower() == "u" or args[1] == "0" then
  27.         direction = "up"
  28.         place = turtle.placeUp
  29.         inspect = turtle.inspectUp
  30.     elseif args[1]:lower() == "d" or args[1] == "2" then
  31.         direction = "down"
  32.         place = turtle.placeDown
  33.         inspect = turtle.inspectDown
  34.     end
  35. end
  36. turtle.select(1)
  37.  
  38. while turtle.getItemCount(1) == 0 do
  39.     print("Add an item to slot 1 and press Enter")
  40.     read()
  41. end
  42. data = turtle.getItemDetail(1)
  43. block = data.name
  44. if block:find("sign") ~= nil then
  45.     print("Type text for sign. + Enter")
  46.     print("Use \\n between lines")
  47.     text = read()
  48. end
  49. success = place(text)
  50. if block == "minecraft:bucket" then
  51.     message = "Water collected "
  52. elseif block == "minecraft:water_bucket" then
  53.     message = "Water placed "
  54. end
  55.  
  56. if success then
  57.     if message == "" then
  58.         print(block.." placed: "..direction)
  59.     else
  60.         print(message..direction)
  61.         success, data = inspect()
  62.         if success then
  63.             if data.name:find("water")~= nil then
  64.                 if data.state.level == 0 then
  65.                     print("Source block found "..direction)
  66.                 else
  67.                     print("Flowing water found "..direction.." level="..data.state.level)
  68.                 end
  69.             end
  70.         end
  71.     end
  72. else
  73.     print(block.." NOT placed")
  74. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement