scanner app improvements

This commit is contained in:
kepler155c
2018-10-19 19:34:29 -04:00
parent 51e73e1c98
commit 1290ca5486
3 changed files with 56 additions and 35 deletions

View File

@@ -5,7 +5,6 @@ local Util = require('util')
local device = _G.device local device = _G.device
local os = _G.os local os = _G.os
local term = _G.term
local turtle = _G.turtle local turtle = _G.turtle
local config = { local config = {
@@ -31,7 +30,6 @@ local function getCowCount()
end end
end) end)
term.clearLine()
Util.print('%d grown, %d babies', grown, babies) Util.print('%d grown, %d babies', grown, babies)
return #blocks return #blocks

View File

@@ -16,13 +16,17 @@ local scanner = device['plethora:scanner'] or
local crops = Util.readTable(CONFIG_FILE) or { local crops = Util.readTable(CONFIG_FILE) or {
['minecraft:wheat'] = ['minecraft:wheat'] =
{ seed = 'minecraft:wheat_seeds', mature = 7 }, { seed = 'minecraft:wheat_seeds', mature = 7, action = 'plant' },
['minecraft:carrots'] = ['minecraft:carrots'] =
{ seed = 'minecraft:carrot', mature = 7 }, { seed = 'minecraft:carrot', mature = 7, action = 'plant' },
['minecraft:potatoes'] = ['minecraft:potatoes'] =
{ seed = 'minecraft:potato', mature = 7 }, { seed = 'minecraft:potato', mature = 7, action = 'plant' },
['minecraft:beetroots'] = ['minecraft:beetroots'] =
{ seed = 'minecraft:beetroot_seeds', mature = 3 }, { seed = 'minecraft:beetroot_seeds', mature = 3, 'plant' },
['minecraft:reeds'] = { action = 'bash' },
['minecraft:melon_block'] = { action = 'smash' },
['minecraft:pumpkin'] = { action = 'smash' },
['minecraft:chest'] = { action = 'drop' },
} }
if not fs.exists(CONFIG_FILE) then if not fs.exists(CONFIG_FILE) then
@@ -31,21 +35,36 @@ end
local function scan() local function scan()
local blocks = scanner.scan() local blocks = scanner.scan()
local summed = turtle.getSummedInventory()
local doDropOff
for _,v in pairs(summed) do
if v.count > 48 then
doDropOff = true
break
end
end
Util.filterInplace(blocks, function(v) Util.filterInplace(blocks, function(v)
if v.name == 'minecraft:reeds' then v.action = crops[v.name] and crops[v.name].action
if v.action == 'bash' then
return v.y == 0 return v.y == 0
end end
if v.name == 'minecraft:chest' then if v.action == 'drop' then
return doDropOff and v.y == -1
end
if v.action == 'smash' then
return v.y == -1 return v.y == -1
end end
return crops[v.name] and return v.action == 'plant' and
scanner.getBlockMeta(v.x, v.y, v.z).metadata == crops[v.name].mature v.metadata == crops[v.name].mature and
v.y == -1
end) end)
local harvestCount = 0 local harvestCount = 0
for _,v in pairs(blocks) do for _,v in pairs(blocks) do
if v.name ~= 'minecraft:chest' then if v.action ~= 'drop' then
harvestCount = harvestCount + 1 harvestCount = harvestCount + 1
end end
end end
@@ -56,29 +75,31 @@ 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.setPoint({ x = 0, y = 0, z = 0, heading = turtle.point.heading })
turtle.select(1)
local dropped
Point.eachClosest(turtle.point, blocks, function(b) Point.eachClosest(turtle.point, blocks, function(b)
turtle.select(1) if b.action == 'bash' then
if b.name == 'minecraft:reeds' then turtle.digForwardAt(b)
turtle._goto(b) elseif b.action == 'drop' and not dropped then
elseif b.name == 'minecraft:chest' then
local summed = turtle.getSummedInventory()
for _,v in pairs(summed) do
if v.count > 48 then
if turtle._goto(Point.above(b)) then if turtle._goto(Point.above(b)) then
for k,v2 in pairs(summed) do local summed = turtle.getSummedInventory()
if v2.count > 16 then for k,v in pairs(summed) do
turtle.dropDown(k, v2.count - 16) if v.count > 16 then
turtle.dropDown(k, v.count - 16)
end end
end end
dropped = true
turtle.select(1)
end end
break elseif b.action == 'smash' then
end turtle.digDownAt(b)
end elseif b.action == 'plant' then
else if turtle.digDownAt(b) then
turtle._goto(Point.above(b))
turtle.digDown()
turtle.placeDown(crops[b.name].seed) turtle.placeDown(crops[b.name].seed)
turtle.select(1)
end
end end
end) end)
turtle.equip('right', 'plethora:module:2') turtle.equip('right', 'plethora:module:2')
@@ -89,6 +110,7 @@ turtle.run(function()
turtle.point.heading = Point.facings[facing].heading turtle.point.heading = Point.facings[facing].heading
turtle.setPolicy('digOnly') turtle.setPolicy('digOnly')
turtle.setMovementStrategy('goto')
repeat repeat
local blocks, harvestCount = scan() local blocks, harvestCount = scan()
if harvestCount > 0 then if harvestCount > 0 then

View File

@@ -522,15 +522,16 @@ end
local success, msg local success, msg
Event.addRoutine(function()
turtle.reset()
if not fs.exists(DICTIONARY_FILE) or options.setTrash.value then if not fs.exists(DICTIONARY_FILE) or options.setTrash.value then
print('Add blocks to ignore, press enter when ready') print('Place blocks into the turtles inventor to ignore, such as cobble, stone, gravel, etc.')
print('\nPress enter when ready')
read() read()
addTrash() addTrash()
end end
Event.addRoutine(function()
turtle.reset()
ejectTrash() ejectTrash()
turtle.initialize { turtle.initialize {