Good vs. Evil

lenscas

Over-Achiever
Jul 31, 2013
2,015
1,799
248
58 Slightly slower still isn't too bad
59 especially not considering it will run 24/7. I also never planned/designed it to completely remove any need to mine ever, but be used in addition to other mining efforts that can't run 24/7. Though, maybe I should time it one day? See how fast it is able to mine 3 blocks + move forward.
 

lenscas

Over-Achiever
Jul 31, 2013
2,015
1,799
248
60 I think I edited the mining script correctly.

Assuming I didn't screw up it should be less likely for it to get stuck (Which never happened anyway), the code is a bit easier to understand, less error prone and easier to configure. The turtle should also be faster.

Before it assumed that after 15 items it should unload, now it only send the items back if the last slot contains any items. This technically means it can loose items if that slot is the only one empty and it mines something that drops more than 1 type of item but.... I can live with that.

There are some slowdowns that I introduced though, however they are introduced to keep the state as simple as possible and should almost have no effect. For example, before a refuel it now will offload all the items.

One other feature that I lost now that I can't use enderchests as a peripheral is the ability to call "condense" on them. However, I think that this also becomes less of a problem (And only happened if your ore processing couldn't keep up anyway)
Code:
--some config
local SEND = 1 --the slot with the enderchest to return items
local FUEL = 2 --the slot with the enderchest to get fuel from
local FIRST_SLOT = 3 --first slot that will be used as storage
local LAST_SLOT = 16 --last slot that will be used as storage
local SLEEP_TIME = 0.5 --prevetion loops getting killed
local BREAK_TIME = 100 --how long to wait if it gets stuck
local TIMES_UNTIL_TRY_REFUEL = 2 --how often to try to go forward before trying to get fuel
local TIMES_UNTIL_TRY_BREAK = 4 --how often to fail going forward before going into "stuck" mode
local WAIT_FOR_ROOM_TIME = 20 --how long to wait before trying to add items into the send chest if it was full

local turtle = turtle or {} --to make my editor shut up

--run func after selecting the correct chest and placing it at the top of the turtle
--it also gets the enderchest back and sets the selected itemslot back to what it was before this was called
local function useChest(slotId, func)
    local selected = turtle.getSelectedSlot()
    turtle.select(slotId)
    --do whatever it takes to make place at the top
    while not turtle.placeUp() do
        turtle.select(selected)
        turtle.digUp()
        turtle.attackUp()
        turtle.select(slotId)
        sleep(SLEEP_TIME)
    end
    func()
    --reset, make it look like this function was never called
    turtle.select(slotId)
    turtle.digUp()
    turtle.select(selected)
end

--send every item back to the base
local function sendItems()
   useChest(SEND,function()
    for slot = FIRST_SLOT, LAST_SLOT do
        turtle.select(slot)
        while not turtle.dropUp() do sleep(WAIT_FOR_ROOM_TIME) end
    end
   end)
end

--refuel, if needed
local function refuel()
    print(turtle.getFuelLevel())
    if turtle.getFuelLevel() < 200 then
     sendItems()
     useChest(FUEL,function()
         turtle.select(LAST_SLOT)
         turtle.suckUp()
         turtle.refuel()
         if not turtle.dropUp() then
             turtle.drop()
         end
     end)
    end
    print(turtle.getFuelLevel())
end

--get the turtle in a known good state
local function startup()

   turtle.select(FIRST_SLOT)
   local hasSendChest = turtle.getItemCount(SEND) == 1
   local hasRefuelChest = turtle.getItemCount(FUEL) == 1

   if hasRefuelChest == false and hasSendChest == false then
        print("Missing fuel and send chest")
        --bad state :(
        return false
   end
   --reclaim fuel chest
   if not hasRefuelChest then
        turtle.select(FUEL)
        turtle.digUp()
   end
   --reclaim send chest
   if not hasSendChest then
        turtle.select(SEND)
        turtle.digUp()
   end
   --bring to known good state
   sendItems()
   refuel()
   turtle.select(FIRST_SLOT)
   --we are now in a known good state! HOORAY!
   return true
end


local function mine()
    while turtle.detectUp() do
     turtle.select(FIRST_SLOT)
     turtle.digUp()
     sleep(SLEEP_TIME)
   end
   while turtle.detect() do
     turtle.select(FIRST_SLOT)
     turtle.dig()
     sleep(SLEEP_TIME)
   end
   turtle.select(FIRST_SLOT)
   turtle.digDown()
end

--something caused the turtle to be unable to fullfill its task
--waiting may solve the problem, or at least gives you time to notice it and fix it while keeping CPU load to a minimum
local function takeBreak(reason)
    while true do
        turtle.sleep(BREAK_TIME)
        if reason then
            print("Taking a break because : ",reason)
        end
    end
end

local function forward()
   local counter=0
   while not turtle.forward() do
     mine()
     turtle.attack()
     counter=counter+1
     if counter > TIMES_UNTIL_TRY_REFUEL then
        print("Something is blocking me. Maybe fuel is low?")
        refuel()
     elseif counter > TIMES_UNTIL_TRY_BREAK then
        takeBreak("Something is really blockig me.")
     end
   end
end

--here is the main part of the program
if not startup() then
   error("Failed discover last state :(")
end

--main loop. Forever, dig forward, if last_slot has items then send everything back
while true do
    while turtle.getItemCount(LAST_SLOT) == 0 do
        mine()
        forward()
   end
   sendItems()
   refuel()
end
 

GamerwithnoGame

Over-Achiever
Jan 29, 2015
2,808
1,507
224
60. It’s a TV series, much more adult oriented than the cartoons like Teen Titans but featuring many of the same characters.
 

lenscas

Over-Achiever
Jul 31, 2013
2,015
1,799
248
61 and.... I saw a mistake in the script. I still use a function that is too new. So, now I need to think on implementing it myself or work around it
 

lenscas

Over-Achiever
Jul 31, 2013
2,015
1,799
248
61 meh, at least I can work around it, also I kind of like that it isn't a "drag and drop" process this time to set it up but it actually requires me to think.

It is that I don't like mining but otherwise I could see myself having dumped the script after the first time I used it as setting it up is so boring....
 

lenscas

Over-Achiever
Jul 31, 2013
2,015
1,799
248
61 I got the script working and also discovered a stupid "feature" of emerald pipes.

Because I am not at all setup yet for automatic ore processing (Nor have a decent storage system) I just wanted to automatically void items like cobble stone. I wanted to use emerald pipes for that, as they can extract and have a white list.

Turns out however that they operate in blocking round-robin mode. Aka, it will loop through the filter and will only do the next item in the list if it extracted the current one. Even if the current one isn't in the chest.

So, for now I have a turtle put everything from the ender chest into a double chest and I extract only cobble from this double chest.
 

lenscas

Over-Achiever
Jul 31, 2013
2,015
1,799
248
63 I can see some use for that, with auto crafting for example. However, it would have been nice if there was a pipe that didn't work like that, but sadly not even clay pipes are a thing in this version. Let alone a pipe that does do what I want.
 

lenscas

Over-Achiever
Jul 31, 2013
2,015
1,799
248
62. Wait, no clay pipes?? The liquid versions of those were a godsend in Regrowth.
64 a lot of pipes aren't made yet, and with buildcraft being the main way I can see myself doing item transport for the foreseeable future that can become quite a challenge.

I know I can dive into red power for its tubes, but I remember its recipes being annoying. And the only other item transport I know of are the conveyors from minefactory reloaded.