Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local ms = require("movescript")
- local component = require("component")
- local robot = require("robot")
- local ic = component.inventory_controller
- local BLOCK_NAME = "minecraft:dirt"
- local BLOCK_DATA = 0
- local arg = {...}
- --[[
- Select an item, given its name and damage value.
- item_name - string: The id string for an item.
- item_data - number: The damage value, or variation of an item. Defaults to zero.
- return - boolean: True if at least one slot contains the item. That slot is now
- selected.
- --]]
- local function selectItemByName(item_name, item_data)
- for i=1,16 do
- local stack = ic.getStackInInternalSlot(i)
- if (stack ~= nil and stack.name == item_name and stack.damage == item_data) then
- robot.select(i)
- return true
- end
- end
- return false
- end
- --[[
- Select an item, similar to selectItemByName, but if the item cannot be found,
- the user will be prompted to add it to the robot's inventory and press enter to
- continue.
- item_name - string: The id string for an item.
- item_data - number: The damage value, or variation of an item. Defaults to zero.
- return - nil: If set to be continuous, then if the item cannot be found, then
- the program will exit. If not, it will loop until the item is provided by the
- user.
- --]]
- local function selectSafely(item_name, item_data)
- local success = selectItemByName(item_name, item_data)
- while not success do
- print("Cannot find "..item_name.." in inventory. Please add some, and press enter.")
- io.read()
- success = selectItemByName(item_name, item_data)
- end
- end
- local function flattenSpot()
- -- Dig out top part.
- local displacement = 0
- local success, data = robot.detectUp()
- while (success) do
- ms.execute("d_U")
- success, data = robot.detectUp()
- displacement = displacement + 1
- end
- ms.execute(displacement .. "D")
- -- Fill in floor.
- displacement = 0
- success, data = robot.detectDown()
- while ((not success) or (data == "replaceable")) do
- ms.execute("d_D")
- success, data = robot.detectDown()
- displacement = displacement + 1
- end
- for i = 1, displacement do
- ms.execute("U")
- selectSafely(BLOCK_NAME, BLOCK_DATA)
- robot.placeDown()
- end
- end
- local function fillLine(length)
- for i = 1, length do
- ms.execute("d_F")
- flattenSpot()
- end
- end
- local function mainMenu()
- print("[1] Use " .. BLOCK_NAME .. ":" .. BLOCK_DATA .. " as default.")
- print("[2] Define your own block to use.")
- choice = tonumber(io.read())
- if choice == 2 then
- print("What is the name of the block?")
- BLOCK_NAME = io.read()
- print("What is the data value?")
- BLOCK_DATA = tonumber(io.read())
- end
- print("What is the length of the area to fill? (How far forward)")
- length = tonumber(io.read())
- fillLine(length)
- end
- local function parseArgs()
- if (arg[1] ~= nil and arg[2] ~= nil and arg[3] ~= nil) then
- BLOCK_NAME = arg[1]
- BLOCK_DATA = tonumber(arg[2])
- return tonumber(arg[3])
- else
- return false
- end
- end
- local length = parseArgs()
- if (not length) then
- mainMenu()
- else
- fillLine(length)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement