Advertisement
HandieAndy

Filler

May 5th, 2019
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.78 KB | None | 0 0
  1. local ms = require("movescript")
  2. local component = require("component")
  3. local robot = require("robot")
  4. local ic = component.inventory_controller
  5.  
  6. local BLOCK_NAME = "minecraft:dirt"
  7. local BLOCK_DATA = 0
  8.  
  9. --[[
  10. Select an item, given its name and damage value.
  11. item_name - string: The id string for an item.
  12. item_data - number: The damage value, or variation of an item. Defaults to zero.
  13. return - boolean: True if at least one slot contains the item. That slot is now
  14. selected.
  15. --]]
  16. local function selectItemByName(item_name, item_data)
  17.     for i=1,16 do
  18.         local stack = ic.getStackInInternalSlot(i)
  19.         if (stack ~= nil and stack.name == item_name and stack.damage == item_data) then
  20.             robot.select(i)
  21.             return true
  22.         end
  23.     end
  24.     return false
  25. end
  26.  
  27. --[[
  28. Select an item, similar to selectItemByName, but if the item cannot be found,
  29. the user will be prompted to add it to the robot's inventory and press enter to
  30. continue.
  31. item_name - string: The id string for an item.
  32. item_data - number: The damage value, or variation of an item. Defaults to zero.
  33. return - nil: If set to be continuous, then if the item cannot be found, then
  34. the program will exit. If not, it will loop until the item is provided by the
  35. user.
  36. --]]
  37. local function selectSafely(item_name, item_data)
  38.     local success = selectItemByName(item_name, item_data)
  39.     while not success do
  40.         print("Cannot find "..item_name.." in inventory. Please add some, and press enter.")
  41.         io.read()
  42.         success = selectItemByName(item_name, item_data)
  43.     end
  44. end
  45.  
  46. local function fillSpot()
  47.     local displacement = 0
  48.     local success, data = robot.detectDown()
  49.     while ((not success) or (data == "replaceable")) do
  50.         ms.execute("d_D")
  51.         success, data = robot.detectDown()
  52.         displacement = displacement + 1
  53.     end
  54.     for i = 1, displacement do
  55.         ms.execute("U")
  56.         selectSafely(BLOCK_NAME, BLOCK_DATA)
  57.         robot.placeDown()
  58.     end
  59. end
  60.  
  61. local function fillArea(length, width)
  62.     for row = 1, length do
  63.         ms.execute("d_F")
  64.  
  65.         if (row % 2) == 1 then robot.turnRight() else robot.turnLeft() end
  66.  
  67.         for col = 1, width - 1 do
  68.             fillSpot()
  69.             ms.execute("d_F")
  70.         end
  71.  
  72.         fillSpot()
  73.         if (row % 2) == 1 then robot.turnLeft() else robot.turnRight() end
  74.     end
  75. end
  76.  
  77. local function mainMenu()
  78.     print("[1] Use " .. BLOCK_NAME .. ":" .. BLOCK_DATA .. " as default.")
  79.     print("[2] Define your own block to use.")
  80.     choice = tonumber(io.read())
  81.     if choice == 2 then
  82.         print("What is the name of the block?")
  83.         BLOCK_NAME = io.read()
  84.         print("What is the data value?")
  85.         BLOCK_DATA = tonumber(io.read())
  86.     end
  87.  
  88.     print("What is the length of the area to fill? (How far forward)")
  89.     length = tonumber(io.read())
  90.     print("What is the width of the area to fill? (How far to the right)")
  91.     width = tonumber(io.read())
  92.  
  93.     fillArea(length, width)
  94. end
  95.  
  96. mainMenu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement