Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local modem = peripheral.wrap('left')
- turtle.select(1)
- local crafting = {}
- local tm = {}
- function tm.fw(number)
- modem.transmit(25, 26, turtle.getFuelLevel())
- for i=1,number do
- while not turtle.forward() do
- modem.transmit(27, 28, 'Blocked')
- end
- end
- end
- function tm.bw(number)
- modem.transmit(25, 26, turtle.getFuelLevel())
- for i=1,number do
- while not turtle.back() do
- modem.transmit(27, 28, 'Blocked')
- end
- end
- end
- function tm.up(number)
- modem.transmit(25, 26, turtle.getFuelLevel())
- for i=1,number do
- while not turtle.up() do
- modem.transmit(27, 28, 'Blocked')
- end
- end
- end
- function tm.down(number)
- modem.transmit(25, 26, turtle.getFuelLevel())
- for i=1,number do
- while not turtle.down() do
- modem.transmit(27, 28, 'Blocked')
- end
- end
- end
- function safeDropDown(ammount)
- if ammount == nil then
- ammount = 64
- end
- local currentAmmount = turtle.getItemCount()
- if currentAmmount < ammount then
- turtle.dropDown()
- turtle.select(turtle.getSelectedSlot() + 1)
- safeDropDown(ammount - currentAmmount)
- else
- turtle.dropDown(ammount)
- end
- end
- function crafting.prepare()
- local itemCount = 0
- turtle.transferTo(16)
- turtle.select(turtle.getSelectedSlot() - 1)
- turtle.transferTo(15)
- for i=1,14 do
- itemCount = itemCount + turtle.getItemCount(i)
- end
- local injectors = ( itemCount - turtle.getItemCount(15) ) / turtle.getItemCount(16)
- return injectors
- end
- function crafting.craft(amount1, amount2)
- local injectors = crafting.prepare()
- local toCraft = amount1
- local injectorsDone = 0
- tm.fw(1)
- tm.down(1)
- tm.fw(2)
- tm.up(1)
- tm.fw(2)
- turtle.turnLeft()
- turtle.select(1)
- for i=1,3 do
- for j=1,3 do
- if turtle.getItemCount() == 0 then turtle.select(turtle.getSelectedSlot() + 1) end
- if injectorsDone < injectors then safeDropDown(toCraft) end
- injectorsDone = injectorsDone + 1
- tm.fw(1)
- end
- turtle.turnRight()
- tm.fw(1)
- end
- tm.fw(1)
- turtle.turnRight()
- tm.fw(2)
- while turtle.getItemCount() == 0 or turtle.getSelectedSlot() == 15 or turtle.getSelectedSlot() == 16 do turtle.select(turtle.getSelectedSlot() + 1) end
- turtle.dropDown()
- tm.bw(1)
- turtle.turnLeft()
- tm.fw(4)
- tm.down(1)
- tm.fw(2)
- tm.up(1)
- tm.fw(1)
- turtle.select(16)
- turtle.drop()
- turtle.select(15)
- turtle.drop()
- turtle.turnRight()
- turtle.turnRight()
- turtle.select(1)
- end
- function crafting.idle()
- local prevCount = 0
- while true do
- for i=1,16 do
- data = turtle.getItemDetail(i)
- if data then
- if data.name == 'minecraft:stone' then
- sleep(0.5)
- if prevCount < data.count then
- prevCount = data.count
- elseif data.count == prevCount then
- turtle.select(i)
- crafting.craft(data.count, turtle.getItemCount(i - 1))
- break
- end
- end
- end
- modem.transmit(27, 28, 'Waiting')
- modem.transmit(25, 26, turtle.getFuelLevel())
- sleep(0)
- end
- end
- crafting.idle()
- end
- crafting.idle()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement