Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local altarSide = "front"
- local altarInputChestSide = "WEST"
- local altar = peripheral.wrap(altarSide)
- local redstoneSignal = "back"
- local altarFuelLevelToFillAt = .50 -- The percentage of life pool to begin filling the turtle at.
- local modem = peripheral.wrap("left") -- Wrap the modem
- local modemPort =25566 -- The port to communicate to
- local status = " Running"
- function pullItem()
- altar.pullItem(altarInputChestSide, 1, 1, 1)
- end
- function getItemInAltar()
- return altar.getStackInSlot(1)
- end
- function printItemInAltar()
- local stack = altar.getStackInSlot(1)
- for k, v in pairs(stack) do
- print(k.." - ")
- print(v)
- end
- end
- function checkIfTurnedOff()
- if rs.getInput(redstoneSignal) then
- return true
- else
- return false
- end
- end
- function isTable(t) return type(t) == 'table' end
- function printTankInfos()
- local tankinfos = altar.getTankInfo()
- for k, v in pairs(tankinfos) do
- write("["..k.."][")
- if isTable(v) then
- write("Table { \r\n")
- for kk, vv in pairs(v) do
- write(" ["..kk.."]")
- if isTable(vv) then
- write("[Table {\r\n")
- for kkk, vvv in pairs(vv) do
- write(" ["..kkk.."][")
- write(vvv)
- write("]\r\n")
- end
- write(" }]")
- else
- write("["..vv.."]")
- end
- write("\r\n")
- end
- write(" }]")
- else
- write(v.."\r\n")
- end
- end
- write("\r\n")
- end -- End Function
- function getTankLevel() -- Calculates the amount of life pool in the tank
- tankInfos = altar.getTankInfo()
- return tankInfos[1]["contents"]["amount"]
- end
- function getTankCapacity() -- Calculates the capacity of the tank
- tankInfos = altar.getTankInfo()
- return tankInfos[1]["capacity"]
- end
- function printTankStatus()
- print(getTankLevel().." / "..getTankCapacity().." - "..100 * (getTankLevel() / getTankCapacity()).."%")
- end
- function updateStatus()
- modem.transmit(modemPort, 100, getTankLevel().." / "..getTankCapacity().." - "..100 * (getTankLevel() / getTankCapacity()).."% "..status)
- local stack = altar.getStackInSlot(1)
- local stackMessage = ""
- if stack then
- stackMessage = "Item In Altar: "..stack["display_name"]
- else
- stackMessage = "Altar is Empty"
- end
- modem.transmit(modemPort, 102, stackMessage)
- end
- function sendMessage(message)
- modem.transmit(modemPort, 101, message)
- print(message)
- end
- function checkIfTankCapacityFullEnoughByPercent(percent)
- if getTankLevel() / getTankCapacity() > percent then
- --print("Detected we are full enough"..getTankLevel() / getTankCapacity())
- return true
- else
- --print("Detected we don't have enough fuel"..getTankLevel() / getTankCapacity())
- return false
- end
- end
- function waitForEmptyAltar()
- while getItemInAltar() do
- status = "Altar Currently Infusing"
- updateStatus()
- os.sleep(1)
- updateStatus()
- os.sleep(1)
- updateStatus()
- os.sleep(1)
- updateStatus()
- os.sleep(1)
- updateStatus()
- os.sleep(1)
- print("Detected an item in the alter. Sleeping 5 seconds.")
- end
- end
- function run()
- while true do
- printTankStatus()
- updateStatus()
- while not checkIfTurnedOff() do
- sendMessage("Detected we are turned off. waiting for 5 seconds")
- status = "BloodyTurtle Turned Off"
- updateStatus()
- os.sleep(1)
- updateStatus()
- os.sleep(1)
- updateStatus()
- os.sleep(1)
- updateStatus()
- os.sleep(1)
- updateStatus()
- os.sleep(1)
- end
- waitForEmptyAltar() -- Wait until the altar is empty
- updateStatus()
- while not checkIfTankCapacityFullEnoughByPercent(altarFuelLevelToFillAt) do
- sendMessage("detected the altar isn't full enough. waiting.")
- status = "Altar Not Full Enough ["..(100 * altarFuelLevelToFillAt).."%] Required"
- updateStatus()
- os.sleep(1)
- updateStatus()
- os.sleep(1)
- updateStatus()
- os.sleep(1)
- updateStatus()
- os.sleep(1)
- updateStatus()
- os.sleep(1)
- end
- pullItem() -- Pull the 1st thing in the Altar.
- status = "Running"
- sendMessage("Placed an item in the altar")
- updateStatus()
- os.sleep(1)
- updateStatus()
- os.sleep(1)
- updateStatus()
- os.sleep(1)
- updateStatus()
- os.sleep(1)
- updateStatus()
- os.sleep(1)
- end
- end
- run()
- write("\r\nPress any key to continue")
- os.pullEvent("key")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement