app tweaks
This commit is contained in:
@@ -1,12 +1,13 @@
|
|||||||
_G.requireInjector(_ENV)
|
_G.requireInjector(_ENV)
|
||||||
|
|
||||||
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 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 CONFIG_FILE = 'usr/config/farm'
|
local CONFIG_FILE = 'usr/config/farm'
|
||||||
|
|
||||||
@@ -29,12 +30,25 @@ local crops = Util.readTable(CONFIG_FILE) or {
|
|||||||
['minecraft:melon_block'] = { action = 'smash' },
|
['minecraft:melon_block'] = { action = 'smash' },
|
||||||
['minecraft:pumpkin'] = { action = 'smash' },
|
['minecraft:pumpkin'] = { action = 'smash' },
|
||||||
['minecraft:chest'] = { action = 'drop' },
|
['minecraft:chest'] = { action = 'drop' },
|
||||||
|
['minecraft:cactus'] = { action = 'bump' },
|
||||||
}
|
}
|
||||||
|
|
||||||
if not fs.exists(CONFIG_FILE) then
|
if not fs.exists(CONFIG_FILE) then
|
||||||
Util.writeTable(CONFIG_FILE, crops)
|
Util.writeTable(CONFIG_FILE, crops)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local retain = Util.transpose {
|
||||||
|
"minecraft:diamond_pickaxe",
|
||||||
|
"plethora:module:2",
|
||||||
|
"plethora:module:3",
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, v in pairs(crops) do
|
||||||
|
if v.seed then
|
||||||
|
retain[v.seed] = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local function scan()
|
local function scan()
|
||||||
local blocks = scanner.scan()
|
local blocks = scanner.scan()
|
||||||
local summed = turtle.getSummedInventory()
|
local summed = turtle.getSummedInventory()
|
||||||
@@ -47,29 +61,35 @@ local function scan()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Util.filterInplace(blocks, function(v)
|
Util.filterInplace(blocks, function(b)
|
||||||
v.action = crops[v.name] and crops[v.name].action
|
b.action = crops[b.name] and crops[b.name].action
|
||||||
|
|
||||||
if v.action == 'bash' then
|
if b.action == 'bash' then
|
||||||
return v.y == 0
|
return b.y == 0
|
||||||
end
|
end
|
||||||
if v.action == 'drop' then
|
if b.action == 'drop' then
|
||||||
return doDropOff and v.y == -1
|
return doDropOff and b.y == -1
|
||||||
end
|
end
|
||||||
if v.action == 'smash' then
|
if b.action == 'smash' then
|
||||||
return v.y == -1
|
return b.y == -1
|
||||||
end
|
end
|
||||||
if v.action == 'pick' then
|
if b.action == 'pick' then
|
||||||
return v.y == 0 and v.state.age == 2
|
return b.y == 0 and b.state.age == 2
|
||||||
end
|
end
|
||||||
return v.action == 'plant' and
|
if b.action == 'bump' then
|
||||||
v.metadata == crops[v.name].mature and
|
return b.y == 0
|
||||||
v.y == -1
|
end
|
||||||
|
return b.action == 'plant' and
|
||||||
|
b.metadata == crops[b.name].mature and
|
||||||
|
b.y == -1
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local harvestCount = 0
|
local harvestCount = 0
|
||||||
for _,v in pairs(blocks) do
|
for _,b in pairs(blocks) do
|
||||||
if v.action ~= 'drop' then
|
b.x = b.x + turtle.point.x
|
||||||
|
b.y = b.y + turtle.point.y
|
||||||
|
b.z = b.z + turtle.point.z
|
||||||
|
if b.action ~= 'drop' then
|
||||||
harvestCount = harvestCount + 1
|
harvestCount = harvestCount + 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -79,7 +99,6 @@ end
|
|||||||
|
|
||||||
local function harvest(blocks)
|
local function harvest(blocks)
|
||||||
turtle.equip('right', 'minecraft:diamond_pickaxe')
|
turtle.equip('right', 'minecraft:diamond_pickaxe')
|
||||||
turtle.setPoint({ x = 0, y = 0, z = 0, heading = turtle.point.heading })
|
|
||||||
turtle.select(1)
|
turtle.select(1)
|
||||||
|
|
||||||
local dropped
|
local dropped
|
||||||
@@ -87,25 +106,58 @@ local function harvest(blocks)
|
|||||||
Point.eachClosest(turtle.point, blocks, function(b)
|
Point.eachClosest(turtle.point, blocks, function(b)
|
||||||
if b.action == 'bash' then
|
if b.action == 'bash' then
|
||||||
turtle.digForwardAt(b)
|
turtle.digForwardAt(b)
|
||||||
|
|
||||||
elseif b.action == 'drop' and not dropped then
|
elseif b.action == 'drop' and not dropped then
|
||||||
if turtle._goto(Point.above(b)) then
|
if turtle._goto(Point.above(b)) then
|
||||||
|
turtle.eachFilledSlot(function(slot)
|
||||||
|
if not retain[slot.name] and not retain[slot.key] then
|
||||||
|
turtle.select(slot.index)
|
||||||
|
turtle.dropDown()
|
||||||
|
end
|
||||||
|
end)
|
||||||
local summed = turtle.getSummedInventory()
|
local summed = turtle.getSummedInventory()
|
||||||
for k,v in pairs(summed) do
|
for k,v in pairs(summed) do
|
||||||
if v.count > 16 then
|
if v.count > 16 then
|
||||||
turtle.dropDown(k, v.count - 16)
|
turtle.dropDown(k, v.count - 16)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
dropped = true
|
dropped = true
|
||||||
turtle.condense()
|
turtle.condense()
|
||||||
turtle.select(1)
|
turtle.select(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
elseif b.action == 'smash' then
|
elseif b.action == 'smash' then
|
||||||
turtle.digDownAt(b)
|
turtle.digDownAt(b)
|
||||||
|
|
||||||
elseif b.action == 'plant' then
|
elseif b.action == 'plant' then
|
||||||
if turtle.digDownAt(b) then
|
if turtle.digDownAt(b) then
|
||||||
turtle.placeDown(crops[b.name].seed)
|
turtle.placeDown(crops[b.name].seed)
|
||||||
turtle.select(1)
|
turtle.select(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
elseif b.action == 'bump' then
|
||||||
|
if turtle.faceAgainst(b) then
|
||||||
|
turtle.equip('right', 'plethora:module:3')
|
||||||
|
local sensed = peripheral.call('right', 'sense')
|
||||||
|
turtle.equip('right', 'minecraft:diamond_pickaxe')
|
||||||
|
os.sleep(.25)
|
||||||
|
Util.filterInplace(sensed, function(s)
|
||||||
|
if s.displayName == 'item.tile.cactus' and Point.distance(b, s) < 6 then
|
||||||
|
s.ex = s.x
|
||||||
|
s.ez = s.z
|
||||||
|
s.x = Util.round(s.x) + turtle.point.x
|
||||||
|
s.z = Util.round(s.z) + turtle.point.z
|
||||||
|
s.y = -1
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
Point.eachClosest(turtle.point, sensed, function(s)
|
||||||
|
turtle.suckDownAt(s)
|
||||||
|
end)
|
||||||
|
turtle.select(1)
|
||||||
|
end
|
||||||
|
|
||||||
elseif b.action == 'pick' then
|
elseif b.action == 'pick' then
|
||||||
local h = Point.facings[b.state.facing].heading
|
local h = Point.facings[b.state.facing].heading
|
||||||
local hi = Point.headings[(h + 2) % 4] -- opposite heading
|
local hi = Point.headings[(h + 2) % 4] -- opposite heading
|
||||||
@@ -126,6 +178,8 @@ local s, m = turtle.run(function()
|
|||||||
local facing = scanner.getBlockMeta(0, 0, 0).state.facing
|
local facing = scanner.getBlockMeta(0, 0, 0).state.facing
|
||||||
turtle.point.heading = Point.facings[facing].heading
|
turtle.point.heading = Point.facings[facing].heading
|
||||||
|
|
||||||
|
print('Fuel: ' .. turtle.getFuelLevel())
|
||||||
|
|
||||||
--turtle.setPolicy('digOnly')
|
--turtle.setPolicy('digOnly')
|
||||||
turtle.setMovementStrategy('goto')
|
turtle.setMovementStrategy('goto')
|
||||||
repeat
|
repeat
|
||||||
|
|||||||
@@ -17,9 +17,9 @@ local retain = Util.transpose {
|
|||||||
}
|
}
|
||||||
local config = {
|
local config = {
|
||||||
animal = 'Cow',
|
animal = 'Cow',
|
||||||
max_cows = 15,
|
max_animals = 15,
|
||||||
}
|
}
|
||||||
Config.load('cows', config)
|
Config.load('rancher', config)
|
||||||
|
|
||||||
local sensor = device['plethora:sensor'] or
|
local sensor = device['plethora:sensor'] or
|
||||||
turtle.equip('right', 'plethora:module:3') and device['plethora:sensor'] or
|
turtle.equip('right', 'plethora:module:3') and device['plethora:sensor'] or
|
||||||
@@ -50,7 +50,7 @@ local function turnOnWater()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function getCowCount()
|
local function getAnimalCount()
|
||||||
local blocks = sensor.sense()
|
local blocks = sensor.sense()
|
||||||
|
|
||||||
local grown = 0
|
local grown = 0
|
||||||
@@ -114,8 +114,8 @@ local s, m = turtle.run(function()
|
|||||||
turnOffWater()
|
turnOffWater()
|
||||||
|
|
||||||
repeat
|
repeat
|
||||||
local cowCount, xpCount = getCowCount()
|
local animalCount, xpCount = getAnimalCount()
|
||||||
if cowCount > config.max_cows then
|
if animalCount > config.max_animals then
|
||||||
turtle.setStatus('Butchering')
|
turtle.setStatus('Butchering')
|
||||||
butcher()
|
butcher()
|
||||||
elseif turtle.getItemCount('minecraft:wheat') == 0 then
|
elseif turtle.getItemCount('minecraft:wheat') == 0 then
|
||||||
@@ -1,9 +1,12 @@
|
|||||||
|
_G.requireInjector(_ENV)
|
||||||
|
|
||||||
|
local device = _G.device
|
||||||
|
local multishell = _G.multishell
|
||||||
|
|
||||||
if not device.wireless_modem then
|
if not device.wireless_modem then
|
||||||
error('Wireless modem is required')
|
error('Wireless modem is required')
|
||||||
end
|
end
|
||||||
|
|
||||||
requireInjector(getfenv(1))
|
|
||||||
|
|
||||||
local Event = require('event')
|
local Event = require('event')
|
||||||
local GPS = require('gps')
|
local GPS = require('gps')
|
||||||
local Socket = require('socket')
|
local Socket = require('socket')
|
||||||
@@ -20,11 +23,10 @@ local mainPage = UI.Page({
|
|||||||
y = 2,
|
y = 2,
|
||||||
height = 8,
|
height = 8,
|
||||||
menuItems = {
|
menuItems = {
|
||||||
|
{ prompt = 'Add', event = 'add_location', help = 'Add a new location' },
|
||||||
{ prompt = 'Pickup', event = 'pickup', help = 'Pickup items from this location' },
|
{ prompt = 'Pickup', event = 'pickup', help = 'Pickup items from this location' },
|
||||||
{ prompt = 'Charge cell', event = 'charge', help = 'Recharge this cell' },
|
|
||||||
{ prompt = 'Refill', event = 'refill', help = 'Recharge this cell' },
|
{ prompt = 'Refill', event = 'refill', help = 'Recharge this cell' },
|
||||||
{ prompt = 'Set drop off location', event = 'setPickup', help = 'Recharge this cell' },
|
{ prompt = 'Set drop off location', event = 'setPickup', help = 'Recharge this cell' },
|
||||||
{ prompt = 'Set recharge location', event = 'setRecharge', help = 'Recharge this cell' },
|
|
||||||
{ prompt = 'Clear', event = 'clear', help = 'Remove this location' },
|
{ prompt = 'Clear', event = 'clear', help = 'Remove this location' },
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
@@ -203,7 +205,6 @@ function mainPage:eventHandler(event)
|
|||||||
end
|
end
|
||||||
|
|
||||||
elseif event.type == 'pickup' or event.type == 'setPickup' or
|
elseif event.type == 'pickup' or event.type == 'setPickup' or
|
||||||
event.type == 'setRecharge' or event.type == 'charge' or
|
|
||||||
event.type == 'clear' then
|
event.type == 'clear' then
|
||||||
local pt = getPoint()
|
local pt = getPoint()
|
||||||
if pt then
|
if pt then
|
||||||
|
|||||||
Reference in New Issue
Block a user