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 packetSize=16
- 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)
- return validWithList(slot.name, fuel_types)
- end
- function isFuelSource(type)
- if validWithList(type, container_types) then
- --print("valid fuel source")
- return true
- else
- print("Fuel source is not supported!")
- 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,packetSize,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()
- local step = 0.5
- while not isFull() do
- eatFuel(p)
- local charge = getFuel()
- if not ( charge > lastState ) then
- if step<8 then
- step = step + 0.5
- print("Fuel source empty, waiting step="..step)
- else
- print("Fuel source still empty, Stop charging.")
- break
- end
- else
- step=0.5
- end
- lastState = charge
- sleep(step)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement