package management
This commit is contained in:
9
builder/.package
Normal file
9
builder/.package
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
required = {
|
||||||
|
'opus-develop-1.8',
|
||||||
|
},
|
||||||
|
title = 'Schematic Builder',
|
||||||
|
repository = 'kepler155c/opus-apps/develop1.8/builder',
|
||||||
|
description = [[ ... ]],
|
||||||
|
licence = 'MIT',
|
||||||
|
}
|
||||||
9
core/.package
Normal file
9
core/.package
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
required = {
|
||||||
|
'opus-develop-1.8',
|
||||||
|
},
|
||||||
|
title = 'Core apps and apis',
|
||||||
|
repository = 'kepler155c/opus-apps/develop1.8/core',
|
||||||
|
description = [[ ... ]],
|
||||||
|
licence = 'MIT',
|
||||||
|
}
|
||||||
@@ -3,7 +3,7 @@ local TableDB = require('tableDB')
|
|||||||
|
|
||||||
local fs = _G.fs
|
local fs = _G.fs
|
||||||
|
|
||||||
local NAME_DIR = '/usr/etc/names'
|
local NAME_DIR = '/packages/core/etc/names'
|
||||||
|
|
||||||
local nameDB = TableDB()
|
local nameDB = TableDB()
|
||||||
|
|
||||||
@@ -4,7 +4,7 @@ local Util = require('util')
|
|||||||
local fs = _G.fs
|
local fs = _G.fs
|
||||||
local turtle = _G.turtle
|
local turtle = _G.turtle
|
||||||
|
|
||||||
local RECIPES_DIR = 'usr/etc/recipes'
|
local RECIPES_DIR = 'packages/core/etc/recipes'
|
||||||
local USER_RECIPES = 'usr/config/recipes.db'
|
local USER_RECIPES = 'usr/config/recipes.db'
|
||||||
|
|
||||||
local Craft = { }
|
local Craft = { }
|
||||||
9
farms/.package
Normal file
9
farms/.package
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
required = {
|
||||||
|
'opus-develop-1.8',
|
||||||
|
},
|
||||||
|
title = 'Programs for farming resources',
|
||||||
|
repository = 'kepler155c/opus-apps/develop1.8/farms',
|
||||||
|
description = [[ ... ]],
|
||||||
|
licence = 'MIT',
|
||||||
|
}
|
||||||
9
forestry/.package
Normal file
9
forestry/.package
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
required = {
|
||||||
|
'opus-develop-1.8',
|
||||||
|
},
|
||||||
|
title = 'Forestry mod applications',
|
||||||
|
repository = 'kepler155c/opus-apps/develop1.8/forestry',
|
||||||
|
description = [[ ... ]],
|
||||||
|
licence = 'MIT',
|
||||||
|
}
|
||||||
106
forestry/alveary.lua
Normal file
106
forestry/alveary.lua
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
_G.requireInjector(_ENV)
|
||||||
|
|
||||||
|
local Event = require('event')
|
||||||
|
local UI = require('ui')
|
||||||
|
|
||||||
|
redstone.setBundledOutput('bottom', 0)
|
||||||
|
|
||||||
|
local function regulate(humidity, heat)
|
||||||
|
local heater = heat == 'Up 1' or heat == 'Both 1'
|
||||||
|
local lava = heat == 'Both 1'
|
||||||
|
local water = humidity == 'Up 1'
|
||||||
|
|
||||||
|
local c = colors.combine(
|
||||||
|
lava and colors.green or 0,
|
||||||
|
heater and colors.red or 0,
|
||||||
|
water and colors.blue or 0)
|
||||||
|
|
||||||
|
redstone.setBundledOutput('bottom', c)
|
||||||
|
end
|
||||||
|
|
||||||
|
function create(alveary, terminal)
|
||||||
|
local window = UI.Window({
|
||||||
|
alveary = alveary,
|
||||||
|
parent = UI.Device({
|
||||||
|
device = terminal,
|
||||||
|
textScale = 0.5,
|
||||||
|
backgroundColor = colors.green
|
||||||
|
}),
|
||||||
|
progressBar = UI.ProgressBar({
|
||||||
|
y = 3,
|
||||||
|
x = 2, ex = -2,
|
||||||
|
}),
|
||||||
|
--[[
|
||||||
|
heater = UI.Button {
|
||||||
|
x = 2, y = -2, width = 7,
|
||||||
|
text = 'heater',
|
||||||
|
},
|
||||||
|
humidifier = UI.Button {
|
||||||
|
x = 2, y = -4,
|
||||||
|
text = 'Humidify',
|
||||||
|
},
|
||||||
|
dehumidifier = UI.Button {
|
||||||
|
x = 2, y = -6,
|
||||||
|
text = 'Dehumidify',
|
||||||
|
},
|
||||||
|
--]]
|
||||||
|
})
|
||||||
|
|
||||||
|
function window:draw()
|
||||||
|
|
||||||
|
local queen = self.alveary.getQueen()
|
||||||
|
if not queen then
|
||||||
|
self:clear(colors.black)
|
||||||
|
regulate()
|
||||||
|
else
|
||||||
|
self.backgroundColor = self.alveary.canBreed() and colors.green or colors.red
|
||||||
|
self:clear()
|
||||||
|
local percDone = 100 - math.floor(queen.health * 100 / queen.maxHealth)
|
||||||
|
if not queen.canSpawn then
|
||||||
|
percDone = 0
|
||||||
|
end
|
||||||
|
self.progressBar.value = percDone
|
||||||
|
--self.progressBar:draw()
|
||||||
|
for _,c in pairs(self.children) do
|
||||||
|
c:draw()
|
||||||
|
end
|
||||||
|
|
||||||
|
self:centeredWrite(2, queen.displayName)
|
||||||
|
self:centeredWrite(4, percDone .. '%')
|
||||||
|
self:write(1, 6, 'Generation: ' .. queen.generation)
|
||||||
|
self:setCursorPos(1, 7)
|
||||||
|
if queen.active then
|
||||||
|
regulate(
|
||||||
|
queen.active.humidityTolerance,
|
||||||
|
queen.active.temperatureTolerance)
|
||||||
|
|
||||||
|
if queen.active.flowerProvider ~= 'Flowers' then
|
||||||
|
self:print(queen.active.flowerProvider .. '\n')
|
||||||
|
end
|
||||||
|
if queen.active.effect ~= 'None' then
|
||||||
|
self:print('Effect: ' .. queen.active.effect)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
self:print('(pure)')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return window
|
||||||
|
end
|
||||||
|
|
||||||
|
local pages = {
|
||||||
|
create(device.items, device.monitor),
|
||||||
|
--create(device.items_6, device.monitor_22),
|
||||||
|
--create(device.items_5, device.monitor_21),
|
||||||
|
}
|
||||||
|
|
||||||
|
Event.onInterval(5, function()
|
||||||
|
for _,v in pairs(pages) do
|
||||||
|
v:draw()
|
||||||
|
v:sync()
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
UI:pullEvents()
|
||||||
|
|
||||||
176
forestry/beeInfo.lua
Normal file
176
forestry/beeInfo.lua
Normal file
@@ -0,0 +1,176 @@
|
|||||||
|
_G.requireInjector(_ENV)
|
||||||
|
|
||||||
|
local Event = require('event')
|
||||||
|
local UI = require('ui')
|
||||||
|
local Util = require('util')
|
||||||
|
|
||||||
|
local chest = peripheral.wrap('bottom')
|
||||||
|
|
||||||
|
local data
|
||||||
|
local monitor = UI.Device({
|
||||||
|
deviceType = 'monitor',
|
||||||
|
textScale = .5
|
||||||
|
})
|
||||||
|
|
||||||
|
UI:setDefaultDevice(monitor)
|
||||||
|
|
||||||
|
local breedingPage = UI.Page({
|
||||||
|
titleBar = UI.TitleBar(),
|
||||||
|
grid = UI.Grid({
|
||||||
|
columns = {
|
||||||
|
{ heading = ' ', key = 'chance' },
|
||||||
|
{ heading = 'Princess', key = 'princess', },
|
||||||
|
{ heading = 'Drone', key = 'drone' },
|
||||||
|
{ heading = 'Result', key = 'result', },
|
||||||
|
},
|
||||||
|
y = 2, ey = -8,
|
||||||
|
sortColumn = 'result',
|
||||||
|
autospace = true
|
||||||
|
}),
|
||||||
|
specialConditions = UI.Window({
|
||||||
|
backgroundColor = colors.red,
|
||||||
|
y = -7,
|
||||||
|
height = 2
|
||||||
|
}),
|
||||||
|
buttons = UI.Window({
|
||||||
|
y = monitor.height - 4,
|
||||||
|
width = monitor.width,
|
||||||
|
height = 5,
|
||||||
|
backgroundColor = colors.gray,
|
||||||
|
prevButton = UI.Button({
|
||||||
|
event = 'previous',
|
||||||
|
x = 2,
|
||||||
|
y = 2,
|
||||||
|
height = 3,
|
||||||
|
width = 5,
|
||||||
|
text = ' < '
|
||||||
|
}),
|
||||||
|
resetButton = UI.Button({
|
||||||
|
event = 'clear',
|
||||||
|
x = 8,
|
||||||
|
y = 2,
|
||||||
|
height = 3,
|
||||||
|
width = monitor.width - 14,
|
||||||
|
text = 'Clear'
|
||||||
|
}),
|
||||||
|
nextButton = UI.Button({
|
||||||
|
event = 'next',
|
||||||
|
x = monitor.width - 5,
|
||||||
|
y = 2,
|
||||||
|
height = 3,
|
||||||
|
width = 5,
|
||||||
|
text = ' > '
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
function breedingPage:getBreedingData()
|
||||||
|
self.grid.values = { }
|
||||||
|
local stacks = chest.getAllStacks(false)
|
||||||
|
local stack = stacks[1]
|
||||||
|
self.titleBar.title = stack.individual.displayName
|
||||||
|
if stack.individual.active then
|
||||||
|
end
|
||||||
|
for _,d in pairs(data) do
|
||||||
|
if d.allele1 == stack.individual.displayName or
|
||||||
|
d.allele2 == stack.individual.displayName then
|
||||||
|
local ind = ''
|
||||||
|
if d.specialConditions then
|
||||||
|
ind = '*'
|
||||||
|
end
|
||||||
|
table.insert(self.grid.values, {
|
||||||
|
princess = d.allele1 .. ind,
|
||||||
|
drone = d.allele2,
|
||||||
|
result = d.result,
|
||||||
|
chance = d.chance .. '%',
|
||||||
|
specialConditions = d.specialConditions
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
self.grid.index = 1
|
||||||
|
self.grid:adjustWidth()
|
||||||
|
self.grid:update()
|
||||||
|
self:draw()
|
||||||
|
self:sync()
|
||||||
|
end
|
||||||
|
|
||||||
|
function breedingPage.specialConditions:draw()
|
||||||
|
local selected = self.parent.grid:getSelected()
|
||||||
|
if selected and selected.specialConditions then
|
||||||
|
local sc = ''
|
||||||
|
if selected.specialConditions then
|
||||||
|
for _,v in ipairs(selected.specialConditions) do
|
||||||
|
if sc ~= '' then
|
||||||
|
sc = sc .. ', '
|
||||||
|
end
|
||||||
|
sc = sc .. v
|
||||||
|
end
|
||||||
|
end
|
||||||
|
self:clear()
|
||||||
|
self:setCursorPos(2, 1)
|
||||||
|
self:print(sc)
|
||||||
|
else
|
||||||
|
self:clear(colors.red)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function breedingPage.grid:draw()
|
||||||
|
UI.Grid.draw(self)
|
||||||
|
self.parent.specialConditions:draw()
|
||||||
|
end
|
||||||
|
|
||||||
|
function breedingPage:eventHandler(event)
|
||||||
|
if event.type == 'next' then
|
||||||
|
self.grid:setPage(self.grid:getPage() + 1)
|
||||||
|
elseif event.type == 'previous' then
|
||||||
|
self.grid:setPage(self.grid:getPage() - 1)
|
||||||
|
elseif event.type == 'clear' then
|
||||||
|
self.grid:setTable({})
|
||||||
|
self.grid:draw()
|
||||||
|
elseif event.type == 'grid_focus_row' then
|
||||||
|
self.specialConditions:draw()
|
||||||
|
else
|
||||||
|
return UI.Page.eventHandler(self, event)
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
Event.on('turtle_inventory', function()
|
||||||
|
local slot = turtle.selectSlotWithQuantity(1)
|
||||||
|
|
||||||
|
if slot then
|
||||||
|
turtle.dropDown()
|
||||||
|
breedingPage:getBreedingData()
|
||||||
|
turtle.suckDown()
|
||||||
|
turtle.drop()
|
||||||
|
end
|
||||||
|
|
||||||
|
end)
|
||||||
|
|
||||||
|
if not fs.exists('.bee.data') then
|
||||||
|
local p = peripheral.wrap("back")
|
||||||
|
local data = p.getBeeBreedingData()
|
||||||
|
local t = { }
|
||||||
|
for _,d in pairs(data) do
|
||||||
|
d = Util.shallowCopy(d)
|
||||||
|
if type(d.specialConditions) == 'string' then
|
||||||
|
if d.specialConditions == '[]' then
|
||||||
|
d.specialConditions = ''
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if #d.specialConditions == 0 then
|
||||||
|
d.specialConditions = nil
|
||||||
|
else
|
||||||
|
d.specialConditions = Util.shallowCopy(d.specialConditions)
|
||||||
|
end
|
||||||
|
table.insert(t, d)
|
||||||
|
end
|
||||||
|
Util.writeTable('.bee.data', t)
|
||||||
|
else
|
||||||
|
data = Util.readTable('.bee.data')
|
||||||
|
end
|
||||||
|
|
||||||
|
UI:setPage(breedingPage)
|
||||||
|
|
||||||
|
UI:pullEvents()
|
||||||
|
|
||||||
34
forestry/filing.lua
Normal file
34
forestry/filing.lua
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
_G.requireInjector(_ENV)
|
||||||
|
|
||||||
|
local Event = require('event')
|
||||||
|
local Util = require('util')
|
||||||
|
|
||||||
|
local chest = peripheral.wrap('top')
|
||||||
|
|
||||||
|
function getOpenChestSlot(stacks)
|
||||||
|
for i = 1, chest.getInventorySize() do
|
||||||
|
if not stacks[i] then
|
||||||
|
return i
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
Event.on('turtle_inventory', function()
|
||||||
|
for i = 1, 16 do
|
||||||
|
if turtle.getItemCount(i) > 0 then
|
||||||
|
chest.pullItem('down', i, 1)
|
||||||
|
os.sleep(.5)
|
||||||
|
local stacks = chest.getAllStacks(false)
|
||||||
|
local _,slot = Util.find(stacks, 'qty', 2)
|
||||||
|
if slot then
|
||||||
|
print('Duplicate')
|
||||||
|
chest.pushItem('north', slot, 1)
|
||||||
|
else
|
||||||
|
print('New Serum')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
Event.pullEvents()
|
||||||
|
|
||||||
34
forestry/serums.lua
Normal file
34
forestry/serums.lua
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
_G.requireInjector(_ENV)
|
||||||
|
|
||||||
|
local Event = require('event')
|
||||||
|
local Util = require('util')
|
||||||
|
|
||||||
|
local chest = peripheral.wrap('top')
|
||||||
|
|
||||||
|
function getOpenChestSlot(stacks)
|
||||||
|
for i = 1, chest.getInventorySize() do
|
||||||
|
if not stacks[i] then
|
||||||
|
return i
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
Event.on('turtle_inventory', function()
|
||||||
|
for i = 1, 16 do
|
||||||
|
if turtle.getItemCount(i) > 0 then
|
||||||
|
local stacks = chest.getAllStacks(false)
|
||||||
|
local slot = getOpenChestSlot(stacks)
|
||||||
|
chest.pullItemIntoSlot('down', i, 1, slot)
|
||||||
|
local serum = chest.getStackInSlot(slot)
|
||||||
|
if Util.find(stacks, 'nbt_hash', serum.nbt_hash) then
|
||||||
|
print('Duplicate')
|
||||||
|
chest.pushItem('north', slot, 1)
|
||||||
|
else
|
||||||
|
print('New Serum')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end)
|
||||||
|
|
||||||
|
Event.pullEvents()
|
||||||
9
glasses/.package
Normal file
9
glasses/.package
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
required = {
|
||||||
|
'opus-develop-1.8',
|
||||||
|
},
|
||||||
|
title = 'Plethora overlay glasses support',
|
||||||
|
repository = 'kepler155c/opus-apps/develop1.8/glasses',
|
||||||
|
description = [[ ... ]],
|
||||||
|
licence = 'MIT',
|
||||||
|
}
|
||||||
@@ -440,7 +440,6 @@ out.setTextScale = function(scale)
|
|||||||
end
|
end
|
||||||
if textScale ~= scale then
|
if textScale ~= scale then
|
||||||
local factor = textScale/scale
|
local factor = textScale/scale
|
||||||
debug({ scale, textScale, factor, tx*factor, ty*factor })
|
|
||||||
textScale = scale
|
textScale = scale
|
||||||
resize(tx*factor, ty*factor)
|
resize(tx*factor, ty*factor)
|
||||||
end
|
end
|
||||||
@@ -3,10 +3,7 @@
|
|||||||
'opus-develop-1.8',
|
'opus-develop-1.8',
|
||||||
},
|
},
|
||||||
title = 'Inventory manager for Opus OS',
|
title = 'Inventory manager for Opus OS',
|
||||||
description = [[
|
repository = 'kepler155c/opus-apps/develop1.8/milo',
|
||||||
Unstable Branch
|
description = [[ ... ]],
|
||||||
]],
|
|
||||||
licence = 'MIT',
|
licence = 'MIT',
|
||||||
--location = '',
|
|
||||||
--mount = 'packages/opus-neural gitfs kepler155c/opus-neural/master',
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ local Craft = {
|
|||||||
STATUS_ERROR = 'error',
|
STATUS_ERROR = 'error',
|
||||||
STATUS_SUCCESS = 'success',
|
STATUS_SUCCESS = 'success',
|
||||||
|
|
||||||
RECIPES_DIR = 'usr/etc/recipes',
|
RECIPES_DIR = 'packages/core/etc/recipes',
|
||||||
USER_RECIPES = 'usr/config/recipes.db',
|
USER_RECIPES = 'usr/config/recipes.db',
|
||||||
MACHINE_LOOKUP = 'usr/config/machine_crafting.db',
|
MACHINE_LOOKUP = 'usr/config/machine_crafting.db',
|
||||||
}
|
}
|
||||||
|
|||||||
9
miners/.package
Normal file
9
miners/.package
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
required = {
|
||||||
|
'opus-develop-1.8',
|
||||||
|
},
|
||||||
|
title = 'Turtle mining programs',
|
||||||
|
repository = 'kepler155c/opus-apps/develop1.8/miners',
|
||||||
|
description = [[ ... ]],
|
||||||
|
licence = 'MIT',
|
||||||
|
}
|
||||||
9
neural/.package
Normal file
9
neural/.package
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
required = {
|
||||||
|
'opus-develop-1.8',
|
||||||
|
},
|
||||||
|
title = 'Programs for the neural interface',
|
||||||
|
repository = 'kepler155c/opus-apps/develop1.8/neural',
|
||||||
|
description = [[ ... ]],
|
||||||
|
licence = 'MIT',
|
||||||
|
}
|
||||||
11
neural/apis/neural/angle.lua
Normal file
11
neural/apis/neural/angle.lua
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
local Angle = { }
|
||||||
|
|
||||||
|
function Angle.towards(x, y, z)
|
||||||
|
return math.deg(math.atan2(-x, z)), 0
|
||||||
|
end
|
||||||
|
|
||||||
|
function Angle.away(x, y, z)
|
||||||
|
return math.deg(math.atan2(x, -z)), 0
|
||||||
|
end
|
||||||
|
|
||||||
|
return Angle
|
||||||
139
neural/apis/neural/interface.lua
Normal file
139
neural/apis/neural/interface.lua
Normal file
@@ -0,0 +1,139 @@
|
|||||||
|
local Interface = { }
|
||||||
|
|
||||||
|
local Angle = require('neural.angle')
|
||||||
|
local Util = require('util')
|
||||||
|
|
||||||
|
local device = _G.device
|
||||||
|
local os = _G.os
|
||||||
|
|
||||||
|
local ni = device.neuralInterface or { }
|
||||||
|
for k,v in pairs(ni) do
|
||||||
|
Interface[k] = v
|
||||||
|
end
|
||||||
|
|
||||||
|
local function yap(pt)
|
||||||
|
local x, y, z = pt.x, pt.y + 1, pt.z
|
||||||
|
local pitch = -math.atan2(y, math.atan2(-(x - .5), z - .5))
|
||||||
|
local yaw = math.deg(math.atan2(-(x - .5), z - .5))
|
||||||
|
|
||||||
|
return math.deg(yaw), math.deg(pitch)
|
||||||
|
end
|
||||||
|
|
||||||
|
function Interface.launchTo(pt, strength)
|
||||||
|
local yaw = math.deg(math.atan2(pt.x, -pt.z))
|
||||||
|
if not strength then
|
||||||
|
local dist = math.sqrt(
|
||||||
|
math.pow(pt.x, 2) +
|
||||||
|
math.pow(pt.z, 2))
|
||||||
|
strength = math.sqrt(math.max(32, dist) / 3)
|
||||||
|
debug(strength)
|
||||||
|
end
|
||||||
|
Interface.launch(yaw, 225, strength or 1)
|
||||||
|
end
|
||||||
|
|
||||||
|
function Interface.dropArmor()
|
||||||
|
for i = 3, 5 do
|
||||||
|
Interface.unequip(i)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function Interface.walkTo(pt)
|
||||||
|
local s, m = ni.walk(pt.x, pt.y, pt.z)
|
||||||
|
if not s then
|
||||||
|
_G.printError(m)
|
||||||
|
end
|
||||||
|
os.sleep(.05)
|
||||||
|
while ni.isWalking() do
|
||||||
|
os.sleep(0)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- flatten equipment functions
|
||||||
|
function Interface.getEquipmentList()
|
||||||
|
local l = Interface.getEquipment and Interface.getEquipment().list() or { }
|
||||||
|
|
||||||
|
for k, v in pairs(l) do
|
||||||
|
v.slot = k
|
||||||
|
end
|
||||||
|
|
||||||
|
return l
|
||||||
|
end
|
||||||
|
|
||||||
|
function Interface.equip(slot)
|
||||||
|
return Interface.getEquipment and Interface.getEquipment().suck(slot) or 0
|
||||||
|
end
|
||||||
|
|
||||||
|
function Interface.unequip(slot)
|
||||||
|
return Interface.getEquipment and Interface.getEquipment().drop(slot)
|
||||||
|
end
|
||||||
|
|
||||||
|
function Interface.getUniqueNames()
|
||||||
|
local t = { }
|
||||||
|
for _,v in pairs(Interface.sense()) do
|
||||||
|
t[v.name] = v.name
|
||||||
|
end
|
||||||
|
return Util.transpose(t)
|
||||||
|
end
|
||||||
|
|
||||||
|
function Interface.lookAt(pt)
|
||||||
|
local yaw, pitch = Angle.towards(pt.x - .5, pt.y + 1, pt.z - .5)
|
||||||
|
return Interface.look(yaw, pitch)
|
||||||
|
end
|
||||||
|
|
||||||
|
function Interface.shootAt(entity, strength)
|
||||||
|
Interface.lookAt(entity)
|
||||||
|
return Interface.shoot(strength or 1)
|
||||||
|
end
|
||||||
|
|
||||||
|
function Interface.shootAt2(entity, strength)
|
||||||
|
local x, z = entity.x - .5, entity.z - .5
|
||||||
|
|
||||||
|
local function quad(a, b, c)
|
||||||
|
if math.abs(a) < 1e-6 then
|
||||||
|
if math.abs(b) < 1e-6 then
|
||||||
|
return math.abs(c) < 1e-6 and 0, 0
|
||||||
|
else
|
||||||
|
return -c/b, -c/b
|
||||||
|
end
|
||||||
|
else
|
||||||
|
local disc = b*b - 4*a*c
|
||||||
|
if disc >= 0 then
|
||||||
|
disc = math.sqrt(disc)
|
||||||
|
a = 2*a
|
||||||
|
return (-b-disc)/a, (-b+disc)/a
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local v = .025 -- velocity of arrow
|
||||||
|
|
||||||
|
local tvx = entity.motionX
|
||||||
|
local tvz = entity.motionZ
|
||||||
|
local a = tvx*tvx + tvz*tvz - v*v
|
||||||
|
local b = 2 * (tvx * x + tvz * z)
|
||||||
|
local c = x * x + z * z
|
||||||
|
local t0, t1 = quad(a, b, c)
|
||||||
|
if t0 then
|
||||||
|
local t = math.min(t0, t1)
|
||||||
|
if t < 0 then
|
||||||
|
t = math.max(t0, t1)
|
||||||
|
end
|
||||||
|
if t > 0 then
|
||||||
|
--Util.print({ x, t, tvx, x + tvx * t })
|
||||||
|
x = x + tvx * t
|
||||||
|
z = z + tvz * t
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local yaw = math.deg(math.atan2(-(x - .5), z - .5))
|
||||||
|
local pitch = -math.deg(math.atan2(entity.y, math.sqrt(x * x + z * z)))
|
||||||
|
|
||||||
|
Interface.look(yaw, pitch) -- pitch is broken
|
||||||
|
return Interface.shoot(strength or 1)
|
||||||
|
end
|
||||||
|
|
||||||
|
function Interface.setStatus(s)
|
||||||
|
ni.status = s
|
||||||
|
end
|
||||||
|
|
||||||
|
return Interface
|
||||||
22
neural/apis/neural/mobs.lua
Normal file
22
neural/apis/neural/mobs.lua
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
local Mobs = { }
|
||||||
|
|
||||||
|
local hostiles = {
|
||||||
|
ancient_golem = true,
|
||||||
|
BabySkeleton = true,
|
||||||
|
BabyZombie = true,
|
||||||
|
Bat = true,
|
||||||
|
Creeper = true,
|
||||||
|
Husk = true,
|
||||||
|
Skeleton = true,
|
||||||
|
Slime = true,
|
||||||
|
Spider = true,
|
||||||
|
Witch = true,
|
||||||
|
Zombie = true,
|
||||||
|
ZombieVillager = true,
|
||||||
|
}
|
||||||
|
|
||||||
|
function Mobs.getNames()
|
||||||
|
return hostiles
|
||||||
|
end
|
||||||
|
|
||||||
|
return Mobs
|
||||||
24
neural/autorun/6.neural.lua
Normal file
24
neural/autorun/6.neural.lua
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
_G.requireInjector(_ENV)
|
||||||
|
|
||||||
|
local GPS = require('gps')
|
||||||
|
|
||||||
|
local kernel = _G.kernel
|
||||||
|
|
||||||
|
kernel.onDeviceAttach('neuralInterface', function(dev)
|
||||||
|
dev.goTo = function(x, _, z)
|
||||||
|
local pt = GPS.locate(2)
|
||||||
|
if pt then
|
||||||
|
return pcall(function()
|
||||||
|
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 dev.walk(gpt.x, gpt.y, gpt.z)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
return false, 'No GPS'
|
||||||
|
end
|
||||||
|
end)
|
||||||
22
neural/etc/apps/neural-apps.db
Normal file
22
neural/etc/apps/neural-apps.db
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
{
|
||||||
|
[ "shootingGallery" ] = {
|
||||||
|
title = "Gallery",
|
||||||
|
category = "Neural",
|
||||||
|
run = "shootingGallery.lua",
|
||||||
|
},
|
||||||
|
[ "neuralFight" ] = {
|
||||||
|
title = "Fight",
|
||||||
|
category = "Neural",
|
||||||
|
run = "neuralFight.lua",
|
||||||
|
},
|
||||||
|
[ "neuralFly" ] = {
|
||||||
|
title = "Fly",
|
||||||
|
category = "Neural",
|
||||||
|
run = "neuralFly.lua",
|
||||||
|
},
|
||||||
|
[ "neuralRemote" ] = {
|
||||||
|
title = "Remote",
|
||||||
|
category = "Neural",
|
||||||
|
run = "neuralRemote.lua",
|
||||||
|
},
|
||||||
|
}
|
||||||
49
neural/mobfollow.lua
Normal file
49
neural/mobfollow.lua
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
_G.requireInjector(_ENV)
|
||||||
|
|
||||||
|
local GPS = require('gps')
|
||||||
|
local Util = require('util')
|
||||||
|
local Peripheral = require('peripheral')
|
||||||
|
local Point = require('point')
|
||||||
|
|
||||||
|
local os = _G.os
|
||||||
|
|
||||||
|
local args = { ... }
|
||||||
|
local remoteId = args[1] or error('mobFollow <remote id>')
|
||||||
|
local ni = Peripheral.lookup(remoteId .. '://name/neuralInterface')
|
||||||
|
|
||||||
|
if not ni then
|
||||||
|
error('failed to connect')
|
||||||
|
end
|
||||||
|
|
||||||
|
local lpt = nil
|
||||||
|
|
||||||
|
while true do
|
||||||
|
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
|
||||||
|
|
||||||
|
os.sleep(.5)
|
||||||
|
end
|
||||||
98
neural/neuralFight.lua
Normal file
98
neural/neuralFight.lua
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
_G.requireInjector()
|
||||||
|
|
||||||
|
local Angle = require('neural.angle')
|
||||||
|
local GPS = require('gps')
|
||||||
|
local Mobs = require('neural.mobs')
|
||||||
|
local ni = require('neural.interface')
|
||||||
|
local Point = require('point')
|
||||||
|
local Util = require('util')
|
||||||
|
|
||||||
|
local os = _G.os
|
||||||
|
|
||||||
|
local RADIUS = 13
|
||||||
|
local ROTATION = math.pi / 16
|
||||||
|
|
||||||
|
local uid = ni.getID and ni.getID() or error('Introspection module is required')
|
||||||
|
local pos = { x = 0, y = 0, z = 0 }
|
||||||
|
|
||||||
|
local function findTargets()
|
||||||
|
local l = ni.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 math.abs(v.y) < 2 and Point.distance(v, pos) < 16 then -- pitch is broken
|
||||||
|
table.insert(targets, v)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return #targets > 0 and targets
|
||||||
|
end
|
||||||
|
|
||||||
|
local function shootAt(targets)
|
||||||
|
for _,target in ipairs(targets) do
|
||||||
|
target = ni.getMetaByID(target.id)
|
||||||
|
if target and target.isAlive and Point.distance(target, pos) < 14 then
|
||||||
|
ni.shootAt(target)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local potions = Util.filter(
|
||||||
|
ni.getEquipmentList(),
|
||||||
|
function(a)
|
||||||
|
return a.name == 'minecraft:splash_potion'
|
||||||
|
end)
|
||||||
|
|
||||||
|
local function heal(target)
|
||||||
|
local hands = { 'main', 'off' }
|
||||||
|
|
||||||
|
if #potions > 0 and ni.getMetaOwner().health < 10 then
|
||||||
|
local yaw, pitch = Angle.away(target.x - .5, 0, target.z - .5)
|
||||||
|
ni.look(yaw, pitch)
|
||||||
|
ni.use(.01, hands[potions[1].slot])
|
||||||
|
ni.launch(yaw, pitch, 1)
|
||||||
|
table.remove(potions, 1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local pt = GPS.locate()
|
||||||
|
|
||||||
|
while true do
|
||||||
|
local targets = findTargets()
|
||||||
|
if not targets then
|
||||||
|
local cpt = GPS.locate()
|
||||||
|
if Point.distance(pt, cpt) > 2 then
|
||||||
|
print('walking to starting point')
|
||||||
|
local s, m = ni.goTo(pt.x, pt.y, pt.z)
|
||||||
|
Util.print({ s, m })
|
||||||
|
os.sleep(.05)
|
||||||
|
while ni.isWalking() do
|
||||||
|
os.sleep(0)
|
||||||
|
end
|
||||||
|
Util.print('done walking')
|
||||||
|
end
|
||||||
|
os.sleep(1)
|
||||||
|
else
|
||||||
|
local target = targets[1]
|
||||||
|
local angle = math.atan2(-target.x, -target.z) + ROTATION
|
||||||
|
|
||||||
|
ni.launchTo({
|
||||||
|
x = target.x + RADIUS * math.sin(angle),
|
||||||
|
y = 0,
|
||||||
|
z = target.z + RADIUS * math.cos(angle)
|
||||||
|
}, 1)
|
||||||
|
os.sleep(.2)
|
||||||
|
|
||||||
|
shootAt(targets)
|
||||||
|
|
||||||
|
heal(target)
|
||||||
|
|
||||||
|
if math.random(1, 3) == 3 then
|
||||||
|
ROTATION = -ROTATION
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
78
neural/neuralFly.lua
Normal file
78
neural/neuralFly.lua
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
_G.requireInjector(_ENV)
|
||||||
|
|
||||||
|
local ni = require('neural.interface')
|
||||||
|
local GPS = require('gps')
|
||||||
|
|
||||||
|
local strength = .315
|
||||||
|
local delay = .1
|
||||||
|
|
||||||
|
while ni.getMetaOwner().health < 26 do
|
||||||
|
print('health: ' .. ni.getMetaOwner().health)
|
||||||
|
os.sleep(1)
|
||||||
|
end
|
||||||
|
|
||||||
|
ni.launch(0, 270, 1.5)
|
||||||
|
os.sleep(.25)
|
||||||
|
|
||||||
|
local pt
|
||||||
|
|
||||||
|
local function fly()
|
||||||
|
for i = 1, 100 do
|
||||||
|
os.sleep(1)
|
||||||
|
if pt then
|
||||||
|
print(pt.y)
|
||||||
|
print(strength)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function gps()
|
||||||
|
local lastY = 12
|
||||||
|
while true do
|
||||||
|
pt = GPS.locate()
|
||||||
|
if pt then
|
||||||
|
local d = math.abs(lastY - pt.y)
|
||||||
|
|
||||||
|
-- force required to get to lvl 12
|
||||||
|
|
||||||
|
local motionY = ni.getMetaOwner().motionY
|
||||||
|
-- print('y: ' .. pt.y)
|
||||||
|
if pt.y < 12 then
|
||||||
|
if pt.y > lastY then
|
||||||
|
--strength = strength + .001
|
||||||
|
else
|
||||||
|
strength = strength + .02 * d
|
||||||
|
end
|
||||||
|
elseif pt.y > 12 then
|
||||||
|
if pt.y > lastY then
|
||||||
|
strength = strength - .02 * d
|
||||||
|
else
|
||||||
|
--strength = strength - .001
|
||||||
|
end
|
||||||
|
end
|
||||||
|
lastY = pt.y
|
||||||
|
|
||||||
|
-- force required to offset motion
|
||||||
|
local om = (motionY - 0.138) / 0.8
|
||||||
|
|
||||||
|
ni.launch(0, 270, strength-motionY)
|
||||||
|
-- print('strength: ' .. strength)
|
||||||
|
os.sleep(delay)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
parallel.waitForAny(fly, gps)
|
||||||
|
|
||||||
|
repeat
|
||||||
|
ni.launch(0, 270, .25)
|
||||||
|
os.sleep(.1)
|
||||||
|
until not ni.getMetaOwner().isAirborne
|
||||||
|
|
||||||
|
print('descending')
|
||||||
|
for i = 1, 50 do
|
||||||
|
ni.launch(0, 270, .2)
|
||||||
|
os.sleep(.1)
|
||||||
|
end
|
||||||
|
|
||||||
|
ni.look(180, 0)
|
||||||
88
neural/neuralRecorder.lua
Normal file
88
neural/neuralRecorder.lua
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
_G.requireInjector(_ENV)
|
||||||
|
|
||||||
|
local GPS = require('gps')
|
||||||
|
local Point = require('point')
|
||||||
|
local Util = require('util')
|
||||||
|
|
||||||
|
local os = _G.os
|
||||||
|
local parallel = _G.parallel
|
||||||
|
|
||||||
|
local t = { }
|
||||||
|
local ni = _G.device.neuralInterface or error('Neural Interface not found')
|
||||||
|
|
||||||
|
if not ni.getID then
|
||||||
|
error('Missing Introspection Module')
|
||||||
|
end
|
||||||
|
|
||||||
|
local uid = ni.getID()
|
||||||
|
local c = os.clock()
|
||||||
|
|
||||||
|
local pt = GPS.locate(3) or error('GPS failed')
|
||||||
|
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
|
||||||
|
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
|
||||||
|
|
||||||
|
if v then
|
||||||
|
Util.print(v)
|
||||||
|
table.insert(t, v)
|
||||||
|
end
|
||||||
|
until event == 'char' and ch == 'q'
|
||||||
|
end
|
||||||
|
|
||||||
|
parallel.waitForAny(gps, record)
|
||||||
|
Util.writeTable('neural.tbl', t)
|
||||||
56
neural/neuralRemote.lua
Normal file
56
neural/neuralRemote.lua
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
rednet.open("right")
|
||||||
|
local sensor = peripheral.wrap("back")
|
||||||
|
local modules = peripheral.wrap("back")
|
||||||
|
local Ka = peripheral.find("neuralInterface")
|
||||||
|
local function fire(entity)
|
||||||
|
local x, y, z = entity.x, entity.y, entity.z
|
||||||
|
local pitch = -math.atan2(y, math.sqrt(x * x + z * z))
|
||||||
|
local yaw = math.atan2(-x, z)
|
||||||
|
|
||||||
|
Ka.look(math.deg(yaw), math.deg(pitch), 5)
|
||||||
|
Ka.shoot(1)
|
||||||
|
sleep(0.2)
|
||||||
|
end
|
||||||
|
local mobNames = {"Skeleton"}
|
||||||
|
local mobLookup = {}
|
||||||
|
for i = 1, #mobNames do
|
||||||
|
mobLookup[mobNames[i]] = true
|
||||||
|
end
|
||||||
|
|
||||||
|
function SkeletonShoot()
|
||||||
|
local mobs = sensor.sense()
|
||||||
|
local candidates = {}
|
||||||
|
for i = 1, #mobs do
|
||||||
|
local mob = mobs[i]
|
||||||
|
if mobLookup[mob.name] then
|
||||||
|
candidates[#candidates + 1] = mob
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if #candidates > 0 then
|
||||||
|
local mob = candidates[math.random(1, #candidates)]
|
||||||
|
fire(mob)
|
||||||
|
else
|
||||||
|
sleep(.1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
while true do
|
||||||
|
local id,message = rednet.receive()
|
||||||
|
print(tostring(id)..message)
|
||||||
|
if id == 582 then
|
||||||
|
if message == "forward" then --W
|
||||||
|
Ka.walk(1,0,0)
|
||||||
|
elseif message == "back" then --S
|
||||||
|
Ka.walk(-1,0,0)
|
||||||
|
elseif message == "turnLeft" then--A
|
||||||
|
Ka.walk(0,0,-1)
|
||||||
|
elseif message == "turnRight" then--D
|
||||||
|
Ka.walk(0,0,1)
|
||||||
|
elseif message == "shoot" then--Starts fell program
|
||||||
|
SkeletonShoot()
|
||||||
|
end
|
||||||
|
else
|
||||||
|
write(" Denied!")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
52
neural/neuralReplay.lua
Normal file
52
neural/neuralReplay.lua
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
_G.requireInjector(_ENV)
|
||||||
|
|
||||||
|
local GPS = require('gps')
|
||||||
|
local Util = require('util')
|
||||||
|
|
||||||
|
local os = _G.os
|
||||||
|
local shell = _ENV.shell
|
||||||
|
|
||||||
|
local args = { ... }
|
||||||
|
local fileName = args[1] or 'neural.tbl'
|
||||||
|
|
||||||
|
local t = Util.readTable(shell.resolve(fileName)) or error('Unable to read ' .. fileName)
|
||||||
|
local ni = _G.device.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
|
||||||
|
end
|
||||||
|
|
||||||
|
for _,v in pairs(t) do
|
||||||
|
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
|
||||||
|
-- os.sleep(v.delay)
|
||||||
|
-- os.sleep(2)
|
||||||
|
-- read()
|
||||||
|
end
|
||||||
28
neural/neuralSword.lua
Normal file
28
neural/neuralSword.lua
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
_G.requireInjector(_ENV)
|
||||||
|
|
||||||
|
local ni = require('neural.interface')
|
||||||
|
local Util = require('util')
|
||||||
|
|
||||||
|
local os = _G.os
|
||||||
|
|
||||||
|
while true do
|
||||||
|
local target = Util.find(ni.sense(), 'name', 'joebodo')
|
||||||
|
if target then
|
||||||
|
if math.abs(target.x) < 2 and
|
||||||
|
math.abs(target.z) < 2 then
|
||||||
|
ni.lookAt(target)
|
||||||
|
ni.swing()
|
||||||
|
os.sleep(.5)
|
||||||
|
else
|
||||||
|
local angle = math.atan2(-(target.x - .5), target.z - .5)
|
||||||
|
ni.walkTo({
|
||||||
|
x = target.x + 1.5 * math.sin(angle),
|
||||||
|
y = 0,
|
||||||
|
z = target.z - 1.5 * math.cos(angle)
|
||||||
|
}, 1)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
print('no target')
|
||||||
|
os.sleep(1)
|
||||||
|
end
|
||||||
|
end
|
||||||
83
neural/robotWars.lua
Normal file
83
neural/robotWars.lua
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
_G.requireInjector()
|
||||||
|
|
||||||
|
local Angle = require('neural.angle')
|
||||||
|
local ni = require('neural.interface')
|
||||||
|
local Util = require('util')
|
||||||
|
|
||||||
|
local os = _G.os
|
||||||
|
|
||||||
|
local RADIUS = 13
|
||||||
|
local ROTATION = math.pi / 16
|
||||||
|
|
||||||
|
local args = { ... }
|
||||||
|
local TARGET = args[1] or error('Syntax: robotWars <targetName>')
|
||||||
|
local uid = ni.getID and ni.getID() or error('Introspection module is required')
|
||||||
|
|
||||||
|
local function findTarget(name)
|
||||||
|
for _, v in pairs(ni.sense()) do
|
||||||
|
if v.name == name and v.id ~= uid then
|
||||||
|
return v
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function shootAt(entity)
|
||||||
|
local target = ni.getMetaByID(entity.id)
|
||||||
|
if target then
|
||||||
|
ni.shootAt(target)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local enemy = findTarget(TARGET)
|
||||||
|
local potions = Util.filter(
|
||||||
|
ni.getEquipmentList(),
|
||||||
|
function(a)
|
||||||
|
return a.name == 'minecraft:splash_potion'
|
||||||
|
end)
|
||||||
|
|
||||||
|
if not enemy then
|
||||||
|
print('Current enemies:')
|
||||||
|
for _,v in pairs(ni.getUniqueNames()) do
|
||||||
|
print(v)
|
||||||
|
end
|
||||||
|
print()
|
||||||
|
error('Invalid enemy')
|
||||||
|
end
|
||||||
|
|
||||||
|
local function heal(target)
|
||||||
|
local hands = { 'main', 'off' }
|
||||||
|
|
||||||
|
if #potions > 0 and ni.getMetaOwner().health < 10 then
|
||||||
|
local yaw, pitch = Angle.away({ x = target.x, y = 0, z = target.z })
|
||||||
|
ni.look(yaw, pitch)
|
||||||
|
ni.use(.01, hands[potions[1].slot])
|
||||||
|
ni.launch(yaw, pitch, 1)
|
||||||
|
table.remove(potions, 1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
repeat
|
||||||
|
local target = ni.getMetaByID(enemy.id)
|
||||||
|
if not target then
|
||||||
|
print('lost target')
|
||||||
|
break
|
||||||
|
end
|
||||||
|
local angle = math.atan2(-target.x, -target.z) + ROTATION
|
||||||
|
|
||||||
|
ni.launchTo({
|
||||||
|
x = target.x + RADIUS * math.sin(angle),
|
||||||
|
y = 0,
|
||||||
|
z = target.z + RADIUS * math.cos(angle)
|
||||||
|
}, 1)
|
||||||
|
os.sleep(.2)
|
||||||
|
|
||||||
|
shootAt(enemy)
|
||||||
|
|
||||||
|
heal(enemy)
|
||||||
|
|
||||||
|
if math.random(1, 3) == 3 then
|
||||||
|
ROTATION = -ROTATION
|
||||||
|
end
|
||||||
|
until not target.isAlive
|
||||||
|
|
||||||
|
print('Won !')
|
||||||
31
neural/shootMob.lua
Normal file
31
neural/shootMob.lua
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
_G.requireInjector(_ENV)
|
||||||
|
|
||||||
|
local ni = require('neural.interface')
|
||||||
|
local uid = ni.getID and ni.getID() or error('Introspection module is required')
|
||||||
|
|
||||||
|
local os = _G.os
|
||||||
|
|
||||||
|
local args = { ... }
|
||||||
|
|
||||||
|
local function findEntity(name)
|
||||||
|
for _,v in pairs(ni.sense()) do
|
||||||
|
if v.id ~= uid and v.name == name then
|
||||||
|
return v
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
print('Targets:')
|
||||||
|
for _,v in pairs(ni.sense()) do
|
||||||
|
print(v.name)
|
||||||
|
end
|
||||||
|
|
||||||
|
local target = args[1] or error('specify target name')
|
||||||
|
|
||||||
|
repeat
|
||||||
|
local entity = findEntity(target)
|
||||||
|
if entity then
|
||||||
|
ni.shootAt(entity, 1)
|
||||||
|
end
|
||||||
|
os.sleep(.5)
|
||||||
|
until not entity
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user