From 0ec0c63ba67ad17e3740118cbaedf2c59511256c Mon Sep 17 00:00:00 2001 From: "kepler155c@gmail.com" Date: Tue, 30 Apr 2019 23:02:49 -0400 Subject: [PATCH] neural cleanup --- {games => common}/SoundPlayer.lua | 0 ignore/mobPickup.lua | 65 ++++++++++--------------- {neural => ignore}/neuralFight.lua | 0 {neural => ignore}/neuralFly.lua | 0 {neural => ignore}/neuralRemote.lua | 0 {neural => ignore}/neuralSword.lua | 0 {neural => ignore}/robotWars.lua | 9 ++++ neural/apis/interface.lua | 21 +++----- neural/apis/kinetic.lua | 45 ----------------- neural/autorun/interface.lua | 6 +-- neural/fisher.lua | 39 ++++++--------- neural/{mobfollow.lua => mobFollow.lua} | 0 neural/mobRancher.lua | 2 +- neural/neuralLook.lua | 20 ++++---- neural/ores.lua | 19 ++++---- 15 files changed, 82 insertions(+), 144 deletions(-) rename {games => common}/SoundPlayer.lua (100%) rename {neural => ignore}/neuralFight.lua (100%) rename {neural => ignore}/neuralFly.lua (100%) rename {neural => ignore}/neuralRemote.lua (100%) rename {neural => ignore}/neuralSword.lua (100%) rename {neural => ignore}/robotWars.lua (92%) delete mode 100644 neural/apis/kinetic.lua rename neural/{mobfollow.lua => mobFollow.lua} (100%) diff --git a/games/SoundPlayer.lua b/common/SoundPlayer.lua similarity index 100% rename from games/SoundPlayer.lua rename to common/SoundPlayer.lua diff --git a/ignore/mobPickup.lua b/ignore/mobPickup.lua index 94864f0..9be0ace 100644 --- a/ignore/mobPickup.lua +++ b/ignore/mobPickup.lua @@ -1,6 +1,7 @@ -local Point = require('point') +local neural = require('neural.interface') +local Point = require('point') local Sound = require('sound') -local Util = require('util') +local Util = require('util') local device = _G.device local os = _G.os @@ -8,25 +9,17 @@ local os = _G.os local scanner = device['plethora:scanner'] local sensor = device['plethora:sensor'] -local id = sensor.getID() - local function dropOff() + print('dropping') + local blocks = scanner.scan() local b = Util.find(blocks, 'name', 'minecraft:hopper') - print(not not b) + if b then - print('walking ', b.x, b.y + 1, b.z) - os.sleep(1) - sensor.walk(b.x, b.y + 1, b.z) - os.sleep(2) - repeat until not sensor.isWalking() - print('done walking') + neural.walkTo({ x = b.x, y = 0, z = b.z }) blocks = scanner.scan() b = Util.find(blocks, 'name', 'minecraft:hopper') - if b then - print(b.x, b.z) - end if b and math.abs(b.x) < 1 and math.abs(b.z) < 1 then print('dropped') sensor.getEquipment().drop(1) @@ -36,13 +29,24 @@ local function dropOff() end end +local function pickup(id) + local b = sensor.getMetaByID(id) + if b then + neural.walkTo(b) + + local amount = sensor.getEquipment().suck() + print('sucked: ' .. amount) + if amount > 0 then + Sound.play('entity.item.pickup') + return true + end + end +end + while true do local sensed = Util.reduce(sensor.sense(), function(acc, s) s.y = Util.round(s.y) - 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 end return acc @@ -52,32 +56,17 @@ while true do while true do local b = Point.closest(pt, sensed) if not b then + os.sleep(5) break end sensed[b.id] = nil - b = sensor.getMetaByID(b.id) - if b then - print('picking up ', b.x, b.y, b.z) - sensor.walk(b.x, b.y, b.z) - os.sleep(2) - repeat until not sensor.isWalking() - print('done goto') - os.sleep(.5) + + if pickup(b.id) then pt = b - local amount = sensor.getEquipment().suck(1) - print('sucked: ' .. amount) - if amount == 0 then - amount = sensor.getEquipment().suck(2) - if amount == 0 then - print('dropping') - dropOff() - break - end - end - Sound.play('entity.item.pickup') + else + dropOff() + break end end - - os.sleep(5) end diff --git a/neural/neuralFight.lua b/ignore/neuralFight.lua similarity index 100% rename from neural/neuralFight.lua rename to ignore/neuralFight.lua diff --git a/neural/neuralFly.lua b/ignore/neuralFly.lua similarity index 100% rename from neural/neuralFly.lua rename to ignore/neuralFly.lua diff --git a/neural/neuralRemote.lua b/ignore/neuralRemote.lua similarity index 100% rename from neural/neuralRemote.lua rename to ignore/neuralRemote.lua diff --git a/neural/neuralSword.lua b/ignore/neuralSword.lua similarity index 100% rename from neural/neuralSword.lua rename to ignore/neuralSword.lua diff --git a/neural/robotWars.lua b/ignore/robotWars.lua similarity index 92% rename from neural/robotWars.lua rename to ignore/robotWars.lua index 422d053..9778a14 100644 --- a/neural/robotWars.lua +++ b/ignore/robotWars.lua @@ -11,6 +11,15 @@ local args = { ... } local TARGET = args[1] or error('Syntax: robotWars ') local uid = ni.getID and ni.getID() or error('Introspection module is required') +-- fix +function ni.getUniqueNames() + local t = { } + for _,v in pairs(ni.sense()) do + t[v.name] = v.name + end + return Util.transpose(t) +end + local function findTarget(name) for _, v in pairs(ni.sense()) do if v.name == name and v.id ~= uid then diff --git a/neural/apis/interface.lua b/neural/apis/interface.lua index 98865ad..b295bd7 100644 --- a/neural/apis/interface.lua +++ b/neural/apis/interface.lua @@ -43,17 +43,10 @@ function Neural.launchTo(pt, strength) math.pow(pt.x, 2) + math.pow(pt.z, 2)) strength = math.sqrt(math.max(32, dist) / 3) - debug(strength) end Neural.launch(yaw, 225, strength or 1) end -function Neural.dropArmor() - for i = 3, 5 do - Neural.unequip(i) - end -end - function Neural.walkTo(pt, speed) Neural.walk(pt.x, pt.y, pt.z, speed) os.sleep(1) @@ -81,6 +74,12 @@ function Neural.getEquipmentList() return l end +function Neural.dropArmor() + for i = 3, 5 do + Neural.unequip(i) + end +end + function Neural.equip(slot) return Neural.getEquipment and Neural.getEquipment().suck(slot) or 0 end @@ -89,14 +88,6 @@ function Neural.unequip(slot) return Neural.getEquipment and Neural.getEquipment().drop(slot) end -function Neural.getUniqueNames() - local t = { } - for _,v in pairs(Neural.sense()) do - t[v.name] = v.name - end - return Util.transpose(t) -end - function Neural.lookAt(pt) if pt then local yaw, pitch = Angle.towards(pt.x, pt.y, pt.z) diff --git a/neural/apis/kinetic.lua b/neural/apis/kinetic.lua deleted file mode 100644 index b8a7179..0000000 --- a/neural/apis/kinetic.lua +++ /dev/null @@ -1,45 +0,0 @@ -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) - 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/autorun/interface.lua b/neural/autorun/interface.lua index 81c0cbe..032d73a 100644 --- a/neural/autorun/interface.lua +++ b/neural/autorun/interface.lua @@ -8,7 +8,7 @@ if device.neuralInterface and device.wireless_modem then local pt = GPS.locate(2) if pt then return pcall(function() - if false and device.neuralInterface.walk then + if device.neuralInterface.walk then local gpt = { x = x - pt.x, y = 0, @@ -16,8 +16,8 @@ if device.neuralInterface and device.wireless_modem then } gpt.x = math.min(math.max(gpt.x, -15), 15) gpt.z = math.min(math.max(gpt.z, -15), 15) - return device.neuralInterface.walk(gpt.x, gpt.y, gpt.z) - else + return device.neuralInterface.walk(gpt.x, gpt.y, gpt.z, 2) + elseif ni.launch then local y, p = ni.yap(pt, { x = x, y = y + 3, z = z }) ni.look(y, 0) return ni.launch(y, p, 1.5) diff --git a/neural/fisher.lua b/neural/fisher.lua index 733c431..e11065f 100644 --- a/neural/fisher.lua +++ b/neural/fisher.lua @@ -1,28 +1,21 @@ local machine = require('neural.statemachine') +local neural = require('neural.interface') -local device = _G.device -local os = _G.os +local os = _G.os -local function Syntax(missing) - print([[Required: Neural Interface containing: - * Kinetic augment - * Entity sensor - * Introspection module]]) - error('Missing: ' .. missing) -end +neural.assertModules({ + 'plethora:kinetic', + 'plethora:introspection', + 'plethora:sensor', +}) -local kinetic = device['plethora:kinetic'] or Syntax('kinetic augment') -local sensor = device['plethora:sensor'] or Syntax('entity sensor') -local canvas = device['plethora:glasses'] and device['plethora:glasses'].canvas() - -if not sensor.getMetaOwner then Syntax('introspection module') end - -local depth = -3 -local icon +local depth = -3 local scales = { .2, .4, .6, .8, 1, .8, .6, .4 } -local scale = 0 +local scale = 0 +local icon local w, h +local canvas = neural.canvas and neural.canvas() if canvas then w, h = canvas.getSize() icon = canvas.addItem({ w - 20, h - 20 }, 'minecraft:fishing_rod' ) @@ -41,14 +34,14 @@ local fsm = machine.create({ callbacks = { -- events oncast = function() - kinetic.use(.2) + neural.use(.2) os.sleep(.5) - local meta = sensor.getMetaByName('unknown') + local meta = neural.getMetaByName('unknown') depth = meta and meta.y - .5 or depth end, onreel = function() - kinetic.use(.3) + neural.use(.3) os.sleep(.5) end, @@ -76,7 +69,7 @@ local fsm = machine.create({ }) local function isHoldingRod() - local owner = sensor.getMetaOwner() + local owner = neural.getMetaOwner() local held = owner.heldItem and owner.heldItem.getMetadata() return held and held.rawName == 'item.fishingRod' end @@ -84,7 +77,7 @@ end local function fish() fsm:startup() while true do - local meta = sensor.getMetaByName('unknown') + local meta = neural.getMetaByName('unknown') if isHoldingRod() then fsm:rod() if not meta then diff --git a/neural/mobfollow.lua b/neural/mobFollow.lua similarity index 100% rename from neural/mobfollow.lua rename to neural/mobFollow.lua diff --git a/neural/mobRancher.lua b/neural/mobRancher.lua index 177d98a..f932e9d 100644 --- a/neural/mobRancher.lua +++ b/neural/mobRancher.lua @@ -2,7 +2,7 @@ local neural = require('neural.interface') local Sound = require('sound') local Util = require('util') -local os = _G.os +local os = _G.os local WALK_SPEED = 1.5 local MAX_COWS = 12 diff --git a/neural/neuralLook.lua b/neural/neuralLook.lua index 7924bcb..db5ad8a 100644 --- a/neural/neuralLook.lua +++ b/neural/neuralLook.lua @@ -1,22 +1,24 @@ local Array = require('array') -local kinetic = require('neural.kinetic') +local neural = require('neural.interface') local Point = require('point') -local device = _G.device -local os = _G.os +local os = _G.os + +neural.assertModules({ + 'plethora:sensor', + 'plethora:introspection', +}) local pos = { x = 0, y = 0, z = 0 } -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 ownerId = neural.getMetaOwner().id local targets = { } local function findTargets() local now = os.clock() local moved = { } - local l = Array.filter(sensor.sense(), function(a) + local l = Array.filter(neural.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 @@ -53,10 +55,10 @@ while true do local target = findTargets() if target then count = 0 - kinetic.lookAt(target) + neural.lookAt(target) os.sleep(0) elseif count > 25 then - kinetic.lookAt({ + neural.lookAt({ x = math.random(-10, 10), y = math.random(-10, 10), z = math.random(-10, 10) diff --git a/neural/ores.lua b/neural/ores.lua index 9f84415..69bb5c3 100644 --- a/neural/ores.lua +++ b/neural/ores.lua @@ -41,17 +41,16 @@ local function getPoint() end local targets = { - ["minecraft:emerald_ore"] = { "minecraft:emerald_ore", 0 }, - ["minecraft:diamond_ore"] = { "minecraft:diamond_ore", 0 }, - ["minecraft:gold_ore"] = { "minecraft:gold_ore", 0 }, - ["minecraft:redstone_ore"] = { "minecraft:redstone_ore", 0 }, + ["minecraft:emerald_ore"] = { "minecraft:emerald_ore", 0 }, + ["minecraft:diamond_ore"] = { "minecraft:diamond_ore", 0 }, + ["minecraft:gold_ore"] = { "minecraft:gold_ore", 0 }, + ["minecraft:redstone_ore"] = { "minecraft:redstone_ore", 0 }, ["minecraft:lit_redstone_ore"] = { "minecraft:redstone_ore", 0 }, - ["minecraft:iron_ore"] = { "minecraft:iron_ore", 0 }, - ["minecraft:lapis_ore"] = { "minecraft:lapis_ore", 0 }, - ["minecraft:coal_ore"] = { "minecraft:coal_ore", 0 }, - --["quark:biotite_ore"] = 0x02051C66, - ["minecraft:quartz_ore"] = { "minecraft:quartz_ore", 0 }, - ["minecraft:glowstone"] = { "minecraft:glowstone", 0 }, + ["minecraft:iron_ore"] = { "minecraft:iron_ore", 0 }, + ["minecraft:lapis_ore"] = { "minecraft:lapis_ore", 0 }, + ["minecraft:coal_ore"] = { "minecraft:coal_ore", 0 }, + ["minecraft:quartz_ore"] = { "minecraft:quartz_ore", 0 }, + ["minecraft:glowstone"] = { "minecraft:glowstone", 0 }, } local projecting = { } local offset = getPoint() or showRequirements('GPS')