Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local fuel_types = {"charcoal", "coal"}
- local container_types = {"mcp_mobius_betterbarrel", "container_chest"}
- local side="bottom"
- local reverse ="up"
- local p=peripheral.wrap(side)
- function isFull()
- if turtle.getFuelLevel() > turtle.getFuelLimit()-100 then
- print("Turtle charged!")
- return true
- else
- return false
- end
- end
- function validWithList(type,list)
- for i=1,#list do
- if list[i]==type then
- return true
- end
- end
- return false
- end
- function isFuel(slot)
- if validWithList(slot.name, fuel_types) then
- print("fuel found.")
- return true
- else
- return false
- end
- end
- function isFuelSource(type)
- if validWithList(type, container_types) then
- print("Sitting on a fuel source.")
- return true
- else
- print("No fuel source down there.")
- return false
- end
- end
- function eatFuel(cont)
- turtle.select(1)
- local stacks = cont.getAllStacks()
- for i, slot in pairs(stacks) do
- if not isFull() and isFuel(slot) then
- cont.pushItemIntoSlot(reverse,i,16,1)
- turtle.refuel()
- end
- end
- end
- function getFuel()
- local charge = turtle.getFuelLevel()
- local max= turtle.getFuelLimit()
- local percent = charge * 100 / max
- print("charge level : "..percent.." ( "..charge.."/ "..max..")")
- return charge
- end
- if isFuelSource(peripheral.getType(side),container_types) then
- print("CHARGING FROM")
- print("name : "..p.getInventoryName())
- print("size : "..p.getInventorySize())
- local lastState = turtle.getFuelLevel()
- while not isFull() do
- eatFuel(p)
- if not ( getFuel() > lastState ) then
- print("Fuel source empty, Stop charging.")
- break
- end
- sleep(1)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement