milo manipulator + crafting fixes

This commit is contained in:
kepler155c
2018-11-12 11:44:24 -05:00
parent 3f095ff522
commit 52ea4e039c
6 changed files with 63 additions and 43 deletions

View File

@@ -4,6 +4,7 @@ local Util = require('util')
local device = _G.device
local fs = _G.fs
local turtle = _G.turtle
local intro = device['plethora:introspection']
local Craft = {
STATUS_INFO = 'info',
@@ -16,20 +17,6 @@ local Craft = {
MACHINE_LOOKUP = 'usr/config/machine_crafting.db',
}
local function clearGrid(storage)
turtle.eachFilledSlot(function(slot)
storage:import(storage.localName, slot.index, slot.count, slot)
end)
for i = 1, 16 do
if turtle.getItemCount(i) ~= 0 then
return false
end
end
return true
end
local function splitKey(key)
local t = Util.split(key, '(.-):')
local item = { }
@@ -48,6 +35,27 @@ local function makeRecipeKey(item)
return table.concat({ item.name, item.damage or 0, item.nbtHash }, ':')
end
function Craft.clearGrid(storage)
turtle.eachFilledSlot(function(slot)
local item = slot
if intro then
item = intro.getInventory().getItemMeta(slot.index)
if not itemDB:get(item) then
itemDB:add(item)
end
end
storage:import(storage.localName, slot.index, slot.count, item)
end)
for i = 1, 16 do
if turtle.getItemCount(i) ~= 0 then
return false
end
end
return true
end
function Craft.getItemCount(items, item)
if type(item) == 'string' then
item = splitKey(item)
@@ -117,7 +125,7 @@ local function machineCraft(recipe, storage, machineName, request, count, item)
end
local function turtleCraft(recipe, storage, request, count)
if not clearGrid(storage) then
if not Craft.clearGrid(storage) then
request.status = 'grid in use'
request.statusCode = Craft.STATUS_ERROR
return
@@ -142,7 +150,7 @@ local function turtleCraft(recipe, storage, request, count)
request.status = 'Failed to craft'
request.statusCode = Craft.STATUS_ERROR
end
clearGrid(storage)
Craft.clearGrid(storage)
return request.statusCode == Craft.STATUS_SUCCESS
end