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
- --[[
- 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 fillSpot()
- local displacement = 0
- local 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 fillArea(length, width)
- for row = 1, length do
- ms.execute("d_F")
- if (row % 2) == 1 then robot.turnRight() else robot.turnLeft() end
- for col = 1, width - 1 do
- fillSpot()
- ms.execute("d_F")
- end
- fillSpot()
- if (row % 2) == 1 then robot.turnLeft() else robot.turnRight() end
- 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())
- print("What is the width of the area to fill? (How far to the right)")
- width = tonumber(io.read())
- fillArea(length, width)
- end
- mainMenu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement