From 71b343cf86f7d729b5d02a1a24b6834d410518d0 Mon Sep 17 00:00:00 2001 From: "kepler155c@gmail.com" Date: Mon, 1 Apr 2019 08:51:53 -0400 Subject: [PATCH] better armor stand intelligence --- monitor/help/mirror | 11 ++++++++ neural/neuralLook.lua | 64 +++++++++++++++++++++++++++++-------------- 2 files changed, 54 insertions(+), 21 deletions(-) create mode 100644 monitor/help/mirror diff --git a/monitor/help/mirror b/monitor/help/mirror new file mode 100644 index 0000000..ddfd7f5 --- /dev/null +++ b/monitor/help/mirror @@ -0,0 +1,11 @@ +Mirror the terminal or a program on a monitor. Monitor touch events are translated to mouse click events. + +Optional arguments: + -s : set monitor to .5 scaling + -r : resize the terminal to the size of the monitor + -e : run a program on the monitor + +If the -e argument is not used, the current terminal will be mirrored. + +Example: +mirror -s -r -e edit /startup diff --git a/neural/neuralLook.lua b/neural/neuralLook.lua index 2e29ac8..7924bcb 100644 --- a/neural/neuralLook.lua +++ b/neural/neuralLook.lua @@ -10,39 +10,61 @@ local sensor = device['plethora:sensor'] or error('Missing sensor') local intro = device['plethora:introspection'] or error('Missing introspection module') local ownerId = intro.getMetaOwner().id +local targets = { } local function findTargets() - local l = Array.filter(sensor.sense(), function(a) - return math.abs(a.motionY) > 0 and ownerId ~= a.id - end) - table.sort(l, function(e1, e2) - return Point.distance(e1, pos) < Point.distance(e2, pos) - end) + local now = os.clock() + local moved = { } + local l = Array.filter(sensor.sense(), function(a) + if math.abs(a.motionY) > 0 and ownerId ~= a.id then + local loc = table.concat({ a.x, a.y, a.z }, ':') + if not targets[a.id] then + targets[a.id] = { c = now } + elseif targets[a.id].loc ~= loc then + targets[a.id].c = now + table.insert(moved, a) + end + targets[a.id].loc = loc + a.c = targets[a.id].c + return now - a.c < 5 + end + end) + + if #moved > 0 then + table.sort(moved, function(e1, e2) + return Point.distance(e1, pos) < Point.distance(e2, pos) + end) + return moved[1] + end + + if #l > 1 then + table.sort(l, function(e1, e2) + return now - e1.c < now - e2.c + end) + return targets[1] + end return l[1] end -local last -local count = 0 +local count = 50 while true do local target = findTargets() - if target and (not last or Point.distance(last, target) > .2) then - last = target - kinetic.lookAt(target) + if target then count = 0 + kinetic.lookAt(target) os.sleep(0) + elseif count > 25 then + kinetic.lookAt({ + x = math.random(-10, 10), + y = math.random(-10, 10), + z = math.random(-10, 10) + }) + os.sleep(3) else count = count + 1 - if count > 50 or not target then - kinetic.lookAt({ - x = math.random(-10, 10), - y = math.random(-10, 10), - z = math.random(-10, 10) - }) - os.sleep(3) - else - os.sleep(.1) - end + os.sleep(.1) end end +