diff --git a/ignore/mobPickup.lua b/ignore/mobPickup.lua index 4e205f8..94864f0 100644 --- a/ignore/mobPickup.lua +++ b/ignore/mobPickup.lua @@ -1,4 +1,5 @@ local Point = require('point') +local Sound = require('sound') local Util = require('util') local device = _G.device @@ -27,8 +28,9 @@ local function dropOff() print(b.x, b.z) end if b and math.abs(b.x) < 1 and math.abs(b.z) < 1 then -print('dropped') + print('dropped') sensor.getEquipment().drop(1) + sensor.getEquipment().drop(2) os.sleep(1) end end @@ -38,7 +40,7 @@ while true do local sensed = Util.reduce(sensor.sense(), function(acc, s) s.y = Util.round(s.y) - if s.y == 0 and s.id ~= id then + if s.y == 0 and s.name == 'Item' then --s.x = Util.round(s.x) --s.z = Util.round(s.z) acc[s.id] = s @@ -65,10 +67,14 @@ while true do local amount = sensor.getEquipment().suck(1) print('sucked: ' .. amount) if amount == 0 then - print('dropping') - dropOff() - break + amount = sensor.getEquipment().suck(2) + if amount == 0 then + print('dropping') + dropOff() + break + end end + Sound.play('entity.item.pickup') end end diff --git a/neural/apis/kinetic.lua b/neural/apis/kinetic.lua index 22e3ba4..b8a7179 100644 --- a/neural/apis/kinetic.lua +++ b/neural/apis/kinetic.lua @@ -2,14 +2,44 @@ local Angle = require('neural.angle') local Util = require('util') local device = _G.device +local os = _G.os local module = device['plethora:kinetic'] or error('Missing kinetic') local Kinetic = Util.shallowCopy(module) function Kinetic.lookAt(pt) - local yaw, pitch = Angle.towards(pt.x, pt.y, pt.z) - return Kinetic.look(yaw, pitch) + if pt then + local yaw, pitch = Angle.towards(pt.x, pt.y, pt.z) + return Kinetic.look(yaw, pitch) + end end +function Kinetic.fireAt(pt) + local yaw, pitch = Angle.towards(pt.x, pt.y, pt.z) + return Kinetic.fire(yaw, pitch, .5) +end + +function Kinetic.walkTo(pt) + Kinetic.walk(pt.x, 0, pt.z) + os.sleep(1) + repeat until not Kinetic.isWalking() +end + +function Kinetic.walkAgainst(pt, radius) + local angle = math.atan2(pt.x, pt.z) + local x = pt.x - ((radius or .8) * math.sin(angle)) + local z = pt.z - ((radius or .8) * math.cos(angle)) + + Kinetic.walk(x, 0, z) + os.sleep(1) + repeat until not Kinetic.isWalking() +end + +function Kinetic.testWalk() + local e = Kinetic.getMetaByName('kepler155c') + Kinetic.walkToEntity(e) +end + + return Kinetic diff --git a/neural/mobRancher.lua b/neural/mobRancher.lua new file mode 100644 index 0000000..91fb25b --- /dev/null +++ b/neural/mobRancher.lua @@ -0,0 +1,99 @@ +local Kinetic = require('neural.kinetic') +local Sound = require('sound') +local Util = require('util') + +local device = _G.device +local os = _G.os + +local sensor = device['plethora:sensor'] +local scanner = device['plethora:scanner'] + +local fed = { } + +local function resupply() + local slot = sensor.getEquipment().list()[1] + if slot and slot.count > 32 then + return + end + print('resupplying') + for _ = 1, 8 do + local dispenser = Util.find(scanner.scan(), 'name', 'minecraft:dispenser') + if dispenser and math.abs(dispenser.x) <= 1 and math.abs(dispenser.z) <= 1 then + Kinetic.lookAt(dispenser) + Kinetic.use(0, 'off') + os.sleep(.2) + Kinetic.getEquipment().suck(1, 64) + elseif dispenser then + Kinetic.walkTo(dispenser) + end + end +end + +local function feed(entity) + print('feeding') + entity.lastFed = os.clock() + fed[entity.id] = entity + + Kinetic.walkAgainst(entity) + entity = sensor.getMetaByID(entity.id) + if entity then + Kinetic.lookAt(entity) + Kinetic.use(1) + os.sleep(.1) + end +end + +local function kill(entity) + print('killing') + Kinetic.walkAgainst(entity, 2) + entity = sensor.getMetaByID(entity.id) + if entity then + Kinetic.lookAt(entity) + Kinetic.fireAt({ x = entity.x, y = 0, z = entity.z }) + Sound.play('entity.firework.launch') + end +end + +local function getEntities() + return Util.filter(sensor.sense(), function(entity) + if entity.name == 'Cow' and entity.y > -.5 then + return true + end + end) +end + +local function getHungry(entities) + for _,v in pairs(entities) do + if not fed[v.id] or os.clock() - fed[v.id].lastFed > 60 then + return v + end + end +end + +local function randomEntity(entities) + local r = math.random(1, Util.size(entities)) + local i = 1 + for _, v in pairs(entities) do + i = i + 1 + if i > r then + return v + end + end +end + +while true do + resupply() + + local entities = getEntities() + + if Util.size(entities) > 10 then + kill(randomEntity(entities)) + else + local entity = getHungry(entities) + if entity then + feed(entity) + else + os.sleep(5) + end + end +end