MAX_FUEL = 100000 PRINT_REDNET = false MOM_ID = 1 BOB_ID = 2 CHRIS_ID = 3 MARTY_ID = 4 BOT_NAMES = {} BOT_NAMES[MOM_ID] = "MOM" BOT_NAMES[BOB_ID] = "BOB" BOT_NAMES[CHRIS_ID] = "CHRIS" BOT_NAMES[MARTY_ID] = "MARTY" toolsMonitor = nil function setMonitor(monitor) toolsMonitor = monitor end function selectItem(itemName) local currentSlot = turtle.getSelectedSlot() for i=1,16 do local details = turtle.getItemDetail(currentSlot) if details ~= nil and details.name == itemName then turtle.select(currentSlot) return true end currentSlot = (currentSlot % 16) + 1 end return false end -- Consume all compatible fuel in inventory function refuelFromInventory() local fuelOld = turtle.getFuelLevel() local selectedSlot = turtle.getSelectedSlot() for i=1,16 do turtle.select(i) turtle.refuel() end turtle.select(selectedSlot) print("Refueled "..(turtle.getFuelLevel() - fuelOld)..".") sendFuelToMom() end -- input "minecraft:nether_wart" -- output "nether_wart" function cleanName(str) local delimiter = ":" local startIndex = string.find(str, delimiter) + 1 if startIndex == nil then return str end return string.sub(str, startIndex) end -- Don't stop until a iron block is behind the computer function calibrateDirection() for i=1,4 do local hasBlock, infos = turtle.inspect() if hasBlock and infos.name == 'minecraft:iron_block' then tools.uTurn() return true end turtle.turnRight() end print("Calibration block (iron block) not found.") print("An iron block must be behind the bot in order to start") print("Hold CTRL+R to retry") return false end CROP_MATURE_STAGE = { nether_wart = 3, wheat = 7, onions = 7, carrots = 7, potatoes = 7, } function farmLine(nbBlock, noMove, neededItem) for i=1,nbBlock do if noMove ~= true or i ~= 1 then turtle.forward() end local hasBlock, infos = turtle.inspectDown() if hasBlock then infos.name = cleanName(infos.name) if CROP_MATURE_STAGE[infos.name] == nil or CROP_MATURE_STAGE[infos.name] == infos.state.age then turtle.digDown() if (selectItem(neededItem)) then turtle.placeDown() end end else turtle.digDown() if (selectItem(neededItem)) then turtle.placeDown() end end end end function farmLineCane(nbBlock) for i=1, nbBlock do turtle.dig() turtle.forward() turtle.digDown() end end function uTurn() turtle.turnLeft() turtle.turnLeft() end function driftLeft() turtle.turnLeft() turtle.forward() turtle.turnLeft() end function driftRight() turtle.turnRight() turtle.forward() turtle.turnRight() end function forward(numBlock) for i=1,numBlock do turtle.forward() end end function back(numBlock) for i=1,numBlock do turtle.back() end end function dropAll() local selectedSlot = turtle.getSelectedSlot() for i=1,16 do turtle.select(i) turtle.drop() end turtle.select(selectedSlot) end function needFuel() return turtle.getFuelLevel() < turtle.getFuelLimit() * 0.75 end -- Count number of items in inventory function getItemQuantity() local quantity = 0 for i=1,16 do quantity = quantity + turtle.getItemCount(i) end return quantity end function displayFuelBar(fuel, x, y, nbBox) toolsMonitor.setCursorPos(x, y) toolsMonitor.write("FUEL("..fuel.."/"..MAX_FUEL..") ") toolsMonitor.setCursorPos(x, y + 1) nbGreenBoxes = math.floor(fuel * nbBox / MAX_FUEL) toolsMonitor.setBackgroundColor(colors.green) for i=1,nbGreenBoxes do toolsMonitor.write(" ") end toolsMonitor.setBackgroundColor(colors.red) for i=1,(nbBox - nbGreenBoxes) do toolsMonitor.write(" ") end toolsMonitor.setBackgroundColor(colors.black) end -- input 800 -- output "13m20" -- input 30 -- output "30s" function niceTime(seconds) return tostring(seconds).."s" end function writeHighlight(text, x, y, width) toolsMonitor.setCursorPos(x, y) toolsMonitor.write(text) toolsMonitor.setCursorPos(x, y + 1) toolsMonitor.write(string.rep("=", width)) end function sleepAndInformMom(seconds) local toSleep = seconds while toSleep > 0 do sleep(1) toSleep = toSleep - 1 sendToBot(MOM_ID, "s"..toSleep) end end function sendFuelToMom() fuel = turtle.getFuelLevel() sendToBot(MOM_ID, "f"..fuel) end function sendToBot(botId, message) rednet.send(botId, message) if PRINT_REDNET then print("[REDNET] To "..tools.BOT_NAMES[botId]..": \""..message.."\"") end end function receiveFromBot(message) local botId, message = rednet.receive() local botName = tools.BOT_NAMES[botId] if botName == nil then botName = "unknown" end if PRINT_REDNET then print("[REDNET] From "..botName..": \""..message.."\"") end return botId, message end