Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Uses ender chests and floppy disks to transfer data across dimensions.
- -- This program queries the reactor, writes active status, stored energy, current fuel amount, max fuel, and waste to a floppy.
- -- Then the floppy is moved into an ender chest to be read by the querying system.
- -- Placement:
- -- 1. Back of turtle to reactor's ComputerCraft interface.
- -- 2. Enderchest in front of the turtle.
- -- 3. Disk drive on top of turtle
- -- Define whose reactor this is for. This will allow multiple reactor checks to share a disk if necessary.
- reactor_name = "rungok_moon"
- -- Wrap the reactor now.
- reactor = peripheral.wrap("back")
- -- Define reactor stats variable.
- -- Yes, it's a global variable. Dealwithit.jpg
- t_reactor_stats = {
- ["energyStored"] = 0,
- ["fuelAmount"] = 0,
- ["fuelMax"] = 0,
- ["active"] = 0,
- ["waste"] = 0
- }
- function disk_to_chest()
- print("Pulling disk from drive.")
- turtle.suckUp()
- print("Putting disk in ender chest.")
- turtle.drop()
- end
- function disk_to_drive()
- print("Pulling disk from ender chest.")
- -- If we try to pull the disk and the job fails, sleep 1 second before trying again.
- while not turtle.suck() do
- print("Disk pull failed; sleeping for 1 second.")
- os.sleep(1)
- end
- print("Putting disk into drive.")
- turtle.dropUp()
- end
- function pull_reactor_stats()
- t_reactor_stats["active"] = reactor.getActive()
- t_reactor_stats["energyStored"] = reactor.getEnergyStored()
- t_reactor_stats["fuelAmount"] = reactor.getFuelAmount()
- t_reactor_stats["fuelMax"] = reactor.getFuelAmountMax()
- t_reactor_stats["waste"] = reactor.getWasteAmount()
- -- Print results
- -- for key,value in pairs(t_reactor_stats) do print(key,value) end
- end
- function main()
- -- First, we run a job to pull the disk from the drive and put it into the ender chest, just in case things rebooted mid-run.
- -- This will put the disk in the chest even if it is in the turtle's inventory.
- disk_to_chest()
- -- Now we begin the procedure.
- while true do
- -- First, load the disk into the drive.
- disk_to_drive()
- -- Populate the table with the reactor's current stats
- pull_reactor_stats()
- -- Write the results to the disk
- print("Writing reactor stats to disk...")
- reactor_dump = fs.open("/disk/"..reactor_name, "w")
- reactor_dump.write(textutils.serialize(t_reactor_stats))
- reactor_dump.close()
- -- Move the disk back to the ender chest
- disk_to_chest()
- -- Sleep for 60 seconds to save computing cycles and give other systems a chance to query.
- print("Sleeping...")
- os.sleep(60)
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement