spaces->tab, equipper improvements, supertreefarm rewrite, follow improvements, sensor cleanup, milo multiple items allowed in recipes, remote canvas access
This commit is contained in:
@@ -3,4 +3,7 @@
|
||||
repository = 'kepler155c/opus-apps/{{OPUS_BRANCH}}/neural',
|
||||
description = [[ Applications using various plethora modules ]],
|
||||
licence = 'MIT',
|
||||
required = {
|
||||
'core',
|
||||
},
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
local Event = require('event')
|
||||
local itemDB = require('core.itemDB')
|
||||
local UI = require('ui')
|
||||
local Util = require('util')
|
||||
local Event = require('event')
|
||||
local itemDB = require('core.itemDB')
|
||||
local UI = require('ui')
|
||||
local Util = require('util')
|
||||
|
||||
local device = _G.device
|
||||
local gps = _G.gps
|
||||
local device = _G.device
|
||||
local gps = _G.gps
|
||||
local multishell = _ENV.multishell
|
||||
|
||||
local glasses = device['plethora:glasses']
|
||||
local scanner = device['plethora:scanner'] or
|
||||
@@ -14,11 +15,13 @@ local projecting = { }
|
||||
|
||||
local function getPoint()
|
||||
local pt = { gps.locate() }
|
||||
return {
|
||||
x = pt[1],
|
||||
y = pt[2],
|
||||
z = pt[3],
|
||||
}
|
||||
if pt[1] then
|
||||
return {
|
||||
x = pt[1],
|
||||
y = pt[2],
|
||||
z = pt[3],
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
local offset = getPoint()
|
||||
@@ -60,7 +63,7 @@ local page = UI.Page {
|
||||
},
|
||||
sortColumn = 'name',
|
||||
accelerators = {
|
||||
grid_select = 'noop',
|
||||
grid_select = 'inspect',
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -75,21 +78,25 @@ function page:scan()
|
||||
local entry = itemDB:get(table.concat({ b.name, b.metadata }, ':'))
|
||||
if not entry then
|
||||
local meta = scanner.getBlockMeta(b.x, b.y, b.z)
|
||||
entry = itemDB:add({
|
||||
name = meta.name,
|
||||
displayName = meta.displayName,
|
||||
damage = meta.metadata,
|
||||
})
|
||||
if meta.name == b.name and meta.metadata == b.metadata then
|
||||
entry = itemDB:add({
|
||||
name = meta.name,
|
||||
displayName = meta.displayName,
|
||||
damage = meta.metadata,
|
||||
})
|
||||
end
|
||||
end
|
||||
b.key = entry.displayName
|
||||
if acc[b.key] then
|
||||
acc[b.key].count = acc[b.key].count + 1
|
||||
else
|
||||
entry = Util.shallowCopy(entry)
|
||||
entry.lname = entry.displayName:lower()
|
||||
entry.count = 1
|
||||
entry.key = b.key
|
||||
acc[b.key] = entry
|
||||
if entry then
|
||||
b.key = entry.displayName
|
||||
if acc[b.key] then
|
||||
acc[b.key].count = acc[b.key].count + 1
|
||||
else
|
||||
entry = Util.shallowCopy(entry)
|
||||
entry.lname = entry.displayName:lower()
|
||||
entry.count = 1
|
||||
entry.key = b.key
|
||||
acc[b.key] = entry
|
||||
end
|
||||
end
|
||||
throttle()
|
||||
return acc
|
||||
@@ -121,43 +128,45 @@ function page.detail:show(blocks, entry)
|
||||
local scanned = scanner.scan()
|
||||
local pos = getPoint()
|
||||
|
||||
blocks = Util.reduce(scanned, function(acc, b)
|
||||
if b.name == t.name and b.metadata == t.damage then
|
||||
-- track block's world position
|
||||
b.id = table.concat({
|
||||
math.floor(pos.x + b.x),
|
||||
math.floor(pos.y + b.y),
|
||||
math.floor(pos.z + b.z) }, ':')
|
||||
acc[b.id] = b
|
||||
end
|
||||
return acc
|
||||
end, { })
|
||||
|
||||
for _, b in pairs(blocks) do
|
||||
if not projecting[b.id] then
|
||||
projecting[b.id] = b
|
||||
pcall(function()
|
||||
b.box = canvas.addItem({
|
||||
pos.x - offset.x + b.x + -(pos.x % 1) + .5,
|
||||
pos.y - offset.y + b.y + -(pos.y % 1) + .5,
|
||||
pos.z - offset.z + b.z + -(pos.z % 1) + .5 },
|
||||
b.name, b.damage, .5)
|
||||
end)
|
||||
if not b.box then
|
||||
b.box = canvas.addBox(
|
||||
pos.x - offset.x + b.x + -(pos.x % 1) + .25,
|
||||
pos.y - offset.y + b.y + -(pos.y % 1) + .25,
|
||||
pos.z - offset.z + b.z + -(pos.z % 1) + .25,
|
||||
.5, .5, .5)
|
||||
if pos and offset then
|
||||
blocks = Util.reduce(scanned, function(acc, b)
|
||||
if b.name == t.name and b.metadata == t.damage then
|
||||
-- track block's world position
|
||||
b.id = table.concat({
|
||||
math.floor(pos.x + b.x),
|
||||
math.floor(pos.y + b.y),
|
||||
math.floor(pos.z + b.z) }, ':')
|
||||
acc[b.id] = b
|
||||
end
|
||||
b.box.setDepthTested(false)
|
||||
end
|
||||
end
|
||||
return acc
|
||||
end, { })
|
||||
|
||||
for _, b in pairs(projecting) do
|
||||
if not blocks[b.id] then
|
||||
b.box.remove()
|
||||
projecting[b.id] = nil
|
||||
for _, b in pairs(blocks) do
|
||||
if not projecting[b.id] then
|
||||
projecting[b.id] = b
|
||||
pcall(function()
|
||||
b.box = canvas.addItem({
|
||||
pos.x - offset.x + b.x + -(pos.x % 1) + .5,
|
||||
pos.y - offset.y + b.y + -(pos.y % 1) + .5,
|
||||
pos.z - offset.z + b.z + -(pos.z % 1) + .5 },
|
||||
b.name, b.damage, .5)
|
||||
end)
|
||||
if not b.box then
|
||||
b.box = canvas.addBox(
|
||||
pos.x - offset.x + b.x + -(pos.x % 1) + .25,
|
||||
pos.y - offset.y + b.y + -(pos.y % 1) + .25,
|
||||
pos.z - offset.z + b.z + -(pos.z % 1) + .25,
|
||||
.5, .5, .5)
|
||||
end
|
||||
b.box.setDepthTested(false)
|
||||
end
|
||||
end
|
||||
|
||||
for _, b in pairs(projecting) do
|
||||
if not blocks[b.id] then
|
||||
b.box.remove()
|
||||
projecting[b.id] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -178,7 +187,14 @@ function page:eventHandler(event)
|
||||
elseif event.type == 'scan' then
|
||||
self:scan()
|
||||
|
||||
elseif event.type == 'grid_select' and event.element == page.grid then
|
||||
elseif event.type == 'grid_select' and event.element == self.detail.grid then
|
||||
multishell.openTab({
|
||||
path = 'sys/apps/Lua.lua',
|
||||
args = { event.selected },
|
||||
focused = true,
|
||||
})
|
||||
|
||||
elseif event.type == 'grid_select' and event.element == self.grid then
|
||||
self.detail:show(self.blocks, self.grid:getSelected())
|
||||
|
||||
elseif event.type == 'cancel' then
|
||||
|
||||
@@ -18,22 +18,13 @@ local projecting = { }
|
||||
local offset
|
||||
local canvas = glasses and intro and glasses.canvas3d().create()
|
||||
|
||||
local config = Config.load('Sensor', {
|
||||
ignore = { }
|
||||
})
|
||||
local config = Config.load('Sensor')
|
||||
|
||||
local page = UI.Page {
|
||||
tabs = UI.Tabs {
|
||||
listing = UI.Tab {
|
||||
tabTitle = 'Listing',
|
||||
menuBar = UI.MenuBar {
|
||||
buttons = {
|
||||
{ text = 'Ignore', event = 'ignore' },
|
||||
{ text = 'Details', event = 'detail' },
|
||||
},
|
||||
},
|
||||
grid = UI.ScrollingGrid {
|
||||
y = 2,
|
||||
columns = {
|
||||
{ heading = 'Name', key = 'displayName' },
|
||||
{ heading = 'X', key = 'x', width = 3, align = 'right' },
|
||||
@@ -45,14 +36,7 @@ local page = UI.Page {
|
||||
},
|
||||
summary = UI.Tab {
|
||||
tabTitle = 'Summary',
|
||||
menuBar = UI.MenuBar {
|
||||
buttons = {
|
||||
{ text = 'Projector', event = 'project' },
|
||||
{ text = 'Ignore', event = 'ignore' },
|
||||
},
|
||||
},
|
||||
grid = UI.ScrollingGrid {
|
||||
y = 2,
|
||||
columns = {
|
||||
{ heading = 'Name', key = 'displayName' },
|
||||
{ heading = 'Count', key = 'count', width = 5, align = 'right' },
|
||||
@@ -134,13 +118,6 @@ local function project(entities)
|
||||
end
|
||||
end
|
||||
|
||||
local function ignoreEntity(entity)
|
||||
if entity then
|
||||
config.ignore[entity.name] = true
|
||||
Config.update('Sensor', config)
|
||||
end
|
||||
end
|
||||
|
||||
function detail:enable(entity)
|
||||
local function update()
|
||||
local t = { }
|
||||
@@ -194,8 +171,6 @@ end
|
||||
function listing:enable()
|
||||
self.handler = Event.onInterval(.5, function()
|
||||
local entities = sensor.sense()
|
||||
Util.filterInplace(entities, function(e) return not config.ignore[e.name] end)
|
||||
|
||||
self.grid:setValues(entities)
|
||||
self.grid:draw()
|
||||
self:sync()
|
||||
@@ -209,14 +184,11 @@ function listing:disable()
|
||||
end
|
||||
|
||||
function listing:eventHandler(event)
|
||||
if event.type == 'detail' or event.type == 'grid_select' then
|
||||
if event.type == 'grid_select' then
|
||||
local selected = self.grid:getSelected()
|
||||
if selected then
|
||||
UI:setPage(detail, selected)
|
||||
end
|
||||
|
||||
elseif event.type == 'ignore' then
|
||||
ignoreEntity(self.grid:getSelected())
|
||||
end
|
||||
|
||||
return UI.Tab.eventHandler(self, event)
|
||||
@@ -225,7 +197,6 @@ end
|
||||
function summary:enable()
|
||||
self.handler = Event.onInterval(.5, function()
|
||||
local entities = sensor.sense()
|
||||
Util.filterInplace(entities, function(e) return not config.ignore[e.name] end)
|
||||
|
||||
local t = { }
|
||||
local highlight = { }
|
||||
@@ -265,10 +236,7 @@ function summary.grid:getRowTextColor(row, selected)
|
||||
end
|
||||
|
||||
function summary:eventHandler(event)
|
||||
if event.type == 'ignore' then
|
||||
ignoreEntity(self.grid:getSelected())
|
||||
|
||||
elseif event.type == 'project' or event.type == 'grid_select' then
|
||||
if event.type == 'grid_select' then
|
||||
local selected = self.grid:getSelected()
|
||||
if selected then
|
||||
self.target = selected.name
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
local Angle = { }
|
||||
|
||||
function Angle.towards(x, y, z)
|
||||
return math.deg(math.atan2(-x, z)), math.deg(-math.atan2(y, math.sqrt(x * x + z * z)))
|
||||
return math.deg(math.atan2(-x, z)), math.deg(-math.atan2(y, math.sqrt(x * x + z * z)))
|
||||
end
|
||||
|
||||
function Angle.away(x, y, z)
|
||||
return math.deg(math.atan2(x, -z)), 0
|
||||
return math.deg(math.atan2(x, -z)), 0
|
||||
end
|
||||
|
||||
return Angle
|
||||
|
||||
@@ -1,27 +1,27 @@
|
||||
local Mobs = { }
|
||||
|
||||
local hostiles = {
|
||||
BabySkeleton = true,
|
||||
BabyZombie = true,
|
||||
Bat = true,
|
||||
Blaze = true,
|
||||
CaveSpider = true,
|
||||
Creeper = true,
|
||||
Ghast = true,
|
||||
Husk = true,
|
||||
LavaSlime = true,
|
||||
PigZombie = true,
|
||||
Skeleton = true,
|
||||
Slime = true,
|
||||
Spider = true,
|
||||
Witch = true,
|
||||
WitherSkeleton = true,
|
||||
Zombie = true,
|
||||
ZombieVillager = true,
|
||||
BabySkeleton = true,
|
||||
BabyZombie = true,
|
||||
Bat = true,
|
||||
Blaze = true,
|
||||
CaveSpider = true,
|
||||
Creeper = true,
|
||||
Ghast = true,
|
||||
Husk = true,
|
||||
LavaSlime = true,
|
||||
PigZombie = true,
|
||||
Skeleton = true,
|
||||
Slime = true,
|
||||
Spider = true,
|
||||
Witch = true,
|
||||
WitherSkeleton = true,
|
||||
Zombie = true,
|
||||
ZombieVillager = true,
|
||||
}
|
||||
|
||||
function Mobs.getNames()
|
||||
return hostiles
|
||||
return hostiles
|
||||
end
|
||||
|
||||
return Mobs
|
||||
|
||||
@@ -7,149 +7,149 @@ local NONE = "none"
|
||||
local ASYNC = "async"
|
||||
|
||||
local function call_handler(handler, params)
|
||||
if handler then
|
||||
return handler(unpack(params))
|
||||
end
|
||||
if handler then
|
||||
return handler(unpack(params))
|
||||
end
|
||||
end
|
||||
|
||||
local function create_transition(name)
|
||||
local can, to, from, params
|
||||
local can, to, from, params
|
||||
|
||||
local function transition(self, ...)
|
||||
if self.asyncState == NONE then
|
||||
can, to = self:can(name)
|
||||
from = self.current
|
||||
params = { self, name, from, to, ...}
|
||||
local function transition(self, ...)
|
||||
if self.asyncState == NONE then
|
||||
can, to = self:can(name)
|
||||
from = self.current
|
||||
params = { self, name, from, to, ...}
|
||||
|
||||
if not can then return false end
|
||||
self.currentTransitioningEvent = name
|
||||
if not can then return false end
|
||||
self.currentTransitioningEvent = name
|
||||
|
||||
local beforeReturn = call_handler(self["onbefore" .. name], params)
|
||||
local leaveReturn = call_handler(self["onleave" .. from], params)
|
||||
local beforeReturn = call_handler(self["onbefore" .. name], params)
|
||||
local leaveReturn = call_handler(self["onleave" .. from], params)
|
||||
|
||||
if beforeReturn == false or leaveReturn == false then
|
||||
return false
|
||||
end
|
||||
if beforeReturn == false or leaveReturn == false then
|
||||
return false
|
||||
end
|
||||
|
||||
self.asyncState = name .. "WaitingOnLeave"
|
||||
self.asyncState = name .. "WaitingOnLeave"
|
||||
|
||||
if leaveReturn ~= ASYNC then
|
||||
transition(self, ...)
|
||||
end
|
||||
if leaveReturn ~= ASYNC then
|
||||
transition(self, ...)
|
||||
end
|
||||
|
||||
return true
|
||||
elseif self.asyncState == name .. "WaitingOnLeave" then
|
||||
self.current = to
|
||||
return true
|
||||
elseif self.asyncState == name .. "WaitingOnLeave" then
|
||||
self.current = to
|
||||
|
||||
local enterReturn = call_handler(self["onenter" .. to] or self["on" .. to], params)
|
||||
local enterReturn = call_handler(self["onenter" .. to] or self["on" .. to], params)
|
||||
|
||||
self.asyncState = name .. "WaitingOnEnter"
|
||||
self.asyncState = name .. "WaitingOnEnter"
|
||||
|
||||
if enterReturn ~= ASYNC then
|
||||
transition(self, ...)
|
||||
end
|
||||
if enterReturn ~= ASYNC then
|
||||
transition(self, ...)
|
||||
end
|
||||
|
||||
return true
|
||||
elseif self.asyncState == name .. "WaitingOnEnter" then
|
||||
call_handler(self["onafter" .. name] or self["on" .. name], params)
|
||||
call_handler(self["onstatechange"], params)
|
||||
self.asyncState = NONE
|
||||
self.currentTransitioningEvent = nil
|
||||
return true
|
||||
else
|
||||
if string.find(self.asyncState, "WaitingOnLeave") or string.find(self.asyncState, "WaitingOnEnter") then
|
||||
self.asyncState = NONE
|
||||
transition(self, ...)
|
||||
return true
|
||||
end
|
||||
end
|
||||
return true
|
||||
elseif self.asyncState == name .. "WaitingOnEnter" then
|
||||
call_handler(self["onafter" .. name] or self["on" .. name], params)
|
||||
call_handler(self["onstatechange"], params)
|
||||
self.asyncState = NONE
|
||||
self.currentTransitioningEvent = nil
|
||||
return true
|
||||
else
|
||||
if string.find(self.asyncState, "WaitingOnLeave") or string.find(self.asyncState, "WaitingOnEnter") then
|
||||
self.asyncState = NONE
|
||||
transition(self, ...)
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
self.currentTransitioningEvent = nil
|
||||
return false
|
||||
end
|
||||
self.currentTransitioningEvent = nil
|
||||
return false
|
||||
end
|
||||
|
||||
return transition
|
||||
return transition
|
||||
end
|
||||
|
||||
local function add_to_map(map, event)
|
||||
if type(event.from) == 'string' then
|
||||
map[event.from] = event.to
|
||||
else
|
||||
for _, from in ipairs(event.from) do
|
||||
map[from] = event.to
|
||||
end
|
||||
end
|
||||
if type(event.from) == 'string' then
|
||||
map[event.from] = event.to
|
||||
else
|
||||
for _, from in ipairs(event.from) do
|
||||
map[from] = event.to
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function machine.create(options)
|
||||
assert(options.events)
|
||||
assert(options.events)
|
||||
|
||||
local fsm = {}
|
||||
setmetatable(fsm, machine)
|
||||
local fsm = {}
|
||||
setmetatable(fsm, machine)
|
||||
|
||||
fsm.options = options
|
||||
fsm.current = options.initial or 'none'
|
||||
fsm.asyncState = NONE
|
||||
fsm.events = {}
|
||||
fsm.options = options
|
||||
fsm.current = options.initial or 'none'
|
||||
fsm.asyncState = NONE
|
||||
fsm.events = {}
|
||||
|
||||
for _, event in ipairs(options.events or {}) do
|
||||
local name = event.name
|
||||
fsm[name] = fsm[name] or create_transition(name)
|
||||
fsm.events[name] = fsm.events[name] or { map = {} }
|
||||
add_to_map(fsm.events[name].map, event)
|
||||
end
|
||||
for _, event in ipairs(options.events or {}) do
|
||||
local name = event.name
|
||||
fsm[name] = fsm[name] or create_transition(name)
|
||||
fsm.events[name] = fsm.events[name] or { map = {} }
|
||||
add_to_map(fsm.events[name].map, event)
|
||||
end
|
||||
|
||||
for name, callback in pairs(options.callbacks or {}) do
|
||||
fsm[name] = callback
|
||||
end
|
||||
for name, callback in pairs(options.callbacks or {}) do
|
||||
fsm[name] = callback
|
||||
end
|
||||
|
||||
return fsm
|
||||
return fsm
|
||||
end
|
||||
|
||||
function machine:is(state)
|
||||
return self.current == state
|
||||
return self.current == state
|
||||
end
|
||||
|
||||
function machine:can(e)
|
||||
local event = self.events[e]
|
||||
local to = event and event.map[self.current] or event.map['*']
|
||||
return to ~= nil, to
|
||||
local event = self.events[e]
|
||||
local to = event and event.map[self.current] or event.map['*']
|
||||
return to ~= nil, to
|
||||
end
|
||||
|
||||
function machine:cannot(e)
|
||||
return not self:can(e)
|
||||
return not self:can(e)
|
||||
end
|
||||
|
||||
function machine:todot(filename)
|
||||
local dotfile = io.open(filename,'w')
|
||||
dotfile:write('digraph {\n')
|
||||
local transition = function(event,from,to)
|
||||
dotfile:write(string.format('%s -> %s [label=%s];\n',from,to,event))
|
||||
end
|
||||
for _, event in pairs(self.options.events) do
|
||||
if type(event.from) == 'table' then
|
||||
for _, from in ipairs(event.from) do
|
||||
transition(event.name,from,event.to)
|
||||
end
|
||||
else
|
||||
transition(event.name,event.from,event.to)
|
||||
end
|
||||
end
|
||||
dotfile:write('}\n')
|
||||
dotfile:close()
|
||||
local dotfile = io.open(filename,'w')
|
||||
dotfile:write('digraph {\n')
|
||||
local transition = function(event,from,to)
|
||||
dotfile:write(string.format('%s -> %s [label=%s];\n',from,to,event))
|
||||
end
|
||||
for _, event in pairs(self.options.events) do
|
||||
if type(event.from) == 'table' then
|
||||
for _, from in ipairs(event.from) do
|
||||
transition(event.name,from,event.to)
|
||||
end
|
||||
else
|
||||
transition(event.name,event.from,event.to)
|
||||
end
|
||||
end
|
||||
dotfile:write('}\n')
|
||||
dotfile:close()
|
||||
end
|
||||
|
||||
function machine:transition(event)
|
||||
if self.currentTransitioningEvent == event then
|
||||
return self[self.currentTransitioningEvent](self)
|
||||
end
|
||||
if self.currentTransitioningEvent == event then
|
||||
return self[self.currentTransitioningEvent](self)
|
||||
end
|
||||
end
|
||||
|
||||
function machine:cancelTransition(event)
|
||||
if self.currentTransitioningEvent == event then
|
||||
self.asyncState = NONE
|
||||
self.currentTransitioningEvent = nil
|
||||
end
|
||||
if self.currentTransitioningEvent == event then
|
||||
self.asyncState = NONE
|
||||
self.currentTransitioningEvent = nil
|
||||
end
|
||||
end
|
||||
|
||||
machine.NONE = NONE
|
||||
|
||||
@@ -3,28 +3,28 @@ local GPS = require('gps')
|
||||
local device = _G.device
|
||||
|
||||
if device.neuralInterface and device.wireless_modem then
|
||||
local ni = require('neural.interface')
|
||||
device.neuralInterface.goTo = function(x, y, z)
|
||||
local pt = GPS.locate(2)
|
||||
if pt then
|
||||
return pcall(function()
|
||||
if device.neuralInterface.walk then
|
||||
local gpt = {
|
||||
x = x - pt.x,
|
||||
y = 0,
|
||||
z = z - pt.z,
|
||||
}
|
||||
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, 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)
|
||||
end
|
||||
end)
|
||||
end
|
||||
return false, 'No GPS'
|
||||
end
|
||||
local ni = require('neural.interface')
|
||||
device.neuralInterface.goTo = function(x, y, z)
|
||||
local pt = GPS.locate(2)
|
||||
if pt then
|
||||
return pcall(function()
|
||||
if device.neuralInterface.walk then
|
||||
local gpt = {
|
||||
x = x - pt.x,
|
||||
y = 0,
|
||||
z = z - pt.z,
|
||||
}
|
||||
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, 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)
|
||||
end
|
||||
end)
|
||||
end
|
||||
return false, 'No GPS'
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,70 +1,70 @@
|
||||
local opus = {
|
||||
'fffff00',
|
||||
'ffff07000',
|
||||
'ff00770b00 4444',
|
||||
'ff077777444444444',
|
||||
'f07777744444444444',
|
||||
'f0000777444444444',
|
||||
'070000111744444',
|
||||
'777770000',
|
||||
'7777000000',
|
||||
'70700000000',
|
||||
'077000000000',
|
||||
'fffff00',
|
||||
'ffff07000',
|
||||
'ff00770b00 4444',
|
||||
'ff077777444444444',
|
||||
'f07777744444444444',
|
||||
'f0000777444444444',
|
||||
'070000111744444',
|
||||
'777770000',
|
||||
'7777000000',
|
||||
'70700000000',
|
||||
'077000000000',
|
||||
}
|
||||
|
||||
local hex = {
|
||||
['0'] = 0xF0F0F04F,
|
||||
['1'] = 0xF2B2334F,
|
||||
['2'] = 0xE57FD84F,
|
||||
['3'] = 0x99B2F24F,
|
||||
['4'] = 0xDEDE6C4F,
|
||||
['5'] = 0x7FCC194F,
|
||||
['6'] = 0xF2B2CC4F,
|
||||
['7'] = 0x4C4C4C4F,
|
||||
['8'] = 0x9999994F,
|
||||
['9'] = 0x4C99B24F,
|
||||
['a'] = 0xB266E54F,
|
||||
['b'] = 0x3366CC4F,
|
||||
['c'] = 0x7F664C4F,
|
||||
['d'] = 0x57A64E4F,
|
||||
['e'] = 0xCC4C4C4F,
|
||||
['0'] = 0xF0F0F04F,
|
||||
['1'] = 0xF2B2334F,
|
||||
['2'] = 0xE57FD84F,
|
||||
['3'] = 0x99B2F24F,
|
||||
['4'] = 0xDEDE6C4F,
|
||||
['5'] = 0x7FCC194F,
|
||||
['6'] = 0xF2B2CC4F,
|
||||
['7'] = 0x4C4C4C4F,
|
||||
['8'] = 0x9999994F,
|
||||
['9'] = 0x4C99B24F,
|
||||
['a'] = 0xB266E54F,
|
||||
['b'] = 0x3366CC4F,
|
||||
['c'] = 0x7F664C4F,
|
||||
['d'] = 0x57A64E4F,
|
||||
['e'] = 0xCC4C4C4F,
|
||||
-- ['f'] = 0x191919FF, -- transparent
|
||||
}
|
||||
|
||||
local function update()
|
||||
local canvas = device['plethora:glasses'] and device['plethora:glasses'].canvas()
|
||||
if canvas then
|
||||
local Tween = require('ui.tween')
|
||||
local canvas = device['plethora:glasses'] and device['plethora:glasses'].canvas()
|
||||
if canvas then
|
||||
local Tween = require('ui.tween')
|
||||
|
||||
canvas.clear()
|
||||
local w, h = canvas.getSize()
|
||||
local pos = { x = w / 2, y = h / 2 - 30 }
|
||||
local group = canvas.addGroup(pos)
|
||||
local function drawLine(k, line)
|
||||
for i = 1, #line do
|
||||
local pix = hex[line:sub(i, i)]
|
||||
if pix then
|
||||
group.addRectangle(i*1.5, k*2.25, 1.5, 2.25, pix)
|
||||
end
|
||||
end
|
||||
end
|
||||
canvas.clear()
|
||||
local w, h = canvas.getSize()
|
||||
local pos = { x = w / 2, y = h / 2 - 30 }
|
||||
local group = canvas.addGroup(pos)
|
||||
local function drawLine(k, line)
|
||||
for i = 1, #line do
|
||||
local pix = hex[line:sub(i, i)]
|
||||
if pix then
|
||||
group.addRectangle(i*1.5, k*2.25, 1.5, 2.25, pix)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
for k,line in ipairs(opus) do
|
||||
drawLine(k, line)
|
||||
end
|
||||
os.sleep(.5)
|
||||
local tween = Tween.new(40, pos, { x = w - 60, y = h - 30 }, 'outBounce')
|
||||
repeat
|
||||
local finished = tween:update(1)
|
||||
os.sleep(0)
|
||||
group.setPosition(pos.x, pos.y)
|
||||
until finished
|
||||
end
|
||||
for k,line in ipairs(opus) do
|
||||
drawLine(k, line)
|
||||
end
|
||||
os.sleep(.5)
|
||||
local tween = Tween.new(40, pos, { x = w - 60, y = h - 30 }, 'outBounce')
|
||||
repeat
|
||||
local finished = tween:update(1)
|
||||
os.sleep(0)
|
||||
group.setPosition(pos.x, pos.y)
|
||||
until finished
|
||||
end
|
||||
end
|
||||
|
||||
kernel.run({
|
||||
title = 'opus',
|
||||
env = _ENV,
|
||||
hidden = true,
|
||||
fn = update,
|
||||
title = 'opus',
|
||||
env = _ENV,
|
||||
hidden = true,
|
||||
fn = update,
|
||||
})
|
||||
|
||||
189
neural/canvasServer.lua
Normal file
189
neural/canvasServer.lua
Normal file
@@ -0,0 +1,189 @@
|
||||
local neural = require('neural.interface')
|
||||
|
||||
local device = _G.device
|
||||
local gps = _G.gps
|
||||
local os = _G.os
|
||||
local parallel = _G.parallel
|
||||
|
||||
neural.assertModules({
|
||||
'plethora:glasses',
|
||||
'plethora:introspection',
|
||||
'plethora:sensor',
|
||||
})
|
||||
|
||||
local function getPoint()
|
||||
local pt = { gps.locate() }
|
||||
if pt[1] then
|
||||
return {
|
||||
x = pt[1],
|
||||
y = pt[2],
|
||||
z = pt[3],
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
local projecting = { }
|
||||
local offset = getPoint() or error('GPS not found')
|
||||
|
||||
local canvas = neural.canvas3d().create({
|
||||
-(offset.x % 1),
|
||||
-(offset.y % 1),
|
||||
-(offset.z % 1)
|
||||
})
|
||||
|
||||
local function update(scanned)
|
||||
for _, b in pairs(scanned) do
|
||||
if not projecting[b.id] then
|
||||
local box
|
||||
|
||||
local x = b.x - math.floor(offset.x)
|
||||
local y = b.y - math.floor(offset.y)
|
||||
local z = b.z - math.floor(offset.z)
|
||||
|
||||
-- items are centered at the mid-point of the cube
|
||||
-- boxes are aligned to the top corner - sigh
|
||||
if b.path then
|
||||
box = canvas.addBox(x + .4, y + .4, z + .4, .2, .2, .2, 0xa0902080)
|
||||
elseif b.name then
|
||||
pcall(function()
|
||||
box = canvas.addItem({ x + .5, y + .5, z + .5 }, b.name, b.damage or b.metadata, .5)
|
||||
end)
|
||||
end
|
||||
if not box then
|
||||
box = canvas.addBox(x, y, z, 1, 1, 1, 0x8080ff30)
|
||||
end
|
||||
if box then
|
||||
box.setDepthTested(false)
|
||||
end
|
||||
projecting[b.id] = box
|
||||
end
|
||||
end
|
||||
|
||||
for id, box in pairs(projecting) do
|
||||
if not scanned[id] then
|
||||
box.remove()
|
||||
projecting[id] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local scanned = { }
|
||||
local dirty
|
||||
|
||||
local function processMessage(msg)
|
||||
if msg.type == 'canvas_clear' then
|
||||
scanned = { }
|
||||
projecting = { }
|
||||
canvas.clear()
|
||||
|
||||
elseif msg.type == 'canvas_remove' then
|
||||
for _, v in pairs(msg.data) do
|
||||
v.id = table.concat({ v.x, v.y, v.z }, ':')
|
||||
scanned[v.id] = nil
|
||||
end
|
||||
dirty = true
|
||||
|
||||
elseif msg.type == 'canvas_update' then
|
||||
scanned = { }
|
||||
for _, v in pairs(msg.data) do
|
||||
v.id = table.concat({ v.x, v.y, v.z }, ':')
|
||||
scanned[v.id] = v
|
||||
end
|
||||
dirty = true
|
||||
|
||||
elseif msg.type == 'canvas_barrier' then
|
||||
for _, v in pairs(msg.data) do
|
||||
v.id = table.concat({ v.x, v.y, v.z }, ':')
|
||||
if projecting[v.id] then
|
||||
projecting[v.id].remove()
|
||||
projecting[v.id] = nil
|
||||
end
|
||||
v.name = 'minecraft:barrier'
|
||||
v.damage = 0
|
||||
scanned[v.id] = v
|
||||
end
|
||||
dirty = true
|
||||
|
||||
elseif msg.type == 'canvas_path' then
|
||||
for k, v in pairs(scanned or { }) do
|
||||
if v.path then
|
||||
scanned[k] = nil
|
||||
end
|
||||
end
|
||||
|
||||
for _, v in pairs(msg.data) do
|
||||
v.path = true
|
||||
v.id = table.concat({ v.x, v.y, v.z }, ':')
|
||||
scanned[v.id] = v
|
||||
end
|
||||
dirty = true
|
||||
end
|
||||
end
|
||||
|
||||
local function recenter()
|
||||
while true do
|
||||
os.sleep(3)
|
||||
|
||||
local pos = getPoint()
|
||||
|
||||
if pos then
|
||||
if math.abs(pos.x - offset.x) +
|
||||
math.abs(pos.y - offset.y) +
|
||||
math.abs(pos.z - offset.z) > 64 then
|
||||
for _, box in pairs(projecting) do
|
||||
box.remove()
|
||||
end
|
||||
projecting = { }
|
||||
offset = pos
|
||||
canvas.recenter({
|
||||
-(offset.x % 1),
|
||||
-(offset.y % 1),
|
||||
-(offset.z % 1)
|
||||
})
|
||||
|
||||
update(scanned)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function queueListener()
|
||||
while true do
|
||||
local _, msg = os.pullEvent('canvas_message')
|
||||
processMessage(msg)
|
||||
end
|
||||
end
|
||||
|
||||
local function modemListener()
|
||||
device.wireless_modem.open(3773)
|
||||
while true do
|
||||
local _, _, dport, _, msg = os.pullEvent('modem_message')
|
||||
if dport == 3773 and type(msg) == 'table' then
|
||||
processMessage(msg)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local s, m = pcall(function()
|
||||
parallel.waitForAny(
|
||||
queueListener,
|
||||
modemListener,
|
||||
recenter,
|
||||
function()
|
||||
while true do
|
||||
if dirty then
|
||||
dirty = false
|
||||
update(scanned)
|
||||
end
|
||||
os.sleep(1)
|
||||
end
|
||||
end
|
||||
)
|
||||
end)
|
||||
|
||||
canvas.clear()
|
||||
device.wireless_modem.close(3773)
|
||||
|
||||
if not s and m then
|
||||
_G.printError(m)
|
||||
end
|
||||
@@ -1,10 +1,10 @@
|
||||
local device = _G.device
|
||||
|
||||
local kinetic = device['plethora:kinetic'] or
|
||||
error('Missing kinetic augment')
|
||||
error('Missing kinetic augment')
|
||||
|
||||
if not kinetic.disableAI then
|
||||
error('Nope')
|
||||
error('Nope')
|
||||
end
|
||||
|
||||
kinetic.disableAI()
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
local device = _G.device
|
||||
|
||||
local intro = device['plethora:introspection'] or
|
||||
error('Missing Introspection module')
|
||||
error('Missing Introspection module')
|
||||
|
||||
if intro.getBaubles then
|
||||
intro.getBaubles().drop(5)
|
||||
intro.getBaubles().drop(5)
|
||||
else
|
||||
intro.getEquipment().drop(6)
|
||||
intro.getEquipment().drop(6)
|
||||
end
|
||||
|
||||
@@ -11,154 +11,154 @@ local parallel = _G.parallel
|
||||
local STARTUP_FILE = 'usr/autorun/fly.lua'
|
||||
|
||||
if not modules.launch or not modules.getMetaOwner then
|
||||
print([[Required:
|
||||
print([[Required:
|
||||
* Kinetic augment
|
||||
* Entity sensor
|
||||
* Introspection module]])
|
||||
error('missing required item')
|
||||
error('missing required item')
|
||||
end
|
||||
|
||||
if not fs.exists(STARTUP_FILE) then
|
||||
Util.writeFile(STARTUP_FILE, [[os.sleep(1)
|
||||
Util.writeFile(STARTUP_FILE, [[os.sleep(1)
|
||||
shell.openHiddenTab('elytraFly.lua')]])
|
||||
print('Autorun program created: ' .. STARTUP_FILE)
|
||||
print('Autorun program created: ' .. STARTUP_FILE)
|
||||
end
|
||||
|
||||
local canvas = modules.canvas and modules.canvas()
|
||||
|
||||
local function dist(x, y, z)
|
||||
return math.sqrt(
|
||||
math.pow(x, 2) +
|
||||
math.pow(y, 2) +
|
||||
math.pow(z, 2))
|
||||
return math.sqrt(
|
||||
math.pow(x, 2) +
|
||||
math.pow(y, 2) +
|
||||
math.pow(z, 2))
|
||||
end
|
||||
|
||||
local function display(meta)
|
||||
if canvas then
|
||||
if not canvas.group then
|
||||
canvas.group = canvas.addGroup({ 4, 90 })
|
||||
canvas.group.addRectangle(0, 0, 70, 30, 0x00000033)
|
||||
canvas.pitch = canvas.group.addText({ 4, 5 }, '') -- , 0x202020FF)
|
||||
canvas.pitch.setShadow(true)
|
||||
canvas.pitch.setScale(.75)
|
||||
canvas.group.addItem({ 5, 30 }, 'minecraft:elytra')
|
||||
canvas.group2 = canvas.addGroup({ 80, 10 })
|
||||
canvas.group2.addLines(
|
||||
{ 0, 0 },
|
||||
{ 0, 180 },
|
||||
{ 5, 180 },
|
||||
{ 5, 0 },
|
||||
0x202020FF,
|
||||
2)
|
||||
canvas.meter = canvas.group2.addRectangle(0, 0, 5, 1)
|
||||
end
|
||||
local size = math.abs(meta.pitch) -- math.ceil(math.abs(meta.pitch) / 9)
|
||||
local y = 0
|
||||
local color = 0x202020FF
|
||||
if meta.pitch < 0 then
|
||||
y = size
|
||||
color = 0x808080FF
|
||||
end
|
||||
canvas.meter.setPosition(0, 90 - y)
|
||||
canvas.meter.setSize(5, size)
|
||||
canvas.meter.setColor(color)
|
||||
canvas.pitch.setText(string.format('Pitch: %s\nMotion Y: %s\nSpeed: %s m/s',
|
||||
math.floor(-meta.pitch),
|
||||
Util.round(meta.motionY, 2),
|
||||
Util.round(dist(meta.motionX, meta.motionY, meta.motionZ) * 20, 2)))
|
||||
end
|
||||
if canvas then
|
||||
if not canvas.group then
|
||||
canvas.group = canvas.addGroup({ 4, 90 })
|
||||
canvas.group.addRectangle(0, 0, 70, 30, 0x00000033)
|
||||
canvas.pitch = canvas.group.addText({ 4, 5 }, '') -- , 0x202020FF)
|
||||
canvas.pitch.setShadow(true)
|
||||
canvas.pitch.setScale(.75)
|
||||
canvas.group.addItem({ 5, 30 }, 'minecraft:elytra')
|
||||
canvas.group2 = canvas.addGroup({ 80, 10 })
|
||||
canvas.group2.addLines(
|
||||
{ 0, 0 },
|
||||
{ 0, 180 },
|
||||
{ 5, 180 },
|
||||
{ 5, 0 },
|
||||
0x202020FF,
|
||||
2)
|
||||
canvas.meter = canvas.group2.addRectangle(0, 0, 5, 1)
|
||||
end
|
||||
local size = math.abs(meta.pitch) -- math.ceil(math.abs(meta.pitch) / 9)
|
||||
local y = 0
|
||||
local color = 0x202020FF
|
||||
if meta.pitch < 0 then
|
||||
y = size
|
||||
color = 0x808080FF
|
||||
end
|
||||
canvas.meter.setPosition(0, 90 - y)
|
||||
canvas.meter.setSize(5, size)
|
||||
canvas.meter.setColor(color)
|
||||
canvas.pitch.setText(string.format('Pitch: %s\nMotion Y: %s\nSpeed: %s m/s',
|
||||
math.floor(-meta.pitch),
|
||||
Util.round(meta.motionY, 2),
|
||||
Util.round(dist(meta.motionX, meta.motionY, meta.motionZ) * 20, 2)))
|
||||
end
|
||||
end
|
||||
|
||||
local function clearDisplay()
|
||||
if canvas and canvas.group then
|
||||
canvas.group.remove()
|
||||
canvas.group = nil
|
||||
canvas.group2.remove()
|
||||
end
|
||||
if canvas and canvas.group then
|
||||
canvas.group.remove()
|
||||
canvas.group = nil
|
||||
canvas.group2.remove()
|
||||
end
|
||||
end
|
||||
|
||||
local function run()
|
||||
local launchCounter = 0
|
||||
local launchCounter = 0
|
||||
|
||||
while true do
|
||||
local meta = modules.getMetaOwner()
|
||||
while true do
|
||||
local meta = modules.getMetaOwner()
|
||||
|
||||
if meta.isOnLadder then
|
||||
os.sleep(0.5)
|
||||
if meta.isOnLadder then
|
||||
os.sleep(0.5)
|
||||
|
||||
elseif not meta.isSneaking and meta.isElytraFlying then
|
||||
elseif not meta.isSneaking and meta.isElytraFlying then
|
||||
|
||||
if meta.isInWater then
|
||||
display(meta)
|
||||
os.sleep(0.5)
|
||||
if meta.isInWater then
|
||||
display(meta)
|
||||
os.sleep(0.5)
|
||||
|
||||
elseif meta.pitch < 0 then -- looking up
|
||||
modules.launch(meta.yaw, meta.pitch, -meta.pitch / 22.5)
|
||||
Sound.play('entity.bobber.throw', .6)
|
||||
display(meta)
|
||||
os.sleep(0.1)
|
||||
elseif meta.pitch < 0 then -- looking up
|
||||
modules.launch(meta.yaw, meta.pitch, -meta.pitch / 22.5)
|
||||
Sound.play('entity.bobber.throw', .6)
|
||||
display(meta)
|
||||
os.sleep(0.1)
|
||||
|
||||
elseif meta.motionY < -0.5 then -- falling fast
|
||||
modules.launch(0, 270, math.min(-meta.motionY + 1, 4))
|
||||
Sound.play('entity.bat.takeoff')
|
||||
display(meta)
|
||||
os.sleep(0)
|
||||
elseif meta.motionY < -0.5 then -- falling fast
|
||||
modules.launch(0, 270, math.min(-meta.motionY + 1, 4))
|
||||
Sound.play('entity.bat.takeoff')
|
||||
display(meta)
|
||||
os.sleep(0)
|
||||
|
||||
else
|
||||
display(meta)
|
||||
os.sleep(0.1)
|
||||
end
|
||||
else
|
||||
display(meta)
|
||||
os.sleep(0.1)
|
||||
end
|
||||
|
||||
elseif meta.isSneaking and not meta.isElytraFlying and meta.pitch == -90 then
|
||||
if launchCounter < 2 then
|
||||
launchCounter = launchCounter + 1
|
||||
Sound.play('block.note.pling', .5)
|
||||
os.sleep(0.5)
|
||||
elseif meta.isSneaking and not meta.isElytraFlying and meta.pitch == -90 then
|
||||
if launchCounter < 2 then
|
||||
launchCounter = launchCounter + 1
|
||||
Sound.play('block.note.pling', .5)
|
||||
os.sleep(0.5)
|
||||
|
||||
else
|
||||
Sound.play('entity.bobber.throw', 1)
|
||||
modules.launch(0, 270, 4)
|
||||
os.sleep(0.2)
|
||||
end
|
||||
else
|
||||
Sound.play('entity.bobber.throw', 1)
|
||||
modules.launch(0, 270, 4)
|
||||
os.sleep(0.2)
|
||||
end
|
||||
|
||||
elseif not meta.isSneaking and meta.motionY < -0.8 then
|
||||
print('falling...')
|
||||
modules.launch(0, 270, -meta.motionY + 1)
|
||||
Sound.play('entity.bat.takeoff')
|
||||
os.sleep(0)
|
||||
elseif not meta.isSneaking and meta.motionY < -0.8 then
|
||||
print('falling...')
|
||||
modules.launch(0, 270, -meta.motionY + 1)
|
||||
Sound.play('entity.bat.takeoff')
|
||||
os.sleep(0)
|
||||
|
||||
elseif meta and meta.isElytraFlying and meta.isSneaking then
|
||||
display(meta)
|
||||
os.sleep(0.1)
|
||||
elseif meta and meta.isElytraFlying and meta.isSneaking then
|
||||
display(meta)
|
||||
os.sleep(0.1)
|
||||
|
||||
else
|
||||
clearDisplay()
|
||||
--display(meta)
|
||||
launchCounter = 0
|
||||
os.sleep(0.4)
|
||||
end
|
||||
end
|
||||
else
|
||||
clearDisplay()
|
||||
--display(meta)
|
||||
launchCounter = 0
|
||||
os.sleep(0.4)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
parallel.waitForAny(
|
||||
function()
|
||||
print('\nFlight control initialized')
|
||||
print('\nSneak and look straight up for launch')
|
||||
print('Sneak to deactivate during flight')
|
||||
print('\nPress any key to exit')
|
||||
os.pullEvent('char')
|
||||
end,
|
||||
function()
|
||||
while true do
|
||||
local _, m = pcall(run)
|
||||
if m then
|
||||
print(m)
|
||||
end
|
||||
print('Waiting for 5 seconds before restarting')
|
||||
os.sleep(5)
|
||||
modules = _G.peripheral.wrap('back')
|
||||
canvas = modules and modules.canvas and modules.canvas()
|
||||
end
|
||||
end)
|
||||
function()
|
||||
print('\nFlight control initialized')
|
||||
print('\nSneak and look straight up for launch')
|
||||
print('Sneak to deactivate during flight')
|
||||
print('\nPress any key to exit')
|
||||
os.pullEvent('char')
|
||||
end,
|
||||
function()
|
||||
while true do
|
||||
local _, m = pcall(run)
|
||||
if m then
|
||||
print(m)
|
||||
end
|
||||
print('Waiting for 5 seconds before restarting')
|
||||
os.sleep(5)
|
||||
modules = _G.peripheral.wrap('back')
|
||||
canvas = modules and modules.canvas and modules.canvas()
|
||||
end
|
||||
end)
|
||||
|
||||
clearDisplay()
|
||||
|
||||
@@ -1,36 +1,36 @@
|
||||
{
|
||||
[ "elytraFly" ] = {
|
||||
title = "ElytraFly",
|
||||
category = "Neural",
|
||||
run = "elytraFly.lua",
|
||||
requires = "neuralInterface",
|
||||
},
|
||||
[ "fisher" ] = {
|
||||
title = "Fisher",
|
||||
category = "Neural",
|
||||
run = "fisher.lua",
|
||||
requires = "neuralInterface",
|
||||
},
|
||||
[ "9101fc1744ab274aaa0b54ee22b14ca53ee6e236" ] = {
|
||||
title = "Sensor",
|
||||
category = "Neural",
|
||||
run = "Sensor.lua",
|
||||
iconExt = "\0315\156\0305\031f\131\147\0300\159\129\031e\152\031f\139\
|
||||
[ "elytraFly" ] = {
|
||||
title = "ElytraFly",
|
||||
category = "Neural",
|
||||
run = "elytraFly.lua",
|
||||
requires = "neuralInterface",
|
||||
},
|
||||
[ "fisher" ] = {
|
||||
title = "Fisher",
|
||||
category = "Neural",
|
||||
run = "fisher.lua",
|
||||
requires = "neuralInterface",
|
||||
},
|
||||
[ "9101fc1744ab274aaa0b54ee22b14ca53ee6e236" ] = {
|
||||
title = "Sensor",
|
||||
category = "Neural",
|
||||
run = "Sensor.lua",
|
||||
iconExt = "\0315\156\0305\031f\131\147\0300\159\129\031e\152\031f\139\
|
||||
\0315\157\131\0305\031f\145\030b\157\0300\031b\157\031e\136\140\030f\0316\148\
|
||||
\0305\031f\138\131\133\030f\0310\130\0300\031f\144\031e\137\030f\0310\135\0306\031f\149",
|
||||
},
|
||||
[ "c7ee483aa3d72126406fe52b8ed91bb9c419d02f" ] = {
|
||||
title = "Scanner",
|
||||
category = "Neural",
|
||||
run = "Scanner.lua",
|
||||
iconExt = "\030d\031f\143\143\143\0300\159\129\031e\152\031f\139\
|
||||
},
|
||||
[ "c7ee483aa3d72126406fe52b8ed91bb9c419d02f" ] = {
|
||||
title = "Scanner",
|
||||
category = "Neural",
|
||||
run = "Scanner.lua",
|
||||
iconExt = "\030d\031f\143\143\143\0300\159\129\031e\152\031f\139\
|
||||
\030c\031d\129\129\130\030b\031f\157\0300\031b\157\031e\136\140\030f\0316\148\
|
||||
\031c\143\143\143\0310\130\0300\031f\144\031e\137\030f\0310\135\0306\031f\149",
|
||||
},
|
||||
[ "orescanner" ] = {
|
||||
title = "Ores",
|
||||
category = "Neural",
|
||||
run = "ores.lua",
|
||||
requires = "neuralInterface",
|
||||
},
|
||||
},
|
||||
[ "orescanner" ] = {
|
||||
title = "Ores",
|
||||
category = "Neural",
|
||||
run = "ores.lua",
|
||||
requires = "neuralInterface",
|
||||
},
|
||||
}
|
||||
|
||||
@@ -4,9 +4,9 @@ local neural = require('neural.interface')
|
||||
local os = _G.os
|
||||
|
||||
neural.assertModules({
|
||||
'plethora:kinetic',
|
||||
'plethora:introspection',
|
||||
'plethora:sensor',
|
||||
'plethora:kinetic',
|
||||
'plethora:introspection',
|
||||
'plethora:sensor',
|
||||
})
|
||||
|
||||
local depth = -3
|
||||
@@ -17,93 +17,93 @@ 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' )
|
||||
w, h = canvas.getSize()
|
||||
icon = canvas.addItem({ w - 20, h - 20 }, 'minecraft:fishing_rod' )
|
||||
end
|
||||
|
||||
local fsm = machine.create({
|
||||
events = {
|
||||
{ name = 'startup', from = 'none', to = 'wait' },
|
||||
{ name = 'rod', from = 'wait', to = 'idle' },
|
||||
{ name = 'norod', from = 'idle', to = 'wait' },
|
||||
{ name = 'norod', from = 'fishing', to = 'wait' },
|
||||
{ name = 'cast', from = 'idle', to = 'fishing' },
|
||||
{ name = 'reel', from = 'fishing', to = 'idle' },
|
||||
},
|
||||
events = {
|
||||
{ name = 'startup', from = 'none', to = 'wait' },
|
||||
{ name = 'rod', from = 'wait', to = 'idle' },
|
||||
{ name = 'norod', from = 'idle', to = 'wait' },
|
||||
{ name = 'norod', from = 'fishing', to = 'wait' },
|
||||
{ name = 'cast', from = 'idle', to = 'fishing' },
|
||||
{ name = 'reel', from = 'fishing', to = 'idle' },
|
||||
},
|
||||
|
||||
callbacks = {
|
||||
-- events
|
||||
oncast = function()
|
||||
neural.use(.2)
|
||||
os.sleep(.5)
|
||||
local meta = neural.getMetaByName('unknown')
|
||||
depth = meta and meta.y - .5 or depth
|
||||
end,
|
||||
callbacks = {
|
||||
-- events
|
||||
oncast = function()
|
||||
neural.use(.2)
|
||||
os.sleep(.5)
|
||||
local meta = neural.getMetaByName('unknown')
|
||||
depth = meta and meta.y - .5 or depth
|
||||
end,
|
||||
|
||||
onreel = function()
|
||||
neural.use(.3)
|
||||
os.sleep(.5)
|
||||
end,
|
||||
onreel = function()
|
||||
neural.use(.3)
|
||||
os.sleep(.5)
|
||||
end,
|
||||
|
||||
-- state changes
|
||||
onenterwait = function()
|
||||
print('waitng for fishing rod to be selected')
|
||||
if icon then
|
||||
icon.remove()
|
||||
icon = canvas.addItem({ w - 20, h - 20 }, 'minecraft:fishing_rod' )
|
||||
end
|
||||
end,
|
||||
-- state changes
|
||||
onenterwait = function()
|
||||
print('waitng for fishing rod to be selected')
|
||||
if icon then
|
||||
icon.remove()
|
||||
icon = canvas.addItem({ w - 20, h - 20 }, 'minecraft:fishing_rod' )
|
||||
end
|
||||
end,
|
||||
|
||||
onleavewait = function()
|
||||
print('fishing...')
|
||||
end,
|
||||
onleavewait = function()
|
||||
print('fishing...')
|
||||
end,
|
||||
|
||||
onenterfishing = function()
|
||||
if icon then
|
||||
icon.remove()
|
||||
scale = 0
|
||||
icon = canvas.addItem({ w - 20, h - 20 }, 'minecraft:fish', math.random(0, 3) )
|
||||
end
|
||||
end,
|
||||
}
|
||||
onenterfishing = function()
|
||||
if icon then
|
||||
icon.remove()
|
||||
scale = 0
|
||||
icon = canvas.addItem({ w - 20, h - 20 }, 'minecraft:fish', math.random(0, 3) )
|
||||
end
|
||||
end,
|
||||
}
|
||||
})
|
||||
|
||||
local function isHoldingRod()
|
||||
local owner = neural.getMetaOwner()
|
||||
local held = owner.heldItem and owner.heldItem.getMetadata()
|
||||
return held and held.rawName == 'item.fishingRod'
|
||||
local owner = neural.getMetaOwner()
|
||||
local held = owner.heldItem and owner.heldItem.getMetadata()
|
||||
return held and held.rawName == 'item.fishingRod'
|
||||
end
|
||||
|
||||
local function fish()
|
||||
fsm:startup()
|
||||
while true do
|
||||
local meta = neural.getMetaByName('unknown')
|
||||
if isHoldingRod() then
|
||||
fsm:rod()
|
||||
if not meta then
|
||||
fsm:cast()
|
||||
elseif meta.y < depth then
|
||||
fsm:reel()
|
||||
end
|
||||
os.sleep(.1)
|
||||
else
|
||||
fsm:norod()
|
||||
os.sleep(1)
|
||||
end
|
||||
fsm:startup()
|
||||
while true do
|
||||
local meta = neural.getMetaByName('unknown')
|
||||
if isHoldingRod() then
|
||||
fsm:rod()
|
||||
if not meta then
|
||||
fsm:cast()
|
||||
elseif meta.y < depth then
|
||||
fsm:reel()
|
||||
end
|
||||
os.sleep(.1)
|
||||
else
|
||||
fsm:norod()
|
||||
os.sleep(1)
|
||||
end
|
||||
|
||||
if icon and fsm.current == 'fishing' then
|
||||
scale = scale + 1
|
||||
icon.setScale(scales[(scale % #scales) + 1])
|
||||
end
|
||||
end
|
||||
if icon and fsm.current == 'fishing' then
|
||||
scale = scale + 1
|
||||
icon.setScale(scales[(scale % #scales) + 1])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local s, m = pcall(fish)
|
||||
|
||||
if icon then
|
||||
icon.remove()
|
||||
icon.remove()
|
||||
end
|
||||
|
||||
if not s and m then
|
||||
error(m)
|
||||
error(m)
|
||||
end
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
local GPS = require('gps')
|
||||
local Util = require('util')
|
||||
local Point = require('point')
|
||||
local Proxy = require('proxy')
|
||||
local Proxy = require('core.proxy')
|
||||
|
||||
local os = _G.os
|
||||
|
||||
@@ -10,38 +10,38 @@ local remoteId = args[1] or error('mobFollow <remote id>')
|
||||
local ni = Proxy.create(remoteId, 'device/neuralInterface')
|
||||
|
||||
if not ni then
|
||||
error('failed to connect')
|
||||
error('failed to connect')
|
||||
end
|
||||
|
||||
local lpt = nil
|
||||
|
||||
while true do
|
||||
local pt = GPS.locate(2)
|
||||
local pt = GPS.locate(2)
|
||||
|
||||
if not pt then
|
||||
print('No GPS')
|
||||
else
|
||||
local gpt = Util.shallowCopy(pt)
|
||||
if pt and lpt and Point.same(pt, lpt) then
|
||||
-- havent moved
|
||||
print('no move')
|
||||
else
|
||||
if not lpt then
|
||||
gpt.x = gpt.x - 2
|
||||
else
|
||||
local dx = lpt.x - pt.x
|
||||
local dz = lpt.z - pt.z
|
||||
local angle = math.atan2(dx, dz)
|
||||
gpt.x = pt.x + 2.5 * math.sin(angle)
|
||||
gpt.z = pt.z + 2.5 * math.cos(angle)
|
||||
end
|
||||
lpt = pt
|
||||
local s, m = ni.goTo(gpt.x, gpt.y + 1, gpt.z)
|
||||
if not s then
|
||||
print(m)
|
||||
end
|
||||
end
|
||||
end
|
||||
if not pt then
|
||||
print('No GPS')
|
||||
else
|
||||
local gpt = Util.shallowCopy(pt)
|
||||
if pt and lpt and Point.same(pt, lpt) then
|
||||
-- havent moved
|
||||
print('no move')
|
||||
else
|
||||
if not lpt then
|
||||
gpt.x = gpt.x - 2
|
||||
else
|
||||
local dx = lpt.x - pt.x
|
||||
local dz = lpt.z - pt.z
|
||||
local angle = math.atan2(dx, dz)
|
||||
gpt.x = pt.x + 2.5 * math.sin(angle)
|
||||
gpt.z = pt.z + 2.5 * math.cos(angle)
|
||||
end
|
||||
lpt = pt
|
||||
local s, m = ni.goTo(gpt.x, gpt.y + 1, gpt.z)
|
||||
if not s then
|
||||
print(m)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
os.sleep(.5)
|
||||
os.sleep(.5)
|
||||
end
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
--[[
|
||||
Pickup items from a flat area and drop into a hopper.
|
||||
Must be a 1 high mob
|
||||
Pickup items from a flat area and drop into a hopper.
|
||||
Must be a 1 high mob
|
||||
]]
|
||||
|
||||
local neural = require('neural.interface')
|
||||
@@ -11,66 +11,66 @@ local Util = require('util')
|
||||
local os = _G.os
|
||||
|
||||
neural.assertModules({
|
||||
'plethora:sensor',
|
||||
'plethora:scanner',
|
||||
'plethora:kinetic',
|
||||
'plethora:introspection',
|
||||
'plethora:sensor',
|
||||
'plethora:scanner',
|
||||
'plethora:kinetic',
|
||||
'plethora:introspection',
|
||||
})
|
||||
|
||||
local function dropOff()
|
||||
print('dropping')
|
||||
print('dropping')
|
||||
|
||||
local b = Util.find(neural.scan(), 'name', 'minecraft:hopper')
|
||||
if b then
|
||||
neural.walkTo({ x = b.x, y = 0, z = b.z }, 2)
|
||||
local b = Util.find(neural.scan(), 'name', 'minecraft:hopper')
|
||||
if b then
|
||||
neural.walkTo({ x = b.x, y = 0, z = b.z }, 2)
|
||||
|
||||
b = Util.find(neural.scan(), 'name', 'minecraft:hopper')
|
||||
if b and math.abs(b.x) < 1 and math.abs(b.z) < 1 then
|
||||
print('dropped')
|
||||
neural.getEquipment().drop(1)
|
||||
neural.getEquipment().drop(2)
|
||||
os.sleep(1)
|
||||
end
|
||||
end
|
||||
b = Util.find(neural.scan(), 'name', 'minecraft:hopper')
|
||||
if b and math.abs(b.x) < 1 and math.abs(b.z) < 1 then
|
||||
print('dropped')
|
||||
neural.getEquipment().drop(1)
|
||||
neural.getEquipment().drop(2)
|
||||
os.sleep(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function pickup(id)
|
||||
local b = neural.getMetaByID(id)
|
||||
if b then
|
||||
neural.walkTo(b, 2)
|
||||
local b = neural.getMetaByID(id)
|
||||
if b then
|
||||
neural.walkTo(b, 2)
|
||||
|
||||
local amount = neural.getEquipment().suck()
|
||||
print('sucked: ' .. amount)
|
||||
if amount > 0 then
|
||||
Sound.play('entity.item.pickup')
|
||||
return true
|
||||
end
|
||||
end
|
||||
local amount = neural.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(neural.sense(), function(acc, s)
|
||||
if Util.round(s.y) == 0 and s.name == 'Item' then
|
||||
acc[s.id] = s
|
||||
end
|
||||
return acc
|
||||
end, { })
|
||||
local sensed = Util.reduce(neural.sense(), function(acc, s)
|
||||
if Util.round(s.y) == 0 and s.name == 'Item' then
|
||||
acc[s.id] = s
|
||||
end
|
||||
return acc
|
||||
end, { })
|
||||
|
||||
local pt = { x = 0, y = 0, z = 0 }
|
||||
while true do
|
||||
local b = Point.closest(pt, sensed)
|
||||
if not b then
|
||||
os.sleep(5)
|
||||
break
|
||||
end
|
||||
sensed[b.id] = nil
|
||||
local pt = { x = 0, y = 0, z = 0 }
|
||||
while true do
|
||||
local b = Point.closest(pt, sensed)
|
||||
if not b then
|
||||
os.sleep(5)
|
||||
break
|
||||
end
|
||||
sensed[b.id] = nil
|
||||
|
||||
if pickup(b.id) then
|
||||
pt = b
|
||||
else
|
||||
dropOff()
|
||||
break
|
||||
end
|
||||
end
|
||||
if pickup(b.id) then
|
||||
pt = b
|
||||
else
|
||||
dropOff()
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
--[[
|
||||
Breed either cows or sheep.
|
||||
Must be run on a mob with the same height.
|
||||
Breed either cows or sheep.
|
||||
Must be run on a mob with the same height.
|
||||
]]
|
||||
|
||||
local neural = require('neural.interface')
|
||||
@@ -14,107 +14,107 @@ local WALK_SPEED = 1.5
|
||||
local MAX_GROWN = 12
|
||||
|
||||
neural.assertModules({
|
||||
'plethora:sensor',
|
||||
'plethora:scanner',
|
||||
'plethora:laser',
|
||||
'plethora:kinetic',
|
||||
'plethora:introspection',
|
||||
'plethora:sensor',
|
||||
'plethora:scanner',
|
||||
'plethora:laser',
|
||||
'plethora:kinetic',
|
||||
'plethora:introspection',
|
||||
})
|
||||
|
||||
local fed = { }
|
||||
|
||||
local function resupply()
|
||||
local slot = neural.getEquipment().list()[1]
|
||||
if slot and slot.count > 32 then
|
||||
return
|
||||
end
|
||||
print('resupplying')
|
||||
for _ = 1, 2 do
|
||||
local dispenser = Map.find(neural.scan(), 'name', 'minecraft:dispenser')
|
||||
if not dispenser then
|
||||
print('dispenser not found')
|
||||
break
|
||||
end
|
||||
if math.abs(dispenser.x) <= 1 and math.abs(dispenser.z) <= 1 then
|
||||
neural.lookAt(dispenser)
|
||||
for _ = 1, 8 do
|
||||
neural.use(0, 'off')
|
||||
os.sleep(.2)
|
||||
neural.getEquipment().suck(1, 64)
|
||||
end
|
||||
break
|
||||
else
|
||||
neural.walkTo({ x = dispenser.x, y = 0, z = dispenser.z }, WALK_SPEED)
|
||||
end
|
||||
end
|
||||
local slot = neural.getEquipment().list()[1]
|
||||
if slot and slot.count > 32 then
|
||||
return
|
||||
end
|
||||
print('resupplying')
|
||||
for _ = 1, 2 do
|
||||
local dispenser = Map.find(neural.scan(), 'name', 'minecraft:dispenser')
|
||||
if not dispenser then
|
||||
print('dispenser not found')
|
||||
break
|
||||
end
|
||||
if math.abs(dispenser.x) <= 1 and math.abs(dispenser.z) <= 1 then
|
||||
neural.lookAt(dispenser)
|
||||
for _ = 1, 8 do
|
||||
neural.use(0, 'off')
|
||||
os.sleep(.2)
|
||||
neural.getEquipment().suck(1, 64)
|
||||
end
|
||||
break
|
||||
else
|
||||
neural.walkTo({ x = dispenser.x, y = 0, z = dispenser.z }, WALK_SPEED)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function breed(entity)
|
||||
print('breeding')
|
||||
entity.lastFed = os.clock()
|
||||
fed[entity.id] = entity
|
||||
print('breeding')
|
||||
entity.lastFed = os.clock()
|
||||
fed[entity.id] = entity
|
||||
|
||||
neural.walkTo(entity, WALK_SPEED, 1)
|
||||
entity = neural.getMetaByID(entity.id)
|
||||
if entity then
|
||||
neural.lookAt(entity)
|
||||
neural.use(1)
|
||||
os.sleep(.1)
|
||||
end
|
||||
neural.walkTo(entity, WALK_SPEED, 1)
|
||||
entity = neural.getMetaByID(entity.id)
|
||||
if entity then
|
||||
neural.lookAt(entity)
|
||||
neural.use(1)
|
||||
os.sleep(.1)
|
||||
end
|
||||
end
|
||||
|
||||
local function kill(entity)
|
||||
print('killing')
|
||||
neural.walkTo(entity, WALK_SPEED, 2.5)
|
||||
entity = neural.getMetaByID(entity.id)
|
||||
if entity then
|
||||
neural.lookAt(entity)
|
||||
neural.fireAt({ x = entity.x, y = 0, z = entity.z })
|
||||
Sound.play('entity.firework.launch')
|
||||
os.sleep(.2)
|
||||
end
|
||||
print('killing')
|
||||
neural.walkTo(entity, WALK_SPEED, 2.5)
|
||||
entity = neural.getMetaByID(entity.id)
|
||||
if entity then
|
||||
neural.lookAt(entity)
|
||||
neural.fireAt({ x = entity.x, y = 0, z = entity.z })
|
||||
Sound.play('entity.firework.launch')
|
||||
os.sleep(.2)
|
||||
end
|
||||
end
|
||||
|
||||
local function getEntities()
|
||||
return Map.filter(neural.sense(), function(entity)
|
||||
if entity.name == BREEDING and entity.y > -.5 then
|
||||
return true
|
||||
end
|
||||
end)
|
||||
return Map.filter(neural.sense(), function(entity)
|
||||
if entity.name == BREEDING 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
|
||||
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, Map.size(entities))
|
||||
local i = 1
|
||||
for _, v in pairs(entities) do
|
||||
i = i + 1
|
||||
if i > r then
|
||||
return v
|
||||
end
|
||||
end
|
||||
local r = math.random(1, Map.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()
|
||||
resupply()
|
||||
|
||||
local entities = getEntities()
|
||||
local entities = getEntities()
|
||||
|
||||
if Map.size(entities) > MAX_GROWN then
|
||||
kill(randomEntity(entities))
|
||||
else
|
||||
local entity = getHungry(entities)
|
||||
if entity then
|
||||
breed(entity)
|
||||
else
|
||||
os.sleep(5)
|
||||
end
|
||||
end
|
||||
if Map.size(entities) > MAX_GROWN then
|
||||
kill(randomEntity(entities))
|
||||
else
|
||||
local entity = getHungry(entities)
|
||||
if entity then
|
||||
breed(entity)
|
||||
else
|
||||
os.sleep(5)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,8 +5,8 @@ local Point = require('point')
|
||||
local os = _G.os
|
||||
|
||||
neural.assertModules({
|
||||
'plethora:sensor',
|
||||
'plethora:introspection',
|
||||
'plethora:sensor',
|
||||
'plethora:introspection',
|
||||
})
|
||||
|
||||
local pos = { x = 0, y = 0, z = 0 }
|
||||
@@ -15,58 +15,58 @@ local ownerId = neural.getMetaOwner().id
|
||||
local targets = { }
|
||||
|
||||
local function findTargets()
|
||||
local now = os.clock()
|
||||
local moved = { }
|
||||
local now = os.clock()
|
||||
local moved = { }
|
||||
|
||||
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
|
||||
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)
|
||||
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
|
||||
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 #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]
|
||||
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 count = 50
|
||||
|
||||
while true do
|
||||
local target = findTargets()
|
||||
if target then
|
||||
count = 0
|
||||
neural.lookAt(target)
|
||||
os.sleep(0)
|
||||
elseif count > 25 then
|
||||
neural.lookAt({
|
||||
x = math.random(-10, 10),
|
||||
y = math.random(-10, 10),
|
||||
z = math.random(-10, 10)
|
||||
})
|
||||
os.sleep(3)
|
||||
else
|
||||
count = count + 1
|
||||
os.sleep(.1)
|
||||
end
|
||||
local target = findTargets()
|
||||
if target then
|
||||
count = 0
|
||||
neural.lookAt(target)
|
||||
os.sleep(0)
|
||||
elseif count > 25 then
|
||||
neural.lookAt({
|
||||
x = math.random(-10, 10),
|
||||
y = math.random(-10, 10),
|
||||
z = math.random(-10, 10)
|
||||
})
|
||||
os.sleep(3)
|
||||
else
|
||||
count = count + 1
|
||||
os.sleep(.1)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -8,11 +8,11 @@ local peripheral = _G.peripheral
|
||||
|
||||
local t = { }
|
||||
local ni =
|
||||
peripheral.find('neuralInterface') or
|
||||
error('Neural Interface not found')
|
||||
peripheral.find('neuralInterface') or
|
||||
error('Neural Interface not found')
|
||||
|
||||
if not ni.getID then
|
||||
error('Missing Introspection Module')
|
||||
error('Missing Introspection Module')
|
||||
end
|
||||
|
||||
local uid = ni.getID()
|
||||
@@ -23,66 +23,66 @@ local lpt
|
||||
local me = Util.find(ni.sense(), 'id', uid)
|
||||
|
||||
local function gps()
|
||||
while true do
|
||||
me = Util.find(ni.sense(), 'id', uid)
|
||||
pt = GPS.locate(3) or error('GPS failed')
|
||||
os.sleep(.3)
|
||||
print('got gps')
|
||||
end
|
||||
while true do
|
||||
me = Util.find(ni.sense(), 'id', uid)
|
||||
pt = GPS.locate(3) or error('GPS failed')
|
||||
os.sleep(.3)
|
||||
print('got gps')
|
||||
end
|
||||
end
|
||||
|
||||
local function record()
|
||||
local timerId = os.startTimer(.1)
|
||||
repeat
|
||||
local event, ch = os.pullEvent()
|
||||
local v
|
||||
local delay = os.clock() - c
|
||||
c = os.clock()
|
||||
--print(event .. ' ' .. tostring(ch))
|
||||
if event == 'char' then
|
||||
print('char ' .. ch)
|
||||
if ch == ' ' then
|
||||
v = {
|
||||
action = 'walk',
|
||||
x = pt.x,
|
||||
y = pt.y,
|
||||
z = pt.z,
|
||||
pitch = me.pitch,
|
||||
yaw = me.yaw,
|
||||
delay = delay,
|
||||
}
|
||||
elseif ch == 'u' then
|
||||
v = {
|
||||
action = 'use',
|
||||
x = pt.x,
|
||||
y = pt.y,
|
||||
z = pt.z,
|
||||
pitch = me.pitch,
|
||||
yaw = me.yaw,
|
||||
delay = delay,
|
||||
}
|
||||
end
|
||||
elseif event == 'timer' and ch == timerId then
|
||||
if not lpt or not Point.same(pt, lpt) then
|
||||
v = {
|
||||
action = 'walk',
|
||||
x = pt.x,
|
||||
y = pt.y,
|
||||
z = pt.z,
|
||||
pitch = me.pitch,
|
||||
yaw = me.yaw,
|
||||
delay = delay,
|
||||
}
|
||||
lpt = pt
|
||||
end
|
||||
timerId = os.startTimer(.2)
|
||||
end
|
||||
local timerId = os.startTimer(.1)
|
||||
repeat
|
||||
local event, ch = os.pullEvent()
|
||||
local v
|
||||
local delay = os.clock() - c
|
||||
c = os.clock()
|
||||
--print(event .. ' ' .. tostring(ch))
|
||||
if event == 'char' then
|
||||
print('char ' .. ch)
|
||||
if ch == ' ' then
|
||||
v = {
|
||||
action = 'walk',
|
||||
x = pt.x,
|
||||
y = pt.y,
|
||||
z = pt.z,
|
||||
pitch = me.pitch,
|
||||
yaw = me.yaw,
|
||||
delay = delay,
|
||||
}
|
||||
elseif ch == 'u' then
|
||||
v = {
|
||||
action = 'use',
|
||||
x = pt.x,
|
||||
y = pt.y,
|
||||
z = pt.z,
|
||||
pitch = me.pitch,
|
||||
yaw = me.yaw,
|
||||
delay = delay,
|
||||
}
|
||||
end
|
||||
elseif event == 'timer' and ch == timerId then
|
||||
if not lpt or not Point.same(pt, lpt) then
|
||||
v = {
|
||||
action = 'walk',
|
||||
x = pt.x,
|
||||
y = pt.y,
|
||||
z = pt.z,
|
||||
pitch = me.pitch,
|
||||
yaw = me.yaw,
|
||||
delay = delay,
|
||||
}
|
||||
lpt = pt
|
||||
end
|
||||
timerId = os.startTimer(.2)
|
||||
end
|
||||
|
||||
if v then
|
||||
Util.print(v)
|
||||
table.insert(t, v)
|
||||
end
|
||||
until event == 'char' and ch == 'q'
|
||||
if v then
|
||||
Util.print(v)
|
||||
table.insert(t, v)
|
||||
end
|
||||
until event == 'char' and ch == 'q'
|
||||
end
|
||||
|
||||
parallel.waitForAny(gps, record)
|
||||
|
||||
@@ -12,39 +12,39 @@ local t = Util.readTable(shell.resolve(fileName)) or error('Unable to read ' ..
|
||||
local ni = peripheral.find('neuralInterface')
|
||||
|
||||
local function walkTo(x, y, z)
|
||||
local pt = GPS.locate(2)
|
||||
if pt then
|
||||
local s, m, m2 = pcall(function()
|
||||
local gpt = {
|
||||
x = x - pt.x,
|
||||
y = math.floor(y) - math.floor(pt.y),
|
||||
z = z - pt.z,
|
||||
}
|
||||
gpt.x = math.min(math.max(gpt.x, -30), 30)
|
||||
gpt.z = math.min(math.max(gpt.z, -30), 30)
|
||||
return ni.walk(gpt.x, gpt.y, gpt.z)
|
||||
end)
|
||||
if not s or not m then
|
||||
_G.printError(m2 or m)
|
||||
end
|
||||
end
|
||||
os.sleep(.5)
|
||||
while ni.isWalking() do
|
||||
os.sleep(0)
|
||||
end
|
||||
local pt = GPS.locate(2)
|
||||
if pt then
|
||||
local s, m, m2 = pcall(function()
|
||||
local gpt = {
|
||||
x = x - pt.x,
|
||||
y = math.floor(y) - math.floor(pt.y),
|
||||
z = z - pt.z,
|
||||
}
|
||||
gpt.x = math.min(math.max(gpt.x, -30), 30)
|
||||
gpt.z = math.min(math.max(gpt.z, -30), 30)
|
||||
return ni.walk(gpt.x, gpt.y, gpt.z)
|
||||
end)
|
||||
if not s or not m then
|
||||
_G.printError(m2 or m)
|
||||
end
|
||||
end
|
||||
os.sleep(.5)
|
||||
while ni.isWalking() do
|
||||
os.sleep(0)
|
||||
end
|
||||
end
|
||||
|
||||
for _,v in pairs(t) do
|
||||
Util.print(v)
|
||||
Util.print(v)
|
||||
|
||||
--if v.action == 'walk' then
|
||||
walkTo(v.x, v.y, v.z)
|
||||
--end
|
||||
ni.look(v.yaw, v.pitch)
|
||||
if v.action == 'use' then
|
||||
ni.use()
|
||||
os.sleep(2)
|
||||
end
|
||||
--if v.action == 'walk' then
|
||||
walkTo(v.x, v.y, v.z)
|
||||
--end
|
||||
ni.look(v.yaw, v.pitch)
|
||||
if v.action == 'use' then
|
||||
ni.use()
|
||||
os.sleep(2)
|
||||
end
|
||||
-- os.sleep(v.delay)
|
||||
-- os.sleep(2)
|
||||
-- read()
|
||||
|
||||
191
neural/ores.lua
191
neural/ores.lua
@@ -12,126 +12,133 @@ local parallel = _G.parallel
|
||||
local peripheral = _G.peripheral
|
||||
|
||||
local function showRequirements(missing)
|
||||
print([[A neural interface is required containing:
|
||||
print([[A neural interface is required containing:
|
||||
* Overlay glasses
|
||||
* Scanner
|
||||
* Modem
|
||||
]])
|
||||
error('Missing: ' .. missing)
|
||||
error('Missing: ' .. missing)
|
||||
end
|
||||
|
||||
local modules = peripheral.find('neuralInterface')
|
||||
if not modules then
|
||||
showRequirements('Neural interface')
|
||||
showRequirements('Neural interface')
|
||||
elseif not modules.canvas then
|
||||
showRequirements('Overlay glasses')
|
||||
showRequirements('Overlay glasses')
|
||||
elseif not modules.scan then
|
||||
showRequirements('Scanner module')
|
||||
showRequirements('Scanner module')
|
||||
end
|
||||
|
||||
-- size of displayed block
|
||||
local BLOCK_SIZE = .5
|
||||
|
||||
local function getPoint()
|
||||
local pt = { gps.locate() }
|
||||
if pt[1] then
|
||||
return {
|
||||
x = pt[1],
|
||||
y = pt[2],
|
||||
z = pt[3],
|
||||
}
|
||||
end
|
||||
local pt = { gps.locate() }
|
||||
if pt[1] then
|
||||
return {
|
||||
x = pt[1],
|
||||
y = pt[2],
|
||||
z = pt[3],
|
||||
}
|
||||
end
|
||||
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: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 },
|
||||
["minecraft:quartz_ore"] = { "minecraft:quartz_ore", 0 },
|
||||
["minecraft:glowstone"] = { "minecraft:glowstone", 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 },
|
||||
["minecraft:quartz_ore"] = { "minecraft:quartz_ore", 0 },
|
||||
["minecraft:glowstone"] = { "minecraft:glowstone", 0 },
|
||||
}
|
||||
local projecting = { }
|
||||
local offset = getPoint() or showRequirements('GPS')
|
||||
local canvas = modules.canvas3d().create()
|
||||
local canvas = modules.canvas3d().create({
|
||||
-(offset.x % 1) + .5,
|
||||
-(offset.y % 1) + .5,
|
||||
-(offset.z % 1) + .5 })
|
||||
|
||||
local function update()
|
||||
while true do
|
||||
-- order matters
|
||||
local scanned = modules.scan()
|
||||
local pos = getPoint()
|
||||
while true do
|
||||
-- order matters
|
||||
local scanned = modules.scan()
|
||||
local pos = getPoint()
|
||||
|
||||
if pos then
|
||||
if math.abs(pos.x - offset.x) +
|
||||
math.abs(pos.y - offset.y) +
|
||||
math.abs(pos.z - offset.z) > 64 then
|
||||
for _, b in pairs(projecting) do
|
||||
b.box.remove()
|
||||
end
|
||||
projecting = { }
|
||||
offset = pos
|
||||
canvas.recenter()
|
||||
end
|
||||
if pos then
|
||||
if math.abs(pos.x - offset.x) +
|
||||
math.abs(pos.y - offset.y) +
|
||||
math.abs(pos.z - offset.z) > 64 then
|
||||
for _, b in pairs(projecting) do
|
||||
b.box.remove()
|
||||
end
|
||||
projecting = { }
|
||||
offset = pos
|
||||
canvas.recenter({
|
||||
-(offset.x % 1) + .5,
|
||||
-(offset.y % 1) + .5,
|
||||
-(offset.z % 1) + .5 })
|
||||
end
|
||||
|
||||
local blocks = { }
|
||||
for _, b in pairs(scanned) do
|
||||
if targets[b.name] then
|
||||
-- track block's world position
|
||||
b.id = table.concat({
|
||||
math.floor(pos.x + b.x),
|
||||
math.floor(pos.y + b.y),
|
||||
math.floor(pos.z + b.z) }, ':')
|
||||
blocks[b.id] = b
|
||||
end
|
||||
end
|
||||
local blocks = { }
|
||||
for _, b in pairs(scanned) do
|
||||
if targets[b.name] then
|
||||
-- track block's world position
|
||||
b.id = table.concat({
|
||||
math.floor(pos.x + b.x),
|
||||
math.floor(pos.y + b.y),
|
||||
math.floor(pos.z + b.z) }, ':')
|
||||
blocks[b.id] = b
|
||||
end
|
||||
end
|
||||
|
||||
for _, b in pairs(blocks) do
|
||||
if not projecting[b.id] then
|
||||
projecting[b.id] = b
|
||||
local target = targets[b.name]
|
||||
--[[
|
||||
b.box = canvas.addFrame({
|
||||
pos.x - offset.x + b.x + -(pos.x % 1),
|
||||
pos.y - offset.y + b.y + -(pos.y % 1),
|
||||
pos.z - offset.z + b.z + -(pos.z % 1),
|
||||
})
|
||||
b.box.setDepthTested(false)
|
||||
b.box.addItem({ .25, .25 }, target[1], target[2], 2)
|
||||
--]]
|
||||
b.box = canvas.addItem({
|
||||
pos.x - offset.x + b.x + -(pos.x % 1) + .5,
|
||||
pos.y - offset.y + b.y + -(pos.y % 1) + .5,
|
||||
pos.z - offset.z + b.z + -(pos.z % 1) + .5,
|
||||
}, target[1], target[2], .5)
|
||||
b.box.setDepthTested(false)
|
||||
end
|
||||
end
|
||||
for _, b in pairs(blocks) do
|
||||
if not projecting[b.id] then
|
||||
projecting[b.id] = b
|
||||
local target = targets[b.name]
|
||||
|
||||
for _, b in pairs(projecting) do
|
||||
if not blocks[b.id] then
|
||||
b.box.remove()
|
||||
projecting[b.id] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
local x = b.x - math.floor(offset.x) + math.floor(pos.x)
|
||||
local y = b.y - math.floor(offset.y) + math.floor(pos.y)
|
||||
local z = b.z - math.floor(offset.z) + math.floor(pos.z)
|
||||
|
||||
os.sleep(.5)
|
||||
end
|
||||
--[[
|
||||
b.box = canvas.addFrame({ x, y, z })
|
||||
b.box.setDepthTested(false)
|
||||
b.box.addItem({ .25, .25 }, target[1], target[2], 2)
|
||||
--]]
|
||||
|
||||
b.box = canvas.addItem({ x, y, z }, target[1], target[2], BLOCK_SIZE)
|
||||
b.box.setDepthTested(false)
|
||||
end
|
||||
end
|
||||
|
||||
for _, b in pairs(projecting) do
|
||||
if not blocks[b.id] then
|
||||
b.box.remove()
|
||||
projecting[b.id] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
os.sleep(.5)
|
||||
end
|
||||
end
|
||||
|
||||
parallel.waitForAny(
|
||||
function()
|
||||
print('Ore visualization started')
|
||||
print('Press enter to exit')
|
||||
while true do
|
||||
local e, key = os.pullEventRaw('key')
|
||||
if key == keys.enter or e == 'terminate' then
|
||||
break
|
||||
end
|
||||
end
|
||||
end,
|
||||
update
|
||||
function()
|
||||
print('Ore visualization started')
|
||||
print('Press enter to exit')
|
||||
while true do
|
||||
local e, key = os.pullEventRaw('key')
|
||||
if key == keys.enter or e == 'terminate' then
|
||||
break
|
||||
end
|
||||
end
|
||||
end,
|
||||
update
|
||||
)
|
||||
|
||||
canvas.clear()
|
||||
canvas.clear()
|
||||
|
||||
@@ -11,46 +11,46 @@ local uid = ''
|
||||
|
||||
local function shootAt(pt)
|
||||
local yaw, pitch = Angle.towards(pt.x, pt.y, pt.z)
|
||||
weapon.fire(yaw, pitch, 4)
|
||||
weapon.fire(yaw, pitch, 4)
|
||||
end
|
||||
|
||||
if not weapon then
|
||||
weapon = device['plethora:introspection']
|
||||
if not weapon or not weapon.shoot then
|
||||
error('Either a laser or a skeleton with introspection module is required')
|
||||
end
|
||||
uid = weapon.getID()
|
||||
shootAt = function(pt)
|
||||
local yaw, pitch = Angle.towards(pt.x, pt.y, pt.z)
|
||||
weapon.look(yaw, pitch)
|
||||
weapon.shoot(1)
|
||||
end
|
||||
weapon = device['plethora:introspection']
|
||||
if not weapon or not weapon.shoot then
|
||||
error('Either a laser or a skeleton with introspection module is required')
|
||||
end
|
||||
uid = weapon.getID()
|
||||
shootAt = function(pt)
|
||||
local yaw, pitch = Angle.towards(pt.x, pt.y, pt.z)
|
||||
weapon.look(yaw, pitch)
|
||||
weapon.shoot(1)
|
||||
end
|
||||
end
|
||||
|
||||
local function findTargets()
|
||||
local pos = { x = 0, y = 0, z = 0 }
|
||||
local l = sensor.sense()
|
||||
table.sort(l, function(e1, e2)
|
||||
return Point.distance(e1, pos) < Point.distance(e2, pos)
|
||||
end)
|
||||
local pos = { x = 0, y = 0, z = 0 }
|
||||
local l = sensor.sense()
|
||||
table.sort(l, function(e1, e2)
|
||||
return Point.distance(e1, pos) < Point.distance(e2, pos)
|
||||
end)
|
||||
|
||||
local targets = { }
|
||||
for _,v in ipairs(l) do
|
||||
if v.id ~= uid and Mobs.getNames()[v.name] then
|
||||
if v.y >= 0 and v.y < 1 then
|
||||
table.insert(targets, v)
|
||||
end
|
||||
end
|
||||
end
|
||||
return #targets > 0 and targets
|
||||
local targets = { }
|
||||
for _,v in ipairs(l) do
|
||||
if v.id ~= uid and Mobs.getNames()[v.name] then
|
||||
if v.y >= 0 and v.y < 1 then
|
||||
table.insert(targets, v)
|
||||
end
|
||||
end
|
||||
end
|
||||
return #targets > 0 and targets
|
||||
end
|
||||
|
||||
while true do
|
||||
local targets = findTargets()
|
||||
if targets then
|
||||
for _, entity in ipairs(targets) do
|
||||
shootAt(entity, 1)
|
||||
end
|
||||
end
|
||||
os.sleep(.5)
|
||||
local targets = findTargets()
|
||||
if targets then
|
||||
for _, entity in ipairs(targets) do
|
||||
shootAt(entity, 1)
|
||||
end
|
||||
end
|
||||
os.sleep(.5)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user