This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Rivil's profile picture

Mining turtle. Not digging/attacking mobs

Started by Rivil, 24 May 2013 - 02:34 PM
Rivil #1
Posted 24 May 2013 - 04:34 PM
I've written a program for strip mining and was so happy with it working great until my turtle had a "romance" with a chicken…
The problem occurs when mob/player is standing on a path of turtle against the wall or on the back edge of block to which turtle wants to move.
In normal conditions. Turtle attacks mob moving them away. Though in circumstances above it just stops and counts up the loop, at the end of which it decides that it has faced an un-diggable barier and decides to move to base (which it should do if a block in front is un-diggable)

Code that is responsible for moving the turtle

function tMineForward(whenmining)
local isblocked = true
local attempts = 0
local returnValue = "Mine"
while isblocked == true do
  turtle.attack()
  turtle.dig()
  if turtle.detect() == false then
   isblocked = false
  else
   attempts = attempts + 1
  end
  if attempts > tonumber(GetVariable("maxattempts")) then
   returnValue = "GoToEnd"
   isblocked = false
  end
end
if returnValue == "Mine" then
  if tMoveForward(whenmining) ~= "Continue" then
   returnValue = "GoToEnd"
  end
end

return returnValue
end
function tMoveForward(whenmining)
local isBlocked = true
local attempts = 0
local returnValue = "Continue"
while isBlocked == true do
  turtle.attack()
  turtle.dig()
  if turtle.forward() == true then
   isBlocked = false
   SaveMovement(whenmining, "F")
  else

   attempts = attempts + 1
  end
  if attempts >  tonumber(GetVariable("maxattempts")) then
   returnValue = "GoToEnd"
   isblocked = false
  end
end

return returnValue
end

My question: Is there a better way to move mobs in front or detect them?
My reason for having maxattempts variable is that the turtle can start mining on x levels below current one. So I wanted to have something that will handle falling gravel/sand and not make turtle stuck on bedrock.

Any help is greatly appreciated.

Thanks

PS. Just looked on the home page and attack range was increased in 1.51. Though I'm using FTB and it looks like this update doesn't come there for quite some time :(/>/>
Lyqyd #2
Posted 24 May 2013 - 05:43 PM
Split into new topic.
BlankTitle #3
Posted 26 May 2013 - 01:20 PM
I think you need an attack turtle to remove mobs, I would just chicken-proof your mining area though.
W00dyR #4
Posted 26 May 2013 - 01:41 PM
Instead of the system you use, just use something like:


attempts = 0
maxAttempts = 10
local function newForward()
  while not turtle.forward() do
	  turtle.dig()
	  turtle.attack()
	  attempts = attempts + 1
	  if attempts == maxAttempts then
	    break -- This break ends the while loop and makes it stop attempting to go forward, you can also change it into "return" which just ends the program.
	  end
      sleep(1)
  end
end