better turtle.equip
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
{
|
||||
required = {
|
||||
'core',
|
||||
'turtle',
|
||||
},
|
||||
title = 'Programs for farming resources',
|
||||
repository = 'kepler155c/opus-apps/{{OPUS_BRANCH}}/farms',
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
local Peripheral = require('peripheral')
|
||||
local Equipper = require('turtle.equipper')
|
||||
local Point = require('point')
|
||||
local Util = require('util')
|
||||
|
||||
@@ -18,34 +18,14 @@ local Runners = {
|
||||
Blaze = false,
|
||||
}
|
||||
|
||||
local function equip(side, item, rawName)
|
||||
local equipped = Peripheral.lookup('side/' .. side)
|
||||
Equipper.equipLeft('minecraft:diamond_sword')
|
||||
Equipper.equipRight('plethora:module:2', 'plethora:scanner')
|
||||
|
||||
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)
|
||||
end
|
||||
end
|
||||
|
||||
turtle.select(1)
|
||||
end
|
||||
|
||||
equip('left', 'minecraft:diamond_sword')
|
||||
|
||||
equip('right', 'plethora:scanner', 'plethora:module:2')
|
||||
local scanner = device['plethora:scanner']
|
||||
local facing = scanner.getBlockMeta(0, 0, 0).state.facing
|
||||
turtle.point.heading = Point.facings[facing].heading
|
||||
|
||||
equip('right', 'plethora:sensor', 'plethora:module:3')
|
||||
Equipper.equipRight('plethora:module:3', 'plethora:sensor')
|
||||
local sensor = device['plethora:sensor']
|
||||
|
||||
turtle.setMovementStrategy('goto')
|
||||
@@ -55,9 +35,9 @@ local function findChests()
|
||||
if chest then
|
||||
return { chest }
|
||||
end
|
||||
equip('right', 'plethora:scanner', 'plethora:module:2')
|
||||
Equipper.equipRight('plethora:module:2', 'plethora:scanner')
|
||||
local chests = scanner.scan()
|
||||
equip('right', 'plethora:sensor', 'plethora:module:3')
|
||||
Equipper.equipRight('plethora:module:3', 'plethora:sensor')
|
||||
|
||||
Util.filterInplace(chests, function(b)
|
||||
if b.name == 'minecraft:chest' or
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
local Equipper = require('turtle.equipper')
|
||||
local Point = require('point')
|
||||
local Util = require('util')
|
||||
|
||||
@@ -17,9 +18,8 @@ local FUEL = Util.transpose {
|
||||
'minecraft:blaze_rod:0',
|
||||
}
|
||||
|
||||
local scanner = device['plethora:scanner'] or
|
||||
turtle.equip('right', 'plethora:module:2') and device['plethora:scanner'] or
|
||||
error('Plethora scanner required')
|
||||
Equipper.equipRight('plethora:module:2', 'plethora:scanner')
|
||||
local scanner = device['plethora:scanner']
|
||||
|
||||
local crops = Util.readTable(CONFIG_FILE) or {
|
||||
['minecraft:wheat'] =
|
||||
@@ -126,7 +126,7 @@ local function scan()
|
||||
end
|
||||
|
||||
local function harvest(blocks)
|
||||
turtle.equip('right', 'minecraft:diamond_pickaxe')
|
||||
Equipper.equipRight('minecraft:diamond_pickaxe')
|
||||
|
||||
local dropped
|
||||
|
||||
@@ -185,11 +185,11 @@ local function harvest(blocks)
|
||||
|
||||
elseif b.action == 'bump' then
|
||||
if turtle.faceAgainst(b) then
|
||||
turtle.equip('right', 'plethora:module:3')
|
||||
Equipper.equipRight('plethora:module:3', 'plethora:sensor')
|
||||
os.sleep(.5)
|
||||
-- search the ground for the dropped cactus
|
||||
local sensed = peripheral.call('right', 'sense')
|
||||
turtle.equip('right', 'minecraft:diamond_pickaxe')
|
||||
Equipper.equipRight('minecraft:diamond_pickaxe')
|
||||
Util.filterInplace(sensed, function(s)
|
||||
if s.displayName == 'item.tile.cactus' then
|
||||
s.x = Util.round(s.x) + turtle.point.x
|
||||
@@ -217,7 +217,7 @@ local function harvest(blocks)
|
||||
end
|
||||
end
|
||||
end)
|
||||
turtle.equip('right', 'plethora:module:2')
|
||||
Equipper.equipRight('plethora:module:2', 'plethora:scanner')
|
||||
end
|
||||
|
||||
local s, m = turtle.run(function()
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
local Adapter = require('core.chestAdapter18')
|
||||
local Config = require('config')
|
||||
local Peripheral = require('peripheral')
|
||||
local Equipper = require('turtle.equipper')
|
||||
local Util = require('util')
|
||||
|
||||
local device = _G.device
|
||||
@@ -30,28 +30,8 @@ local ANIMALS = {
|
||||
|
||||
local animal = ANIMALS[config.animal]
|
||||
|
||||
local function equip(side, item, rawName)
|
||||
local equipped = Peripheral.lookup('side/' .. side)
|
||||
|
||||
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)
|
||||
end
|
||||
end
|
||||
|
||||
turtle.select(1)
|
||||
end
|
||||
|
||||
equip('left', 'minecraft:diamond_sword')
|
||||
equip('right', 'plethora:sensor', 'plethora:module:3')
|
||||
Equipper.equipLeft('minecraft:diamond_sword')
|
||||
Equipper.equipRight('plethora:module:3', 'plethora:sensor')
|
||||
|
||||
local sensor = device['plethora:sensor']
|
||||
|
||||
@@ -84,7 +64,7 @@ local function getAnimalCount()
|
||||
end
|
||||
|
||||
local function butcher()
|
||||
turtle.equip('right', 'minecraft:diamond_sword')
|
||||
Equipper.equipRight('minecraft:diamond_sword')
|
||||
turtle.select(1)
|
||||
|
||||
turtle.attack()
|
||||
@@ -92,7 +72,7 @@ local function butcher()
|
||||
turtle.turnRight()
|
||||
turtle.attack()
|
||||
end
|
||||
turtle.equip('right', 'plethora:module:3')
|
||||
Equipper.equipRight('plethora:module:3', 'plethora:sensor')
|
||||
|
||||
turtle.eachFilledSlot(function(slot)
|
||||
if not retain[slot.name] then
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
local Peripheral = require('peripheral')
|
||||
local Equipper = require('turtle.equipper')
|
||||
local Point = require('point')
|
||||
local Util = require('util')
|
||||
|
||||
@@ -11,29 +11,8 @@ local STARTUP_FILE = 'usr/autorun/spawner.lua'
|
||||
|
||||
local mobTypes = { }
|
||||
|
||||
local function equip(side, item, rawName)
|
||||
local equipped = Peripheral.lookup('side/' .. side)
|
||||
|
||||
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)
|
||||
end
|
||||
end
|
||||
|
||||
turtle.select(1)
|
||||
end
|
||||
|
||||
equip('left', 'minecraft:diamond_sword')
|
||||
|
||||
equip('right', 'plethora:scanner', 'plethora:module:2')
|
||||
Equipper.equipLeft('minecraft:diamond_sword')
|
||||
Equipper.equipRight('plethora:module:2', 'plethora:scanner')
|
||||
local scanner = device['plethora:scanner']
|
||||
|
||||
turtle.reset()
|
||||
@@ -51,7 +30,7 @@ Util.filterInplace(data, function(b)
|
||||
end)
|
||||
local chest = Point.closest(spawner, data) or error('missing drop off chest')
|
||||
|
||||
equip('right', 'plethora:sensor', 'plethora:module:3')
|
||||
Equipper.equipRight('plethora:module:3', 'plethora:sensor')
|
||||
local sensor = device['plethora:sensor']
|
||||
|
||||
if not fs.exists(STARTUP_FILE) then
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
local Equipper = require('turtle.equipper')
|
||||
local GPS = require('gps')
|
||||
local Point = require('point')
|
||||
local Util = require('util')
|
||||
@@ -469,7 +470,7 @@ local function makeKey(b)
|
||||
end
|
||||
|
||||
local function findDroppedSaplings()
|
||||
equip('left', 'plethora:sensor', SENSOR)
|
||||
Equipper.equipLeft(SENSOR, 'plethora:sensor')
|
||||
local raw = peripheral.call('left', 'sense')
|
||||
|
||||
local sensed = Util.reduce(raw, function(acc, b)
|
||||
@@ -490,7 +491,7 @@ end
|
||||
local function scan(pt, filter, blocks)
|
||||
turtle.pathfind(pt)
|
||||
|
||||
equip('left', 'plethora:scanner', SCANNER)
|
||||
Equipper.equipLeft(SCANNER, 'plethora:scanner')
|
||||
local raw = peripheral.call('left', 'scan')
|
||||
|
||||
return Util.reduce(raw, function(acc, b)
|
||||
@@ -595,7 +596,7 @@ local function fell()
|
||||
local pt = Util.shallowCopy(HOME_PT)
|
||||
while Util.any(blocks, function(b) return b.y > pt.y + 6 end) do
|
||||
-- tree might be above low scan range, do a scan higher up
|
||||
equip('left', PICKAXE)
|
||||
Equipper.equipLeft(PICKAXE)
|
||||
pt.y = pt.y + 8
|
||||
blocks = scan(pt, filter, blocks)
|
||||
end
|
||||
@@ -605,7 +606,7 @@ local function fell()
|
||||
-- add any locations that need saplings
|
||||
getPlantLocations(blocks)
|
||||
|
||||
equip('left', PICKAXE)
|
||||
Equipper.equipLeft(PICKAXE)
|
||||
if not Util.empty(blocks) then
|
||||
print('Chopping')
|
||||
|
||||
@@ -657,12 +658,12 @@ end
|
||||
local function findHome()
|
||||
local pt = GPS.getPoint(2) or error('GPS not found')
|
||||
|
||||
equip('left', SCANNER)
|
||||
Equipper.equipLeft(SCANNER, 'plethora:scanner')
|
||||
|
||||
local facing = peripheral.call('left', 'getBlockMeta', 0, 0, 0).state.facing
|
||||
pt.heading = Point.facings[facing].heading
|
||||
|
||||
equip('left', PICKAXE)
|
||||
Equipper.equipLeft(PICKAXE)
|
||||
|
||||
if not state.home then
|
||||
setState('home', pt)
|
||||
@@ -716,8 +717,8 @@ local function updateClock()
|
||||
end
|
||||
|
||||
local function startupCheck()
|
||||
equip('right', 'modem', MODEM)
|
||||
equip('left', PICKAXE)
|
||||
Equipper.equipRight(MODEM, 'modem')
|
||||
Equipper.equipLeft(PICKAXE)
|
||||
|
||||
local slots = turtle.getSummedInventory()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user