attack program - new

This commit is contained in:
kepler155c
2018-11-23 16:13:53 -05:00
parent dc61f89739
commit cf39d1d74c

View File

@@ -31,21 +31,40 @@ local function equip(side, item, rawName)
turtle.select(1) turtle.select(1)
end end
local function setHeading() equip('left', 'minecraft:diamond_sword')
equip('right', 'plethora:scanner', 'plethora:module:2')
local scanner = device['plethora:scanner'] equip('right', 'plethora:scanner', 'plethora:module:2')
local facing = scanner.getBlockMeta(0, 0, 0).state.facing local scanner = device['plethora:scanner']
turtle.point.heading = Point.facings[facing].heading local facing = scanner.getBlockMeta(0, 0, 0).state.facing
turtle.point.heading = Point.facings[facing].heading
local scanned = scanner.scan()
local chest = Util.find(scanned, 'name', 'minecraft:chest')
if chest then
chest.x = Util.round(chest.x) + turtle.point.x
chest.y = Util.round(chest.y) + turtle.point.y
chest.z = Util.round(chest.z) + turtle.point.z
end end
equip('left', 'minecraft:diamond_sword')
setHeading()
equip('right', 'plethora:sensor', 'plethora:module:3') equip('right', 'plethora:sensor', 'plethora:module:3')
local sensor = device['plethora:sensor'] local sensor = device['plethora:sensor']
turtle.setMovementStrategy('goto') turtle.setMovementStrategy('goto')
local function dropOff()
if not chest then
return
end
local inv = turtle.getSummedInventory()
for _, slot in pairs(inv) do
if slot.count >= 16 then
turtle.dropDownAt(chest, slot.name)
end
end
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)
@@ -65,9 +84,9 @@ while true do
os.sleep(3) os.sleep(3)
else else
Point.eachClosest(turtle.point, mobs, function(b) Point.eachClosest(turtle.point, mobs, function(b)
if turtle.faceAgainst(b) then repeat until not turtle.attackAt(b)
repeat until not turtle.attack()
end
end) end)
end end
dropOff()
end end