attack program - new
This commit is contained in:
@@ -9,7 +9,13 @@ local os = _G.os
|
|||||||
local turtle = _G.turtle
|
local turtle = _G.turtle
|
||||||
|
|
||||||
local args = { ... }
|
local args = { ... }
|
||||||
local mob = args[1] or error('Syntax: attack <mob name>')
|
local mobType = args[1] or error('Syntax: attack <mob name>')
|
||||||
|
|
||||||
|
local Runners = {
|
||||||
|
Cow = true,
|
||||||
|
Chicken = true,
|
||||||
|
Blaze = false,
|
||||||
|
}
|
||||||
|
|
||||||
local function equip(side, item, rawName)
|
local function equip(side, item, rawName)
|
||||||
local equipped = Peripheral.lookup('side/' .. side)
|
local equipped = Peripheral.lookup('side/' .. side)
|
||||||
@@ -64,14 +70,17 @@ local function dropOff()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function normalize(b)
|
||||||
|
b.x = Util.round(b.x) + turtle.point.x
|
||||||
|
b.y = Util.round(b.y) + turtle.point.y
|
||||||
|
b.z = Util.round(b.z) + turtle.point.z
|
||||||
|
end
|
||||||
|
|
||||||
while true do
|
while true do
|
||||||
local blocks = sensor.sense()
|
local blocks = sensor.sense()
|
||||||
local mobs = Util.filterInplace(blocks, function(b)
|
local mobs = Util.filterInplace(blocks, function(b)
|
||||||
if b.name == mob then
|
if b.name == mobType then
|
||||||
b.x = Util.round(b.x) + turtle.point.x
|
normalize(b)
|
||||||
b.y = Util.round(b.y) + turtle.point.y
|
|
||||||
b.z = Util.round(b.z) + turtle.point.z
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
@@ -83,11 +92,27 @@ while true do
|
|||||||
if #mobs == 0 then
|
if #mobs == 0 then
|
||||||
os.sleep(3)
|
os.sleep(3)
|
||||||
else
|
else
|
||||||
Point.eachClosest(turtle.point, mobs, function(b)
|
if Runners[mobType] then
|
||||||
if turtle.faceAgainst(b) then
|
-- if this mob runs away, just attack next closest
|
||||||
repeat until not turtle.attack()
|
Point.eachClosest(turtle.point, mobs, function(b)
|
||||||
end
|
if turtle.faceAgainst(b) then
|
||||||
end)
|
repeat until not turtle.attack()
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
os.sleep(2) --- give a little time for mobs to calm down
|
||||||
|
else
|
||||||
|
-- this mob doesn't run, attack and follow until dead
|
||||||
|
local mob = Point.closest(turtle.point, mobs)
|
||||||
|
repeat
|
||||||
|
if turtle.faceAgainst(mob) then
|
||||||
|
repeat until not turtle.attack()
|
||||||
|
end
|
||||||
|
mob = sensor.getMetaByID(mob.id)
|
||||||
|
if mob then
|
||||||
|
normalize(mob)
|
||||||
|
end
|
||||||
|
until not mob
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
dropOff()
|
dropOff()
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ local activityWizardPage = UI.Window {
|
|||||||
marginRight = 0,
|
marginRight = 0,
|
||||||
value = string.format(template, Ansi.yellow, Ansi.reset),
|
value = string.format(template, Ansi.yellow, Ansi.reset),
|
||||||
},
|
},
|
||||||
|
timestamp = os.clock(),
|
||||||
}
|
}
|
||||||
|
|
||||||
function activityWizardPage:isValidType(node)
|
function activityWizardPage:isValidType(node)
|
||||||
|
|||||||
Reference in New Issue
Block a user