Jump to content




Mining turtle. Not digging/attacking mobs


3 replies to this topic

#1 Rivil

  • New Members
  • 1 posts

Posted 24 May 2013 - 03: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 :(/>

#2 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 24 May 2013 - 04:43 PM

Split into new topic.

#3 BlankTitle

  • Members
  • 20 posts

Posted 26 May 2013 - 12:20 PM

I think you need an attack turtle to remove mobs, I would just chicken-proof your mining area though.

#4 W00dyR

  • Members
  • 135 posts

Posted 26 May 2013 - 12: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






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users