Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --constants
- local casing_slot_one = 1
- local casing_slot_two = 2
- local spike_slot = 3
- local wither_skulls_needed = 3
- local soul_sand_needed = 4
- local casing_needed = 112
- local spikes_needed = 9
- local redstone_direction = "left"
- local chest_direction = "right"
- --functions
- function show_usage()
- print("wither_farm build --> build the casing for the farm")
- print("wither_farm run ----> run the actual witherboss farm")
- end
- function pre_boss_builder()
- turtle.up()
- move_direction("forward", 2)
- move_direction("down", 2)
- end
- function post_boss_builder()
- move_direction("back", 2)
- turtle.down()
- end
- function move_direction(direction, count)
- direction = string.lower(direction)
- --this is to perform more of a strafe than just moving in a given direction
- --turn left/right before moving
- if direction == "left" then
- turtle.turnLeft()
- elseif direction == "right" then
- turtle.turnRight()
- end
- --move in the requested direction x number of times
- for x = 1, count, 1 do
- if direction == "up" then
- turtle.up()
- elseif direction == "down" then
- turtle.down()
- elseif direction == "left" then
- turtle.forward()
- elseif direction == "right" then
- turtle.forward()
- elseif direction == "forward" then
- turtle.forward()
- elseif direction == "back" then
- turtle.back()
- else
- print("An undefined direction string was entered!")
- end
- end
- --turn back left/right after moving
- if direction == "left" then
- turtle.turnRight()
- elseif direction == "right" then
- turtle.turnLeft()
- end
- end
- function compare_casing_slots()
- local current = turtle.getSelectedSlot()
- turtle.select(casing_slot_one)
- local result = turtle.compareTo(casing_slot_two)
- turtle.select(current)
- return result
- end
- function is_case_constructed()
- local current = turtle.getSelectedSlot()
- turtle.select(casing_slot_one)
- local result = turtle.compare()
- if result then
- turtle.select(casing_slot_two)
- result = turtle.compare()
- turtle.select(current)
- return result
- end
- return false
- end
- function build_casing()
- --first layer
- turtle.select(casing_slot_one)
- turtle.place() --1
- turtle.up()
- turtle.forward()
- turtle.turnLeft()
- turtle.forward()
- turtle.placeDown() --2
- turtle.forward()
- turtle.placeDown() --3
- turtle.turnRight()
- turtle.forward()
- turtle.placeDown() --4
- turtle.forward()
- turtle.placeDown() --5
- turtle.forward()
- turtle.placeDown() --6
- turtle.forward()
- turtle.placeDown() --7
- turtle.turnRight()
- turtle.forward()
- turtle.placeDown() --8
- turtle.turnRight()
- turtle.forward()
- turtle.placeDown() --8
- turtle.forward()
- turtle.placeDown() --9
- turtle.forward()
- turtle.placeDown() --10
- turtle.forward()
- turtle.placeDown() --11
- turtle.turnLeft()
- turtle.forward()
- turtle.turnLeft()
- turtle.forward()
- turtle.placeDown() --12
- turtle.forward()
- turtle.placeDown() --13
- turtle.forward()
- turtle.placeDown() --14
- turtle.forward()
- turtle.placeDown() --15
- turtle.turnRight()
- turtle.forward()
- turtle.placeDown() --16
- turtle.turnRight()
- turtle.forward()
- turtle.placeDown() --17
- turtle.forward()
- turtle.placeDown() --18
- turtle.forward()
- turtle.placeDown() --19
- turtle.forward()
- turtle.placeDown() --20
- turtle.turnLeft()
- turtle.forward()
- turtle.placeDown() --21
- turtle.turnLeft()
- turtle.forward()
- turtle.placeDown() --22
- turtle.forward()
- turtle.placeDown() --23
- turtle.forward()
- turtle.placeDown() --24
- turtle.forward()
- turtle.placeDown() --25
- --second layer -> fifth layer
- for y = 1, 5 do
- turtle.up()
- turtle.placeDown() --26
- --top right corner
- turtle.turnLeft()
- for x = 1, 4 do
- turtle.forward()
- turtle.placeDown() --27-30
- end
- --top left corner
- turtle.turnLeft()
- for x = 1, 4 do
- turtle.forward()
- if turtle.getItemCount(casing_slot_one) == 0 then --runs out at this point
- turtle.select(casing_slot_two)
- end
- turtle.placeDown() --30-35
- end
- --bottom left corner
- turtle.turnLeft()
- turtle.forward()
- turtle.placeDown() --36
- if y == 2 or y == 4 or y == 5 then --level 2, 4, and 5 or the hollow part
- turtle.forward()
- turtle.placeDown()
- turtle.forward()
- else
- for x = 1, 2 do
- turtle.forward()
- end
- end
- turtle.placeDown() --37
- turtle.forward()
- turtle.placeDown() --38
- --bottom right corner
- turtle.turnLeft()
- for x = 1, 3 do
- turtle.forward()
- turtle.placeDown() --38-42
- end
- turtle.forward()
- end
- turtle.turnLeft()
- turtle.forward()
- turtle.turnLeft()
- turtle.forward()
- for x = 1, 2 do
- turtle.down()
- end
- turtle.placeUp()
- turtle.forward()
- turtle.placeUp()
- turtle.forward()
- turtle.placeUp()
- turtle.turnRight()
- turtle.forward()
- turtle.placeUp()
- turtle.turnRight()
- turtle.forward()
- turtle.placeUp()
- turtle.forward()
- turtle.placeUp()
- turtle.turnLeft()
- turtle.forward()
- turtle.placeUp()
- turtle.turnLeft()
- turtle.forward()
- turtle.placeUp()
- turtle.forward()
- turtle.placeUp()
- turtle.select(spike_slot)
- turtle.down()
- turtle.placeUp()
- for x = 1, 2 do
- turtle.turnLeft()
- end
- turtle.forward()
- turtle.placeUp()
- turtle.forward()
- turtle.placeUp()
- turtle.turnRight()
- turtle.forward()
- turtle.placeUp()
- turtle.turnRight()
- turtle.forward()
- turtle.placeUp()
- turtle.forward()
- turtle.placeUp()
- turtle.turnLeft()
- turtle.forward()
- turtle.placeUp()
- turtle.turnLeft()
- turtle.forward()
- turtle.placeUp()
- turtle.forward()
- turtle.placeUp()
- turtle.turnLeft()
- turtle.forward()
- turtle.turnLeft()
- for x = 1, 4 do
- turtle.forward()
- end
- for x = 1, 2 do
- turtle.turnLeft()
- end
- turtle.down()
- end
- function build_wither(wither_slot, ss_slot)
- turtle.down() --move from the middle of the wither to the bottom
- --select soul sand slot
- turtle.select(ss_slot)
- turtle.place() --soul sand bottom
- turtle.up()
- turtle.place() --soul sand middle
- turtle.turnLeft()
- turtle.forward()
- turtle.turnRight()
- turtle.place() --soul sand left
- turtle.select(wither_slot)
- turtle.up()
- turtle.place() --wither skull left
- turtle.down()
- turtle.turnRight()
- --move forward 2
- move_direction("forward", 2)
- turtle.turnLeft()
- turtle.select(ss_slot)
- turtle.place() --soul sand right
- turtle.up()
- turtle.select(wither_slot)
- turtle.place() --wither skull right
- turtle.turnLeft()
- turtle.forward()
- turtle.turnRight()
- turtle.place() --wither skull middle
- end
- function drop_direction(direction, slot, amount)
- local current = turtle.getSelectedSlot()
- turtle.select(slot)
- direction = string.lower(direction)
- local success = false
- if direction == "right" then
- turtle.turnRight()
- success = turtle.drop(amount)
- turtle.turnLeft()
- elseif direction == "left" then
- turtle.turnLeft()
- success = turtle.drop(amount)
- turtle.turnRight()
- elseif direction == "up" then
- success = turtle.dropUp(amount)
- elseif direction == "down" then
- success = turtle.dropDown(amount)
- elseif direction == "back" then
- for x = 1, 2 do
- turtle.turnLeft()
- end
- success = turtle.drop(amount)
- for x = 1, 2 do
- turtle.turnRight()
- end
- elseif direction == "front" then
- success = turtle.drop(amount)
- else
- print("An undefined direction string was entered!")
- end
- turtle.select(current)
- return success
- end
- function valid_fuel(item_name, item_damage)
- if item_name == "minecraft:coal" and (item_damage == 0 or item_damage == 1) then --vanilla
- return true
- elseif item_name == "Railcraft:fuel.coke" then --railcraft
- return true
- elseif item_name == "ImmersiveEngineering:material" and item_damage == 6 then --immersive engineering
- return true
- end
- return false
- end
- function table_length(T)
- local count = 0
- for _ in pairs(T) do count = count + 1 end
- return count
- end
- function determine_slots()
- local soul_sand_found = false
- local soul_sand_slot = 0
- local wither_skulls_found = false
- local wither_skull_slot = 0
- local fuel_slot = 0
- for x = 4, 16 do --loop through all slots
- local item_info = turtle.getItemDetail(x)
- if item_info ~= nil then --valid item
- local item_name = item_info.name
- local item_damage = item_info.damage
- if item_name == "minecraft:skull" and item_damage == 1 then --wither skulls
- wither_skulls_found = true
- wither_skull_slot = x
- elseif item_name == "minecraft:soul_sand" then --soul sand
- soul_sand_found = true
- soul_sand_slot = x
- elseif valid_fuel(item_name, item_damage) then
- fuel_slot = x
- end
- end
- end
- if soul_sand_found and wither_skulls_found then
- local response = {wither_skull_slot, soul_sand_slot}
- if fuel_slot > 0 then
- response[3] = fuel_slot
- end
- return response
- end
- return false
- end
- function refuel_turtle(count)
- local current = turtle.getSelectedSlot()
- turtle.select(slot)
- turtle.refuel(count)
- turtle.select(current)
- end
- --arguments
- local command = ...
- if command then
- command = string.lower(command)
- else
- show_usage()
- return
- end
- --variables
- --slot variables
- local wither_skull_slot = 0
- local soul_sand_slot = 0
- local fuel_slot = 0
- --handle commands
- if command == "test" then --tests for debugging
- determine_slots()
- elseif command == "build" then --build casing
- if not is_case_constructed() then
- if compare_casing_slots() then
- local casing_count_one = turtle.getItemCount(casing_slot_one)
- local casing_count_two = turtle.getItemCount(casing_slot_two)
- local total_casing_count = casing_count_one + casing_count_two
- local spike_count = turtle.getItemCount(spike_slot)
- if total_casing_count >= casing_needed then
- if spike_count >= spikes_needed then
- print("Building witherboss farm casing (this may take a while)...")
- build_casing()
- print("Done!")
- else
- print(tostring(spike_count) .. "/" .. tostring(spikes_needed) .. " Spike Blocks")
- end
- else
- print(tostring(total_casing_count) .. "/" .. tostring(casing_needed) .. " Casing Blocks")
- end
- else
- print("Casing materials aren't the same!")
- end
- else
- print("Casing is already constructed!")
- end
- elseif command == "run" then --run the actual wither builder
- --1.5 second loop to wait on a redstone signal
- local announced = false
- while true do
- --determine slots every 1.5 seconds
- local fuel_found = false
- local slot_response = determine_slots()
- if type(slot_response) == "table" then
- wither_skull_slot = slot_response[1]
- soul_sand_slot = slot_response[2]
- if table_length(slot_response) == 3 then
- fuel_slot = slot_response[3]
- fuel_found = true
- end
- else
- print("Soul sand and/or wither skulls not found!")
- return
- end
- --variables
- local soul_sand_count = turtle.getItemCount(soul_sand_slot)
- local wither_skull_count = turtle.getItemCount(wither_skull_slot)
- local wither_skull_remainder = wither_skull_count % wither_skulls_needed
- local soul_sand_remainder = soul_sand_count % soul_sand_needed
- --refuel if low fuel level
- if fuel_found then
- local fuel_count = turtle.getItemCount(fuel_slot)
- if turtle.getFuelLevel() ~= "unlimited" and turtle.getFuelLevel() < 1 and fuel_count > 0 then
- print("Refueling turtle...")
- refuel_turtle(fuel_count)
- print("Done!")
- end
- end
- --errors with divisibility in wither skulls correction
- if wither_skull_remainder > 0 and wither_skull_count > wither_skulls_needed then
- print("Wither skulls count not divisible by " .. tostring(wither_skulls_needed) .. "! Fixing...")
- drop_direction(chest_direction, wither_skull_slot, wither_skull_remainder)
- wither_skull_count = wither_skull_count - wither_skull_remainder
- wither_skull_remainder = 0
- print("Wither skull divisibility error fixed!")
- end
- --error with divisibility in soul sand correction
- if soul_sand_remainder > 0 and soul_sand_count > soul_sand_needed then
- print("Soul sand count not divisible by " .. tostring(soul_sand_needed) .. "! Fixing...")
- drop_direction(chest_direction, soul_sand_slot, soul_sand_remainder)
- soul_sand_count = soul_sand_count - soul_sand_remainder
- soul_sand_remainder = 0
- print("Soul sand divisibility error fixed!")
- end
- --wait on a redstone signal on the back
- if redstone.getInput(redstone_direction) == true then
- if wither_skull_count > 0 and soul_sand_count > 0 and wither_skull_remainder == 0 and soul_sand_remainder == 0 then
- --reset announced
- announced = false
- --find out how many wither bosses it can generate
- total_with_skulls = wither_skull_count / wither_skulls_needed
- total_with_ss = soul_sand_count / soul_sand_needed
- if total_with_skulls == total_with_ss then
- --print the amount the turtle is able to spawn
- print(tostring(total_with_skulls) .. " Wither Bosses Left!")
- --run pre-boss build tasks
- pre_boss_builder()
- --begin building the wither from the bottom up and ending with the central wither skull
- build_wither(wither_skull_slot, soul_sand_slot)
- --run post-boss build tasks
- post_boss_builder()
- print("Wither Boss Spawned, Prepare Yourself!")
- else
- if total_with_skulls > total_with_ss then
- local deficit = (total_with_skulls - total_with_ss) * wither_skulls_needed
- drop_direction("right", wither_skull_slot, deficit)
- print("The soul sand deficit has been corrected!")
- elseif total_with_ss > total_with_skulls then
- local deficit = (total_with_ss - total_with_skulls) * soul_sand_needed
- drop_direction("right", soul_sand_slot, deficit)
- print("The wither skull deficit has been corrected!")
- end
- end
- else
- if not announced then
- print("Slot 1 = wither skulls (minimum of 3)!")
- print("Slot 2 = soul sand (minimum of 4)!")
- announced = true
- end
- end
- end
- sleep(1.5) --sleep because why not?
- end
- else
- show_usage()
- end
Advertisement
Add Comment
Please, Sign In to add comment