Advertisement
Inksaver

data.lua

Apr 30th, 2023 (edited)
1,169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.32 KB | Software | 0 0
  1. version = 20230430.1000
  2. --[[
  3. https://pastebin.com/fCKDc9Vi
  4. pastebin get fCKDc9Vi data.lua
  5. ]]
  6. local usage = [[usage:
  7. data   (getBlockType forward) or data 1
  8. data u (getBlockType up)      or data 0
  9. data d (getBlockType down)    or data 2
  10. ]]
  11. args = {...}
  12.  
  13. local direction = "forward"
  14. --local blockType = ""
  15. --local blockModifier = nil
  16. local success = false
  17. local data = {} --initialise empty table variable
  18. local inspect = turtle.inspect
  19.  
  20. if args[1] ~= nil then
  21.     if args[1]:lower() == "h" then
  22.         term.clear()
  23.         term.setCursorPos(1,1)
  24.         print(usage)
  25.         print("Fuel Level: "..turtle.getFuelLevel())
  26.         error()
  27.     elseif args[1]:lower() == "u" or args[1] == "0" then
  28.         direction = "up"
  29.         inspect = turtle.inspectUp
  30.     elseif args[1]:lower() == "d" or args[1] == "2" then
  31.         direction = "down"
  32.         inspect = turtle.inspectDown
  33.     end
  34. end
  35. success, data = inspect()
  36. if success then -- block found
  37.     -- data.name                -- eg "minecraft:log"
  38.     -- data.metadata            -- no longer used
  39.     -- data.state.level         -- in water 0 to 8 0=source
  40.     -- data.state.shape         -- eg straight
  41.     -- data.state.waterlogged   -- bool
  42.     -- data.state.half          -- eg "bottom"
  43.     -- data.state.facing        -- eg "south"
  44.     -- data.state.drag          -- bool eg bubble_column
  45.     term.clear()
  46.     term.setCursorPos(1,1)
  47.     local lines = 0
  48.     local isSource = false
  49.     print("Block "..direction.."="..data.name)
  50.     lines = lines + 1
  51.     if data.name:find("water") ~= nil then -- allows for bubble_column
  52.         if data.state.level ~= nil then
  53.             if data.state.level == 0 then
  54.                 isSource = true
  55.             end
  56.         end
  57.         term.write("data.state.level = "..data.state.level)
  58.         if isSource then
  59.             term.write(" (source)\n")
  60.         else
  61.             term.write(" (flowing)\n")
  62.         end
  63.     end
  64.     if data.state ~= nil then
  65.         for k,v in pairs(data.state) do
  66.             if k ~= "level" then
  67.                 print("data.state."..k.." = "..tostring(v))
  68.                 lines = lines + 1
  69.             end
  70.         end
  71.     end
  72.     if data.metadata ~= nil then
  73.         for k,v in pairs(data.metadata) do
  74.             print("data.metadata."..k.." = "..v)
  75.         end
  76.     end
  77.     if data.tags ~= nil then
  78.         for k,v in pairs(data.tags) do
  79.             if k:find("minecraft:") ~= nil then
  80.                 k = k:sub(11)
  81.             end
  82.             print("tags."..k.."="..tostring(v))
  83.             lines = lines + 1
  84.             if lines > 10 then
  85.                 print("Enter to continue")
  86.                 read()
  87.                 lines = 0
  88.             end
  89.         end
  90.     end
  91. else
  92.     print("Unable to inspect block "..direction)
  93. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement