autocrafting improvements

This commit is contained in:
kepler155c
2018-01-10 16:48:23 -05:00
parent d4cf76b8e8
commit f7893ab2fe
24 changed files with 1798 additions and 159 deletions

View File

@@ -1,5 +1,3 @@
local Util = require('util')
local Adapter = { }
function Adapter.wrap(args)
@@ -7,43 +5,46 @@ function Adapter.wrap(args)
--'refinedAdapter',
'chestAdapter18',
-- adapters for version 1.7
'meAdapter',
'chestAdapter',
}
if args and args.side and args.facing and not args.direction then
args = Util.shallowCopy(args)
local horz = { top = 'down', bottom = 'up' }
args.direction = horz[args.side]
if not args.direction then
local sides = {
front = 0,
back = 2,
right = 1,
left = 3,
}
-- pretty sure computer/turtle have sides reversed
local cards = {
east = 0,
south = 1,
west = 2,
north = 3,
}
local icards = {
[ 0 ] = 'west',
[ 1 ] = 'north',
[ 2 ] = 'east',
[ 3 ] = 'south',
}
args.direction = icards[(cards[args.facing] + sides[args.side]) % 4]
end
end
for _,adapterType in ipairs(adapters) do
local adapter = require(adapterType)(args)
if adapter:isValid() then
-- figure out which direction to push/pull items from an inventory
-- based on the side the inventory is attached and which way the
-- turtle/computer is facing
if args and args.facing and adapter.side and not adapter.direction then
local horz = { top = 'down', bottom = 'up' }
adapter.direction = horz[adapter.side]
if not adapter.direction then
local sides = {
front = 0,
right = 1,
back = 2,
left = 3,
}
-- pretty sure computer/turtle have sides reversed
local cards = {
east = 0,
south = 1,
west = 2,
north = 3,
}
local icards = {
[ 0 ] = 'west',
[ 1 ] = 'north',
[ 2 ] = 'east',
[ 3 ] = 'south',
}
adapter.direction = icards[(cards[args.facing] + sides[adapter.side]) % 4]
end
end
return adapter
end
end