Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Changelog
- -- version 0.1
- -- First Version.
- -- version 0.2
- -- Fixed think function
- -- Added canThink()
- -- started on chest functions
- print("defining variables...")
- local storeSlots = {
- livingwood = {1,2,3,4},
- livingrock = {5,6,7,8}
- }
- local placeSlots = {
- log = {9,10},
- stone = {11,12}
- }
- local fuelSlots = {13,14,15,16}
- mineThese = {"livingwood","livingrock"}
- placeThese = {"log","stone"}
- fuelThese = {"minecraft:coal","minecraft:charcoal"}
- local function movePreventObstruct(x)
- print("movePreventObstruct(x) was called. x is ".. tostring(x))
- for i = 1,x do
- local hasMoved = false
- while hasMoved == false do
- print("Attempting to move forward...")
- hasMoved = turtle.forward()
- if hasMoved == false then
- print("Something got in my way! Attacking it now.")
- turtle.attack()
- end
- end
- end
- print("movePreventObstruct(x) has finished")
- end
- local function refuel()
- print("refuel() was called")
- if type(turtle.getFuelLevel()) == "string" then return end -- fucking hell, why cant you just return -1 as an int?
- while turtle.getFuelLevel() <= 9 do
- print("refuel() while loop started!")
- local fuelslots = {}
- for k,v in pairs(fuelSlots) do --Reserve 13-16 for fuel to minimize calc time.
- print("refuel() pairs loop started")
- local itemDetail = turtle.getItemDetail(v)
- for i = 1, #fuelThese do
- print("refuel() for i = 1 loop started")
- if itemDetail.name == fuelThese[i] then
- turtle.select(v) -- duh
- turtle.refuel(turtle.getItemCount(v)) -- DUh, count not space.
- print("I should be loading ".. turtle.getItemCount(v) .. " " .. itemDetail.name .. " from slot " .. turtle.getSelectedSlot())
- break
- end
- end
- end
- end
- print("refuel() has finished")
- end
- local function checkBlock()
- print("checkBlock() called")
- local success,block = turtle.inspectDown()
- if success == true then
- for i = 1, #mineThese do
- if block.name == "Botania:" .. mineThese[i] then
- for k,v in pairs( storeSlots[mineThese[i]] ) do
- print("checkBlock() is performing its core task")
- turtle.select(v)
- turtle.digDown()
- --turtle.suck() only needed for chests.
- end
- for k,v in pairs( placeSlots[placeThese[i]] ) do
- print("checkBlock() is trying to place a block")
- turtle.select(v)
- local placed = nil
- if not turtle.getItemCount(v) == 0 then
- placed = turtle.placeDown()
- end
- if placed then break end
- end
- end
- end
- end
- print("checkBlock() finished")
- end
- local function placeBlock()
- local placed = false
- print("placeBlock() called")
- local success,block = turtle.inspectDown()
- if success == false then
- while placed == false do
- print("No block detected below me, lets place something.")
- -- We don't have any information on what block was originally there
- -- so we shall math.random it.
- -- Replacing seed, we do this every time because I don't trust Java as far as I can throw it...
- -- and I know LUA already has a shitty random function in its math library.
- math.randomseed( tonumber(tostring(os.time()):reverse():sub(1,6)) )
- -- Waste some frames, but at least we will get a real random result.
- -- I know I shouldn't care when its a range of 4 values, but when I ask for random, I expect random.
- -- I also know I shouldn't expect good random from LUA emulated in Java on a Linux VPS. But screw you.
- -- And screw every cunt who thinks for a second that java is a good Langauge.
- -- I mean come on, you may as well skip java and move straight onto a real (almost identical) language.
- -- Like C++.
- -- Or C#
- -- Or anything but JAVA mojang. I mean really. Fuck you guys.
- math.random(); math.random(); math.random() -- We do nothing with this but manipulate LUA.
- -- For the actual random slot, we roll...
- local slotToUse = math.random(8,12)
- print("And our lucky number is " .. tostring(slotToUse) .. "!") -- hue hue aren't i fanny
- turtle.select(slotToUse)
- placed = turtle.placeDown() or turtle.inspectDown() -- Should return true if successful.
- end
- end
- print("placeBlock() has finished")
- end
- local function canThink()
- print("canThink() called")
- if not turtle then error("This isn't a turtle!") return false end
- print("canThink() finished")
- return true -- todo: more
- end
- local function chestCheck()
- --DEBUG PRINT
- print("chestCheck() called")
- local success, block = turtle.inspect()
- if not success then return false end
- if not block.name == "minecraft:chest" then return end
- local initialSlot = turtle.getSelectedSlot()
- for i=1,8 do
- turtle.select(i)
- turtle.drop(turtle.getItemCount(i))
- end
- for i=9,12 do
- turtle.select(i)
- turtle.suckUp()
- end
- turtle.turnLeft()
- for i=13,16 do
- turtle.select(i)
- turtle.suck()
- end
- turtle.turnRight()
- turtle.select(initialSlot)
- --DEBUG PRINT
- print("chestCheck() finished")
- end
- local function think()
- print("think() called!")
- while canThink() == true do
- refuel()
- checkBlock()
- placeBlock()
- movePreventObstruct(1)
- checkBlock()
- placeBlock()
- movePreventObstruct(1)
- checkBlock()
- placeBlock()
- chestCheck()
- turtle.turnRight()
- end
- print("think() finished!")
- end
- local function firstThink()
- print("firstThink() called")
- if not canThink() then return end -- the redundancy is real
- think()
- print("firstThink() finished")
- end
- -- Lets start this all up.
- firstThink() -- therefor I am.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement