peripheral updates

This commit is contained in:
kepler155c@gmail.com
2018-12-25 02:33:14 -05:00
parent ffab2372de
commit 32a831862b
6 changed files with 28 additions and 84 deletions

View File

@@ -1,12 +1,12 @@
_G.requireInjector(_ENV) _G.requireInjector(_ENV)
local Peripheral = require('peripheral')
local Point = require('point') local Point = require('point')
local Util = require('util') local Util = require('util')
local device = _G.device local device = _G.device
local os = _G.os local os = _G.os
local turtle = _G.turtle local peripheral = _G.peripheral
local turtle = _G.turtle
local args = { ... } local args = { ... }
local mobType = args[1] or error('Syntax: attack <mob names>') local mobType = args[1] or error('Syntax: attack <mob names>')
@@ -21,23 +21,12 @@ local Runners = {
} }
local function equip(side, item, rawName) local function equip(side, item, rawName)
local equipped = Peripheral.lookup('side/' .. side) if peripheral.getType(side) ~= item then
if not turtle.equip(side, rawName or item) then
if equipped and equipped.type == 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) error('Unable to equip ' .. item)
end end
turtle.select(1)
end end
turtle.select(1)
end end
equip('left', 'minecraft:diamond_sword') equip('left', 'minecraft:diamond_sword')

View File

@@ -3,12 +3,12 @@ _G.requireInjector(_ENV)
local Config = require('config') local Config = require('config')
local Util = require('util') local Util = require('util')
local Adapter = require('chestAdapter18') local Adapter = require('chestAdapter18')
local Peripheral = require('peripheral')
local device = _G.device local device = _G.device
local fs = _G.fs local fs = _G.fs
local os = _G.os local os = _G.os
local turtle = _G.turtle local peripheral = _G.peripheral
local turtle = _G.turtle
local STARTUP_FILE = 'usr/autorun/rancher.lua' local STARTUP_FILE = 'usr/autorun/rancher.lua'
@@ -33,23 +33,12 @@ local ANIMALS = {
local animal = ANIMALS[config.animal] local animal = ANIMALS[config.animal]
local function equip(side, item, rawName) local function equip(side, item, rawName)
local equipped = Peripheral.lookup('side/' .. side) if peripheral.getType(side) ~= item then
if not turtle.equip(side, rawName or item) then
if equipped and equipped.type == 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) error('Unable to equip ' .. item)
end end
turtle.select(1)
end end
turtle.select(1)
end end
local function getLocalName() local function getLocalName()

View File

@@ -1,5 +1,4 @@
local GPS = require('gps') local GPS = require('gps')
local Peripheral = require('peripheral')
local Point = require('point') local Point = require('point')
local Util = require('util') local Util = require('util')
@@ -68,23 +67,12 @@ local state = Util.readTable('usr/config/superTreefarm') or {
local clock = os.clock() local clock = os.clock()
local function equip(side, item, rawName) local function equip(side, item, rawName)
local equipped = Peripheral.lookup('side/' .. side) if peripheral.getType(side) == item or turtle.equip(side, rawName or item) then
turtle.select(1)
if equipped and equipped.type == item then
return true return true
end end
if not turtle.equip(side, rawName or item) then error('Unable to equip ' .. (rawName or item))
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 ' .. (rawName or item))
end
end
turtle.select(1)
end end
local function inspect(fn) local function inspect(fn)
@@ -531,6 +519,7 @@ local function fellTrees(blocks)
turtle.digDownAt(pt) turtle.digDownAt(pt)
if pt.plant then if pt.plant then
turtle.placeDown(pt.plant) turtle.placeDown(pt.plant)
turtle.select(1)
end end
end end
else else

View File

@@ -18,34 +18,23 @@ Use this turtle for machine crafting.
_G.requireInjector(_ENV) _G.requireInjector(_ENV)
local Event = require('event') local Event = require('event')
local Peripheral = require('peripheral')
local Util = require('util') local Util = require('util')
local device = _G.device local device = _G.device
local fs = _G.fs local fs = _G.fs
local os = _G.os local os = _G.os
local peripheral = _G.peripheral
local turtle = _G.turtle local turtle = _G.turtle
local STARTUP_FILE = 'usr/autorun/miloFurni.lua' local STARTUP_FILE = 'usr/autorun/miloFurni.lua'
local function equip(side, item, rawName) local function equip(side, item, rawName)
local equipped = Peripheral.lookup('side/' .. side) if peripheral.getType(side) ~= item then
if not turtle.equip(side, rawName or item) then
if equipped and equipped.type == 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) error('Unable to equip ' .. item)
end end
turtle.select(1)
end end
turtle.select(1)
end end
equip('left', 'plethora:introspection', 'plethora:module:0') equip('left', 'plethora:introspection', 'plethora:module:0')

View File

@@ -1,5 +1,6 @@
local Craft = require('craft2') local Craft = require('craft2')
local Milo = require('milo') local Milo = require('milo')
local Sound = require('sound')
local Util = require('util') local Util = require('util')
local context = Milo:getContext() local context = Milo:getContext()
@@ -61,6 +62,7 @@ function craftTask:cycle()
if item.requested - item.crafted > 0 then if item.requested - item.crafted > 0 then
local recipe = Craft.findRecipe(key) local recipe = Craft.findRecipe(key)
if recipe then if recipe then
Sound.play('entity.experience_orb.pickup')
self:craft(recipe, item) self:craft(recipe, item)
if item.callback and item.crafted >= item.requested then if item.callback and item.crafted >= item.requested then
item.callback(item) -- invoke callback item.callback(item) -- invoke callback

View File

@@ -1,6 +1,5 @@
local Config = require('config') local Config = require('config')
local Event = require('event') local Event = require('event')
local Peripheral = require('peripheral')
local Project = require('neural.project') local Project = require('neural.project')
local UI = require('ui') local UI = require('ui')
local Util = require('util') local Util = require('util')
@@ -9,28 +8,15 @@ local device = _G.device
local peripheral = _G.peripheral local peripheral = _G.peripheral
local turtle = _G.turtle local turtle = _G.turtle
local function equip(side, item, rawName) local function equip(side, rawName)
if turtle then return turtle and turtle.equip(side, rawName) and peripheral.wrap(side)
local equipped = Peripheral.lookup('side/' .. side)
if equipped and equipped.type == item then
return equipped
end
if turtle.equip(side, rawName or item) then
equipped = Peripheral.lookup('side/' .. side)
end
turtle.select(1)
return equipped
end
end end
local ni = device.neuralInterface local ni = device.neuralInterface
local sensor = ni or local sensor = ni or
device['plethora:sensor'] or device['plethora:sensor'] or
peripheral.find('manipulator') or peripheral.find('manipulator') or
equip('left', 'pletora:sensor', 'plethora:module:3') equip('left', 'plethora:module:3')
if not sensor or not sensor.sense then if not sensor or not sensor.sense then
error('Plethora sensor must be equipped') error('Plethora sensor must be equipped')