Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- version = "start.lua 1.1.1"
- pastebinCode = "JVD1RPfg"
- -- http://pastebin.com/JVD1RPfg
- -- origially pasted in 2014. The updated 2018 version is using the original pastebin code: http://pastebin.com/2Zf5an8H
- local function initialise()
- -- create classes/objects
- createCoordObject()
- createFurnaceObject()
- createChestObject()
- createSlotObject()
- createLogfileObject()
- createTreeFarmObject()
- createDigObject()
- createPlaceStorageObject()
- -- set global variables. As each item is identified, set objectives["item"] = true
- objectives = {}
- local items = {}
- items = {"wood","wood2","dirt","cobble","stone","saplings","saplings2","seeds","sand","gravel","clay",
- "apples","coal","charcoal","ironore","?ironore","goldore","?goldore","iron","?iron","gold","?gold",
- "redstone","redstone block","?diamonds","diamonds","emeralds","sugar cane","planks","planks2","chests","sticks",
- "torches","furnaces","signs","item1","item2","item3","item4","item5","item6","item7","item8",
- "fences","nuggets","buckets","paper","computer","crafting table","diamond pickaxe","glass","glass panes","floppy disk",
- "disk drive","turtle","crafty mining turtle","?moss stone","moss stone","walls","obsidian","sandstone",
- "?lapis","lapis","lapis block","flowers","roses","red mushrooms","brown mushrooms"}
- for key, value in ipairs(items) do
- objectives[value] = false
- end
- --special objectives as script progresses:
- objectives["smelt iron"] = false -- confirms ironore identified, iron and buckets crafted
- objectives["smelt gold"] = false -- confirms goldore identified, crafted to gold nuggets and stored in extended storage
- objectives["place extended storage"] = false -- 5 chests placed behind starting point to store goldore, lapis, obsidian, mossy cobblestone
- objectives["choose wood"] = false -- After harvestAllTrees() finished, treeFarm tree type identified, wood2 and saplings2 eliminated
- objectives["goMining1"] = false -- During harvestAllTrees()
- objectives["clear treefarm"] = false -- Treefarm cleared and planted
- objectives["complete sand"] = false -- min 7 sand found, no more needed
- objectives["complete sugar cane"] = false -- min 3 sugar cane found, no more needed
- objectives["diamond pickaxe"] = false -- Diamond pickaxe created as part of identifying diamonds. Stored in storagePickaxes
- objectives["pave treefarm"] = false -- Decorates Treefarm, as not enough cobble when first planted
- objectives["pave extendedStorage"] = false -- Decorates extendedStorage area, if not enough cobble when created
- -- 10 mineshafts down to level 40 during harvestAllTrees() set to true if shaft sunk
- -- shaft may not be mined if insufficient fuel. Check for mined shafts not yet implemented
- mineshaft = {}
- for i = 1, 10 do
- mineshaft[i] = false
- end
- startTime = os.time() -- used to time functions, and allow adjustments to return to base every 24 hours minimum
- end
- function attack()
- local mobAttacked = false
- local itemCount = {}
- for i = 1, 16 do
- itemCount[i] = turtle.getItemCount(i)
- end
- turtle.select(1)
- if turtle.attack() then
- saveToLog("attack: Mob attacked in front!", true, false)
- sleep(1.5)
- while turtle.attack() do --in case mob in front
- saveToLog("attack: Mob attacked in front again!", true, false)
- sleep(1.5)
- end
- mobAttacked = true
- end
- if turtle.attackUp() then
- saveToLog("attack: Mob attacked above!", true, false)
- sleep(1.5)
- while turtle.attackUp() do --in case mob in front
- saveToLog("attack: Mob attacked above again!", true, false)
- sleep(1.5)
- end
- mobAttacked = true
- end
- if turtle.attackDown() then
- saveToLog("attack: Mob attacked below!", true, false)
- sleep(1.5)
- while turtle.attackDown() do --in case mob in front
- saveToLog("attack: Mob attacked below again!", true, false)
- sleep(1.5)
- end
- mobAttacked = true
- end
- if mobAttacked then --remove any mob drops
- for i = 1, 16 do
- if itemCount[i] == 0 then --check only previously empty slots
- if turtle.getItemCount(i) > 0 then
- turtle.select(i)
- while turtle.dropUp() do
- saveToLog ("attack: dumping mob drops", true, false)
- end
- end
- end
- end
- end
- return mobAttacked
- end
- function back(steps, useSlot, itemList)
- useSlot = useSlot or 1
- itemList = itemList or ""
- for i = 1, steps do
- if not turtle.back() then --cant move back
- turnRight(2)
- forward(1, useSlot, itemList)
- turnRight(2)
- end
- changeCoords("back")
- end
- end
- function changeCoords(direction)
- --[[0 = go south (z increases)
- 1 = go west (x decreases)
- 2 = go north (z decreases
- 3 = go east (x increases)]]--
- if direction == "forward" then
- if location:getFacing() == 0 then
- --zCoord = zCoord + 1
- location:setZ(location:getZ() + 1)
- elseif location:getFacing() == 1 then
- --xCoord = xCoord - 1
- location:setX(location:getX() - 1)
- elseif location:getFacing() == 2 then
- --zCoord = zCoord - 1
- location:setZ(location:getZ() - 1)
- else
- --xCoord = xCoord + 1
- location:setX(location:getX() + 1)
- end
- elseif direction == "back" then
- if location:getFacing() == 0 then
- --zCoord = zCoord - 1
- location:setZ(location:getZ() - 1)
- elseif location:getFacing() == 1 then
- --xCoord = xCoord + 1
- location:setX(location:getX() + 1)
- elseif location:getFacing() == 2 then
- --zCoord = zCoord + 1
- location:setZ(location:getZ() + 1)
- else
- --xCoord = xCoord - 1
- location:setX(location:getX() - 1)
- end
- end
- end
- function changeDirection(direction)
- --changeDirection("faceMine")
- --changeDirection("faceExtraStorage")
- if direction == "faceMine" then
- while location:getFacing() ~= coordHome:getFacing() do
- turnRight(1)
- end
- else
- if location:getFacing() == coordHome:getFacing() then
- turnRight(2)
- end
- end
- end
- function checkBedrock(itemList)
- local success = false
- if turtle.detect() then --block in front so not air/water/lava
- if not dig.digNew{self = dig, checkForItems = itemList, callFrom = "checkBedrock"} then --block not broken, so must be bedrock
- success = true
- end
- end
- return success
- end
- function checkDiamonds()
- local numDiamonds = 0
- if objectives["diamond pickaxe"] then
- numDiamonds = 3
- end
- if slot:getItemSlot("diamonds") > 0 then
- numDiamonds = numDiamonds + turtle.getItemCount(slot:getItemSlot("diamonds"))
- end
- return numDiamonds
- end
- function checkDigDown()
- local useSlot = 0
- local useItem = ""
- local useAmount = 0
- local yCoordTemp = 0
- local checkList = {}
- local result = "onLand"
- checkList[1] = "wood"
- checkList[2] = "wood2"
- checkList[3] = "sand"
- --checkList[4] = "item"
- turtle.select(1)
- while not turtle.detectDown() do --could be water, lava or air
- saveToLog("checkDigDown: checking for water", true)
- if checkWater("down") then -- water found.
- result = "onWater"
- break
- else --no water so go down
- --check if in a cave or ravine
- result = "onLand"
- if location:getY() <= 55 then
- --place block and exit
- saveToLog("checkDigDown: Ravine or cave detected, building bridge")
- if turtle.getItemCount(slot:getItemSlot("cobble")) > 1 then
- turtle.select(slot:getItemSlot("cobble"))
- elseif turtle.getItemCount(slot:getItemSlot("dirt")) > 1 then
- turtle.select(slot:getItemSlot("dirt"))
- end
- turtle.placeDown()
- break
- end
- down(1, 1)
- saveToLog("checkDigDown: Moved down y = "..location:getY(), false)
- end
- end --block underneath at bottom of air/water, ready to dig or check
- --see if block below is known
- saveToLog("checkDigDown: at base level "..result, false)
- if result == "onLand" then --default
- useSlot, useAmount, useItem = compareBlock("down", checkList, 3) --does block below match wood,wood2,sand
- turtle.select(1)
- -- if wood, wood2, harvest
- if useItem == "wood" or useItem == "wood2" then
- saveToLog("checkDigDown: digDown: "..useItem, false)
- --turtle.select(1)
- turtle.select(useSlot)
- while turtle.compareDown() do
- down(1, 1) --will automatically dig
- turtle.select(useSlot)
- end
- elseif useItem == "sand" then
- yCoordTemp = location:getY()
- if turtle.getItemCount(useSlot) < 8 then
- turtle.select(useSlot)
- while turtle.compareDown() do
- saveToLog("checkDigDown: compareDown = "..useItem, false)
- down(1, 1, "sand,gravel", "checkDigDown")
- turtle.select(useSlot)
- end
- turtle.select(slot:getItemSlot("dirt"))
- while location:getY() < yCoordTemp do
- up(1, 1)
- if turtle.getItemCount(slot:getItemSlot("dirt")) > 0 then
- turtle.placeDown()
- end
- end
- else
- saveToLog("checkDigDown: digDown: sand found but not mined", false)
- end
- elseif string.find(useItem, "item") ~= nil then
- dig.digNew{self = dig, direction = "down", checkForItems = "sand", callFrom = "checkDigDown"}
- end
- end
- return result --"onLand", "onWater"
- end
- function checkDigUp()
- while turtle.detect() do --if block in front move up
- if turtle.detectUp() then
- dig.digNew{self = dig, direction = "up", slotNo = 1, checkForItems = "wood2,saplings", callFrom = "checkDigUp"}
- if dig:getSuccess() then --success digging. If dirt/grass itemcount ++
- --see if 1 item in slot 16 matches anything
- if dig:getDugItem() == "wood2" then
- saveToLog("harvesting new tree type, wood2", false)
- harvestTree("wood2")
- break
- end
- end
- end
- up(1, 1)
- end
- end
- function checkForLooseSaplings()
- --pick up loose ?saplings
- dig.digNew{self = dig, suck = true, checkForItems = "saplings", callFrom = "checkForLooseSaplings"} --forward, slot1 by default
- end
- function checkGravel()
- --[[place gravel repeatedly. eventually will produce flint
- which cannot be placed, need 2 blocks for comparison]]--
- local tempyCoord = location:getY()
- local emptySlot = 0
- local slotCount = 0
- local reRun = false
- local doBreak = false
- local gravelFound = false
- local sTime = os.time()
- if slot:getItemSlot("gravel") == 0 or slot:getItemSlot("sand") == 0 then
- if slot:getItemSlot("gravel") == 0 and slot:getItemSlot("sand") == 0 then
- saveToLog("checkGravel: testing for gravel and sand")
- elseif slot:getItemSlot("gravel") == 0 then
- saveToLog("checkGravel: sand already found, testing for gravel")
- else
- saveToLog("checkGravel: gravel already found, testing for sand")
- end
- emptySlot = getFirstEmptySlot(true)
- saveToLog("checkGravel: testing slot "..slot:getLeastUnknownItemSlot().." to "..slot:getMostUnknownItemSlot(), false)
- --gravel, iron ore, sand, coal may have been found
- --clear the area
- saveToLog("checkGravel: clearing test area", true)
- dig.digNew{self = dig, direction = "forward", callFrom = "checkGravel"}
- up(1, 1) --move up 1 place
- dig.digNew{self = dig, direction = "forward", callFrom = "checkGravel"}
- repeat
- reRun = false
- if slot:getLeastUnknownItemSlot() > 0 then --updated when sortInventory(true) is run
- for i = slot:getLeastUnknownItemSlot(), slot:getMostUnknownItemSlot() do
- saveToLog("checkGravel: testing slot "..i.." ("..slot:getSlotContains(i)..")", true)
- turtle.select(i)
- saveToLog("Placing ? sand/gravel..")
- if turtle.place() then --sand, gravel, iron ore,
- saveToLog("checkGravel: ? sand/gravel placed, waiting for drop", true)
- sleep(.5)
- if turtle.detect() then --cobble, ironore
- saveToLog("checkGravel: slot "..i.." is not gravel or sand", true)
- dig.digNew{self = dig, callFrom = "checkGravel"}
- if slot:getItemSlot("cobble") > 0 then --cobble known
- slot.update{self = slot, slotNo = i, newItem = "?ironore"}
- doBreak = true
- reRun = true
- break
- --else
- --continue with for loop (no break)
- --reRun already false
- end
- else
- saveToLog("checkGravel: gravel / sand fell")
- down(1)
- if slot:getItemSlot("gravel") > 0 then --gravel found
- slot.update{self = slot, slotNo = i, newItem = "sand"}
- dig.digNew{self = dig, callFrom = "checkGravel"} --will recover sand
- else
- if turtle.getItemCount(i) > 0 then -- at least 1 ?gravel /?sand remaining
- slotCount = turtle.getItemCount(i)
- dig.digNew{self = dig, callFrom = "checkGravel"} --will recover either sand, gravel or flint, which would go to emptySlot
- if turtle.getItemCount(i) == slotCount then -- flint dug
- turtle.select(emptySlot)
- while turtle.drop() do --drop flint
- saveToLog("checkGravel: Dumping flint Found in slot "..emptySlot, false)
- end
- slot.update{self = slot, slotNo = emptySlot, delete = true}
- slot.update{self = slot, slotNo = i, newItem = "gravel"}
- else -- gravel or sand dug
- if slot:getItemSlot("sand") == 0 then -- sand unknown
- saveToLog("Checking if slot "..i.." is gravel")
- turtle.select(i)
- for j = 1, 100 do
- if turtle.place() then --gravel placed
- turtle.dig()
- if turtle.getItemCount(emptySlot) > 0 then --flint found
- saveToLog("checkGravel: Gravel Found in slot "..i, true)
- slot.update{self = slot, slotNo = i, newItem = "gravel"}
- turtle.select(emptySlot)
- turnRight(2)
- while turtle.drop() do --drop flint
- saveToLog("checkGravel: Dumping flint Found in slot "..emptySlot, false)
- end
- turnRight(2)
- gravelFound = true
- break
- end
- end
- end
- if not gravelFound then
- saveToLog("checkGravel: Sand Found in slot "..i, true)
- slot.update{self = slot, slotNo = i, newItem = "sand"}
- end
- else --sand known therefore gravel just dug
- saveToLog("checkGravel: Gravel Found in slot "..i, true)
- slot.update{self = slot, slotNo = i, newItem = "gravel"}
- end
- end
- else -- only 1 remaining so dump anyway
- saveToLog("checkGravel: only one item in slot "..i, true)
- turnRight(2)
- while turtle.drop() do --drop flint
- saveToLog("checkGravel: Dumping item in slot "..emptySlot, false)
- end
- turnRight(2)
- slot.update{self = slot, slotNo = i, delete = true}
- end
- end
- doBreak = true
- reRun = true
- up(1)-- go up again ready for testing next item (gravel/sand/flint only -NOT cobble)
- break
- end
- else -- flint, coal
- if turtle.refuel(0) then
- slot.update{self = slot, slotNo = i, newItem = "coal"}
- saveToLog("checkGravel: coal found in slot "..i, false)
- else
- turnRight(2)
- while turtle.drop() do --drop flint
- saveToLog("checkGravel: Dumping flint Found in slot "..i, false)
- end
- turnRight(2)
- slot.update{self = slot, slotNo = i, delete = true}
- end
- doBreak = true
- reRun = true
- break
- end
- end
- if doBreak then
- sortInventory(true)
- end
- end
- until not reRun
- while tempyCoord < location:getY() do
- down(1)
- end
- saveToLog("checkGravel started at "..textutils.formatTime(sTime, true).." finished at "..textutils.formatTime(os.time(), true), false)
- else
- saveToLog("checkGravel: sand and gravel already known", true)
- end
- end
- function checkItems(arg)
- --checkItems{keepTorches = 2 + torchesNeeded, keepSigns = 1}
- --checkItems{keepTorches = 2}
- --checkItems{keepSticks = 0, keepTorches = 16, keepSigns = 0}
- local numSticksOnboard = 0
- local numTorchesOnboard = 0
- local numSignsOnboard = 0
- local numWoodStored = 0
- local numSticksStored = 0
- local numTorchesStored = 0
- local numSignsStored = 0
- local getTorches = false
- local getSigns = false
- local makeTorches = false
- local makeSigns = false
- arg.keepSticks = arg.keepSticks or 0
- arg.keepTorches = arg.keepTorches or 0
- arg.keepSigns = arg.keepSigns or 0
- arg.keepWood = arg.keepWood or 64
- changeDirection("faceMine")
- saveToLog("checkItems: keepWood = "..arg.keepWood..
- " keepSticks = "..tostring(arg.keepSticks)..
- " keepTorches = "..tostring(arg.keepTorches)..
- " keepSigns = "..tostring(arg.keepSigns), false)
- numTorchesStored = storageTorches:getItemCount("torches")
- numSignsStored = storageSigns:getItemCount("signs")
- numSticksStored = storageSticks:getItemCount("sticks")
- numWoodStored = storageWood:getItemCount("wood")
- if slot:getItemSlot("torches") > 0 then
- numTorchesOnboard = turtle.getItemCount(slot:getItemSlot("torches"))
- end
- if slot:getItemSlot("signs") > 0 then
- numSignsOnboard = turtle.getItemCount(slot:getItemSlot("signs"))
- end
- if slot:getItemSlot("sticks") > 0 then
- numSticksOnboard = turtle.getItemCount(slot:getItemSlot("sticks"))
- end
- --check if any signs or torches need to be crafted
- --if so store torches and signs first, craft, then re-stock
- if arg.keepTorches > 0 then
- if numTorchesOnboard >= arg.keepTorches then
- saveToLog("checkItems: "..numTorchesOnboard.." torches already in stock", false)
- success = true
- elseif numTorchesStored >= arg.keepTorches then
- saveToLog("checkItems: "..numTorchesStored.." torches are in storage", false)
- getTorches = true
- elseif numTorchesOnboard + numTorchesStored >= arg.keepTorches then
- saveToLog("checkItems: "..numTorchesOnboard + numTorchesStored.." torches are in stock / storage", false)
- getTorches = true
- else -- not enough onBoard or store
- saveToLog("checkItems: insufficient torches in stock / store, crafting more", false)
- makeTorches = true
- end
- end
- if arg.keepSigns > 0 then
- if numSignsOnboard >= arg.keepSigns then
- saveToLog("checkItems: "..numSignsOnboard.." signs already in stock", false)
- success = true
- elseif numSignsStored >= arg.keepSigns then
- saveToLog("checkItems: "..numSignsStored.." signs are in storage", false)
- getSigns = true
- elseif numSignsOnboard + numSignsStored >= arg.keepSigns then
- saveToLog("checkItems: "..numSignsOnboard + numSignsStored.." signs are in stock / storage", false)
- getSigns = true
- else -- not enough onBoard or store
- saveToLog("checkItems: insufficient signs in stock / store, crafting more", false)
- makeSigns = true
- end
- end
- if arg.keepSticks > 0 then
- if numSticksOnboard >= arg.keepSticks then
- saveToLog("checkItems: "..numSticksOnboard.." sticks already in stock", false)
- success = true
- elseif numSticksStored >= arg.keepSticks then
- saveToLog("checkItems: "..numSticksStored.." sticks are in storage", false)
- getSticks = true
- elseif numSticksOnboard + numSticksStored >= arg.keepSticks then
- saveToLog("checkItems: "..numSticksOnboard + numSticksStored.." sticks are in stock / storage", false)
- getSticks = true
- else -- not enough onBoard or store
- saveToLog("checkItems: insufficient sticks in stock / store, crafting more", false)
- makeSticks = true
- end
- end
- if makeSticks then --store existing torches/signs first
- if placeStorage:getStoragePlaced("torches") then
- storeItem{toStore = storageTorches, item = "torches", quantity = 0, updateSlot = true, doSort = true}
- if arg.keepTorches > 0 then
- getTorches = true
- end
- end
- if placeStorage:getStoragePlaced("signs") then
- forward(2, 1)
- turnRight(2)
- storeItem{toStore = storageSigns, item = "signs", quantity = 0, updateSlot = true, doSort = true}
- if arg.keepSigns > 0 then
- getSigns = true
- end
- forward(2, 1)
- turnRight(2)
- end
- if numSticksStored > 0 then --get stored sticks
- forward(4, 1)
- turnRight(2)
- getItemsFromStorage{fromStore = storageSticks, item1 = "sticks"}
- forward(4, 1)
- turnRight(2)
- end
- craftSticks(arg.keepSticks - numSticksOnboard)
- end
- if makeSigns then --store existing torches first
- if placeStorage:getStoragePlaced("torches") then
- storeItem{toStore = storageTorches, item = "torches", quantity = 0, updateSlot = true, doSort = true}
- if arg.keepTorches > 0 then
- getTorches = true
- end
- end
- if numSignsStored > 0 then --get stored signs
- forward(2, 1)
- turnRight(2)
- getItemsFromStorage{fromStore = storageSigns, item1 = "signs"}
- forward(2, 1)
- turnRight(2)
- end
- craftSigns(3, true)
- end
- if makeTorches then --store existing signs first
- if placeStorage:getStoragePlaced("signs") then
- forward(2, 1)
- turnRight(2)
- storeItem{toStore = storageSigns, item = "signs", quantity = 0, updateSlot = true, doSort = true}
- if arg.keepSigns > 0 then
- getSigns = true
- end
- forward(2, 1)
- turnRight(2)
- end
- if numTorchesStored > 0 then --get stored torches
- getItemsFromStorage{fromStore = storageTorches, item1 = "torches"}
- end
- craftTorches(arg.keepTorches - numTorchesOnboard)
- end
- if getSticks then
- forward(4, 1)
- getItemsFromStorage{fromStore = storageSticks, item1 = "sticks"}
- back(4)
- end
- if slot:getItemSlot("sticks") > 0 then
- numSticksOnboard = turtle.getItemCount(slot:getItemSlot("sticks"))
- end
- if numSticksOnboard - arg.keepSticks > 0 then --store sticks
- if placeStorage:getStoragePlaced("sticks") then
- forward(4, 1)
- turnRight(2)
- saveToLog("checkItems: toStore = "..storageSticks:getStoreName().." storing "..numSticksOnboard - arg.keepSticks.." sticks", true)
- if arg.keepSticks > 0 then
- storeItem{toStore = storageSticks, item = "sticks", quantity = numSticksOnboard - arg.keepSticks, updateSlot = true, doSort = false}
- else
- storeItem{toStore = storageSticks, item = "sticks", quantity = 0, updateSlot = true, doSort = true}
- end
- forward(4, 1)
- turnRight(2)
- end
- end
- if getTorches then
- getItemsFromStorage{fromStore = storageTorches, item1 = "torches"}
- end
- if slot:getItemSlot("torches") > 0 then
- numTorchesOnboard = turtle.getItemCount(slot:getItemSlot("torches"))
- end
- if numTorchesOnboard - arg.keepTorches > 0 then
- if placeStorage:getStoragePlaced("torches") then
- saveToLog("checkItems: storing "..numTorchesOnboard - arg.keepTorches.." torches in storageTorches", true)
- if arg.keepTorches > 0 then
- storeItem{toStore = storageTorches, item = "torches", quantity = numTorchesOnboard - arg.keepTorches, updateSlot = true, doSort = false}
- else
- storeItem{toStore = storageTorches, item = "torches", quantity = 0, updateSlot = true, doSort = true}
- end
- end
- end
- if getSigns then
- forward(2, 1)
- turnRight(2)
- getItemsFromStorage{fromStore = storageSigns, item1 = "signs"}
- forward(2, 1)
- turnRight(2)
- end
- if slot:getItemSlot("signs") > 0 then
- numSignsOnboard = turtle.getItemCount(slot:getItemSlot("signs"))
- end
- if numSignsOnboard - arg.keepSigns > 0 then
- if placeStorage:getStoragePlaced("signs") then
- forward(2, 1)
- turnRight(2)
- saveToLog("checkItems: storing "..numSignsOnboard - arg.keepSigns.." signs in storageSigns", true)
- if arg.keepSigns > 0 then
- storeItem{toStore = storageSigns, item = "signs", quantity = numSignsOnboard - arg.keepSigns, updateSlot = true, doSort = false}
- else
- storeItem{toStore = storageSigns, item = "signs", quantity = 0, updateSlot = true, doSort = true}
- end
- forward(2, 1)
- turnRight(2)
- end
- end
- if slot:getItemSlot("wood") > 0 then
- numWoodOnboard = turtle.getItemCount(slot:getItemSlot("wood"))
- end
- if arg.keepWood == 0 and slot:getItemSlot("wood") > 0 then --mining run, no wood onboard
- if placeStorage:getStoragePlaced("wood") then
- forward(6, 1)
- saveToLog("checkItems: storing "..numWoodOnboard.." wood in storageWood", true)
- storeItem{toStore = storageWood, item = "wood", quantity = 0, updateSlot = true, doSort = true}
- turnRight(2)
- forward(6, 1)
- turnRight(2)
- end
- end
- end
- function checkLapis()
- local success = false
- --assume on ground
- changeDirection("faceMine")
- if not objectives["lapis"] then
- sortInventory(true)
- if slot:getMostUnknownItemSlot() > 0 then
- saveToLog("checkLapis: slot with most items = "..slot:getMostUnknownItemSlot().." with "..turtle.getItemCount(slot:getMostUnknownItemSlot()).." items", true)
- for i = slot:getMostUnknownItemSlot(), slot:getLeastUnknownItemSlot(), - 1 do
- turtle.select(i)
- saveToLog("checkLapis: checking "..slot:getSlotContains(i), true)
- if turtle.getItemCount(i) > 10 then
- changeDirection("faceExtraStorage")
- if turtle.place() then
- dig.digNew{self = dig, callFrom = "checkLapis"}
- changeDirection("faceMine")
- else --lapis, redstone,coal
- if objectives["redstone"] and slot:getItemSlot("coal") > 0 then
- saveToLog("checkLapis: lapis found", true)
- slot.update{self = slot, slotNo = i, newItem = "lapis"}
- objectives["lapis"] = true
- success = true
- break
- end
- end
- end
- end
- else
- saveToLog("checkLapis: no unknown items to check", true)
- end
- if success then
- sortInventory(true)
- else
- saveToLog("checkLapis: not found or amount onboard below 10", true)
- end
- else
- saveToLog("checkLapis: lapis already found and in storage", false)
- if slot:getItemSlot("diamonds") == 0 then
- if slot:getMostUnknownItemSlot() > 0 then
- saveToLog("checkLapis: slot with most items = "..slot:getMostUnknownItemSlot().." with "..turtle.getItemCount(slot:getMostUnknownItemSlot()).." items", true)
- for i = slot:getMostUnknownItemSlot(), slot:getLeastUnknownItemSlot(), - 1 do
- turtle.select(i)
- saveToLog("checkLapis: checking "..slot:getSlotContains(i), true)
- if turtle.getItemCount(i) > 3 then
- changeDirection("faceExtraStorage")
- if turtle.place() then
- dig.digNew{self = dig, callFrom = "checkLapis"}
- changeDirection("faceMine")
- else --diamonds, redstone,coal
- if objectives["redstone"] and slot:getItemSlot("coal") > 0 then
- saveToLog("checkLapis: ?diamonds found", true)
- slot.update{self = slot, slotNo = i, newItem = "?diamonds"}
- checkItems{keepTorches = 0, keepSigns = 0, keepSticks = 2}
- if craft{craftItem = "diamond pickaxe", craftQuantity = 1, sourceItem1 = "sticks", sourceItem2 = "?diamonds", destSlot = 0} then
- saveToLog("Pickaxe crafted", true)
- slot.update{self = slot, item = "?diamonds", newItem = "diamonds"}
- itemFound = "diamonds"
- objectives["diamonds"] = true
- success = true
- break
- end
- end
- end
- end
- end
- else
- saveToLog("checkLapis: no unknown items to check", true)
- end
- end
- success = true
- end
- changeDirection("faceMine")
- return success
- end
- function checkMetal(useSlot)
- local result = ""
- local doContinue = true
- local doSort = false
- local tempItem = ""
- useSlot = useSlot or 0
- --checking for ironore and goldore
- --assume on ground
- changeDirection("faceMine")
- if objectives["smelt iron"] and objectives["smelt gold"] then --iron and gold discovered so dont bother
- doContinue = false
- end
- if slot:getItemSlot("?ironore") > 0 then --ironore provisionally identified, not enough to smelt / storageIronore not in place
- if placeStorage:getStoragePlaced("ironore") then -- ok to smelt iron
- if turtle.getItemCount(slot:getItemSlot("?ironore")) > 4 then --smelt to ?iron
- saveToLog("checkMetal: attempting to smelt iron", true)
- if smelt("?ironore", 4) then
- saveToLog("checkMetal: smelt succeeded, ?iron created", true)
- if craft{craftItem = "buckets", craftQuantity = 1, sourceItem1 = "?iron", destSlot = 0} then
- if slot:getItemCount("buckets") == 1 then
- slot.update{self = slot, item = "?iron", newItem = "iron"}
- slot.update{self = slot, item = "?ironore", newItem = "ironore"}
- forward(8) --over storageIronore
- storeItem{toStore = storageIronore, item = "iron", quantity = 0, updateSlot = true, doSort = true}
- storeItem{toStore = storageIronore, item = "buckets", quantity = 0, updateSlot = true, doSort = true}
- objectives["smelt iron"] = true
- turnRight(2)
- forward(8)
- turnRight(2)
- result = "ironore"
- saveToLog("checkMetal: iron and ironore confirmed", true)
- doSort = true
- doContinue = false
- else -- sand->glass->glass bottle x3
- turtle.select(slot:getItemSlot("buckets"))
- while turtle.drop() do
- saveToLog("checkMetal: glass bottles dumped", true)
- end
- slot.update{self = slot, item = "buckets", delete = true}
- sortInventory(true)
- slot.update{self = slot, item = "?iron", newItem = "glass"}
- slot.update{self = slot, item = "?ironore", newItem = "sand"}
- saveToLog("checkMetal: ?iron and ?ironore renamed as glass and sand", true)
- end
- end
- else
- slot.update{self = slot, item = "?ironore", newItem = slot:getFreeUnknownItem()}
- end
- end
- end
- end
- if slot:getItemSlot("?goldore") > 0 then --goldore provisionally identified, not enough to smelt / storageIronore not in place
- if turtle.getItemCount(slot:getItemSlot("?goldore")) > 1 then
- if placeStorage:getStoragePlaced("ironore") then -- ok to smelt gold
- saveToLog("checkMetal: attempting to smelt gold", true)
- if smelt("?goldore", 1) then
- saveToLog("checkMetal: smelt succeeded, ?gold created", true)
- if craft{craftItem = "nuggets", craftQuantity = 9, sourceItem1 = "?gold", destSlot = 0} then
- slot.update{self = slot, item = "?goldore", newItem = "goldore"}
- --[[turtle.select(slot:getItemSlot("nuggets"))
- while turtle.drop() do
- saveToLog("checkMetal: gold nuggets dumped", true)
- end
- slot.update{self = slot, item = "nuggets", delete = true}]]--
- objectives["smelt gold"] = true
- result = "goldore"
- doSort = true
- doContinue = false
- end
- else
- slot.update{self = slot, item = "?ironore", newItem = slot:getFreeUnknownItem()}
- end
- end
- end
- end
- if doContinue then -- either gold or iron not known
- if useSlot > 0 then --only check one item for gold as called from identifyItems
- saveToLog("checkMetal: testing item in slot "..useSlot, true)
- if turtle.getItemCount(useSlot) > 1 then --smelt to ?gold
- if not objectives["smelt gold"] then
- tempItem = slot:getSlotContains(useSlot)
- slot.update{self = slot, slotNo = useSlot, newItem = "?goldore"}
- saveToLog("checkMetal: gold ore provisionally identified from "..tempItem, true)
- if smelt("?goldore", 1) then
- saveToLog("checkMetal: smelt succeeded, ?gold created", true)
- if craft{craftItem = "nuggets", craftQuantity = 9, sourceItem1 = "?gold", destSlot = 0} then
- slot.update{self = slot, item = "?goldore", newItem = "goldore"}
- objectives["smelt gold"] = true
- result = "goldore"
- end
- else
- saveToLog("checkMetal: gold not smelted from "..tempItem, true)
- slot.update{self = slot, item = "?goldore", newItem = tempItem}
- result = ""
- end
- end
- end
- else
- if slot:getMostUnknownItemSlot() > 0 then
- saveToLog("checkMetal: slot with most items = "..slot:getMostUnknownItemSlot().." with "..turtle.getItemCount(slot:getMostUnknownItemSlot()).." items", true)
- for i = slot:getMostUnknownItemSlot(), slot:getLeastUnknownItemSlot(), -1 do
- if turtle.getItemCount(i) > 1 then
- turtle.select(i)
- if turtle.place() then --iron/gold/obsidian ? redstone
- if turtle.compare() then -- not redstone could be iron, gold, obsidian, moss stone
- --iron most likely next item, then gold
- dig.digNew{self = dig, slotNo = i, callFrom = "checkMetal"}
- --if slot:getItemSlot("ironore") == 0 then --not already found
- if not objectives["smelt iron"] then
- slot.update{self = slot, slotNo = i, newItem = "?ironore"}
- saveToLog("checkMetal: iron ore provisionally identified", true)
- result = "?ironore"
- if placeStorage:getStoragePlaced("ironore") then -- ok to smelt iron
- if turtle.getItemCount(slot:getItemSlot("?ironore")) > 4 then --smelt to ?iron
- saveToLog("checkMetal: attempting to smelt iron", true)
- if smelt("?ironore", 4) then
- saveToLog("checkMetal: smelt succeeded, ?iron created", true)
- if craft{craftItem = "buckets", craftQuantity = 1, sourceItem1 = "?iron", destSlot = 0} then
- if slot:getItemCount("buckets") == 1 then
- slot.update{self = slot, item = "?iron", newItem = "iron"}
- slot.update{self = slot, item = "?ironore", newItem = "ironore"}
- forward(8) --over storageIronore
- storeItem{toStore = storageIronore, item = "iron", quantity = 0, updateSlot = true, doSort = true}
- storeItem{toStore = storageIronore, item = "buckets", quantity = 0, updateSlot = true, doSort = true}
- objectives["smelt iron"] = true
- turnRight(2)
- forward(8)
- turnRight(2)
- result = "ironore"
- saveToLog("checkMetal: iron and ironore confirmed", true)
- doSort = true
- break
- else -- sand->glass->glass bottle x3
- turtle.select(slot:getItemSlot("buckets"))
- while turtle.drop() do
- saveToLog("checkMetal: glass bottles dumped", true)
- end
- slot.update{self = slot, item = "buckets", delete = true}
- sortInventory(true)
- slot.update{self = slot, item = "?iron", newItem = "glass"}
- slot.update{self = slot, item = "?ironore", newItem = "sand"}
- saveToLog("checkMetal: ?iron and ?ironore renamed as glass and sand", true)
- end
- end
- else
- slot.update{self = slot, item = "?ironore", newItem = slot:getFreeUnknownItem()}
- end
- end
- end
- --elseif slot:getItemSlot("goldore") == 0 then -- ironore found so check for gold
- elseif not objectives["smelt gold"] then
- tempItem = slot:getSlotContains(i)
- slot.update{self = slot, slotNo = i, newItem = "?goldore"}
- saveToLog("checkMetal: gold ore provisionally identified from "..tempItem, true)
- result = "?goldore"
- if placeStorage:getStoragePlaced("ironore") then -- ok to smelt iron
- if turtle.getItemCount(slot:getItemSlot("?goldore")) > 1 then --smelt to ?gold
- saveToLog("checkMetal: attempting to smelt gold", true)
- if smelt("?goldore", 1) then
- saveToLog("checkMetal: smelt succeeded, ?gold created", true)
- if craft{craftItem = "nuggets", craftQuantity = 9, sourceItem1 = "?gold", destSlot = 0} then
- slot.update{self = slot, item = "?goldore", newItem = "goldore"}
- --[[turtle.select(slot:getItemSlot("nuggets"))
- while turtle.drop() do
- saveToLog("checkMetal: gold nuggets dumped", true)
- end
- slot.update{self = slot, item = "nuggets", delete = true}]]--
- objectives["smelt gold"] = true
- result = "goldore"
- doSort = true
- break
- end
- else
- saveToLog("checkMetal: gold not smelted from "..tempItem.." trying next unknown item", true)
- slot.update{self = slot, item = "?goldore", newItem = tempItem}
- result = ""
- end
- end
- end
- end
- else -- did not compare to placed block
- saveToLog("checkMetal: redstone confirmed - did not compare to placed block", true)
- dig.digNew{self = dig, slotNo = i, callFrom = "checkMetal"}
- slot.update{self = slot, slotNo = i, newItem = "redstone"}
- doSort = true
- break
- end
- else --not placed, could be coal
- if slot:getItemSlot("coal") == 0 then
- if turtle.refuel(1) then
- slot.update{self = slot, slotNo = i, newItem = "coal"}
- doSort = true
- break
- end
- end
- end
- end
- end -- end for loop
- if doSort then
- sortInventory(true)
- end
- else
- saveToLog("checkMetal: no unknown items to check", true)
- end
- end
- else
- saveToLog("checkMetal: gold/iron already discovered or ?ironore confirmed", true)
- end
- return result -- "", ?ironore, ironore, ?goldore, goldore
- end
- function checkMineEntranceForTree(direction)
- local dugItem = ""
- if turtle.detect() then -- block in front
- dugItem = checkSugarCane(true)
- isTreeInFront(dugItem)
- end
- if direction == "right" then
- turnLeft(1)
- else
- turnRight(1)
- end
- if turtle.detect() then -- block in front
- dugItem = checkSugarCane(true)
- isTreeInFront(dugItem)
- end
- if direction == "right" then
- turnRight(1)
- else
- turnLeft(1)
- end
- end
- function checkMineStores()
- --move over each buried block in turn to see if it is stored
- --unknown items checked each time turtle returns to base
- local success = false
- local goBack = 0
- local emptyStore = {}
- local tempStore = {}
- local firstEmptyBlock = 0
- local doContinue = true
- -- check if ironore marker placed
- if placeStorage:getStoragePlaced("ironore") then
- if slot:getItemSlot("ironore") > 0 then
- if not placeStorage:getMarkerPlaced("ironore") then
- placeStorage:place("ironore", true)
- end
- end
- end
- --assume under furnace, facing forwards
- --first check any unknown items
- changeDirection("faceMine")
- if slot:getMostUnknownItemSlot() > 0 or
- slot:getItemSlot("lapis") > 0 or
- slot:getItemSlot("moss stone") > 0 or
- slot:getItemSlot("goldore") > 0 or
- slot:getItemSlot("obsidian") > 0 then --see if anything can be stored
- turnRight(2) --face extended storage
- --find first empty storage area
- firstEmptyBlock, emptyStore = getEmptyStorage()
- saveToLog("checkMineStores: first empty storage is "..emptyStore:getStoreName(), false, true)
- -- first storage area now known, and no of blocks forward needed
- -- move turtle over blocks to check contents, only if not empty
- if firstEmptyBlock > 1 then
- forward(1)
- goBack = 1
- for k = 1, firstEmptyBlock - 2, 2 do
- if k == 1 then
- tempStore = extraStorage1
- elseif k == 3 then
- tempStore = extraStorage2
- elseif k == 5 then
- tempStore = extraStorage3
- elseif k == 7 then
- tempStore = extraStorage4
- elseif k == 9 then
- tempStore = extraStorage5
- end
- if tempStore:getStoreContains() == "lapis" then
- forward(1, 1)
- if slot:getItemSlot("lapis") > 0 then --already onboard and identified
- storeItem{toStore = tempStore, item = "lapis", quantity = 0, updateSlot = true, doSort = true}
- else
- turtle.select(16)
- if turtle.suckDown() then
- for i = 1, 16 do
- if turtle.compareTo(i) then --lapis found
- turtle.select(16)
- while turtle.dropDown() do
- saveToLog("checkMineStores: returning lapis to storage")
- end
- slot.update{self = slot, slotNo = i, newItem = "lapis"}
- sortInventory(true)
- if not placeStorage:getMarkerPlaced("lapis") then
- if slot:getItemCount("lapis") >= 9 then
- if craft{craftItem = "lapis block", craftQuantity = 1, sourceItem1 = "lapis", destSlot = 0} then
- dig.digNew{self = dig, direction = "down", callFrom = "checkMineStores"}
- turtle.select(slot:getItemSlot("lapis block"))
- turtle.placeDown()
- slot.update{self = slot, item = "lapis block", delete = true}
- placeStorage:setMarkerPlaced("lapis")
- end
- end
- end
- saveToLog("checkMineStores: adding additional lapis to storage", true)
- storeItem{toStore = tempStore, item = "lapis", quantity = 0, updateSlot = true, doSort = true}
- break
- end
- end
- end
- end
- back(1)
- else
- if slot:getItemSlot(tempStore:getStoreContains()) > 0 then --item already onboard and identified
- forward(1, 1)
- storeItem{toStore = tempStore, item = tempStore:getStoreContains(), quantity = 0, updateSlot = true, doSort = true}
- back(1)
- else
- for i = 1, 16 do
- if slot:getSlotStatus(i) == "unknown" then
- saveToLog("checkMineStores: comparing items in "..tempStore:getStoreName().." with "..tostring(slot:getSlotContains(i)), true)
- turtle.select(i)
- if turtle.compareDown() then --matches embedded block below
- forward(1, 1)
- while turtle.dropDown() do
- saveToLog("checkMineStores: adding "..tempStore:getStoreContains().." to "..tempStore:getStoreName(), true)
- end
- slot.update{self = slot, item = slot:getSlotContains(i), delete = true}
- sortInventory(true)
- back(1)
- break
- end
- end
- end
- end
- end
- forward(2, 1)
- goBack = goBack + 2
- end
- back(goBack)
- end
- changeDirection("faceMine")
- if slot:getItemSlot("moss stone") > 0 then --put moss stone and walls into storage
- changeDirection("faceExtendedStorage")
- forward(firstEmptyBlock)
- dig.digNew{self = dig, direction = "down", callFrom = "checkMineStores"}
- turtle.select(slot:getItemSlot("moss stone"))
- turtle.placeDown()
- forward(1, 1)
- storeItem{toStore = emptyStore, item = "moss stone", quantity = 0, updateSlot = true, doSort = true}
- storeItem{toStore = emptyStore, item = "walls", quantity = 0, updateSlot = true, doSort = true}
- --slot.update{self = slot, item = slot:getSlotContains(i), delete = true}
- back(firstEmptyBlock + 1)
- changeDirection("faceMine")
- firstEmptyBlock, emptyStore = getEmptyStorage()
- end
- if slot:getItemSlot("goldore") > 0 then
- changeDirection("faceExtendedStorage")
- forward(firstEmptyBlock)
- dig.digNew{self = dig, direction = "down", callFrom = "checkMineStores"}
- turtle.select(slot:getItemSlot("goldore"))
- turtle.placeDown()
- forward(1, 1)
- storeItem{toStore = emptyStore, item = "goldore", quantity = 0, updateSlot = true, doSort = true}
- storeItem{toStore = emptyStore, item = "nuggets", quantity = 0, updateSlot = true, doSort = true}
- back(firstEmptyBlock + 1)
- changeDirection("faceMine")
- firstEmptyBlock, emptyStore = getEmptyStorage()
- end
- if slot:getItemSlot("obsidian") > 0 then
- changeDirection("faceExtendedStorage")
- forward(firstEmptyBlock)
- dig.digNew{self = dig, direction = "down", callFrom = "checkMineStores"}
- turtle.select(slot:getItemSlot("obsidian"))
- turtle.placeDown()
- forward(1, 1)
- storeItem{toStore = emptyStore, item = "obsidian", quantity = 0, updateSlot = true, doSort = true}
- back(firstEmptyBlock + 1)
- changeDirection("faceMine")
- firstEmptyBlock, emptyStore = getEmptyStorage()
- end
- if slot:getItemSlot("lapis") > 0 then
- changeDirection("faceExtendedStorage")
- forward(firstEmptyBlock)
- if slot:getItemCount("lapis") > 9 then
- if craft{craftItem = "lapis block", craftQuantity = 1, sourceItem1 = "lapis", destSlot = 0} then
- dig.digNew{self = dig, direction = "down", callFrom = "checkMineStores"}
- turtle.select(slot:getItemSlot("lapis block"))
- turtle.placeDown()
- slot.update{self = slot, item = "lapis block", delete = true}
- placeStorage:setMarkerPlaced("lapis")
- end
- end
- forward(1, 1)
- storeItem{toStore = emptyStore, item = "lapis", quantity = 0, updateSlot = true, doSort = true}
- back(firstEmptyBlock + 1)
- changeDirection("faceMine")
- firstEmptyBlock, emptyStore = getEmptyStorage()
- end
- else
- saveToLog("checkMineStores: no unknown items to store")
- end
- return success
- end
- function checkMossStone()
- --assume on ground
- local success = false
- local goBack = 0
- local tempItem = ""
- changeDirection("faceMine")
- if slot:getMostUnknownItemSlot() > 0 then
- saveToLog("checkMossStone: slot with most items = "..slot:getMostUnknownItemSlot().." with "..turtle.getItemCount(slot:getMostUnknownItemSlot()).." items", true)
- for i = slot:getMostUnknownItemSlot(), slot:getLeastUnknownItemSlot(), - 1 do
- turtle.select(i)
- if turtle.getItemCount(i) > 6 then
- changeDirection("faceExtraStorage")
- if turtle.place() then --iron/gold/redstone/moss stone
- if turtle.compare() then --iron/gold/redstone/moss stone
- tempItem = slot:getSlotContains(i)
- saveToLog("checkMossStone: testing "..tempItem.." in slot "..i, true)
- dig.digNew{self = dig, slotNo = i, callFrom = "checkMossStone"}
- changeDirection("faceMine")
- slot.update{self = slot, slotNo = i, newItem = "?moss stone"}
- if craft{craftItem = "walls", craftQuantity = 6, sourceItem1 = "?moss stone", destSlot = 0} then
- success = true
- -- slot.update{self = slot, slotNo = i, newItem = "moss stone"}
- slot.update{self = slot, item = "?moss stone", newItem = "moss stone"}
- sortInventory(true)
- --now store moss and walls in extended storage area
- break
- else
- slot.update{self = slot, item = "?moss stone", newItem = tempItem}
- end
- else -- redstone
- saveToLog("checkMossStone: redstone found", true)
- dig.digNew{self = dig, slotNo = i, callFrom = "checkMossStone"}
- changeDirection("faceMine")
- slot.update{self = slot, slotNo = i, newItem = "redstone"}
- sortInventory(true)
- if not placeStorage:getStoragePlaced("redstone") then
- placeStorage:place("redstone", false)
- else
- forward(12, 1)
- turnRight(2)
- storeRedstone()
- --return to furnace
- forward(12, 1)
- turnRight(2)
- end
- break
- end
- end
- end
- end
- changeDirection("faceMine")
- else
- saveToLog("checkMossStone: no unknown items to check", true)
- end
- return success
- end
- function checkObjectives(colNo, side, torchesNeeded)
- local numTorches = 0
- local numSigns = 0
- local numSticks = 0
- local woodCount = 0
- local numSaplings = 0
- local success = false
- local woodType = 0
- local fuelStats = {}
- local doContinue = true
- local woodAvailable = 0
- local wood2Available = 0
- if torchesNeeded == nil then
- torchesNeeded = 0
- end
- refuel(0)
- --should be under furnace. Checks objectives before deep mining starts
- --Also loads turtle with torches/signs ready for next harvest run
- --[[
- before going deep mining:
- 1) goMining1 completed at least once
- 2) storageTorches placed
- 3) storageSigns, storageSticks placed
- 4) found the following items: dirt, cobble, stone, coal, gravel, sand(6), ironore (5), sugar cane (3)
- 5) tree farm planted
- 6) iron smelted (1 bucket crafted)
- 7) storageSand, storageWood, storageRedstone, storageIronore, storagePickaxes, storageSaplings
- If all trees harvested and goMining1 repeated on all areas, can continue without iron and coal
- objectives:
- 1) placeStorage:getStoragePlaced("torches")
- 2) placeStorage:getStoragePlaced("signs")
- 3) placeStorage:getStoragePlaced("sticks")
- 4) placeStorage:getStoragePlaced("wood") -- only when treeFarm planted
- 5) placeStorage:getStoragePlaced("ironore")
- 6) placeStorage:getStoragePlaced("sand")
- 7) placeStorage:getStoragePlaced("redstone") -- only when treeFarm planted
- 8) placeStorage:getStoragePlaced("pickaxes)" -- only when treeFarm planted
- 9) placeStorage:getStoragePlaced("saplings") -- only when treeFarm planted
- ]]--
- changeDirection("faceMine")
- if side == "rightside" and colNo == 1 then --not enough wood on first run unless branched tree harvested
- doContinue = false
- woodType = getWoodAvailable{woodNeeded = 4}
- if woodType ~= "none" then
- doContinue = true
- end
- end
- if doContinue then --excludes first tree harvest run if not enough wood
- --torches already checked by checkTorch()
- if placeStorage:getStoragePlaced("torches") then
- --check if at least 2 torches and 1 sign present first
- saveToLog("checkObjectives: checking for torches onboard or in storage", false, true)
- if getItemsAvailable("torches", true) < 2 + torchesNeeded then --check and remove torches from storage
- -- make torches
- woodType = getWoodAvailable{woodNeeded = 4}
- saveToLog("checkObjectives: crafting torches if wood available", false, true)
- if woodType ~= "none" then
- craftTorches(4)
- end
- end
- -- put them in storage
- saveToLog("checkObjectives: storing torches to free a slot", false, true)
- storeItem{toStore = storageTorches, item = "torches", quantity = 0, updateSlot = true, doSort = true}
- saveToLog("checkObjectives: checking for signs onboard or in storage", false, true)
- if getItemsAvailable("signs", true) < 1 then --check and remove signs from storage
- woodType = getWoodAvailable{woodNeeded = 4}
- saveToLog("checkObjectives: crafting signs if wood available", false, true)
- if woodType ~= "none" then
- craftSigns()
- end
- end
- -- put them in storage
- if placeStorage:getStoragePlaced("signs") then
- if not placeStorage:getMarkerPlaced("signs") then
- placeStorage:place("signs", true)
- end
- forward(2, 1)
- turnRight(2)
- saveToLog("checkObjectives: storing signs to free a slot", false, true)
- storeItem{toStore = storageSigns, item = "signs", quantity = 0, updateSlot = true, doSort = true}
- forward(2, 1)
- turnRight(2)
- else
- refuel(0)
- woodType = getWoodAvailable{woodNeeded = 5}
- if woodType ~= "none" then
- saveToLog('checkObjectives: placeStorage("signs") function started', true)
- getItemsAvailable("signs", true)
- placeStorage:place("signs", false)
- if placeStorage:getStoragePlaced("signs") then
- saveToLog('checkObjectives: 2/9 - placeStorage:getStoragePlaced("signs") completed', true)
- if slot:getItemSlot("signs") > 0 then
- if turtle.getItemCount(slot:getItemSlot("signs")) > 0 then
- forward(2, 1)
- turnRight(2)
- saveToLog("checkObjectives: storing signs to free a slot", false, true)
- storeItem{toStore = storageSigns, item = "signs", quantity = 0, updateSlot = true, doSort = true}
- forward(2, 1)
- turnRight(2)
- end
- end
- end
- else
- saveToLog("checkObjectives: Not enough wood to place storageSigns", false, true)
- end
- end
- --signs and torches made, see if any wood for storage, in order torches, signs, sticks, sand, ironore
- refuel(0)
- if placeStorage:getStoragePlaced("sticks") then
- if not placeStorage:getMarkerPlaced("sticks") then
- woodType = getWoodAvailable{woodNeeded = 4}
- if woodType ~= "none" then
- craftSticks(8)
- placeStorage:place("sticks", true)
- end
- end
- if slot:getItemSlot("sticks") > 0 then
- if turtle.getItemCount(slot:getItemSlot("sticks")) > 0 then
- -- put them in storage
- forward(4, 1)
- turnRight(2)
- saveToLog("checkObjectives: storing signs to free a slot", false, true)
- storeItem{toStore = storageSticks, item = "sticks", quantity = 0, updateSlot = true, doSort = true}
- forward(4, 1)
- turnRight(2)
- end
- end
- else
- woodType = getWoodAvailable{woodNeeded = 6}
- if woodType ~= "none" then
- saveToLog('checkObjectives: placeStorage("sticks") function started', true)
- placeStorage:place("sticks", false)
- if placeStorage:getStoragePlaced("sticks") then
- saveToLog('checkObjectives: 3/9 - placeStorage:getStoragePlaced("sticks") completed', true)
- if slot:getItemSlot("sticks") > 0 then
- if turtle.getItemCount(slot:getItemSlot("sticks")) > 0 then
- forward(4, 1)
- turnRight(2)
- saveToLog("checkObjectives: storing signs to free a slot", false, true)
- storeItem{toStore = storageSticks, item = "sticks", quantity = 0, updateSlot = true, doSort = true}
- forward(4, 1)
- turnRight(2)
- end
- end
- end
- else
- saveToLog("checkObjectives: Not enough wood to place storageSticks", false, true)
- end
- end
- refuel(0)
- if placeStorage:getStoragePlaced("sand") then --storageSand placed
- if not placeStorage:getMarkerPlaced("sand") then
- placeStorage:place("sand", true)
- end
- if slot:getItemSlot("sugar cane") > 0 then
- forward(10)
- storeItem{toStore = storageSand, item = "sugar cane", quantity = 0, updateSlot = true, doSort = true}
- turnRight(2)
- forward(10)
- turnRight(2)
- objectives["complete sugar cane"] = true
- saveToLog('checkObjectives: 6/9 - objectives["complete sugar cane"] completed', true)
- end
- else --storageSand not yet placed
- if slot:getItemSlot("sand") > 0 or
- (placeStorage:getStoragePlaced("signs") and
- placeStorage:getStoragePlaced("sticks")) then --see if sand onboard or signs/sticks already placed
- woodType = getWoodAvailable{woodNeeded = 5}
- if woodType ~= "none" then
- if objectives["sand"] then --place storageSand if enough wood and sand discovered
- placeStorage:place("sand", false)
- saveToLog('checkObjectives: 1/9 - placeStorage:getStoragePlaced("sand") completed', true)
- end
- if slot:getItemSlot("sugar cane") > 0 then
- forward(10)
- storeItem{toStore = storageSand, item = "sugar cane", quantity = 0, updateSlot = true, doSort = true}
- turnRight(2)
- forward(10)
- turnRight(2)
- objectives["complete sugar cane"] = true
- saveToLog('checkObjectives: 6/9 - objectives["complete sugar cane"] completed', true)
- end
- end
- end
- end
- refuel(0)
- if objectives["goMining1"] then --done on each run to see if ironore has been found
- saveToLog('checkObjectives: checkMetal started', true)
- checkMetal() --check if ironore discovered
- if placeStorage:getStoragePlaced("ironore") then
- if slot:getItemSlot("ironore") > 0 then
- if not placeStorage:getMarkerPlaced("ironore") then
- placeStorage:place("ironore", true)
- end
- end
- else
- if slot:getItemSlot("ironore") > 0 or
- (placeStorage:getStoragePlaced("signs") and
- placeStorage:getStoragePlaced("sticks")) then
- woodType = getWoodAvailable{woodNeeded = 5}
- if woodType ~= "none" then
- saveToLog('checkObjectives: placeStorage("ironore") function started', true)
- placeStorage:place("ironore", false)
- if placeStorage:getStoragePlaced("ironore") then
- saveToLog('checkObjectives: 4/9 - placeStorage:getStoragePlaced("ironore") completed', true)
- end
- else
- saveToLog("checkObjectives: Not enough wood to place storageIronore", false, true)
- end
- end
- end
- end
- if colNo > 5 or side == "leftside" then --can plant tree farm anytime from now needs min 500 fuel
- if objectives["clear treefarm"] then --treeFarm already present
- if not objectives["pave treefarm"] then
- objectives["pave treefarm"] = paveTreeFarm()
- end
- woodType = getWoodAvailable{woodNeeded = 1}
- if woodType ~= "none" then
- if not placeStorage:getMarkerPlaced("wood") then
- placeStorage:place("wood", true)
- end
- end
- if placeStorage:getStoragePlaced("ironore") and placeStorage:getStoragePlaced("sand") then
- if not placeStorage:getStoragePlaced("redstone") then
- woodType = getWoodAvailable{woodNeeded = 5}
- if woodType ~= "none" then
- saveToLog('checkObjectives: placeStorage("redstone") function started', true)
- placeStorage:place("redstone", false)
- if placeStorage:getStoragePlaced("redstone") then
- saveToLog('checkObjectives: 7/9 - placeStorage:getStoragePlaced("redstone") completed', true)
- end
- else
- saveToLog("checkObjectives: Not enough wood to place storageRedstone", false, true)
- end
- end
- if not placeStorage:getStoragePlaced("pickaxes") then
- woodType = getWoodAvailable{woodNeeded = 5}
- if woodType ~= "none" then
- saveToLog('checkObjectives: placeStorage("pickaxes") function started', true)
- placeStorage:place("pickaxes", false)
- if placeStorage:getStoragePlaced("pickaxes") then
- saveToLog('checkObjectives: 8/9 - placeStorage:getStoragePlaced("pickaxes") completed', true)
- end
- else
- saveToLog("checkObjectives: Not enough wood to place storagePickaxes", false, true)
- end
- end
- end
- saveToLog('checkObjectives: objectives["clear treefarm"] = true, checking sand and sugar cane', true)
- if objectives["sand"] and objectives["sugar cane"] then
- success = true
- else
- if not objectives["sand"] or not objectives["gravel"] then --check if sand onboard
- back(1)
- turnRight(1)
- checkGravel()
- turnLeft(1)
- forward(1)
- end
- end
- if not objectives["smelt iron"] then
- success = false
- end
- -- need 14 wood for 7 chests, and 16 charcoal for 64 torches, fuel from coal during mining
- woodType, woodAvailable, wood2Available = getWoodAvailable{woodNeeded = 24, checkWoodType = "any"} -- 18 needed for deep mining + 6 spare
- if woodType == "none" then
- success = false
- saveToLog("checkObjectives: not enough wood to start deep mining ("..woodAvailable.." wood, "..wood2Available.." wood2", false, true)
- end
- else --treefarm not yet planted
- --check if enough saplings to plant tree farm - min 5 saplings/saplings2
- if slot:getItemSlot("saplings") > 0 then
- numSaplings = turtle.getItemCount(slot:getItemSlot("saplings"))
- end
- if slot:getItemSlot("saplings2") > 0 then
- if turtle.getItemCount(slot:getItemSlot("saplings2")) > numSaplings then
- numSaplings = turtle.getItemCount(slot:getItemSlot("saplings2"))
- end
- end
- if numSaplings > 4 then --check if tree farm can be cleared
- if slot:getItemCount("coal") > 2 then
- woodType = getWoodAvailable{woodNeeded = 8} -- 4 for chests, 3 for torches, 3 for fuel, 1 for marker
- else
- woodType = getWoodAvailable{woodNeeded = 11} -- 4 for chests, 3 for torches, 3 for fuel, 1 for marker
- end
- if woodType ~= "none" then
- saveToLog("CheckObjectives: checking fuel before clearing Tree Farm", true)
- fuelStats = getFuelAvailable()
- if fuelStats.totalFuelAvailable > 500 then
- saveToLog("CheckObjectives: placing storageSaplings")
- placeStorage:place("saplings", false)
- if placeStorage:getStoragePlaced("saplings") then
- saveToLog('checkObjectives: 9/9 - placeStorage:getStoragePlaced("saplings") completed')
- end
- saveToLog("CheckObjectives: placing storageWood")
- placeStorage:place("wood", false)
- if placeStorage:getStoragePlaced("wood") then
- saveToLog('checkObjectives: 8/9 - placeStorage:getStoragePlaced("wood") completed')
- end
- forward(2)
- storeItem{toStore = storageSigns, item = "signs", quantity = 0, updateSlot = true, doSort = true}
- back(2)
- craftTorches(8)
- saveToLog("CheckObjectives: fuelAvailable = "..fuelStats.totalFuelAvailable.." starting Tree Farm", true)
- objectives["clear treefarm"] = clearTreeFarm()
- if objectives["clear treefarm"] then
- saveToLog('checkObjectives: 9/9 - objectives["clear treefarm"] completed')
- end
- else
- saveToLog("CheckObjectives: fuelAvailable = "..fuelStats.totalFuelAvailable.." not enough for tree farm", true)
- end
- else
- saveToLog("CheckObjectives: not enough wood for storageSaplings and storageWood")
- end
- else
- saveToLog("CheckObjectives: not enough saplings to plant tree farm")
- end
- end
- completeChests() -- use excess wood/wood2 to make chests or refuel
- end
- saveToLog('checkObjectives: checkItems{"keepTorches"} started', true)
- --If turtle loaded, may not be able to carry torches/signs to mark position of mineshafts
- if getNoOfEmptySlots(true) >= 3 then
- saveToLog('checkObjectives: loading torches and signs', true)
- checkItems{keepTorches = 1 + torchesNeeded, keepSigns = 1}
- elseif getNoOfEmptySlots(true) >= 2 then
- saveToLog('checkObjectives: not enough empty slots to carry signs', true)
- checkItems{keepTorches = 2 + torchesNeeded, keepSigns = 0}
- else
- saveToLog('checkObjectives: not enough empty slots to carry signs or torches', true)
- checkItems{keepTorches = 0 + torchesNeeded, keepSigns = 0}
- end
- if torchesNeeded > 0 then
- restoreTorches(side, colNo)
- end
- else --did not get enough wood on first run
- woodType = getWoodAvailable{woodNeeded = 4}
- if woodType ~= "none" then
- saveToLog('checkObjectives: place StorageTorches started', true)
- placeStorage:place("torches", false)
- if placeStorage:getStoragePlaced("torches") then
- saveToLog("checkObjectives: 1/9 - place StorageTorches completed")
- end
- else
- saveToLog("checkObjectives: Not enough wood to place storageTorches", false, true)
- end
- end
- if slot:getItemSlot("planks") > 0 then
- turtle.select(slot:getItemSlot("planks"))
- turtle.refuel()
- slot.update{self = slot, slotNo = slot:getItemSlot("planks"), delete = true}
- sortInventory(true)
- end
- if slot:getItemSlot("planks2") > 0 then
- turtle.select(slot:getItemSlot("planks2"))
- turtle.refuel()
- slot.update{self = slot, slotNo = slot:getItemSlot("planks2"), delete = true}
- sortInventory(true)
- end
- end
- return success --if true ready for deep mining early, otherwise continue harvestAllTrees
- end
- function checkRedstone()
- local success = false
- --assume on ground
- sortInventory(true)
- changeDirection("faceMine")
- if slot:getMostUnknownItemSlot() > 0 then
- saveToLog("checkRedstone: slot with most items = "..slot:getMostUnknownItemSlot().." with "..turtle.getItemCount(slot:getMostUnknownItemSlot()).." items", true)
- for i = slot:getMostUnknownItemSlot(), slot:getLeastUnknownItemSlot(), - 1 do
- if turtle.getItemCount(i) > 1 then
- turtle.select(i)
- if turtle.getItemCount(i) > 15 then
- changeDirection("faceExtraStorage")
- if turtle.place() then --iron/gold/redstone
- if turtle.compare() then
- saveToLog("checkRedstone: redstone not found", true)
- dig.digNew{self = dig, callFrom = "checkRedstone"}
- else -- redstone
- saveToLog("checkRedstone: redstone confirmed", true)
- slot.update{self = slot, slotNo = i, newItem = "redstone"}
- objectives["redstone"] = true
- sortInventory(true)
- dig.digNew{self = dig, callFrom = "checkRedstone"}
- success = true
- break
- end
- changeDirection("faceMine")
- end
- end
- end
- end
- else
- saveToLog("checkRedstone: no unknown items to check", true)
- end
- changeDirection("faceMine")
- if success then
- if not placeStorage:getStoragePlaced("redstone") then
- placeStorage:place("redstone", false)
- else
- forward(12, 1)
- storeRedstone()
- turnRight(2)
- --return to furnace
- forward(12, 1)
- turnRight(2)
- end
- end
- return success
- end
- function checkRemaining()
- local tempItem = ""
- local reRun = false
- local itemFound = ""
- --already checked for iron, gold, redstone, lapis
- --lapis, diamond, obsidian, emerald, planks or fence from abandoned mine
- --see if axe can be crafted to show diamond. need sticks in storage below
- changeDirection("faceMine")
- if objectives["ironore"] and objectives["redstone"] and objectives["lapis"] then -- iron found
- saveToLog("checkRemaining: starting")
- checkItems{keepTorches = 0, keepSigns = 0, keepSticks = 2}
- repeat
- reRun = false
- if slot:getMostUnknownItemSlot() > 0 then
- for i = slot:getLeastUnknownItemSlot(), slot:getMostUnknownItemSlot(), 1 do
- tempItem = slot:getSlotContains(i)
- turtle.select(i)
- changeDirection("faceExtraStorage")
- if turtle.place() then --obsidian, moss stone < 6, planks or fence from old mineshaft
- dig.digNew{self = dig, slotNo = i, callFrom = "checkRemaining"}
- changeDirection("faceMine")
- if turtle.refuel() then --planks / fence
- saveToLog("checkRemaining: used wooden items as fuel", true)
- slot.update{self = slot, slotNo = i, delete = true}
- reRun = true
- break
- else
- if objectives["ironore"] and objectives["goldore"] then --gold and iron found
- itemFound = "obsidian"
- saveToLog("checkRemaining: obsidian found", true)
- slot.update{self = slot, slotNo = i, newItem = "obsidian"}
- --reRun = true
- break
- end
- end
- else --lapis, or diamond, possibly emerald
- changeDirection("faceMine")
- if slot:getItemSlot("diamonds") == 0 then
- -- if all mining complete need min 3 diamonds, if still mining and 4 or more then continue
- if turtle.getItemCount(i) > 3 then --test for diamond
- slot.update{self = slot, slotNo = i, newItem = "?diamonds"}
- if craft{craftItem = "diamond pickaxe", craftQuantity = 1, sourceItem1 = "sticks", sourceItem2 = "?diamonds", destSlot = 0} then
- saveToLog("Pickaxe crafted", true)
- slot.update{self = slot, item = "?diamonds", newItem = "diamonds"}
- itemFound = "diamonds"
- objectives["diamonds"] = true
- reRun = true
- break
- else --diamonds not found
- slot.update{self = slot, slotNo = i, newItem = tempItem}
- --[[turtle.select(i)
- while turtle.drop() do
- saveToLog("checkRemaining: dropping ? lapis after failed pickaxe craft", true)
- end
- slot.update{self = slot, slotNo = i, delete = true}]]--
- end
- end
- else
- if turtle.getItemCount(i) >= 3 then --test for diamond already done
- while turtle.drop() do
- saveToLog("checkRemaining: dropping ? lapis", true)
- end
- slot.update{self = slot, slotNo = i, delete = true}
- reRun = true
- break
- end
- end
- end
- end
- sortInventory(true)
- end
- until not reRun
- changeDirection("faceMine")
- if slot:getItemSlot("sticks") > 0 then
- forward(4, 1)
- storeItem{toStore = storageSticks, item = "sticks", quantity = 0, updateSlot = true, doSort = true}
- turnRight(2)
- forward(4, 1)
- turnRight(2)
- end
- if slot:getItemSlot("wood") > 0 then
- forward(6, 1)
- storeItem{toStore = storageWood, item = "wood", quantity = 0, updateSlot = true, doSort = true}
- turnRight(2)
- forward(6, 1)
- turnRight(2)
- end
- if slot:getItemSlot("diamond pickaxe") > 0 then
- saveToLog("checkRemaining: storing diamond pickaxe in storagePickaxes",true)
- forward(14, 1)
- storeItem{toStore = storagePickaxes, item = "diamond pickaxe", quantity = 0, updateSlot = true, doSort = true}
- turnRight(2)
- forward(14, 1)
- turnRight(2)
- end
- saveToLog("checkRemaining: all remaining items identified or dropped unless <4", true)
- else
- saveToLog("checkRemaining: either iron, gold, lapis, or redstone not yet identified", true)
- end
- return itemFound
- end
- function checkSugarCane(returnToGround)
- --function entered with block in front
- --return block type of top block
- local yCoordTemp = location:getY()
- local yCoordTemp2 = 0
- local useAmount = 0
- local useItem = ""
- local tempSlot = 0
- local tempDugAmount = 0
- local itemFound = ""
- local checkList = {}
- local blocksClimbed = 0
- local blockAbove = false
- local woodType = ""
- --used when forwardSafe is checking right and left sides only
- returnToGround = returnToGround or false
- checkList[1] = "all"
- --see if block in front is wood or wood2
- if slot:getItemSlot("wood") > 0 then
- turtle.select(slot:getItemSlot("wood"))
- if turtle.compare() then
- itemFound = "wood"
- end
- end
- if slot:getItemSlot("wood2") > 0 then
- turtle.select(slot:getItemSlot("wood2"))
- if turtle.compare() then
- itemFound = "wood2"
- end
- end
- --if wood/wood2 found exit function returning "wood"/"wood2"
- if itemFound == "" then --block in front is not wood or wood2 (if wood2 already known)
- saveToLog("checkSugarCane: moving up", true)
- while turtle.detect() do --climb up max 12 blocks
- if slot:getItemSlot("wood") > 0 then
- turtle.select(slot:getItemSlot("wood"))
- if turtle.compare() then
- itemFound = "wood"
- break
- end
- end
- if slot:getItemSlot("wood2") > 0 then
- turtle.select(slot:getItemSlot("wood2"))
- if turtle.compare() then
- itemFound = "wood2"
- break
- end
- end
- if slot:getItemSlot("cobble") > 0 then
- turtle.select(slot:getItemSlot("cobble"))
- if turtle.compare() then
- itemFound = "cobble"
- break
- end
- end
- up(1, 1, "saplings", "checkSugarCane")
- blocksClimbed = blocksClimbed + 1
- if location:getY() - yCoordTemp == 12 then --climb up max 10 places
- saveToLog("checkSugarCane: reached 12 blocks height", true)
- end
- sleep(0.5) --stops random "Too long without yielding" errors
- end
- --gone up until nothing in front, could be top of sugar cane, or top of leaves, or dirt. go forward and down
- if itemFound == "" then --wood/wood2/cobble not found
- saveToLog("checkSugarCane: moving over top of blocks", true)
- forward(1, 1)
- saveToLog("checkSugarCane: digging down", true)
- if blocksClimbed == 1 then --could be mushrooms/flowers/leaves/grass tuft or sand
- --success, dugItem, dugSlot = dig{direction = "down", checkForItems = "flowers"}
- dig.digNew{self = dig, direction = "down", checkForItems = "flowers", callFrom = "checkSugarCane"}
- else
- --success, dugItem, dugSlot = dig{direction = "down", checkForItems = "sugar cane,sand,gravel,wood2,saplings"}
- dig.digNew{self = dig, direction = "down", checkForItems = "sugar cane,sand,gravel,wood2,saplings", callFrom = "checkSugarCane"}
- end
- itemFound = dig:getDugItem()
- if dig:getDugItem() == "sugar cane" then --only happens if sugar cane already onboard
- saveToLog("checkSugarCane: more sugar cane found", true)
- itemFound = "sugar cane"
- down(1)--sit on top of sugar cane
- elseif dig:getDugItem() == "leaves" or dig:getDugItem() == "saplings" or dig:getDugItem() == "saplings2" then
- saveToLog("checkSugarCane: leaves found, digging down", true)
- --continue digging down until dirt/stone/cobble found
- --leaves may disappear so return to ground level anyway
- down(1, 1, "saplings") --move down to detect if more leaves
- while turtle.detectDown() do
- --success, dugItem, dugSlot = dig{self = slot, direction = "down", checkForItems = "saplings"}
- dig.digNew{self = dig, direction = "down", checkForItems = "saplings", callFrom = "checkSugarCane"}
- if dig:getDugItem() == "" or dig:getDugItem() == "leaves" or dig:getDugItem() == "saplings" or dig:getDugItem() == "saplings2" then
- down(1, 1)
- elseif dig:getDugItem() == "wood2" then
- saveToLog("checkSugarCane: wood2 found", true)
- itemFound = "wood2"
- down(2)
- break --leave detectDown() loop
- else --dirt, cobble sand etc found so replace
- saveToLog("checkSugarCane: "..dig:getDugItem().." found, replacing and moving on", true)
- -- replace last block found
- if dig:getDugSlot() > 0 then
- turtle.select(dig:getDugSlot())
- turtle.placeDown()
- end
- break -- leave detectDown() loop
- end
- end
- elseif string.find(dig:getDugItem(), "item") ~= nil then --new item or sugar cane returned
- --sugar cane can be placeDown() but does not compareDown() on top of sugar cane or blocks next to water
- --compareDown to check false = sugar cane, stone, grass but cobble already known and checked. Must be sugar cane
- --true = dirt,sand,gravel,wood,
- saveToLog("checkSugarCane: dug top of blocks checking for sugar cane", true)
- down(1)
- tempSlot, useAmount, useItem = compareBlock("down", checkList, 1) --does block below match anything
- if tempSlot == 0 then --sugar cane, stone, grass, saplings2 only. dirt and cobble known so must be cane
- saveToLog("checkSugarCane: no compareDown(): sugar cane found in "..dig:getDugSlot(), true)
- itemFound = "sugar cane"
- slot.update{self = slot, slotNo = dig:getDugSlot(), newItem = "sugar cane"}
- --dig next block to make certain
- tempDugAmount = turtle.getItemCount(slot:getItemSlot("sugar cane"))
- dig.digNew{self = dig, direction = "down", checkForItems = "wood2", callFrom = "checkSugarCane"}
- if turtle.getItemCount(slot:getItemSlot("sugar cane")) == tempDugAmount then --not sugar cane
- itemFound = dig:getDugItem()
- slot.update{self = slot, slotNo = dig:getDugSlot(), newItem = dig:getDugItem()}
- end
- else
- --check if wood2
- if slot:getItemSlot("wood2") == 0 then
- turtle.select(dig:getDugSlot())
- if turtle.refuel(0) then
- --itemFound = "wood2"
- --dig:getDugItem() = "wood2"
- itemFound = "wood2"
- dig.digNew{self = dig, direction = "down", slotNo = dig:getDugSlot(), expectedItem = "wood2", callFrom = "checkSugarCane"}
- slot.update{self = slot, slotNo = dig:getDugSlot(), newItem = "wood2"}
- sortInventory(true)
- down(1)
- else
- saveToLog("checkSugarCane: "..dig:getDugItem().." found, keeping in stock", true)
- turtle.select(slot:getItemSlot("dirt"))
- turtle.placeDown()
- end
- else
- saveToLog("checkSugarCane: "..dig:getDugItem().." found, keeping in stock", true)
- turtle.select(slot:getItemSlot("dirt"))
- turtle.placeDown()
- end
- end
- elseif dig:getDugItem() == "sand" then
- if slot:getItemCount("sand") >= 7 then
- turtle.select(slot:getItemSlot("sand"))
- turtle.placeDown()
- end
- elseif dig:getDugItem() == "dirt" or dig:getDugItem() == "cobble" then
- turtle.select(dig:getDugSlot())
- turtle.placeDown()
- saveToLog("checkSugarCane: "..dig:getDugItem().." found and replaced", true)
- elseif dig:getDugItem() == "wood" or dig:getDugItem() == "wood2" then --on top of tree so harvest it
- turtle.select(slot:getItemSlot(dig:getDugItem()))
- local isBranched = false
- while turtle.compareDown() do
- isBranched = checkTree(dig:getDugItem(), isBranched, "checkSugarCane")
- down(1, 1)
- turtle.select(slot:getItemSlot(dig:getDugItem()))
- end
- turnRight(2)
- while turtle.detect() do
- --while location:getY() < yCoordTemp do
- up(1, 1)
- end
- turnRight(2)
- end
- if itemFound == "sugar cane" then --recognised by not comparing down. Currently on top of sugar cane
- --dig:getDugItem() = "sugar cane"
- while dig:getDugItem() == "sugar cane" do
- --success, dugItem, dugSlot = dig{self = slot, direction = "down"}
- dig.digNew{self = dig, direction = "down", callFrom = "checkSugarCane"}
- if dig:getDugItem() ~= "sugar cane" then --stop digging at base, should have just dug sand
- if dig:getDugItem() ~= "dirt" then
- if slot:getItemSlot("sand") == 0 then
- slot.update{self = slot, slotNo = dig:getDugSlot(), newItem = "sand"}
- end
- end
- break
- end
- down(1, 1)
- end
- --1 block below base of sugar cane - could be sand below
- yCoordTemp = location:getY() + 1 --water level
- if slot:getItemSlot("sand") > 0 then
- tempSlot = slot:getItemSlot("sand")
- if turtle.getItemCount(slot:getItemSlot("sand")) >= 8 then
- tempSlot = 0
- end
- else --sand not found yet
- dig.digNew{self = dig, direction = "down", expectedItem = "sand", callFrom = "checkSugarCane"}
- tempSlot = slot:getItemSlot("sand")
- end
- if tempSlot > 0 then
- objectives["sand"] = true
- if turtle.getItemCount(tempSlot) < 8 then
- turtle.select(tempSlot)
- down(1, tempSlot)
- while turtle.compareDown() do
- down(1, tempSlot)
- end
- end
- end
- while location:getY() < yCoordTemp do
- --up(1, 1)
- if getDirtStock() > 0 then
- turtle.select(slot:getItemSlot("dirt"))
- turtle.placeDown()
- end
- up(1)
- end
- elseif itemFound == "wood2" then
- turtle.select(slot:getItemSlot("wood2"))
- local isBranched = false
- while turtle.compareDown() do
- isBranched = checkTree(dig:getDugItem(), isBranched, "checkSugarCane")
- down(1, 1)
- turtle.select(slot:getItemSlot("wood2"))
- end
- turnRight(2)
- while turtle.detect() do
- up(1, 1)
- end
- turnRight(2)
- itemFound = "dirt"
- end
- if returnToGround then
- --if location:getY() < yCoordTemp then --lower than starting level, so back() will dig block
- while location:getY() < yCoordTemp do
- up(1, 1)
- end
- while location:getY() > yCoordTemp do
- if turtle.detectDown() then --only go down if nothing below
- break
- else
- down(1, 1)
- end
- end
- --end
- end
- back(1)
- else --itemFound = tree and wood/wood2 selected
- if itemFound ~= "cobble" then
- saveToLog("checkSugarCane: tree found above ground level", true)
- --now harvest rest of tree
- harvestTree(itemFound)
- end
- end
- end
- return itemFound --will return "wood", "wood2" if next to tree
- end
- function checkTorch(direction)
- -- dig torch on way back to base, turn and replace. If not present ignore
- local success = false
- local dugItem = ""
- local dugSlot = 0
- direction = direction or "home"
- if turtle.detect() then --? torch present
- dig.digNew{self = dig, expectedItem = "torches", callFrom = "checkTorch"}
- if dig:getSuccess() then
- if dig:getDugItem() == "torches" then
- forward(2, 1)
- turnRight(2)
- turtle.select(dig:getDugSlot())
- turtle.place()
- slot.update{self = slot, item = "torches", delete = true}
- if slot:getItemSlot("torches") == 0 then
- sortInventory(true)
- end
- turnRight(2)
- end
- else
- forward(2, 1)
- end
- else
- forward(2, 1)
- end
- if direction == "home" then
- changeDirection("faceMine")
- end
- end
- function checkTree(woodType, isBranched, calledFrom)
- for i = 1, 4 do
- isBranched = checkTreeBranch(woodType, isBranched, calledFrom)
- turnRight(1)
- end
- return isBranched
- end
- function checkTreeBranch(woodType, isBranched, calledFrom)
- --success, dugItem, dugSlot = dig{checkForItems = "saplings"} -- dig space for refuelling
- dig.digNew{self = dig, checkForItems = "saplings", callFrom = calledFrom} -- dig space for refuelling
- --saveToLog("checkTreeBranch: fuel level = "..turtle.getFuelLevel())
- if dig:getDugItem() == woodType then --wood/wood2 found
- if turtle.getFuelLevel() < 10 then
- refuel(0)
- end
- isBranched = true
- forward(1, 1, "saplings", calledFrom)
- checkTreeBranch(woodType, isBranched, calledFrom)
- turnLeft(1)
- checkTreeBranch(woodType, isBranched, calledFrom)
- turnRight(2)
- checkTreeBranch(woodType, isBranched, calledFrom)
- turnLeft(1)
- back(1)
- else
- if isBranched then
- if turtle.getFuelLevel() < 10 then
- refuel(0)
- end
- forward(1, 1, "saplings", calledFrom)
- turnLeft(1)
- dig.digNew{self = dig, checkForItems = "saplings", callFrom = calledFrom}
- turnRight(1)
- dig.digNew{self = dig, checkForItems = "saplings", callFrom = calledFrom}
- if dig:getDugItem() == woodType then --wood/wood2 found
- forward(1, 1, "saplings", calledFrom)
- turnLeft(1)
- dig.digNew{self = dig, checkForItems = "saplings", callFrom = calledFrom}
- turnRight(1)
- dig.digNew{self = dig, checkForItems = "saplings", callFrom = calledFrom}
- turnRight(1)
- dig.digNew{self = dig, checkForItems = "saplings", callFrom = calledFrom}
- turnLeft(1)
- back(1)
- end
- turnRight(1)
- dig.digNew{self = dig, checkForItems = "saplings", callFrom = calledFrom}
- turnLeft(1)
- back(1)
- end
- end
- return isBranched
- end
- function checkWalls(itemList, calledFrom)
- for j = 1, 4 do
- mineItem(itemList, calledFrom) --call recursive function
- refuel(0)
- turnRight(1)
- end
- return success
- end
- function checkWater(direction)
- local result = false
- local slotNo = 0
- for i = 1, 16 do
- if turtle.getItemCount(i) == 0 then
- slotNo = i
- break
- end
- end
- if slotNo > 0 then
- turtle.select(slotNo)
- if direction == "down" then
- if not turtle.detectDown() then
- if not turtle.compareDown() then --no block detected, but does not compare to air(empty slot)
- result = true
- end
- end
- elseif direction == "up" then
- if not turtle.detectUp() then
- if not turtle.compareUp() then
- result = true
- end
- end
- elseif direction == "forward" then
- if not turtle.detect() then
- if not turtle.compare() then
- result = true
- end
- end
- end
- end
- return result --true if water, (or lava)
- end
- function chooseWood()
- local woodType = ""
- local woodSpare = ""
- local success = false
- local numMoves = 0
- local emptySlot = 0
- local chestsNeeded = 7
- local numChests = 0
- -- return to tree farm, check if tree has grown.
- -- only do this when ready to mine for diamonds. While harvesting other trees leave alone
- forward(2, 1)
- turnRight(1)
- forward(2, 1)
- turnLeft(1)
- up(1, 1)
- -- compare wood/wood2 to block in front. If tree has grown
- for i = 1, 3 do -- check first 3 trees
- if turtle.detect() then
- turtle.select(slot:getItemSlot("wood"))
- if turtle.compare() then
- woodType = "wood"
- if slot:getItemSlot("wood2") > 0 then
- woodSpare = "wood2"
- end
- saveToLog("chooseWood: wood grown!", true)
- else
- if slot:getItemSlot("wood2") > 0 then
- turtle.select(slot:getItemSlot("wood2"))
- if turtle.compare() then
- woodType = "wood2"
- woodSpare = "wood"
- end
- saveToLog("chooseWood: wood2 grown!", true)
- end
- end
- saveToLog('chooseWood: objectives["choose wood"] = true', true)
- objectives["choose wood"] = true
- break
- else
- saveToLog("chooseWood: Tree "..i.." still a sapling", true)
- forward(3, 1)
- numMoves = numMoves + 1
- end
- end
- if not objectives["choose wood"] then
- saveToLog("chooseWood: wood not grown yet", true)
- end
- down(1, 1)
- turnLeft(1)
- forward(2, 1)
- turnLeft(1) --facing furnace
- if numMoves > 0 then
- for i = 1, numMoves do
- forward(3, 1)
- end
- end
- forward(2, 1) --under furnace
- turnLeft(2)
- if woodType == "" then
- saveToLog("chooseWood: wood not grown yet", true)
- else
- --convert spare wood/wood2 to chests/charcoal
- if woodSpare ~= "" then
- if slot:getItemSlot(woodSpare) > 0 then
- if turtle.getItemCount(slot:getItemSlot(woodSpare)) < 3 then --make planks and burn
- saveToLog("chooseWood: using "..turtle.getItemCount(slot:getItemSlot(woodSpare)).." excess "..woodSpare.." to refuel", true)
- --check no planks around
- if slot:getItemSlot("planks") > 0 then
- turtle.select(slot:getItemSlot("planks"))
- saveToLog("chooseWood: using existing planks to refuel", true)
- turtle.refuel()
- end
- saveToLog("chooseWood: crafting planks", true)
- craft{craftItem = "planks", craftQuantity = 64, sourceItem1 = woodSpare, destSlot = 0, doSort = true}
- turtle.select(slot:getItemSlot("planks"))
- turtle.refuel()
- slot.update{self = slot, item = "planks", delete = true}
- else --craft chests if needed, min 4 wood = 2 chests
- if placeStorage:getStoragePlaced("redstone") then
- chestsNeeded = chestsNeeded - 2
- end
- if objectives["place extended storage"] then
- chestsNeeded = chestsNeeded - 5 --min 7
- end
- chestsNeeded = chestsNeeded - turtle.getItemCount(slot:getItemSlot("chests")) + 1
- if chestsNeeded > 0 then
- saveToLog("chooseWood: converting "..woodSpare.." to chests", true)
- numChests = math.floor(turtle.getItemCount(slot:getItemSlot(woodSpare)) / 2)
- if numChests > chestsNeeded then
- numChests = chestsNeeded
- end
- --need 14 wood for 7 chests
- if slot:getItemSlot("planks") > 0 then
- turtle.select(slot:getItemSlot("planks"))
- turtle.refuel()
- slot.update{self = slot, item = "planks", delete = true}
- sortInventory(true)
- end
- craft{craftItem = "planks", craftQuantity = numChests * 8, sourceItem1 = woodSpare, destSlot = 0, doSort = true}
- craft{craftItem = "chests", craftQuantity = numChests, sourceItem1 = "planks", destSlot = 0, doSort = true}
- end
- if slot:getItemSlot(woodSpare) > 0 then
- if turtle.getItemCount(slot:getItemSlot(woodSpare)) > 0 then
- saveToLog("chooseWood: converting remaining "..woodSpare.." to charcoal", true)
- smelt("charcoal", 0, woodSpare)
- if slot.getItemSlot(slot, woodSpare) > 0 then
- turtle.select(slot.getItemSlot(slot, woodSpare))
- turtle.refuel()
- slot.update{self = slot, item = woodSpare, delete = true}
- end
- end
- end
- end
- if woodType == "wood2" then --change wood2 to wood
- emptySlot = slot:getItemSlot(woodType)
- slot.update{self = slot, slotNo = emptySlot, newItem = "wood"}
- end
- sortInventory(true)
- end
- end
- if slot:getItemSlot("saplings2") > 0 then --burn saplings2
- saveToLog("chooseWood: Saplings2 used for fuel", true)
- turtle.select(slot:getItemSlot("saplings2"))
- turtle.refuel()
- slot.update{self = slot, item = "saplings2", delete = true}
- sortInventory(true)
- end
- if not placeStorage:getMarkerPlaced("wood") then
- forward(7, 1)
- dig.digNew{self = dig, direction = "down", callFrom = "chooseWood"}
- turtle.select(slot:getItemSlot("wood"))
- turtle.placeDown()
- placeStorage:setMarkerPlaced("wood")
- turnRight(2)
- forward(7, 1)
- turnRight(2)
- end
- success = true
- end
- return success
- end
- function clearBase()
- --clear area around first tree 4 X 4 SQUARE
- reposition("FFRFFRFFFFRFFFFRFFFFRFRFFFLFFLFFLFRB", "wood2,saplings", true)
- --put furnace above
- turtle.select(slot:getItemSlot("furnaces"))
- turtle.placeUp()
- saveToLog("clearBase: furnace placed", true, true)
- slot.update{self = slot, item = "furnaces", delete = true}
- sortInventory(true)
- end
- function clearColumn(blockType, columnType)
- --move down to original y coord
- -- columnType = "storage" or "farm"
- local blockAbove = false
- if location:getY() > coordHome:getY() then
- saveToLog("Returning to original yCoord "..coordHome:getY(), true)
- while location:getY() > coordHome:getY() do
- down(1, 1)
- end
- elseif location:getY() < coordHome:getY() then
- while location:getY() < coordHome:getY() do
- up(1, 1)
- end
- end
- saveToLog("clearColumn checking fuel level", true)
- refuel(0)
- --at start of new col, could be space below, blocks above
- for i = 1, 15 do
- if i == 1 then
- placeBlock("cobble", columnType, i) -- placeBlock("cobble", "storage", 1)
- else
- placeBlock(blockType, columnType, i) -- placeBlock("cobble", "farm", 2)
- end
- --check above
- turtle.select(1)
- while turtle.detectUp() do
- up(1, 1)
- sleep(.5) -- allow for sand/gravel
- turnRight(1)
- dig.digNew{self = dig, waitForGravel = true, callFrom = "clearColumn"}
- turnRight(2)
- dig.digNew{self = dig, waitForGravel = true, callFrom = "clearColumn"}
- turnRight(1)
- end
- while location:getY() > coordHome:getY() do --gone upwards
- down(1, 1)
- end
- if i == 8 then --check fuel
- refuel(0)
- end
- if i < 15 then
- forward(1, 1)
- end
- end
- placeBlock("cobble", columnType, 16)
- saveToLog("Finished clearing column", true)
- end
- function clearTreeFarm()
- local emptySlot = 0
- local noOfSaplings = 0
- local noOfSaplings2 = 0
- local tempSlot = 0
- local useWood = "wood"
- local usePlanks = "planks"
- local success = false
- --first see how many saplings of each type and choose the most
- noOfSaplings = turtle.getItemCount(slot.getItemSlot(slot, "saplings"))
- if slot.getItemSlot(slot, "saplings2") > 0 then
- noOfSaplings2 = turtle.getItemCount(slot.getItemSlot(slot, "saplings2"))
- end
- if noOfSaplings < noOfSaplings2 then
- saveToLog(noOfSaplings2.." saplings2 collected, will use these for tree farming", true)
- --swap them over
- saveToLog("Swapping saplings with saplings2", false)
- emptySlot = getFirstEmptySlot()
- turtle.select(slot.getItemSlot(slot, "saplings"))
- turtle.transferTo(emptySlot) --put saplings in spare slot
- turtle.select(slot.getItemSlot(slot, "saplings2"))
- turtle.transferTo(slot.getItemSlot(slot, "saplings")) --put saplings2 into original saplings slot
- turtle.select(emptySlot)
- turtle.transferTo(slot.getItemSlot(slot, "saplings2")) --put original saplings into saplings2 slot
- slot.update{self = slot, item = "saplings"}
- slot.update{self = slot, item = "saplings2"}
- else
- saveToLog(noOfSaplings.." saplings collected, will use these for tree farming", true)
- end
- --delete saplings2 when harvestAllTrees and clearTreeFarm completed
- checkItems{keepSticks = 0, keepTorches = 9, keepSigns = 0} -- make 8 torches
- if slot:getItemSlot("planks") > 0 then
- turtle.select(slot:getItemSlot("planks"))
- turtle.refuel()
- slot.update{self = slot, item = "planks", delete = true}
- end
- if slot:getItemSlot("planks2") > 0 then
- turtle.select(slot:getItemSlot("planks2"))
- turtle.refuel()
- slot.update{self = slot, item = "planks2", delete = true}
- end
- --clear farm area
- forward(1, 1) --start tree farm 1 blocks in front of furnace
- -- may be storage chests on first column
- for i = 1, 4 do --clear 8 columns to ground level with grass
- saveToLog("Clearing column"..i, true)
- if i == 1 then
- clearColumn("cobble", "storage") --left side of square col 1 no saplings
- else
- clearColumn("dirt", "farm") --left side of square col 1 no saplings
- end
- turnRight(1)
- forward(1, 1) --start of next column
- turnRight(1) --ready to go
- saveToLog("Clearing column".. 1 + i, true)
- if i == 1 or i == 4 then
- clearColumn("cobble", "farm") --left side col 2 no saplings
- else
- clearColumn("dirt", "farm") --left side col 2 no saplings
- end
- if i < 4 then --do not move when last col is finished
- turnLeft(1)
- forward(1, 1)
- turnLeft(1)
- end
- end
- turnRight(1)
- refuel(0)
- forward(5, 1)
- turnRight(1)
- forward(1, 1) -- now on bottom of col 3 ready to plant saplings
- saveToLog(" clearTreeFarm: Farm cleared, now planting saplings", true)
- treeFarm:reset()
- up(1, 1)
- plantSaplings()
- turnRight(1)
- forward(3, 1)
- turnRight(1)
- plantSaplings()
- down(1, 1)
- forward(2, 1)
- turnRight(1)
- forward(3, 1)
- --now in front of torch
- checkTorch("home")
- saveToLog(treeFarm:getNumSaplings().." Saplings planted. Continuing tree harvest while waiting for treefarm to grow...", true)
- success = true
- return success
- end
- function compareBlock(direction, checkList, checkNum)
- --direction = "forward"
- --checkList = {} checkList[1] = "wood", checkList[2] = "wood2" etc
- --checkNum = 2 no of items in checklist
- --useSlot, amount, useItem = compareBlock("forward", checkList, 3)
- --useSlot, amount, useItem = compareBlock("forward", {"all"}, 1) checkList[1] = "all"
- local slotFound = 0
- local amount = 0
- local checkItem = ""
- local checkSlot = 0
- local item = ""
- local matchItem = false
- if checkList[1] == "all" then
- for i = 1, 16 do
- if turtle.getItemCount(i) > 0 then
- turtle.select(i)
- if direction == "forward" then
- if turtle.compare() then --compare slot i with block in front
- matchItem = true
- end
- elseif direction == "up" then
- if turtle.compareUp() then --compare slot i with block above
- matchItem = true
- end
- elseif direction == "down" then
- if turtle.compareDown() then --compare slot i with block below
- matchItem = true
- end
- end
- if matchItem then
- slotFound = i
- amount = turtle.getItemCount(i)
- item = slot:getSlotContains(i)
- break
- end
- end
- end
- else
- for i = 1, checkNum do
- if checkList[i] == "item" then
- if slot:getFirstUnknownItem() ~= "" then
- for j = 1, slot:getUnknownItemCount() do
- checkItem = "item"..j
- checkSlot = slot:getItemSlot(checkItem)
- if checkSlot > 0 then
- turtle.select(checkSlot)
- if direction == "forward" then
- if turtle.compare() then --compare slot with block in front
- matchItem = true
- end
- elseif direction == "up" then
- if turtle.compareUp() then --compare slot with block above
- matchItem = true
- end
- elseif direction == "down" then
- if turtle.compareDown() then --compare slot with block below
- matchItem = true
- end
- end
- if matchItem then
- slotFound = checkSlot
- amount = turtle.getItemCount(checkSlot)
- item = checkList[i]
- break
- end
- end
- end
- end
- else
- checkItem = checkList[i]
- checkSlot = slot:getItemSlot(checkList[i])
- if checkSlot > 0 then
- turtle.select(checkSlot)
- if direction == "forward" then
- if turtle.compare() then --compare slot with block in front
- matchItem = true
- end
- elseif direction == "up" then
- if turtle.compareUp() then --compare slot with block above
- matchItem = true
- end
- elseif direction == "down" then
- if turtle.compareDown() then --compare slot with block below
- matchItem = true
- end
- end
- if matchItem then
- slotFound = checkSlot
- amount = turtle.getItemCount(checkSlot)
- item = checkList[i]
- break
- end
- end
- end
- end
- end
- return slotFound, amount, item
- end
- function completeChests()
- local woodAvailable = 0
- local woodNeeded = 0
- local wood4chests = 0
- local chestsFromWood = 0
- local chestsNeeded = 0
- -- Checks quantity of wood/wood2 and uses excess for chests/fuel as required
- -- will only operate if wood/wood2 > 20
- if not placeStorage:getStoragePlaced("redstone") then
- chestsNeeded = 2
- end
- if not objectives["place extended storage"] then
- chestsNeeded = chestsNeeded + 5
- end
- chestsNeeded = chestsNeeded - turtle.getItemCount(slot:getItemSlot("chests")) + 1
- if chestsNeeded < 0 then
- chestsNeeded = 0
- end
- woodNeeded = chestsNeeded * 2
- --max 7 chests needed = 56 planks = 14 wood
- woodAvailable = turtle.getItemCount(slot:getItemSlot("wood")) - 24
- if woodAvailable > 0 then
- if woodAvailable > 16 then
- woodAvailable = 16
- end
- if woodAvailable > 1 then
- wood4chests = math.floor(woodAvailable / 2)
- if chestsNeeded > 0 then
- if chestsNeeded >= wood4chests then --more chests needed than available wood
- chestsFromWood = wood4chests
- else
- chestsFromWood = chestsNeeded
- end
- saveToLog("completeChests: making chests", true)
- craft{craftItem = "planks", craftQuantity = chestsFromWood * 8, sourceItem1 = "wood", destSlot = 0, doSort = true}
- craft{craftItem = "chests", craftQuantity = chestsFromWood, sourceItem1 = "planks", destSlot = 0}
- chestsNeeded = chestsNeeded - chestsFromWood
- else
- saveToLog("completeChests: using excess wood to refuel", true)
- craft{craftItem = "planks", craftQuantity = woodAvailable * 4, sourceItem1 = "wood", destSlot = 0, doSort = true}
- turtle.select(slot:getItemSlot("planks"))
- turtle.refuel()
- slot.update{self = slot, item = "planks", delete = true}
- end
- else
- saveToLog("completeChests: only one spare wood - ignoring", true)
- end
- end
- if slot:getItemSlot("wood2") > 0 then
- woodAvailable = turtle.getItemCount(slot:getItemSlot("wood2")) - 24
- if woodAvailable > 0 then
- if woodAvailable > 16 then
- woodAvailable = 16
- end
- if woodAvailable > 1 then
- wood4chests = math.floor(woodAvailable / 2) --1 wood = 0, 2 wood = 1
- if chestsNeeded > 0 then
- if chestsNeeded >= wood4chests then --more chests needed than available wood
- chestsFromWood = wood4chests
- else
- chestsFromWood = chestsNeeded
- end
- saveToLog("completeChests: making chests", true)
- craft{craftItem = "planks2", craftQuantity = chestsFromWood * 8, sourceItem1 = "wood2", destSlot = 0, doSort = true}
- craft{craftItem = "chests", craftQuantity = chestsFromWood, sourceItem1 = "planks2", destSlot = 0}
- else
- saveToLog("completeChests: using excess wood to refuel", true)
- craft{craftItem = "planks2", craftQuantity = woodAvailable * 4, sourceItem1 = "wood2", destSlot = 0, doSort = true}
- turtle.select(slot:getItemSlot("planks2"))
- turtle.refuel()
- slot.update{self = slot, item = "planks2", delete = true}
- end
- else
- saveToLog("completeChests: only one spare wood2 - ignoring", true)
- end
- end
- end
- if not placeStorage:getStoragePlaced("redstone") then
- placeStorage:place("redstone", false)
- end
- return true
- end
- function confirmCobble()
- --[[suspected cobble found, so empty out
- all slots into chest except cobble,
- move it to slot 16 and craft furnace.
- If craft ok then move furnace
- else try another unknown block]]--
- local sTime = os.time()
- local foundCobble = false
- local useItem = ""
- local useSlot = 0
- sortInventory(true)
- --cobble, gravel, flint, iron ore, ? sand, ? clay may have been found
- term.clear()
- term.setCursorPos(1,1)
- useSlot = slot:getItemSlot("cobble")
- if useSlot > 0 then
- if craft{craftItem = "furnaces", craftQuantity = 1, sourceItem1 = "cobble", destSlot = 0} then
- foundCobble = true
- else
- slot.update{self = slot, slotNo = useSlot, newItem = slot:getFreeUnknownItem()}
- end
- end
- if not foundCobble then
- if slot:getUnknownItemCount() > 0 then
- for i = slot:getMostUnknownItemSlot(), slot:getLeastUnknownItemSlot(), - 1 do
- saveToLog("confirmCobble: testing slot with unknown items = "..i.." with "..turtle.getItemCount(i).." items", false)
- turtle.select(i)
- if turtle.place() then --cobble, gravel, sand, iron ore, clay
- turtle.dig()
- if slot:getItemSlot("cobble") == 0 then
- useItem = slot:getSlotContains(i)
- slot.update{self = slot, slotNo = i, newItem = "cobble"}
- saveToLog("confirmCobble: attempting to craft furnace", true)
- if craft{craftItem = "furnaces", craftQuantity = 1, sourceItem1 = "cobble", destSlot = 0} then
- foundCobble = true
- break
- else
- slot.update{self = slot, slotNo = i, newItem = useItem}
- end
- end
- end
- end
- end
- end
- saveToLog("confirmCobble started at "..textutils.formatTime(sTime, true).." finished at "..textutils.formatTime(os.time(), true), false)
- return foundCobble
- end
- function craft(arg)
- --[[ assume empty chest next to turtle except at very early game stages.
- chest options: "doNotUse"
- doSort = true/false
- Examples:
- firstTree craft - planks from 1 wood: craft{craftItem = "planks", craftQuantity = 4, sourceItem1 = "wood", destSlot = 3, chest = "doNotUse"}
- firstTree make more planks: craft{craftItem = "planks", craftQuantity = 8, sourceItem1 = "wood", destSlot = 3, chest = "doNotUse"}
- firstTree make 1 chest: craft{craftItem = "chests", craftQuantity = 1, sourceItem1 = "planks", destSlot = 4}
- checkRemaining craft{craftItem = "sticks", craftQuantity = 4, sourceItem1 = "planks", destSlot = emptySlot}
- late stage: craft{craftItem = "computer", craftQuantity = 1, sourceItem1 = "glass panes", sourceItem2 = "redstone",sourceItem3 = "stone", destSlot = 16}
- ]]--
- --local sourceItem1 = arg.sourceItem1
- --local sourceItem2 = arg.sourceItem2
- --local sourceItem3 = arg.sourceItem3
- local sourceSlot1 = 0
- local sourceSlot2 = 0
- local sourceSlot3 = 0
- local sourceQuantity1 = 0
- local sourceQuantity2 = 0
- local sourceQuantity3 = 0
- local success = false
- local useChest = true
- local emptySlot = 0
- local gridContents = {}
- local gridSlot = {}
- for i = 1, 16 do
- gridContents[i] = ""
- gridSlot[i] = 0
- end
- if arg.doSort == nil then
- arg.doSort = false
- end
- if arg.doSort then
- sortInventory(true)
- end
- if arg.sourceItem1 == nil then
- sourceSlot1 = 0
- sourceQuantity1 = 0
- else
- sourceSlot1 = slot:getItemSlot(arg.sourceItem1)
- sourceQuantity1 = turtle.getItemCount(sourceSlot1)
- end
- if arg.sourceItem2 == nil then
- arg.sourceItem2 = ""
- sourceSlot2 = 0
- else
- sourceSlot2 = slot.getItemSlot(slot, arg.sourceItem2)
- sourceQuantity2 = turtle.getItemCount(sourceSlot2)
- end
- if arg.sourceItem3 == nil then
- arg.sourceItem3 = ""
- sourceSlot3 = 0
- else
- sourceSlot3 = slot.getItemSlot(slot, arg.sourceItem3)
- sourceQuantity3 = turtle.getItemCount(sourceSlot3)
- end
- if arg.destSlot == nil then
- arg.destSlot = 16
- end
- if arg.chest == "doNotUse" then
- useChest = false
- end
- saveToLog("craft: craftItem = "..tostring(arg.craftItem)..
- ", craftQuantity = "..tostring(arg.craftQuantity)..
- ", sourceItem1 = "..tostring(arg.sourceItem1)..
- ", sourceItem2 = "..tostring(arg.sourceItem2)..
- ", sourceItem3 = "..tostring(arg.sourceItem3)..
- ", destSlot = "..tostring(arg.destSlot), false)
- if useChest then --place chest forwards
- --if arg.doSort then
- --sortInventory(true)
- --end
- turtle.select(1)
- while turtle.detect() do --clear space in front
- --turtle.dig()
- dig.digNew{self = dig, slotNo = 1, callFrom = "craft"}
- end
- --while turtle.attack() do --in case mob in front
- while attack() do --in case mobs in front
- saveToLog("Mob attacked again!", false)
- end
- turtle.select(slot:getItemSlot("chests"))
- if turtle.place() then
- --check if chest is actually in front until cc 1.6.3 bug is sorted
- local tempChestSlot = slot:getItemSlot("chests")
- slot.update{self = slot, item = "chests", delete = true}
- if not turtle.detect() then --chest not present
- saveToLog("cc 1.6.3 place() bug, moving forward to rescue chest", true)
- forward(1)
- if turtle.detect() then
- saveToLog("cc 1.6.3 place() bug, ? chest found in front, digging...", true)
- dig.digNew{self = dig, slotNo = tempChestSlot, expectedItem = "chests", callFrom = "craft"}
- elseif turtle.detectDown() then
- saveToLog("cc 1.6.3 place() bug, ? chest found below, digging...", true)
- dig.digNew{self = dig, direction = "down", slotNo = tempChestSlot, expectedItem = "chests", callFrom = "craft"}
- end
- turtle.select(tempChestSlot)
- if turtle.refuel(0) then
- saveToLog("cc 1.6.3 place() bug, chest found!", true)
- slot.update{self = slot, slotNo = tempChestSlot, item = "chests"}
- else
- saveToLog("cc 1.6.3 place() bug, ? chest lost. exiting program...", true)
- error()
- end
- back(1)
- turtle.select(slot:getItemSlot("chests"))
- turtle.place()
- slot.update{self = slot, item = "chests", delete = true}
- end
- saveToLog("craft: About to fill chest", false)
- fillChest{direction = arg.direction, exceptSlot1 = sourceSlot1, exceptSlot2 = sourceSlot2, exceptSlot3 = sourceSlot3, doReset = false} -- fill except chosen item(s)
- else
- saveToLog("UNABLE TO PLACE CHEST", true)
- error()
- end
- end
- if destSlot == 0 then
- saveToLog("Craft: item = "..arg.craftItem.." Quantity = "..arg.craftQuantity.." from "..arg.sourceItem1..", "..arg.sourceItem2..", "..arg.sourceItem3.." put in first empty slot", true)
- else
- saveToLog("Craft: item = "..arg.craftItem.." Quantity = "..arg.craftQuantity.." from "..arg.sourceItem1..", "..arg.sourceItem2..", "..arg.sourceItem3.." put in slot "..arg.destSlot, true)
- end
- --turtle emptied out except for crafting items
- if sourceSlot1 ~= 16 then --not already in position
- if turtle.getItemCount(16) == 0 then
- saveToLog("Craft: moving "..arg.sourceItem1.." from "..sourceSlot1.." to slot 16", true, false)
- turtle.select(sourceSlot1)
- turtle.transferTo(16) --move selected first item to slot 16
- slot.transfer{self = slot, item = arg.sourceItem1, transferTo = 16}
- else -- already occupied, inventory full, so swap 15 and 16
- for i = 1, 14 do
- if turtle.getItemCount(i) == 0 then
- emptySlot = i
- end
- break
- end
- if sourceSlot2 == 16 then
- sourceSlot2 = emptySlot
- end
- saveToLog("Craft: moving "..slot:getSlotContains(16).." from slot 16 to slot "..emptySlot, false)
- turtle.select(16)
- turtle.transferTo(emptySlot)
- slot.transfer{self = slot, item = slot:getSlotContains(16), transferTo = emptySlot}
- saveToLog("Craft: moving "..arg.sourceItem1.." from "..sourceSlot1.." to slot 16", false)
- turtle.select(sourceSlot1)
- turtle.transferTo(16) --move selected first item to slot 16
- slot.transfer{self = slot, item = arg.sourceItem1, transferTo = 16}
- end
- end
- turtle.select(16)
- if arg.craftItem == "planks" or arg.craftItem == "planks2" then --craft{craftItem = "planks", craftQuantity = 4, sourceItem1 = "wood", destSlot = 3}
- turtle.transferTo(1, arg.craftQuantity / 4)
- gridContents[1] = arg.sourceItem1
- elseif arg.craftItem == "chests" then --craft{craftItem = "chests", craftQuantity = 1, sourceItem1 = "planks", destSlot = 4}
- --8 planks = 1 chest
- turtle.transferTo(1, arg.craftQuantity)
- turtle.transferTo(2, arg.craftQuantity)
- turtle.transferTo(3, arg.craftQuantity)
- turtle.transferTo(5, arg.craftQuantity)
- turtle.transferTo(7, arg.craftQuantity)
- turtle.transferTo(9, arg.craftQuantity)
- turtle.transferTo(10, arg.craftQuantity)
- turtle.transferTo(11, arg.craftQuantity)
- gridContents[1] = arg.sourceItem1
- gridContents[2] = arg.sourceItem1
- gridContents[3] = arg.sourceItem1
- gridContents[5] = arg.sourceItem1
- gridContents[7] = arg.sourceItem1
- gridContents[9] = arg.sourceItem1
- gridContents[10] = arg.sourceItem1
- gridContents[11] = arg.sourceItem1
- gridSlot[1] = sourceSlot1
- gridSlot[2] = sourceSlot1
- gridSlot[3] = sourceSlot1
- gridSlot[5] = sourceSlot1
- gridSlot[7] = sourceSlot1
- gridSlot[9] = sourceSlot1
- gridSlot[10] = sourceSlot1
- gridSlot[11] = sourceSlot1
- elseif arg.craftItem == "furnaces" then --craft{craftItem = "furnaces", craftQuantity = 1, sourceItem1 = "cobble", destSlot = 16}
- -- 8 cobble = 1 furnace
- turtle.transferTo(1, arg.craftQuantity)
- turtle.transferTo(2, arg.craftQuantity)
- turtle.transferTo(3, arg.craftQuantity)
- turtle.transferTo(5, arg.craftQuantity)
- turtle.transferTo(7, arg.craftQuantity)
- turtle.transferTo(9, arg.craftQuantity)
- turtle.transferTo(10, arg.craftQuantity)
- turtle.transferTo(11, arg.craftQuantity)
- gridContents[1] = arg.sourceItem1
- gridContents[2] = arg.sourceItem1
- gridContents[3] = arg.sourceItem1
- gridContents[5] = arg.sourceItem1
- gridContents[7] = arg.sourceItem1
- gridContents[9] = arg.sourceItem1
- gridContents[10] = arg.sourceItem1
- gridContents[11] = arg.sourceItem1
- gridSlot[1] = sourceSlot1
- gridSlot[2] = sourceSlot1
- gridSlot[3] = sourceSlot1
- gridSlot[5] = sourceSlot1
- gridSlot[7] = sourceSlot1
- gridSlot[9] = sourceSlot1
- gridSlot[10] = sourceSlot1
- gridSlot[11] = sourceSlot1
- elseif arg.craftItem == "walls" then --craft{craftItem = "walls", craftQuantity = 6, sourceItem1 = "moss stone", destSlot = 0}
- -- 6 mossy cobble = 6 mossy cobblestone wall
- turtle.transferTo(1, arg.craftQuantity / 6)
- turtle.transferTo(2, arg.craftQuantity / 6)
- turtle.transferTo(3, arg.craftQuantity / 6)
- turtle.transferTo(5, arg.craftQuantity / 6)
- turtle.transferTo(6, arg.craftQuantity / 6)
- turtle.transferTo(7, arg.craftQuantity / 6)
- gridContents[1] = arg.sourceItem1
- gridContents[2] = arg.sourceItem1
- gridContents[3] = arg.sourceItem1
- gridContents[5] = arg.sourceItem1
- gridContents[6] = arg.sourceItem1
- gridContents[7] = arg.sourceItem1
- gridSlot[1] = sourceSlot1
- gridSlot[2] = sourceSlot1
- gridSlot[3] = sourceSlot1
- gridSlot[5] = sourceSlot1
- gridSlot[6] = sourceSlot1
- gridSlot[7] = sourceSlot1
- elseif arg.craftItem == "sticks" then --craft{craftItem = "sticks", craftQuantity = 4, sourceItem1 = "planks", destSlot = 13}
- -- 2 planks gives 4 sticks
- turtle.transferTo(1, arg.craftQuantity / 4)
- turtle.transferTo(5, arg.craftQuantity / 4)
- gridContents[1] = arg.sourceItem1
- gridContents[5] = arg.sourceItem1
- gridSlot[1] = sourceSlot1
- gridSlot[5] = sourceSlot1
- elseif arg.craftItem == "nuggets" then --craft{craftItem = "nuggets", craftQuantity = 9, sourceItem1 = "gold", destSlot = 0}
- --1 gold gives 9 nuggets
- turtle.transferTo(1, arg.craftQuantity / 9)
- gridContents[1] = arg.sourceItem1
- gridSlot[1] = sourceSlot1
- elseif arg.craftItem == "buckets" then --craft{craftItem = "buckets", craftQuantity = 1, sourceItem1 = "iron", destSlot = 16}
- turtle.transferTo(1, arg.craftQuantity)
- turtle.transferTo(3, arg.craftQuantity)
- turtle.transferTo(6, arg.craftQuantity)
- gridContents[1] = arg.sourceItem1
- gridContents[3] = arg.sourceItem1
- gridContents[6] = arg.sourceItem1
- gridSlot[1] = sourceSlot1
- gridSlot[3] = sourceSlot1
- gridSlot[6] = sourceSlot1
- elseif arg.craftItem == "crafting table" then --craft{craftItem = "crafting table", craftQuantity = 1, sourceItem1 = "planks", destSlot = 16}
- -- 4 planks = 1 table
- turtle.transferTo(1, arg.craftQuantity)
- turtle.transferTo(2, arg.craftQuantity)
- turtle.transferTo(5, arg.craftQuantity)
- turtle.transferTo(6, arg.craftQuantity)
- gridContents[1] = arg.sourceItem1
- gridContents[2] = arg.sourceItem1
- gridContents[5] = arg.sourceItem1
- gridContents[6] = arg.sourceItem1
- gridSlot[1] = sourceSlot1
- gridSlot[2] = sourceSlot1
- gridSlot[5] = sourceSlot1
- gridSlot[6] = sourceSlot1
- elseif arg.craftItem == "torches" then --craft{craftItem = "torches", craftQuantity = 4, sourceItem1 = "sticks", sourceItem2 = "charcoal" destSlot = 16}// OR sourceItem2 = "coal"
- -- 1 stick + 1 coal/charcoal = 4 torches
- if sourceSlot2 ~= 15 then
- turtle.select(sourceSlot2) -- move coal/charcoal to 15
- turtle.transferTo(15)
- slot.transfer{self = slot, item = arg.sourceItem2, transferTo = 15}
- end
- turtle.select(16)
- turtle.transferTo(5, arg.craftQuantity / 4) --move sticks to 5
- turtle.select(15)
- turtle.transferTo(1, arg.craftQuantity / 4) --move coal/charcoal to 1
- gridContents[1] = arg.sourceItem2
- gridContents[5] = arg.sourceItem1
- gridSlot[1] = sourceSlot2
- gridSlot[5] = sourceSlot1
- elseif arg.craftItem == "signs" then --craft{craftItem = "signs", craftQuantity = 3, sourceItem1 = "sticks", sourceItem2 = "planks" destSlot = 16}
- -- 1 stick + 6 planks = 3 signs
- if sourceSlot2 ~= 15 then
- turtle.select(sourceSlot2) -- move planks to 15
- turtle.transferTo(15)
- slot.transfer{self = slot, item = arg.sourceItem2, transferTo = 15}
- end
- turtle.select(16)
- turtle.transferTo(10, arg.craftQuantity / 3) --move sticks to 5
- turtle.select(15)
- turtle.transferTo(1, arg.craftQuantity / 3) --move planks to 1
- turtle.transferTo(2, arg.craftQuantity / 3) --move planks to 2
- turtle.transferTo(3, arg.craftQuantity / 3) --move planks to 3
- turtle.transferTo(5, arg.craftQuantity / 3) --move planks to 5
- turtle.transferTo(6, arg.craftQuantity / 3) --move planks to 6
- turtle.transferTo(7, arg.craftQuantity / 3) --move planks to 7
- gridContents[1] = arg.sourceItem2
- gridContents[2] = arg.sourceItem2
- gridContents[3] = arg.sourceItem2
- gridContents[5] = arg.sourceItem2
- gridContents[6] = arg.sourceItem2
- gridContents[7] = arg.sourceItem2
- gridContents[10] = arg.sourceItem1
- gridSlot[1] = sourceSlot2
- gridSlot[2] = sourceSlot2
- gridSlot[3] = sourceSlot2
- gridSlot[5] = sourceSlot2
- gridSlot[6] = sourceSlot2
- gridSlot[7] = sourceSlot2
- gridSlot[10] = sourceSlot1
- elseif arg.craftItem == "lapis block" or arg.craftItem == "redstone block" then --craft{craftItem = "lapis block", craftQuantity = 1, sourceItem1 = "lapis", destSlot = 0}
- --9 lapis = 1 lapis block
- turtle.transferTo(1, arg.craftQuantity)
- turtle.transferTo(2, arg.craftQuantity)
- turtle.transferTo(3, arg.craftQuantity)
- turtle.transferTo(5, arg.craftQuantity)
- turtle.transferTo(6, arg.craftQuantity)
- turtle.transferTo(7, arg.craftQuantity)
- turtle.transferTo(9, arg.craftQuantity)
- turtle.transferTo(10, arg.craftQuantity)
- turtle.transferTo(11, arg.craftQuantity)
- gridContents[1] = arg.sourceItem1
- gridContents[2] = arg.sourceItem1
- gridContents[3] = arg.sourceItem1
- gridContents[5] = arg.sourceItem1
- gridContents[6] = arg.sourceItem1
- gridContents[7] = arg.sourceItem1
- gridContents[9] = arg.sourceItem1
- gridContents[10] = arg.sourceItem1
- gridContents[11] = arg.sourceItem1
- gridSlot[1] = sourceSlot1
- gridSlot[2] = sourceSlot1
- gridSlot[3] = sourceSlot1
- gridSlot[5] = sourceSlot1
- gridSlot[6] = sourceSlot1
- gridSlot[7] = sourceSlot1
- gridSlot[9] = sourceSlot1
- gridSlot[10] = sourceSlot1
- gridSlot[11] = sourceSlot1
- elseif arg.craftItem == "diamond pickaxe" then --craft{craftItem = "diamond pickaxe", craftQuantity = 1, sourceItem1 = "sticks", sourceItem2 = "diamonds" destSlot = 16}
- --2 sticks + 3 diamonds = 1 axe
- if sourceSlot2 ~= 15 then
- turtle.select(sourceSlot2) -- ?diamonds or diamonds
- turtle.transferTo(15)
- slot.transfer{self = slot, item = arg.sourceItem2, transferTo = 15}
- end
- turtle.select(16)
- turtle.transferTo(6, arg.craftQuantity) --move sticks to 6
- turtle.transferTo(10, arg.craftQuantity) --move sticks to 10
- turtle.select(15)
- turtle.transferTo(1, arg.craftQuantity) --move diamond to 1
- turtle.transferTo(2, arg.craftQuantity) --move diamond to 2
- turtle.transferTo(3, arg.craftQuantity) --move diamond to 3
- gridContents[1] = arg.sourceItem2
- gridContents[2] = arg.sourceItem2
- gridContents[3] = arg.sourceItem2
- gridContents[6] = arg.sourceItem1
- gridContents[10] = arg.sourceItem1
- gridSlot[1] = sourceSlot2
- gridSlot[2] = sourceSlot2
- gridSlot[3] = sourceSlot2
- gridSlot[6] = sourceSlot1
- gridSlot[10] = sourceSlot1
- elseif arg.craftItem == "paper" then --craft{craftItem = "paper", craftQuantity = 3, sourceItem1 = "sugar cane", destSlot = 16}
- --3 sugar cane = 3 paper
- turtle.transferTo(1, arg.craftQuantity / 3)
- turtle.transferTo(2, arg.craftQuantity / 3)
- turtle.transferTo(3, arg.craftQuantity / 3)
- gridContents[1] = arg.sourceItem1
- gridContents[2] = arg.sourceItem1
- gridContents[3] = arg.sourceItem1
- gridSlot[1] = sourceSlot1
- gridSlot[2] = sourceSlot1
- gridSlot[3] = sourceSlot1
- elseif arg.craftItem == "fences" then --craft{craftItem = "fences", craftQuantity = 2, sourceItem1 = "sticks", destSlot = 0}
- -- 6 sticks = 2 fences
- turtle.transferTo(5, arg.craftQuantity / 2)
- turtle.transferTo(6, arg.craftQuantity / 2)
- turtle.transferTo(7, arg.craftQuantity / 2)
- turtle.transferTo(9, arg.craftQuantity / 2)
- turtle.transferTo(10, arg.craftQuantity / 2)
- turtle.transferTo(11, arg.craftQuantity / 2)
- gridContents[5] = arg.sourceItem1
- gridContents[6] = arg.sourceItem1
- gridContents[7] = arg.sourceItem1
- gridContents[9] = arg.sourceItem1
- gridContents[10] = arg.sourceItem1
- gridContents[11] = arg.sourceItem1
- gridSlot[5] = sourceSlot1
- gridSlot[6] = sourceSlot1
- gridSlot[7] = sourceSlot1
- gridSlot[9] = sourceSlot1
- gridSlot[10] = sourceSlot1
- gridSlot[11] = sourceSlot1
- elseif arg.craftItem == "glass panes" then --craft{craftItem = "glass panes", craftQuantity = 16, sourceItem1 = "glass", destSlot = 0}
- -- 6 glass = 16 panes
- turtle.transferTo(5, arg.craftQuantity / 16)
- turtle.transferTo(6, arg.craftQuantity / 16)
- turtle.transferTo(7, arg.craftQuantity / 16)
- turtle.transferTo(9, arg.craftQuantity / 16)
- turtle.transferTo(10, arg.craftQuantity / 16)
- turtle.transferTo(11, arg.craftQuantity / 16)
- gridContents[5] = arg.sourceItem1
- gridContents[6] = arg.sourceItem1
- gridContents[7] = arg.sourceItem1
- gridContents[9] = arg.sourceItem1
- gridContents[10] = arg.sourceItem1
- gridContents[11] = arg.sourceItem1
- gridSlot[5] = sourceSlot1
- gridSlot[6] = sourceSlot1
- gridSlot[7] = sourceSlot1
- gridSlot[9] = sourceSlot1
- gridSlot[10] = sourceSlot1
- gridSlot[11] = sourceSlot1
- elseif arg.craftItem == "floppy disk" then --craft{craftItem = "floppy disk", craftQuantity = 1, sourceItem1 = "paper", sourceItem2 = "redstone" destSlot = 16}
- -- 1 paper, 1 redstone
- if sourceSlot2 ~= 15 then
- turtle.select(sourceSlot2) --redstone
- turtle.transferTo(15)
- slot.transfer{self = slot, item = arg.sourceItem2, transferTo = 15}
- end
- turtle.select(16)
- turtle.transferTo(5, arg.craftQuantity) --move paper to 5
- turtle.select(15)
- turtle.transferTo(1, arg.craftQuantity) --move redstone to 1
- gridContents[1] = arg.sourceItem2
- gridContents[5] = arg.sourceItem1
- gridSlot[1] = sourceSlot2
- gridSlot[5] = sourceSlot1
- elseif arg.craftItem == "computer" then --craft{craftItem = "computer", craftQuantity = 1, sourceItem1 = "glass panes", sourceItem2 = "redstone",sourceItem3 = "stone", destSlot = 16}
- -- 1 glass panes, 1 redstone, 7 stone
- if sourceSlot2 ~= 15 then
- turtle.select(sourceSlot2) --redstone
- turtle.transferTo(15)
- slot.transfer{self = slot, item = arg.sourceItem2, transferTo = 15}
- end
- if sourceSlot3 ~= 14 then
- turtle.select(sourceSlot3) --stone
- turtle.transferTo(14)
- slot.transfer{self = slot, item = arg.sourceItem3, transferTo = 14}
- end
- turtle.select(16)
- turtle.transferTo(10, arg.craftQuantity) --move glass panes to 10
- turtle.select(15)
- turtle.transferTo(6, arg.craftQuantity) --move redstone to 6
- turtle.select(14) --stone
- turtle.transferTo(1, arg.craftQuantity) --move stone to 6
- turtle.transferTo(2, arg.craftQuantity)
- turtle.transferTo(3, arg.craftQuantity)
- turtle.transferTo(5, arg.craftQuantity)
- turtle.transferTo(7, arg.craftQuantity)
- turtle.transferTo(9, arg.craftQuantity)
- turtle.transferTo(11, arg.craftQuantity)
- gridContents[1] = arg.sourceItem3
- gridContents[2] = arg.sourceItem3
- gridContents[3] = arg.sourceItem3
- gridContents[5] = arg.sourceItem3
- gridContents[6] = arg.sourceItem2
- gridContents[7] = arg.sourceItem3
- gridContents[9] = arg.sourceItem3
- gridContents[10] = arg.sourceItem1
- gridContents[11] = arg.sourceItem3
- gridSlot[1] = sourceSlot3
- gridSlot[2] = sourceSlot3
- gridSlot[3] = sourceSlot3
- gridSlot[5] = sourceSlot3
- gridSlot[6] = sourceSlot2
- gridSlot[7] = sourceSlot3
- gridSlot[9] = sourceSlot3
- gridSlot[10] = sourceSlot1
- gridSlot[11] = sourceSlot3
- elseif arg.craftItem == "disk drive" then --craft{craftItem = "disk drive", craftQuantity = 1, sourceItem1 = "redstone", sourceItem2 = "stone", destSlot = 16}
- -- 2 redstone, 7 stone
- if sourceSlot2 ~= 15 then
- turtle.select(sourceSlot2) --stone
- turtle.transferTo(15)
- slot.transfer{self = slot, item = arg.sourceItem2, transferTo = 15}
- end
- turtle.select(16)
- turtle.transferTo(6, arg.craftQuantity) --move to 6
- turtle.transferTo(10, arg.craftQuantity) --move to 10
- turtle.select(15)
- turtle.transferTo(1, arg.craftQuantity) --move stone to 6
- turtle.transferTo(2, arg.craftQuantity)
- turtle.transferTo(3, arg.craftQuantity)
- turtle.transferTo(5, arg.craftQuantity)
- turtle.transferTo(7, arg.craftQuantity)
- turtle.transferTo(9, arg.craftQuantity)
- turtle.transferTo(11, arg.craftQuantity)
- gridContents[1] = arg.sourceItem2
- gridContents[2] = arg.sourceItem2
- gridContents[3] = arg.sourceItem2
- gridContents[5] = arg.sourceItem2
- gridContents[6] = arg.sourceItem1
- gridContents[7] = arg.sourceItem2
- gridContents[9] = arg.sourceItem2
- gridContents[10] = arg.sourceItem1
- gridContents[11] = arg.sourceItem2
- gridSlot[1] = sourceSlot2
- gridSlot[2] = sourceSlot2
- gridSlot[3] = sourceSlot2
- gridSlot[5] = sourceSlot2
- gridSlot[6] = sourceSlot1
- gridSlot[7] = sourceSlot2
- gridSlot[9] = sourceSlot2
- gridSlot[10] = sourceSlot1
- gridSlot[11] = sourceSlot2
- elseif arg.craftItem == "turtle" then --craft{craftItem = "turtle", craftQuantity = 1, sourceItem1 = "chests", sourceItem2 = "computer",sourceItem3 = "iron", destSlot = 16}
- -- 1 chest, 1 computer, 7 iron
- if sourceSlot2 ~= 15 then
- turtle.select(sourceSlot2) --computer
- turtle.transferTo(15, arg.craftQuantity)
- slot.transfer{self = slot, item = arg.sourceItem2, transferTo = 15}
- end
- if sourceSlot3 ~= 14 then
- turtle.select(sourceSlot3) --iron
- turtle.transferTo(14)
- slot.transfer{self = slot, item = arg.sourceItem3, transferTo = 14}
- end
- turtle.select(16)
- turtle.transferTo(10, arg.craftQuantity)
- turtle.select(15) --computer
- turtle.transferTo(6, arg.craftQuantity)
- turtle.select(14) --iron
- turtle.transferTo(1, arg.craftQuantity) --move iron
- turtle.transferTo(2, arg.craftQuantity)
- turtle.transferTo(3, arg.craftQuantity)
- turtle.transferTo(5, arg.craftQuantity)
- turtle.transferTo(7, arg.craftQuantity)
- turtle.transferTo(9, arg.craftQuantity)
- turtle.transferTo(11, arg.craftQuantity)
- gridContents[1] = arg.sourceItem3
- gridContents[2] = arg.sourceItem3
- gridContents[3] = arg.sourceItem3
- gridContents[5] = arg.sourceItem3
- gridContents[6] = arg.sourceItem2
- gridContents[7] = arg.sourceItem3
- gridContents[9] = arg.sourceItem3
- gridContents[10] = arg.sourceItem1
- gridContents[11] = arg.sourceItem3
- gridSlot[1] = sourceSlot3
- gridSlot[2] = sourceSlot3
- gridSlot[3] = sourceSlot3
- gridSlot[5] = sourceSlot3
- gridSlot[6] = sourceSlot2
- gridSlot[7] = sourceSlot3
- gridSlot[9] = sourceSlot3
- gridSlot[10] = sourceSlot1
- gridSlot[11] = sourceSlot3
- elseif arg.craftItem == "crafty mining turtle" then --craft{craftItem = "crafty mining turtle", craftQuantity = 1, sourceItem1 = "crafting table", sourceItem2 = "diamond pickaxe",sourceItem3 = "turtle", destSlot = 16}
- -- 1 crafting table, 1 diamond pickaxe, 1 turtle
- if sourceSlot2 ~= 15 then
- turtle.select(sourceSlot2) --pickaxe
- turtle.transferTo(15, arg.craftQuantity)
- slot.transfer{self = slot, item = arg.sourceItem2, transferTo = 15}
- end
- if sourceSlot3 ~= 14 then
- turtle.select(sourceSlot3) --turtle
- turtle.transferTo(14)
- slot.transfer{self = slot, item = arg.sourceItem3, transferTo = 14}
- end
- turtle.select(16)
- turtle.transferTo(1, arg.craftQuantity) --move crafting table to 1
- turtle.select(15)
- turtle.transferTo(3, arg.craftQuantity) --move pickaxe to 3
- turtle.select(14)
- turtle.transferTo(2, arg.craftQuantity) --move turtle to 2
- gridContents[1] = arg.sourceItem1
- gridContents[2] = arg.sourceItem3
- gridContents[3] = arg.sourceItem2
- gridSlot[1] = sourceSlot1
- gridSlot[2] = sourceSlot3
- gridSlot[3] = sourceSlot2
- end
- if useChest then
- if turtle.getItemCount(16) > 0 then
- saveToLog("craft: adding excess "..arg.sourceItem1.." to chest from slot 16 (/"..sourceSlot1..")", false)
- fillChest{direction = arg.direction, addItem = arg.sourceItem1, addAmount = turtle.getItemCount(16), fromSlot = 16, originalSlot = sourceSlot1} -- add remaining source items to chest
- end
- if turtle.getItemCount(15) > 0 then
- saveToLog("craft: adding excess "..arg.sourceItem2.." to chest from slot 15 (/"..sourceSlot2..")", false)
- fillChest{direction = arg.direction, addItem = arg.sourceItem2, addAmount = turtle.getItemCount(15), fromSlot = 15, originalSlot = sourceSlot2} -- add remaining source items to chest
- end
- if turtle.getItemCount(14) > 0 then
- saveToLog("craft: adding excess "..arg.sourceItem3.." to chest from slot 14 (/"..sourceSlot3..")", false)
- fillChest{direction = arg.direction, addItem = arg.sourceItem3, addAmount = turtle.getItemCount(14), fromSlot = 14, originalSlot = sourceSlot3} -- add remaining source items to chest
- end
- --slot.update{self = slot, slotNo = 16, item = arg.sourceItem1, delete = true}
- slot.update{self = slot, item = arg.sourceItem1, delete = true}
- if arg.sourceItem2 ~= "" then
- slot.update{self = slot, item = arg.sourceItem2, delete = true}
- end
- if arg.sourceItem3 ~= "" then
- slot.update{self = slot, item = arg.sourceItem3, delete = true}
- end
- end
- -- Attempt to craft item
- turtle.select(16)
- saveToLog("Attempting to craft "..arg.craftItem.." in slot 16", false)
- if turtle.craft() then
- success = true
- saveToLog("craft: success "..arg.craftItem.." in slot 16", true)
- --now put crafted item in chest first, so will mix with any existing similar items
- if useChest then
- saveToLog("craft: adding crafted item "..arg.craftItem.." to chest", false)
- fillChest{direction = arg.direction, addItem = arg.craftItem, addAmount = turtle.getItemCount(16), fromSlot = 16, originalSlot = 16} -- add crafted item
- end
- else --crafting not successful, so empty out all items from chest
- saveToLog("Attempting to craft "..arg.craftItem.." did not succeed", true)
- --error()
- if useChest then
- saveToLog("craft: failed, filling chest to empty turtle", false)
- for i = 1, 16 do
- if turtle.getItemCount(i) > 0 then
- fillChest{direction = arg.direction, addItem = gridContents[i], addAmount = turtle.getItemCount(i), fromSlot = i, originalSlot = gridSlot[i]} -- add crafted item
- end
- end
- end
- end
- if useChest then -- always, except in firstTree()
- saveToLog("Crafting finished, emptying chest back into turtle", false)
- emptyChest(arg.direction)
- if slot.getItemSlot(slot, "chests") > 0 then
- emptySlot = slot:getItemSlot("chests")
- else
- emptySlot = getFirstEmptySlot(false)
- end
- dig.digNew{self = dig, slotNo = emptySlot, expectedItem = "chests", callFrom = "craft"}
- slot.update{self = slot, slotNo = emptySlot, item = "chests"}
- if success then --item crafted OK. if existing eg torches, will be in correct slot already, else should return to 16
- turtle.select(16)
- if turtle.getItemCount(16) > 0 then --new item, so returned to 16
- if arg.destSlot == 0 then --use any slot
- arg.destSlot = getFirstEmptySlot(false)
- if arg.destSlot == 0 then --no empty slots
- arg.destSlot = 16
- end
- else
- if slot:getItemSlot(arg.craftItem) > 0 then
- arg.destSlot = slot:getItemSlot(arg.craftItem)
- end
- end
- if arg.destSlot == 16 then
- slot.update{self = slot, slotNo = 16, item = arg.craftItem}
- else --move to selected slot
- turtle.select(16)
- if turtle.transferTo(arg.destSlot) then
- saveToLog("craft: Moved "..arg.craftItem.." to slot "..arg.destSlot, false)
- --slot.update{self = slot, slotNo = arg.destSlot, item = arg.craftItem}
- slot.transfer{self = slot, item = arg.craftItem, transferTo = arg.destSlot}
- else --slot full/other item
- saveToLog("craft: Moving "..arg.craftItem.." to slot "..arg.destSlot.." failed. Still in slot 16", false)
- emptySlot = getFirstEmptySlot(false)
- if turtle.transferTo(emptySlot) then
- saveToLog("craft: Moving "..arg.craftItem.." to slot "..emptySlot.." instead", false)
- slot.update{self = slot, slotNo = emptySlot, item = arg.craftItem}
- end
- end
- end
- else
- saveToLog("craft: crafted item "..arg.craftItem.." already in correct slot", false)
- end
- sortInventory(true)
- end
- else --chest not used, only for first log first planks and first chest
- saveToLog("craft: "..arg.craftItem.." created in slot 16, moving to "..arg.destSlot, false)
- turtle.transferTo(arg.destSlot)
- slot.update{self = slot, slotNo = arg.destSlot, item = arg.craftItem}
- slot.update{self = slot, slotNo = 16, delete = true}
- end
- saveToLog("craft: function exit, success = "..tostring(success), false)
- return success
- end
- function craftMiningTurtle()
- local numWood = 0
- local woodNeeded = 0
- local planksNeeded = 0
- local numSticks = 0
- local sticksNeeded = 0
- local numTurtles = 1
- local startFile = ""
- local itemCount = {}
- --[[ storage contents:
- storageTorches: torches
- storageSigns: signs
- storageSticks: sticks
- storageWood: wood
- storageIronore: iron, (ironore), (buckets)
- storageSand: sugar cane, sand, glass, glass panes
- storageRedstone: redstone
- storagePickaxes: diamond pickaxe, paper
- ]]--
- --[[ Items needed:
- 6 sand 2 wood 8 planks -> smelt to glass -> craft to 16 glass panes --> use 1 per turtle
- floppy disk:
- 3 sugar cane
- 1 redstone
- disk drive:
- 7 cobble 2 wood 8 planks -> smelt to stone
- 1 redstone
- per turtle:
- 7 cobble 2 wood 7 planks -> smelt to stone
- 7 ironore 2 wood 7 planks -> smelt to iron
- 1 crafting table 1 wood 4 planks
- 1 chests 2 wood 8 planks
- 1 diamond pickaxe 2 sticks 2 planks
- 1 glass pane
- 1 redstone
- For Disk drive:
- 4 wood, 16 planks (includes glass smelt)
- For 1 turtle:
- 7 wood, 28 planks
- Min 11 wood, 44 planks
- Max 18 wood, 72 planks
- ]]--
- --[[
- start under furnace / over storage torches
- drop un-necessary items first to create crafting space
- storageTorches = 0
- storageSigns = 2
- storageSticks = 4
- storageWood = 6
- storageIronore = 8
- storageSand = 10
- storageRedstone = 12
- storagePickaxes = 14
- ]]--
- saveToLog("craftMiningTurtle: changing logFile Name from "..fso:getCurrentFileName().." to "..fso:getNextFileName().." END OF LOGFILE!", true)
- fso:useFileName("logCraftMiningTurtle.txt")
- saveToLog("craftMiningTurtle: starting..", true)
- --get rid of unknown items
- if slot:getItemSlot("item1") > 0 then
- turnRight(2)
- forward(2, 1)
- for i = 1, 4 do
- storeItem{toStore = extraStorage1, item = "item"..i, quantity = 0, updateSlot = true, doSort = true}
- end
- turnRight(2)
- forward(2, 1)
- end
- if objectives["diamonds"] then
- if turtle.getItemCount(slot:getItemSlot("diamonds")) >= 6 then
- numTurtles = 2
- if storagePickaxes:getItemCount("diamond pickaxe") > 0 then --pickaxe already made
- sticksNeeded = 2
- else
- sticksNeeded = 4
- end
- elseif turtle.getItemCount(slot:getItemSlot("diamonds")) >= 3 then -- 3 - 5 diamonds
- if storagePickaxes:getItemCount("diamond pickaxe") > 0 then --pickaxe already made
- numTurtles = 2
- else
- numTurtles = 1
- end
- sticksNeeded = 2
- else -- 0 - 2 diamonds + pickaxe
- if storagePickaxes:getItemCount("diamond pickaxe") == 0 then
- sticksNeeded = 2
- end
- numTurtles = 1
- end
- if numTurtles == 1 then
- woodNeeded = 11
- planksNeeded = 44
- else
- woodNeeded = 18
- planksNeeded = 72
- end
- turnRight(1)
- dig.digNew{self = dig, expectedItem = "torches", callFrom = "craftMiningTurtle"}
- turnLeft(2)
- dig.digNew{self = dig, expectedItem = "torches", callFrom = "craftMiningTurtle"}
- turnRight(1)
- saveToLog("craftMiningTurtle: storing torches in storageTorches", true)
- storeItem{toStore = storageTorches, item = "torches", quantity = 0, updateSlot = true, doSort = true}
- forward(2) --storageSigns 2
- if slot:getItemSlot("signs") > 0 then
- saveToLog("craftMiningTurtle: storing signs in storageSigns", true)
- storeItem{toStore = storageSigns, item = "signs", quantity = 0, updateSlot = true, doSort = true}
- end
- forward(2, 1) --storageSticks 4
- if slot:getItemSlot("sticks") > 0 then
- saveToLog("craftMiningTurtle: storing sticks in storageSticks", true)
- storeItem{toStore = storageSticks, item = "sticks", quantity = 0, updateSlot = true, doSort = true}
- end
- forward(4) -- storageIronore 8
- saveToLog("craftMiningTurtle: storing iron and buckets in storageIronore", true)
- storeItem{toStore = storageIronore, item = "iron", quantity = 0, updateSlot = true, doSort = true}
- storeItem{toStore = storageIronore, item = "buckets", quantity = 0, updateSlot = true, doSort = true}
- forward(2) -- storageSand 10
- saveToLog("craftMiningTurtle: removing sand and sugar cane from storageSand", true)
- getItemsFromStorage{fromStore = storageSand, item1 = "sand", item2 = "sugar cane"}
- storeItem{toStore = storageSand, item = "sand", quantity = turtle.getItemCount(slot:getItemSlot("sand")) - 6, updateSlot = true, doSort = false}
- saveToLog("craftMiningTurtle: storing dirt in storageSand", true)
- storeItem{toStore = storageSand, item = "dirt", quantity = 0, updateSlot = true, doSort = true}
- saveToLog("craftMiningTurtle: storing gravel in storageSand", true)
- storeItem{toStore = storageSand, item = "gravel", quantity = 0, updateSlot = true, doSort = true}
- saveToLog("craftMiningTurtle: storing coal in storageSand", true)
- storeItem{toStore = storageSand, item = "coal", quantity = 0, updateSlot = true, doSort = true}
- saveToLog("craftMiningTurtle: storing stone in storageSand", true)
- storeItem{toStore = storageSand, item = "stone", quantity = 0, updateSlot = true, doSort = true}
- forward(2) --storageRedstone 12
- saveToLog("craftMiningTurtle: removing redstone from storageRedstone", true)
- -- remove redstone, may be 64 already in store, so prepare to dump the rest
- for i = 1, 16 do
- itemCount[i] = turtle.getItemCount(i)
- end
- --storeItem{toStore = storageRedstone, item = "redstone", quantity = 0, updateSlot = true, doSort = true}
- getItemsFromStorage{fromStore = storageRedstone, item1 = "redstone"}
- -- check if overspill of redstone
- for i = 1, 16 do
- if i ~= slot:getItemSlot("redstone") then
- if turtle.getItemCount(i) > itemCount[i] then
- turtle.select(i)
- turtle.dropUp()
- break
- end
- end
- end
- -- check if enough redstone
- if turtle.getItemCount(slot:getItemSlot("redstone")) < 3 then --try removing more if it exists
- getItemsFromStorage{fromStore = storageRedstone, item1 = "redstone"}
- for i = 1, 16 do
- if i ~= slot:getItemSlot("redstone") then
- if turtle.getItemCount(i) > itemCount[i] then
- turtle.select(i)
- turtle.dropUp()
- break
- end
- end
- end
- end
- if turtle.getItemCount(slot:getItemSlot("redstone")) > 2 then
- storeItem{toStore = storageRedstone, item = "redstone", quantity = turtle.getItemCount(slot:getItemSlot("redstone")) - 3 - numTurtles, updateSlot = true, doSort = false}
- end
- turnRight(2)
- forward(6) --storageWood 6
- turnRight(2)
- saveToLog("craftMiningTurtle: removing wood from storage", true)
- getItemsFromStorage{fromStore = storageWood, item1 = "wood"}
- turnRight(2)
- forward(2) --storageSticks 4
- turnRight(2)
- if sticksNeeded > 0 then --need 2/4 sticks
- saveToLog("craftMiningTurtle: removing sticks from storage", true)
- getItemsFromStorage{fromStore = storageSticks, item1 = "sticks"}
- if slot:getItemSlot("sticks") > 0 then --sticks onboard
- numSticks = turtle.getItemCount(slot:getItemSlot("sticks"))
- end
- if sticksNeeded <= numSticks then
- sticksNeeded = 0
- end
- end
- turnRight(2)
- forward(4) --storageTorches 0
- turnRight(2)
- --wood: crafting table = 2, sticks = 1, smelt
- --planks: crafting table = 8, sticks = 2, smelt cobble = 21, smelt ironore = 14, smelt sand = 6, total 64
- if slot:getItemSlot("wood") > 0 then --wood already on board
- numWood = turtle.getItemCount(slot:getItemSlot("wood"))
- end
- if numWood < woodNeeded then --not enough wood on board
- harvestTreeFarm(false)
- replantTreeFarm(false, true)
- end
- craft{craftItem = "planks", craftQuantity = 64, sourceItem1 = "wood", destSlot = 0, doSort = true}
- if planksNeeded <= 64 then
- planksNeeded = 0
- else
- planksNeeded = planksNeeded - 64
- end
- if sticksNeeded > 0 then
- craft{craftItem = "sticks", craftQuantity = 4, sourceItem1 = "planks", destSlot = 0, doSort = true}
- end
- if numTurtles == 2 then --make diamond pickaxe, even if one is in storage
- craft{craftItem = "diamond pickaxe", craftQuantity = 1, sourceItem1 = "sticks", sourceItem2 = "diamonds", destSlot = 0, doSort = true}
- -- else retrieve or make later
- if storagePickaxes:getItemCount("diamond pickaxe") == 0 then --no pickaxe already made
- saveToLog("craftMiningTurtle: storing diamond pickaxe in storagePickaxes", true)
- forward(14, 1) --storagePickaxes 4
- storeItem{toStore = storagePickaxes, item = "diamond pickaxe", quantity = 0, updateSlot = true, doSort = true}
- turnRight(2)
- forward(14, 1) --under furnace
- turnRight(2)
- --make second pickaxe
- craft{craftItem = "diamond pickaxe", craftQuantity = 1, sourceItem1 = "sticks", sourceItem2 = "diamonds", destSlot = 0, doSort = true}
- end
- end
- if storagePickaxes:getItemCount("diamond pickaxe") > 0 then --pickaxe already made
- saveToLog("craftMiningTurtle: storing sticks in storageSticks", true)
- forward(4, 1) --storageSticks 4
- storeItem{toStore = storageSticks, item = "sticks", quantity = 0, updateSlot = true, doSort = true}
- turnRight(2)
- forward(4, 1) --under furnace
- turnRight(2)
- end
- smelt("cobble", 7 * numTurtles + 7)
- smelt("ironore", 7 * numTurtles)
- smelt("sand", 6)
- if planksNeeded > 0 then
- craft{craftItem = "planks", craftQuantity = planksNeeded, sourceItem1 = "wood", destSlot = 0, doSort = true}
- planksNeeded = 0
- end
- saveToLog("craftMiningTurtle: storing wood in storageWood", true)
- forward(6, 1) -- storageWood = 6
- storeItem{toStore = storageWood, item = "wood", quantity = 0, updateSlot = true, doSort = true}
- forward(2) --over storageIronore 8
- saveToLog("craftMiningTurtle: storing ironore in storageIronore", true)
- storeItem{toStore = storageIronore, item = "ironore", quantity = 0, updateSlot = true, doSort = true}
- forward(2) --over storageSand 10
- saveToLog("craftMiningTurtle: storing cobble in storageSand", true)
- --storeItem{toStore = storageSand, item = "sand", quantity = 0, updateSlot = true, doSort = true}
- storeItem{toStore = storageSand, item = "cobble", quantity = 0, updateSlot = true, doSort = true}
- turnRight(2)
- forward(10, 1) --under furnace
- turnRight(2)
- craft{craftItem = "chests", craftQuantity = numTurtles, sourceItem1 = "planks", destSlot = 0, doSort = true}
- craft{craftItem = "crafting table", craftQuantity = 1 * numTurtles, sourceItem1 = "planks", destSlot = 0, doSort = true}
- forward(6, 1) -- storageWood 6
- saveToLog("craftMiningTurtle: storing planks in storageWood", true)
- storeItem{toStore = storageWood, item = "planks", quantity = 0, updateSlot = true, doSort = true}
- forward(4, 1) --storageSand 10, facing mine
- craft{craftItem = "paper", craftQuantity = 3, sourceItem1 = "sugar cane", destSlot = 0, doSort = true}
- saveToLog("craftMiningTurtle: storing sugar cane in storageSand", true)
- storeItem{toStore = storageSand, item = "sugar cane", quantity = 0, updateSlot = true, doSort = true}
- craft{craftItem = "glass panes", craftQuantity = 16, sourceItem1 = "glass", destSlot = 0, doSort = true}
- saveToLog("craftMiningTurtle: storing glass in storageSand", true)
- storeItem{toStore = storageSand, item = "glass", quantity = 0, updateSlot = true, doSort = true}
- saveToLog("craftMiningTurtle: storing glass panes in storageSand", true)
- storeItem{toStore = storageSand, item = "glass panes", quantity = 16 - numTurtles, updateSlot = true, doSort = true}
- craft{craftItem = "floppy disk", craftQuantity = 1, sourceItem1 = "paper", sourceItem2 = "redstone", destSlot = 0, doSort = true}
- saveToLog("craftMiningTurtle: storing paper in storageSand", true)
- storeItem{toStore = storageSand, item = "paper", quantity = 0, updateSlot = true, doSort = true}
- if numTurtles == 1 then
- --get pickaxe from chest
- if storagePickaxes:getItemCount("diamond pickaxe") > 0 then
- forward(4, 1) --storagePickaxes 14, facing mine
- saveToLog("craftMiningTurtle: removing diamond pickaxe from storagePickaxes", true)
- getItemsFromStorage{fromStore = storagePickaxes, item1 = "diamond pickaxe"}
- turnRight(2)
- forward(4, 1) --storageSand 10, facing furnace
- else
- turnRight(2) -- facing furnace
- end
- else
- turnRight(2) -- facing furnace
- end
- forward(10, 1) --under furnace
- turnRight(2)
- craft{craftItem = "computer", craftQuantity = 1 * numTurtles, sourceItem1 = "glass panes", sourceItem2 = "redstone", sourceItem3 = "stone", destSlot = 0, doSort = true}
- craft{craftItem = "turtle", craftQuantity = 1 * numTurtles, sourceItem1 = "chests", sourceItem2 = "computer", sourceItem3 = "iron", destSlot = 0, doSort = true}
- craft{craftItem = "crafty mining turtle", craftQuantity = 1, sourceItem1 = "crafting table", sourceItem2 = "diamond pickaxe", sourceItem3 = "turtle", destSlot = 0, doSort = true}
- craft{craftItem = "disk drive", craftQuantity = 1, sourceItem1 = "redstone", sourceItem2 = "stone", destSlot = 0, doSort = true}
- forward(8) -- storageIronore 8
- if slot:getItemSlot("iron") > 0 then
- saveToLog("craftMiningTurtle: storing excess iron in storageIronore", true)
- storeItem{toStore = storageIronore, item = "iron", quantity = 0, updateSlot = true, doSort = true}
- end
- forward(6, 1) -- storagePickaxes 14
- if numTurtles == 2 then
- if storagePickaxes:getItemCount("diamond pickaxe") > 0 then
- saveToLog("craftMiningTurtle: removing diamond pickaxe from storagePickaxes", true)
- getItemsFromStorage{fromStore = storagePickaxes, item1 = "diamond pickaxe"}
- end
- end
- turnRight(2)
- forward(2, 1) -- storageRedstone 12
- saveToLog("craftMiningTurtle: storing redstone in storageRedstone", true)
- storeItem{toStore = storageRedstone, item = "redstone", quantity = 0, updateSlot = true, doSort = true}
- forward(10, 1) -- storageSigns 2
- getItemsFromStorage{fromStore = storageSigns, item1 = "signs"}
- storeItem{toStore = storageSigns, item = "signs", quantity = turtle.getItemCount(slot:getItemSlot("signs")) - 1, updateSlot = true, doSort = false}
- forward(3, 1)
- turnRight(2)
- saveToLog("craftMiningTurtle: removing fuel from furnace", true)
- up(1, 1)
- turtle.select(getFirstEmptySlot())
- if turtle.suck() then
- turtle.refuel()
- end
- down(1)
- forward(1, 1)
- sortInventory(true)
- --destroy furnace
- storeItem{toStore = storageTorches, item = "planks", quantity = 0, updateSlot = true, doSort = true}
- saveToLog("craftMiningTurtle: breaking furnace", true)
- dig.digNew{self = dig, direction = "up", expectedItem = "furnaces", callFrom = "craftMiningTurtle"}
- sortInventory(true)
- saveToLog("craftMiningTurtle: storing furnace in storageTorches", true)
- storeItem{toStore = storageTorches, item = "furnaces", quantity = 0, updateSlot = true, doSort = true}
- --program mining turtle
- saveToLog("craftMiningTurtle: placing disk drive", true)
- turtle.select(slot:getItemSlot("disk drive"))
- turtle.place()
- slot.update{self = slot, item = "disk drive", delete = true}
- sortInventory(true)
- saveToLog("craftMiningTurtle: inserting floppy disk", true)
- turtle.select(slot:getItemSlot("floppy disk"))
- turtle.drop()
- slot.update{self = slot, item = "floppy disk", delete = true}
- sortInventory(true)
- up(1)
- forward(1) --now on top of disk drive
- if disk.isPresent("bottom") then
- local filepath = shell.getRunningProgram()
- local filename = fs.getName(filepath)
- if fs.getFreeSpace("/") > 9000000 then --config modified. use filecopy
- saveToLog("craftMiningTurtle: copying files to floppy disk", true)
- fs.copy(filepath, "/disk/"..filename)
- end
- --[[
- This script is a file called startup stored on the floppy disk
- When a turtle is placed next to the disk drive, it reads this script
- which opens 'minerList.txt' and sets the label to Miner2, (as '2' is stored in this file)
- Either copies start.lua to the turtle then modifies 'minerList.txt' to '3'
- or if on a server, requests the start.lua file via http from pastebin
- so the name Miner3 given for the second turtle, (if constructed)
- ]]--
- -- create/overwrite 'minerList.txt' on floppy disk
- startFile = fs.open("/disk/minerList.txt", "w")
- startFile.writeLine("2")
- startFile.close()
- -- create/overwrite startup
- startFile = fs.open("/disk/startup", "w")
- startFile.writeLine('function get(name, code)')
- startFile.writeLine(' local response = http.get("http://pastebin.com/raw.php?i="..textutils.urlEncode(code))')
- startFile.writeLine(' if response then')
- startFile.writeLine(' local sCode = response.readAll()')
- startFile.writeLine(' if sCode ~= nil and sCode ~= "" then')
- startFile.writeLine(' local file = fs.open( name, "w" )')
- startFile.writeLine(' response.close()')
- startFile.writeLine(' file.write(sCode)')
- startFile.writeLine(' file.close()')
- startFile.writeLine(' return true')
- startFile.writeLine(' end')
- startFile.writeLine(' end')
- startFile.writeLine(' return false')
- startFile.writeLine('end')
- startFile.writeLine('if fs.exists("/disk/minerList.txt") then')
- startFile.writeLine(' textFile = fs.open("/disk/minerList.txt", "r")')
- startFile.writeLine(' textIn = textFile.readAll()')
- startFile.writeLine(' minerName = "Miner"..textIn')
- startFile.writeLine(' textFile.close()')
- startFile.writeLine(' textOut = tostring(tonumber(textIn) + 1)')
- startFile.writeLine('else')
- startFile.writeLine(' minerName = "Miner2"')
- startFile.writeLine(' textOut = "3"')
- startFile.writeLine('end')
- startFile.writeLine('textFile = fs.open("/disk/minerList.txt", "w")')
- startFile.writeLine('textFile.writeLine(textOut)')
- startFile.writeLine('textFile.close()')
- startFile.writeLine('if os.getComputerLabel() == nil or string.find(os.getComputerLabel(),"Miner") == nil then')
- startFile.writeLine(' os.setComputerLabel(minerName)')
- startFile.writeLine('end')
- startFile.writeLine('print("Hello, my name is "..os.getComputerLabel())')
- startFile.writeLine('if fs.exists("/disk/start.lua") then')
- startFile.writeLine(' fs.copy("/disk/start.lua", "start.lua")')
- startFile.writeLine(' print("Replication program copied")')
- startFile.writeLine('else')
- startFile.writeLine(' get("start.lua", "'..pastebinCode..'")')
- startFile.writeLine('end')
- startFile.writeLine('print("use start.lua to begin self replicating ")')
- startFile.close()
- end
- back(1)
- down (1)
- turnRight(1)
- forward(1)
- turnLeft(1)
- saveToLog("craftMiningTurtle: placing crafty mining turtle", true)
- turtle.select(slot:getItemSlot("crafty mining turtle"))
- turtle.place() --next to disk drive
- slot.update{self = slot, item = "crafty mining turtle", delete = true}
- sortInventory(true)
- turnLeft(1)
- if numTurtles == 2 then
- craft{craftItem = "crafty mining turtle", craftQuantity = 1, sourceItem1 = "crafting table", sourceItem2 = "diamond pickaxe", sourceItem3 = "turtle", destSlot = 0}
- forward(1)
- turnRight(1)
- up(1)
- saveToLog("craftMiningTurtle: placing second crafty mining turtle", true)
- turtle.select(slot:getItemSlot("crafty mining turtle"))
- turtle.place() --on top of disk drive
- down(1, 1)
- saveToLog("Two Crafty Mining Turtles placed. All objectives acheived!", true)
- else
- forward(1)
- turnRight(1)
- saveToLog("Crafty Mining Turtle placed. Insufficient diamonds found to create two", true)
- end
- up(1)
- if slot:getItemCount("signs") > 0 then
- back(1)
- turtle.select(slot:getItemSlot("signs"))
- turtle.placeDown("Mission\nComplete!")
- forward(1)
- end
- if numTurtles == 2 then
- saveToLog("Mission successful. I have replicated myself twice", true)
- saveToLog("Right-Click on my offspring to check their status...", true)
- else
- saveToLog("Mission partially successful. I have replicated myself once", true)
- saveToLog("Right-Click on my offspring to check its status...", true)
- end
- else
- saveToLog("Insufficient diamonds found in this area. Please break turtle , reposition and restart", true)
- end
- end
- function craftSigns()
- local woodAvailable = 0
- local wood2Available = 0
- local woodType = "wood"
- local planksType = "planks"
- local success = false
- local numSignsOnboard = 0
- local numWoodOnboard = 0
- local numWoodStored = 0
- local numSignsStored = 0
- local overStore = true
- --always make 3 signs only , need 8 planks, leaves 3 sticks
- --only attempt when over storageTorches
- saveToLog("craftSigns: started, crafting 3 signs", true)
- -- will always be over storageTorches unless not yet placed
- if not placeStorage:getStoragePlaced("torches") then
- overStore = false
- end
- numSignsStored = storageSigns:getItemCount("signs")
- numWoodStored = storageWood:getItemCount("wood")
- if slot:getItemSlot("signs") > 0 then
- numSignsOnboard = turtle.getItemCount(slot:getItemSlot("signs"))
- end
- if slot:getItemSlot("wood") > 0 then
- numWoodOnboard = turtle.getItemCount(slot:getItemSlot("wood"))
- if slot:getItemSlot("wood2") > 0 then
- if turtle.getItemCount(slot:getItemSlot("wood2")) > numWoodOnboard then
- numWoodOnboard = turtle.getItemCount(slot:getItemSlot("wood2"))
- woodType = "wood2"
- planksType = "planks2"
- end
- end
- end
- if overStore then
- if numSignsStored > 0 then
- forward(2, 1)
- saveToLog("craftSigns: "..numSignsStored.." signs removed from storage", true)
- getItemsFromStorage{fromStore = storageSigns, item1 = "signs"}
- numSignsOnboard = turtle.getItemCount(slot:getItemSlot("signs"))
- back(2)
- end
- if slot:getItemSlot("wood") == 0 then --wood in storage, needed for signs
- forward(6, 1)
- saveToLog("craftTorches: "..numWoodStored.." wood removed from storage", true)
- getItemsFromStorage{fromStore = storageWood, item1 = "wood"}
- numWoodOnboard = turtle.getItemCount(slot:getItemSlot("wood"))
- turnRight(2)
- forward(6, 1)
- turnRight(2)
- end
- end
- if numWoodOnboard >= 3 then --enough to make signs
- saveToLog("craftSigns: crafting planks from "..woodType, false)
- craft{craftItem = planksType, craftQuantity = 8, sourceItem1 = woodType, destSlot = 0, doSort = true}
- saveToLog("craftSigns: crafting sticks from "..planksType, false)
- craft{craftItem = "sticks", craftQuantity = 4, sourceItem1 = planksType, destSlot = 0, doSort = true}
- saveToLog("craftSigns: crafting signs from "..planksType.." and sticks from slot "..slot.getItemSlot(slot, "sticks"), false)
- if craft{craftItem = "signs", craftQuantity = 3, sourceItem1 = "sticks", sourceItem2 = planksType, destSlot = 0, doSort = true} then
- success = true
- end
- else
- saveToLog("craftSigns: insufficient wood available", true)
- end
- return success
- end
- function craftSticks(quantity)
- local success = false
- local makePlanks = false
- local woodType = "wood"
- local planksType = "planks"
- local woodNeeded = 0
- local planksNeeded = 0
- local success = false
- local numWoodOnboard = 0
- local numPlanksOnboard = 0
- if quantity <= 4 then
- quantity = 4
- planksNeeded = 4
- woodNeeded = 1
- elseif quantity <= 8 then
- quantity = 8
- planksNeeded = 4
- woodNeeded = 1
- elseif quantity <= 12 then
- quantity = 12
- planksNeeded = 8
- woodNeeded = 2
- else
- quantity = 16
- planksNeeded = 8
- woodNeeded = 2
- end
- if slot:getItemSlot("planks") > 0 then
- numPlanksOnboard = turtle.getItemCount(slot:getItemSlot("planks"))
- end
- if slot:getItemSlot("planks2") > 0 then
- numPlanksOnboard = turtle.getItemCount(slot:getItemSlot("planks2"))
- planksType = "planks2"
- end
- if numPlanksOnboard < planksNeeded then
- makePlanks = true
- saveToLog("craftSticks: started, crafting planks", true)
- --woodNeeded already calculated
- else
- woodNeeded = 0 --reset
- saveToLog("craftSticks: started, using "..planksType.." already onboard", true)
- end
- if makePlanks then --need wood
- if slot:getItemSlot("wood") > 0 then
- numWoodOnboard = turtle.getItemCount(slot:getItemSlot("wood"))
- if slot:getItemSlot("wood2") > 0 then
- if turtle.getItemCount(slot:getItemSlot("wood2")) > numWoodOnboard then
- numWoodOnboard = turtle.getItemCount(slot:getItemSlot("wood2"))
- woodType = "wood2"
- planksType = "planks2"
- end
- end
- end
- if slot:getItemSlot("wood") == 0 and storageWood:getItemCount("wood") > 0 then --wood in storage
- if makePlanks then --wood needed for planks so go get
- forward(6, 1)
- saveToLog("craftSticks: "..storageWood:getItemCount("wood").." wood removed from storage", true)
- getItemsFromStorage{fromStore = storageWood, item1 = "wood"}
- numWoodOnboard = turtle.getItemCount(slot:getItemSlot("wood"))
- turnRight(2)
- forward(6, 1)
- turnRight(2)
- end
- end
- if numWoodOnboard >= woodNeeded then
- --planksType will be "planks" unless planks2 are in stock
- saveToLog("craftSticks: crafting "..planksType.." for sticks", true)
- craft{craftItem = planksType, craftQuantity = planksNeeded, sourceItem1 = woodType, destSlot = 0, doSort = true}
- end
- end
- saveToLog("craftSticks: crafting "..quantity.." sticks from "..planksType, true)
- if craft{craftItem = "sticks", craftQuantity = quantity, sourceItem1 = planksType, destSlot = 0, doSort = true} then
- objectives["craft sticks"] = true
- success = true
- end
- return success
- end
- function craftTorches(quantity)
- local headType = "charcoal"
- local headQuantity = 0
- local makeCharcoal = false
- local makePlanks = false
- local makeSticks =false
- local woodType = "wood"
- local planksType = "planks"
- local numWoodNeeded = 0
- local planksNeeded = 0
- local sticksNeeded = 0
- local success = false
- local numSticksOnboard = 0
- local numTorchesOnboard = 0
- local numWoodOnboard = 0
- local numTorchesStored = 0
- local overStore = true
- local doContinue = true
- -- will always be over storageTorches unless not yet placed
- --[[if not placeStorage:getStoragePlaced("torches") then
- overStore = false
- end]]--
- if slot:getItemSlot("torches") > 0 then
- numTorchesOnboard = turtle.getItemCount(slot:getItemSlot("torches"))
- end
- if slot:getItemSlot("sticks") > 0 then
- numSticksOnboard = turtle.getItemCount(slot:getItemSlot("sticks"))
- end
- if slot:getItemSlot("wood") > 0 then
- numWoodOnboard = turtle.getItemCount(slot:getItemSlot("wood"))
- if slot:getItemSlot("wood2") > 0 then
- if turtle.getItemCount(slot:getItemSlot("wood2")) > numWoodOnboard then
- numWoodOnboard = turtle.getItemCount(slot:getItemSlot("wood2"))
- woodType = "wood2"
- planksType = "planks2"
- end
- end
- end
- -- 4 torches min : 1 head + 1 stick = 4 torches. Min sticks = 4, min planks = 4
- -- torches head planks sticks
- -- 4 1 4 4
- -- 8 2 4 4
- -- 12 3 4 4
- -- 16 4 4 4
- -- 20 5 4 8
- -- 24 6 4 8
- -- 28 7 4 8
- -- 32 8 4 8
- -- 36 9 8 12
- -- 40 10 8 12
- -- 44 11 8 12
- -- 48 12 8 12
- -- 52 13 8 16
- -- 56 14 8 16
- -- 60 15 8 16
- -- 64 16 8 16
- quantity = math.floor(quantity / 4) * 4
- if quantity == 0 then
- quantity = 4 -- torches
- headQuantity = 1 -- coal /charcoal
- planksNeeded = 4 -- 1 wood
- sticksNeeded = 4 -- 2 planks
- numWoodNeeded = 1
- elseif quantity <= 16 then-- 4, 8, 12, 16
- headQuantity = quantity / 4 -- coal, charcoal
- planksNeeded = 4 -- 8 planks = 16 sticks
- sticksNeeded = 4 -- 4 sticks
- numWoodNeededwoodNeeded = 1
- elseif quantity <= 32 then-- 4, 8, 12, 16
- headQuantity = quantity / 4 -- coal, charcoal
- planksNeeded = 4 -- 8 planks = 16 sticks
- sticksNeeded = 8 -- 8 sticks
- numWoodNeeded = 2
- elseif quantity <= 48 then-- 4, 8, 12, 16
- headQuantity = quantity / 4 -- coal, charcoal
- planksNeeded = 8 -- 8 planks = 16 sticks
- sticksNeeded = 12 -- 12 sticks
- numWoodNeeded = 2
- else
- headQuantity = quantity / 4 -- coal, charcoal
- planksNeeded = 8 -- 8 planks = 16 sticks
- sticksNeeded = 16 -- 16 sticks
- numWoodNeeded = 2
- end
- saveToLog("craftTorches: quantity = "..quantity, true)
- --need either coal or charcoal
- if slot:getItemSlot("coal") > 0 then
- if turtle.getItemCount(slot:getItemSlot("coal")) - 1 >= headQuantity then
- headType = "coal"
- saveToLog("craftTorches: using coal", true)
- end
- end
- if headType == "charcoal" then --default value
- if slot:getItemSlot("charcoal") > 0 then
- if turtle.getItemCount(slot:getItemSlot("charcoal")) < headQuantity then
- makeCharcoal = true
- saveToLog("craftTorches: using charcoal", true)
- end
- else
- saveToLog("craftTorches: charcoal on crafting list", true)
- makeCharcoal = true
- end
- end
- if storageTorches:getItemCount("torches") > 0 then
- saveToLog("craftTorches: "..storageTorches:getItemCount("torches").." torches removed from storage", true)
- getItemsFromStorage{fromStore = storageTorches, item1 = "torches"}
- numTorchesOnboard = turtle.getItemCount(slot:getItemSlot("torches"))
- end
- if storageSticks:getItemCount("sticks") > 0 then
- forward(4, 1)
- saveToLog("craftTorches: "..storageSticks:getItemCount("sticks").." sticks removed from storage", true)
- getItemsFromStorage{fromStore = storageSticks, item1 = "sticks"}
- numSticksOnboard = turtle.getItemCount(slot:getItemSlot("sticks"))
- turnRight(2)
- forward(4, 1)
- turnRight(2)
- end
- if slot:getItemSlot("wood") == 0 and makeCharcoal then --wood in storage, needed for charcoal
- forward(6, 1)
- saveToLog("craftTorches: "..storageWood:getItemCount("wood").." wood removed from storage", true)
- getItemsFromStorage{fromStore = storageWood, item1 = "wood"}
- numWoodOnboard = turtle.getItemCount(slot:getItemSlot("wood"))
- turnRight(2)
- forward(6, 1)
- turnRight(2)
- end
- if numSticksOnboard == 0 or numSticksOnboard < headQuantity then
- makeSticks = true
- saveToLog("craftTorches: insufficient sticks in stock, on crafting list", true)
- else
- saveToLog("craftTorches: enough sticks in stock", true)
- end
- if makeSticks then
- woodType = getWoodAvailable{woodNeeded = 1}
- if woodType ~= "none" then
- saveToLog("craftTorches: crafting sticks")
- doContinue = false
- if craftSticks(sticksNeeded) then
- doContinue = true
- end
- end
- end
- woodType = getWoodAvailable{woodNeeded = 1}
- if woodType == "none" then
- doContinue = false
- saveToLog("craftTorches: insufficient wood available", false, true)
- end
- if doContinue then
- if makeCharcoal then
- saveToLog("craftTorches: smelting charcoal")
- if smelt("charcoal", headQuantity) then
- saveToLog("craftTorches: charcoal smelted", true)
- else
- saveToLog("craftTorches: charcoal smelting failed", true)
- doContinue = false
- end
- end
- if doContinue then
- saveToLog("craftTorches: crafting torches", true)
- --make quantity torches
- if craft{craftItem = "torches", craftQuantity = quantity, sourceItem1 = "sticks", sourceItem2 = headType, destSlot = 0, doSort = true} then
- saveToLog("craftTorches: "..quantity.." torches made", true)
- success = true
- if placeStorage:getStoragePlaced("torches") then
- if not placeStorage:getMarkerPlaced("torches") then
- if slot:getItemSlot("torches") > 0 then
- if turtle.getItemCount(slot:getItemSlot("torches")) > 0 then
- forward(1, 1)
- dig.digNew{self = dig, direction = "down", callFrom = "craftTorches"}
- turtle.select(slot:getItemSlot("torches"))
- turtle.placeDown()
- placeStorage:setMarkerPlaced("torches")
- back(1, 1)
- end
- end
- end
- end
- else
- saveToLog("craftTorches: error: no torches made", true)
- error()
- end
- end
- end
- return success
- end
- function createBedrockMine()
- local tempYcoord = location:getY()
- local torchesAt = {}
- local sTime = os.time()
- saveToLog("createBedrockMine: starting..", true)
- restoreTorches("bothsides", 1)
- --move to entrance
- forward(16, 1)
- --rewrite sign
- turtle.select(16)
- if turtle.dig() then
- turtle.place("Diamond Mine\nMining Bedrock\nSetting Up\n time: "..textutils.formatTime(os.time(), true))
- end
- turnRight(2)
- while location:getY() > 14 do
- down(1, 1)
- end
- down(7, 1) --now at level 7
- for i = 1, 33 do
- torchesAt[i] = false
- end
- -- now under N side of previous mining area dig 33 x 2 corridor
- torchesAt[1] = true
- torchesAt[9] = true
- torchesAt[17] = true
- torchesAt[25] = true
- torchesAt[33] = true
- for i = 1, 33 do
- mineToBedrock(torchesAt[i]) --goes down and returns, digs out blocks in front
- if i < 33 then
- forward(1, 1)
- end
- end
- turnRight(2)
- forward(16, 1)
- --should be at centre now
- turnRight(1)
- for i = 1, 17 do
- mineToBedrock(torchesAt[i]) --goes down and returns, digs out blocks in front
- if i < 17 then
- forward(1, 1)
- end
- end
- turnRight(2)
- forward(16, 1)
- for i = 1, 17 do
- mineToBedrock(torchesAt[i]) --goes down and returns, digs out blocks in front
- if i < 17 then
- forward(1, 1)
- end
- end
- turnRight(2)
- forward(16, 1)
- turnLeft(1)
- up(7,1)
- forward(16, 1)
- --should be at start now
- turnRight(2)
- while location:getY() < tempYcoord do
- up(1, 1)
- end --at surface now
- forward(16, 1)
- turnRight(2)
- saveToLog("createBedrockMine: started at "..textutils.formatTime(sTime, true).." finished at "..textutils.formatTime(os.time(), true), true)
- end
- function createChestObject()
- -- chest object, used to keep track of stored items
- clsChest = {} -- the table representing the class, which will double as the metatable for any instances
- clsChest.__index = clsChest -- failed table lookups on the instances should fallback to the class table, to get methods
- function clsChest.new(storeNo, setStoreName) --equivalent to VB class initialise
- local self = setmetatable({}, clsChest)
- self.items = {"wood", "wood2","dirt","cobble","stone","saplings","saplings2","seeds","sand","gravel","clay",
- "apples","coal","charcoal","ironore","?ironore","goldore","?goldore","iron","?iron","gold","?gold",
- "redstone","redstone block","?diamonds","diamonds","emeralds","sugar cane","planks","planks2","chests","sticks",
- "torches","furnaces","signs","item1","item2","item3","item4","item5","item6","item7","item8",
- "fences","nuggets","buckets","paper","computer","crafting table","diamond pickaxe","glass","glass panes","floppy disk",
- "disk drive","turtle","crafty mining turtle","?moss stone","moss stone","walls","obsidian","sandstone",
- "?lapis","lapis","lapis block","flowers","roses","red mushrooms","brown mushrooms"}
- self.value = storeNo
- self.slotContains = {}
- self.slotCount = {}
- self.itemSlot = {}
- self.turtleSlot = {}
- self.index = 1
- self.name = setStoreName
- -- initialise variables
- for i = 1, 16 do
- self.slotContains[i] = ""
- self.slotCount[i] = 0
- self.turtleSlot[i] = 0
- end
- for key, value in ipairs(self.items) do
- self.itemSlot[value] = 0
- end
- return self
- end
- function clsChest.resetVariables(self)
- for i = 1, 16 do
- self.slotContains[i] = ""
- self.slotCount[i] = 0
- self.turtleSlot[i] = 0
- end
- for key, value in ipairs(self.items) do
- self.itemSlot[value] = 0
- end
- self.index = 1
- end
- function clsChest.getValue(self) --property get in VB
- return self.value
- end
- --craftingChest.getIndex(craftingChest)
- function clsChest.getIndex(self)
- return self.index
- end
- function clsChest.setSlotCount(self, slotNo, newVal) --property let in VB
- self.slotCount[slotNo] = newVal
- end
- function clsChest.getStoreName(self)
- return self.name
- end
- function clsChest.getSlotCount(self, slotNo)
- return self.slotCount[slotNo]
- end
- function clsChest.getSlotContains(self, slotNo)
- return self.slotContains[slotNo]
- end
- function clsChest.getStoreContains(self)
- -- return contents of first slot
- return self.slotContains[1]
- end
- function clsChest.getItemSlot(self, item)
- local result = 0
- if item ~= nil and item ~= "" then
- result = self.itemSlot[item]
- end
- return result
- end
- function clsChest.getTurtleSlot(self, slotNo )
- return self.turtleSlot[slotNo]
- end
- function clsChest.getItemCount(self, item)
- local result = 0
- if item ~= nil and item ~= "" then
- if self.itemSlot[item] > 0 then
- result = self.slotCount[self.itemSlot[item]]
- end
- end
- return result
- end
- function clsChest.getNoOfItems(self)
- return self.index - 1
- end
- function clsChest.isItemInChest(self, item)
- local success = false
- if item ~= nil then
- if self.itemSlot[item] > 0 then
- success = true
- end
- end
- return success
- end
- function clsChest.addItem(self, item, quantity, turtleSlot)
- --storageSticks:addItem("sticks", 2, 14)
- -- addItem(arg.toStore, arg.item, arg.quantity)
- local slotNo = 0
- local newItemFound = false
- local newIndex = 1
- if turtleSlot == nil then
- turtleSlot = 0
- end
- if item == nil or item == "" then
- item = "item8"
- saveToLog(" clsChest.addItem Error, unknown item found", true)
- end
- if quantity == nil then
- quantity = 0
- saveToLog(" clsChest.addItem Error, nil quantity passed", true)
- end
- --unknown item only dropped in full, not added to
- slotNo = self.itemSlot[item] -- 0 by default, unless items already in chest
- if slotNo == 0 then --none of this item in chest
- self.itemSlot[item] = self.index --default value 1
- slotNo = self.itemSlot[item]
- self.slotContains[self.index] = item
- self.slotCount[self.index] = quantity
- self.turtleSlot[self.index] = turtleSlot
- self.index = self.index + 1 --ready for next item
- else --already in chest, update quantity
- turtleSlot = self.turtleSlot[self.itemSlot[item]]
- self.slotCount[slotNo] = self.slotCount[slotNo] + quantity
- if self.slotCount[slotNo] > 64 then
- self.slotCount[slotNo + 1] = self.slotCount[slotNo] - 64
- self.slotContains[slotNo +