restructure

This commit is contained in:
kepler155c@gmail.com
2019-10-30 22:50:01 -06:00
parent e5866b415e
commit a36d54a372
28 changed files with 2185 additions and 13 deletions

9
miloApps/.package Normal file
View File

@@ -0,0 +1,9 @@
{
required = {
'turtle',
},
title = 'Milo extra applications',
repository = 'kepler155c/opus-apps/{{OPUS_BRANCH}}/miloApps',
description = [[Programs for turtles in a Milo network]],
licence = 'MIT',
}

161
miloApps/apps/brewArray.lua Normal file
View File

@@ -0,0 +1,161 @@
--[[
authors: jakedacatman and kepler155c
pastebin run uzghlbnc
package install core
package install milo
reboot
Use multiple brewing stands at once to brew potions.
SETUP:
Place an introspection module into the turtles inventory.
Connect turtle to milo network with a wired modem.
Connect turtle to a second wired modem that is connected to brewing stands ONLY.
Add as many brewing stands as needed.
CONFIGURATION:
Set turtle as a "Generic Inventory"
export blaze powder to slot 5
import from slots 7-9
Use this turtle for machine crafting.
--]]
local Event = require('opus.event')
local Util = require('opus.util')
local device = _G.device
local fs = _G.fs
local os = _G.os
local peripheral = _G.peripheral
local turtle = _G.turtle
local STARTUP_FILE = 'usr/autorun/brewArray.lua'
local function equip(side, item, rawName)
local equipped = peripheral.getType(side)
if equipped == item then
return true
end
if not turtle.equip(side, rawName or item) then
if not turtle.selectSlotWithQuantity(0) then
error('No slots available')
end
turtle.equip(side)
if not turtle.equip(side, item) then
error('Unable to equip ' .. item)
end
end
turtle.select(1)
end
equip('left', 'plethora:introspection', 'plethora:module:0')
local intro = device['plethora:introspection']
local inv = intro.getInventory()
if not fs.exists(STARTUP_FILE) then
Util.writeFile(STARTUP_FILE,
[[os.sleep(1)
shell.openForegroundTab('packages/milo/apps/brewArray.lua')]])
end
local brew
local localName
print('detecting wired modem connected to brewing stands...')
for _, dev in pairs(device) do
if dev.type == 'wired_modem' then
local list = dev.getNamesRemote()
brew = { }
localName = dev.getNameLocal()
for _, name in pairs(list) do
if device[name].type ~= 'minecraft:brewing_stand' then
brew = nil
break
end
table.insert(brew, device[name])
end
end
if brew then
print('Using wired modem: ' .. dev.name)
print('Brewing stands: ' .. #brew)
break
end
end
if not brew then
error('Turtle must be connected to a second wired_modem connected to brewing stands only')
end
_G.printError([[Program must be restarted if new brewing stands are added.]])
-- slots 1-3: bottles
-- slot 4: ingredient
-- slot 5: blaze powder
local function process(list)
local active = false
for _, brewing in ipairs(Util.shallowCopy(brew)) do
local s, m = pcall(function()-- block updates can cause errors
local bs = brewing.list()
local cooking = bs[1] and bs[2] and bs[3] and bs[4]
if cooking then
active = true
end
-- fuel
local fuel = bs[5] or { count = 0 }
if fuel.count < 1 then
print('fueling ' ..brewing.name)
brewing.pullItems(localName, 5, 1, 5)
end
if not cooking and (bs[1] or bs[2] or bs[3] or bs[4]) then
print('pulling from : ' .. brewing.name)
for i = 1, 4 do
brewing.pushItems(localName, i, 1, 6 + i)
end
end
if not cooking and list[1] and list[2] and list[3] and list[4] then
print('brewing : ' .. brewing.name)
for i = 1, 4 do
brewing.pullItems(localName, i, 1, i)
list[i].count = list[i].count - 1
if list[i].count == 0 then
list[i] = nil
end
end
-- push brewing stand to end of list
Util.removeByValue(brew, brewing)
table.insert(brew, brewing)
end
end)
if not s and m then
_G.printError(m)
end
end
return active
end
Event.on('turtle_inventory', function()
while true do
if not process(inv.list()) then
break
end
os.sleep(3)
end
end)
Event.onInterval(5, function()
-- for some reason, it keeps stalling ...
os.queueEvent('turtle_inventory')
end)
os.queueEvent('turtle_inventory')
Event.pullEvents()

View File

@@ -0,0 +1,28 @@
local Util = require('opus.util')
local fs = _G.fs
local os = _G.os
local turtle = _G.turtle
local STARTUP_FILE = 'usr/autorun/cobbleGen.lua'
if not fs.exists(STARTUP_FILE) then
Util.writeFile(STARTUP_FILE,
[[os.sleep(1)
shell.openForegroundTab('packages/milo/apps/cobblegen')]])
end
os.queueEvent('turtle_inventory')
while true do
print('waiting')
os.pullEvent('turtle_inventory')
print('waiting for cobble')
for _ = 1, 20 do
if turtle.inspectDown() then
break
end
os.sleep(.1)
end
print('digging')
turtle.digDown()
end

View File

@@ -0,0 +1,61 @@
--[[
Send items to a players enderchest.
--]]
local Event = require('opus.event')
local Util = require('opus.util')
local device = _G.device
local fs = _G.fs
local os = _G.os
local turtle = _G.turtle
local STARTUP_FILE = 'usr/autorun/enderchest.lua'
local enderChest = device.manipulator and
device.manipulator.getEnder or
error('Must be connected to a manipulator with a bound introspection module')
if not fs.exists(STARTUP_FILE) then
Util.writeFile(STARTUP_FILE,
[[os.sleep(1)
shell.openForegroundTab('packages/milo/apps/enderchest')]])
end
local directions = Util.transpose {
'north', 'south', 'east', 'west', 'up', 'down'
}
Event.on('turtle_inventory', function()
local s, m = pcall(function()
local direction
for _, d in pairs(enderChest().getTransferLocations()) do
if directions[d] then
direction = d
break
end
end
if not direction then
error('Unable to determine transfer direction')
end
turtle.eachFilledSlot(function(s)
print('sending')
enderChest().pullItems(direction, s.index)
end)
end)
if not s and m then
_G.printError(m)
end
print('idle')
end)
Event.onInterval(5, function()
-- for some reason, it keeps stalling ...
os.queueEvent('turtle_inventory')
end)
os.queueEvent('turtle_inventory')
Event.pullEvents()

186
miloApps/apps/furni.lua Normal file
View File

@@ -0,0 +1,186 @@
--[[
Use multiple furnaces at once to smelt items.
SETUP:
Place an introspection module into the turtles inventory.
Connect turtle to milo network with a wired modem.
Connect turtle to a second wired modem that is connected to furnaces ONLY.
Add as many furnaces as needed.
CONFIGURATION:
Set turtle as a "Generic Inventory"
export coal to slot 2
import from slot 3
Use this turtle for machine crafting.
--]]
local Event = require('opus.event')
local Util = require('opus.util')
local device = _G.device
local fs = _G.fs
local os = _G.os
local peripheral = _G.peripheral
local turtle = _G.turtle
local STARTUP_FILE = 'usr/autorun/miloFurni.lua'
local SMELT_AMOUNT = 8
local INPUT_SLOT = 1
local FUEL_SLOT = 2
local OUTPUT_SLOT = 3
local function equip(side, item, rawName)
local equipped = peripheral.getType(side)
if equipped == item then
return true
end
if not turtle.equip(side, rawName or item) then
if not turtle.selectSlotWithQuantity(0) then
error('No slots available')
end
turtle.equip(side)
if not turtle.equip(side, item) then
error('Unable to equip ' .. item)
end
end
turtle.select(1)
end
equip('left', 'plethora:introspection', 'plethora:module:0')
local intro = device['plethora:introspection']
local inv = intro.getInventory()
if not fs.exists(STARTUP_FILE) then
Util.writeFile(STARTUP_FILE,
[[os.sleep(1)
shell.openForegroundTab('packages/milo/apps/furni')]])
end
local furnaces
local localName
print('detecting wired modem connected to furnaces...')
for _, dev in pairs(device) do
if dev.type == 'wired_modem' and dev.getNameLocal then
local list = dev.getNamesRemote()
furnaces = { }
localName = dev.getNameLocal()
for _, name in pairs(list) do
if device[name].type ~= 'minecraft:furnace' then
furnaces = nil
break
end
table.insert(furnaces, {
dev = device[name],
list = device[name].list(),
})
end
end
if furnaces then
print('Using wired modem: ' .. dev.name)
print('Furnaces: ' .. #furnaces)
break
end
end
if not furnaces then
error('Turtle must be connected to a second wired_modem connected to furnaces only')
end
_G.printError([[Program must be restarted if new furnaces are added.]])
local function getSlot(furnace, slotNo)
if not furnace.list[slotNo] then
furnace.list[slotNo] = {
count = 0
}
end
return furnace.list[slotNo]
end
local function process(list)
local inItem = list[INPUT_SLOT]
local inFuel = list[FUEL_SLOT]
local inReturn = list[OUTPUT_SLOT] or { count = 0 }
for _, furnace in ipairs(Util.shallowCopy(furnaces)) do
local s, m = pcall(function()
if furnace.list[INPUT_SLOT] and furnace.list[INPUT_SLOT].count > 0 then
furnace.list = furnace.dev.list()
print('listing ' .. furnace.dev.name)
end
-- items to cook
local cooking = getSlot(furnace, INPUT_SLOT)
if cooking.count < 64 and inItem and inItem.count > 0 then
if cooking.count == 0 or cooking.name == inItem.name then
print('cooking : ' .. furnace.dev.name)
local count = furnace.dev.pullItems(localName, INPUT_SLOT, SMELT_AMOUNT, INPUT_SLOT)
if count > 0 then
inItem.count = inItem.count - count
cooking.name = inItem.name
cooking.count = cooking.count + count
-- push to end of queue
Util.removeByValue(furnaces, furnace)
table.insert(furnaces, furnace)
end
end
end
-- fuel
local fuel = getSlot(furnace, FUEL_SLOT)
if fuel.count < 8 and inFuel and inFuel.count > 0 then
if fuel.count == 0 or fuel.name == inFuel.name then
print('fueling ' .. furnace.dev.name)
local count = furnace.dev.pullItems(localName, FUEL_SLOT, 8 - fuel.count, FUEL_SLOT)
if count > 0 then
inFuel.count = inFuel.count - count
fuel.name = inFuel.name
fuel.count = fuel.count + count
end
end
end
local result = getSlot(furnace, OUTPUT_SLOT)
if result.count > 0 then
if inReturn.count == 0 or result.name == inReturn.name then
print('pulling from : ' .. furnace.dev.name)
local count = furnace.dev.pushItems(localName, OUTPUT_SLOT, result.count, OUTPUT_SLOT)
if count > 0 then
result.count = result.count - count
if result.count == 0 then
furnace.list[OUTPUT_SLOT] = nil
end
inReturn.name = result.name
inReturn.count = inReturn.count + count
end
end
end
end)
if not s and m then
_G.printError(m)
end
end
end
Event.on('turtle_inventory', function()
process(inv.list())
print('idle')
end)
Event.onInterval(3, function()
os.queueEvent('turtle_inventory')
end)
os.queueEvent('turtle_inventory')
Event.pullEvents()

View File

@@ -0,0 +1,29 @@
--[[
For initially setting up large amounts of storage chests.
]]
local Util = require('opus.util')
local peripheral = _G.peripheral
local args = { ... }
local st = args[1] or error('Specify a storage type (ie. minecraft:chest)')
local config = { }
peripheral.find(st, function(n)
config[n] = {
name = n,
category = 'storage',
mtype = 'storage',
}
end)
print('Found ' .. Util.size(config))
if Util.size(config) == 0 then
error('Invalid peripheral type')
end
Util.writeTable('usr/config/storageGen', config)
print('storageGen file created in usr/config')
print('update /usr/config/storage with contents (or rename to storage)')

44
miloApps/apps/water.lua Normal file
View File

@@ -0,0 +1,44 @@
local Sound = require('opus.sound')
local Util = require('opus.util')
local fs = _G.fs
local os = _G.os
local turtle = _G.turtle
local STARTUP_FILE = 'usr/autorun/miloWater.lua'
if not fs.exists(STARTUP_FILE) then
Util.writeFile(STARTUP_FILE,
[[os.sleep(2)
shell.openForegroundTab('packages/milo/apps/water')]])
end
local played = false
local function play(sound)
if not played then
--played = true
Sound.play(sound)
end
end
while true do
if turtle.placeDown('minecraft:bucket:0') then
play('item.bucket.fill')
end
if turtle.placeDown('minecraft:glass_bottle:0') then
play('item.bottle.fill')
end
for k,v in pairs(turtle.getInventory()) do
if v.name == 'minecraft:concrete_powder' or v.name == 'minecraft:gravel' then
turtle.select(k)
play('block.gravel.break')
for _ = 1, v.count do
turtle.placeDown()
turtle.digDown()
end
end
end
os.pullEvent('turtle_inventory')
played = false
end