Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Time to wait between checking if we can spawn (in seconds)
- local checkDelayS = 10 -- 10 seconds
- -- Time to wait between spawns (in seconds)
- local spawnDelayS = 60 * 2 -- 2 minutes
- -- Slots
- skullSlot = 1
- soulSandSlot = 2
- -- Bring in required modules.
- local robot = require("robot")
- local os = require("os")
- local term = require("term")
- local sides = require("sides")
- local component = require("component")
- -- Function to keep trying to move
- -- forward until success.
- local function moveForward(count)
- for i=1, count do
- while not (robot.forward()) do
- os.sleep(1)
- end
- end
- end
- -- Function to keep trying to move
- -- back until success.
- local function moveBack(count)
- for i=1, count do
- while not (robot.back()) do
- os.sleep(1)
- end
- end
- end
- -- Function to keep trying to move
- -- up until success.
- local function moveUp(count)
- for i=1, count do
- while not (robot.up()) do
- os.sleep(1)
- end
- end
- end
- -- Function to keep trying to move
- -- down until success.
- local function moveDown(count)
- for i=1, count do
- while not (robot.down()) do
- os.sleep(1)
- end
- end
- end
- -- Function to keep trying to place
- -- until success.
- local function placeBlock(inventorySlot, side)
- robot.select(inventorySlot)
- while not (robot.place(side)) do
- os.sleep()
- end
- end
- local function gatherMaterial(inventoryLocation, slotNumber, desiredAmount)
- -- Select desired slot
- robot.select(slotNumber)
- -- Get the current amount
- local currentCount = robot.count()
- -- Loop until we have enough (we'll return if we get to a point where we can't retrieve any more
- while currentCount < desiredAmount do
- -- Determine how much more we need
- local remainingNeeded = desiredAmount - currentCount
- -- Try to get some more
- local gotItems = component.robot.suck(inventoryLocation, remainingNeeded)
- -- Return failure if we got nothing
- if gotItems == false then
- return false
- end
- -- Update count
- currentCount = robot.count()
- end
- -- Success!
- return true
- end
- local function moveIntoPosition()
- moveUp(1)
- moveForward(1)
- robot.turnLeft()
- moveForward(3)
- moveDown(2)
- moveForward(1)
- robot.turnRight()
- moveForward(3)
- robot.turnRight()
- moveForward(2)
- robot.turnLeft()
- end
- local function constructWither()
- placeBlock(soulSandSlot, sides.front)
- moveUp(1)
- placeBlock(soulSandSlot, sides.front)
- robot.turnLeft()
- moveForward(1)
- robot.turnRight()
- placeBlock(soulSandSlot, sides.front)
- robot.turnRight()
- moveForward(2)
- robot.turnLeft()
- placeBlock(soulSandSlot, sides.front)
- moveUp(1)
- placeBlock(skullSlot, sides.front)
- robot.turnLeft()
- moveForward(1)
- robot.turnRight()
- placeBlock(skullSlot, sides.front)
- robot.turnLeft()
- moveForward(1)
- robot.turnRight()
- placeBlock(skullSlot, sides.front)
- end
- local function retreat()
- moveBack(1)
- moveDown(2)
- robot.turnLeft()
- moveForward(1)
- robot.turnLeft()
- moveForward(2)
- robot.turnLeft()
- moveForward(1)
- moveUp(2)
- moveForward(3)
- robot.turnLeft()
- moveBack(1)
- moveDown(1)
- end
- local function checkIfEnabled()
- -- Check for redstone signal on left side of robot
- rs = component.redstone
- enableSignal = rs.getInput(sides.left)
- if enableSignal > 7 then
- return true
- end
- return false
- end
- -- Clear screen
- term.clear()
- term.setCursor(1, 1)
- -- Header
- term.write("Wither Farm\n\n")
- -- Loop forever
- while true do
- -- Check if we are enabled
- term.write("Checking status\n")
- enabled = checkIfEnabled()
- if enabled then
- term.write("Spawn enabled\n")
- -- Gather materials
- term.write("Gathering materials\n")
- enoughSkulls = gatherMaterial(sides.bottom, skullSlot, 3)
- enoughSoulSand = gatherMaterial(sides.front, soulSandSlot, 4)
- -- Do we have enough?
- if enoughSkulls and enoughSoulSand then
- -- Move into position
- term.write("Moving into position")
- moveIntoPosition()
- -- Construct the wither
- term.write("Constructing wither\n")
- constructWither()
- -- Retreat
- term.write("Retreating\n")
- retreat()
- -- Wait awhile before spawning again
- term.write("Waiting for spawn cooldown\n")
- os.sleep(spawnDelayS)
- else
- term.write("Not enough materials yet\n")
- end
- else
- term.write("Spawn disabled!\n")
- end
- -- Check delay
- term.write("Waiting before next check\n")
- os.sleep(checkDelayS)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement