Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- monstercleanup
- -- sweeps a (MAX_X+1) x (MAX_Y+1) area, kills monsters and plants torches (chunks must be loaded!)
- -- plant turtle ONE BLOCK ABOVE ground/floor so that torches could be placed under the turtle !!!
- -- plant turtle to the left bottom corner of the desired cleaning area (this will be the 0,0 position)
- -- X coordinate increases to the right, Y coordinate increases to the front
- -- turtle will need to be refueled to minimum of approx. (MAX_X+2)*(MAX_Y+2) (1 coal=80)
- -- load slots with torches (or whatever you want to be placed under the turtle as it sweeps the area)
- -- you will need about 2 torches per 100m^2 (+borders)
- local MAX_X = 58
- local MAX_Y = 58
- local posX = 0
- local posY = 0
- local orient = 0 -- orientation relative to original placement: 0 = front, 1 = right, 2 = back, 3 = left
- local slotIndex = 1
- -- ------------------------------------------------------------------------------------------------------------
- function left()
- turtle.turnLeft()
- orient = orient-1
- while orient<0 do
- orient = orient+4
- end
- end
- -- ------------------------------------------------------------------------------------------------------------
- function right()
- turtle.turnRight()
- orient = orient+1
- while orient>3 do
- orient = orient-4
- end
- end
- -- ------------------------------------------------------------------------------------------------------------
- function killMonsters()
- turtle.attack()
- turtle.attack()
- turtle.attackUp()
- turtle.attackUp()
- turtle.attackDown()
- turtle.attackDown()
- turtle.dig()
- turtle.digDown()
- os.sleep(0.7)
- end
- -- ------------------------------------------------------------------------------------------------------------
- function forward()
- while not turtle.forward() do
- killMonsters()
- end
- if orient==0 then
- posY = posY+1
- end
- if orient==1 then
- posX = posX+1
- end
- if orient==2 then
- posY = posY-1
- end
- if orient==3 then
- posX = posX-1
- end
- end
- -- ------------------------------------------------------------------------------------------------------------
- function cleanupPlaceTorch()
- while turtle.getItemCount(slotIndex)==0 and slotIndex<16 do
- slotIndex = slotIndex + 1
- end
- if turtle.getItemCount(slotIndex) > 0 then
- while not turtle.placeDown() do
- killMonsters()
- end
- end
- end
- -- ------------------------------------------------------------------------------------------------------------
- function cleanupStepAction()
- -- kill monsters all around
- for i=1,4 do
- killMonsters()
- turtle.turnRight()
- end
- if (posX % 10 == 0 and posY % 10 == 0) or ((posX+5) % 10 == 0 and (posY+5) % 10 == 0) then
- cleanupPlaceTorch()
- end
- end
- -- ------------------------------------------------------------------------------------------------------------
- function cleanupStepMove()
- local result = true
- if orient==0 then
- if posY<MAX_Y then
- forward()
- elseif posX<MAX_X then
- right()
- forward()
- right()
- else
- result = false
- end
- elseif orient==2 then
- if posY>0 then
- forward()
- elseif posX<MAX_X then
- left()
- forward()
- left()
- else
- result = false
- end
- end
- return result
- end
- -- ------------------------------------------------------------------------------------------------------------
- function cleanupFinish()
- -- move back to starting position
- while orient~=3 do
- right()
- end
- while posX>0 do
- forward()
- end
- while orient~=2 do
- left()
- end
- while posY>0 do
- forward()
- end
- end
- -- ------------------------------------------------------------------------------------------------------------
- function main()
- local cycle = true
- while cycle do
- cleanupStepAction()
- cycle = cleanupStepMove() -- returns false if finished
- end
- cleanupFinish() -- move back to starting position
- end
- -- ============================================================================================================
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement