This commit is contained in:
kepler155c
2017-10-08 17:45:37 -04:00
parent bba7841c43
commit ed2d6eeef1
23 changed files with 222 additions and 207 deletions

View File

@@ -64,7 +64,7 @@ function blockDB:lookup(id, dmg)
if not id then
return
end
return self.data[id .. ':' .. dmg]
end
@@ -136,12 +136,12 @@ function placementDB:addSubsForBlockType(id, dmg, bt)
sub.extra)
end
end
function placementDB:add(id, dmg, sid, sdmg, direction, extra)
if direction and #direction == 0 then
direction = nil
end
local entry = {
oid = id, -- numeric ID
odmg = dmg, -- dmg with placement info
@@ -176,9 +176,9 @@ function blockTypeDB:addTemp(blockType, subs)
end
self.dirty = true
end
function blockTypeDB:load()
blockTypeDB:addTemp('stairs', {
{ 0, nil, 0, 'east-up' },
{ 1, nil, 0, 'west-up' },
@@ -575,7 +575,8 @@ function Blocks:init(args)
placementDB:load2(blockDB, blockTypeDB)
end
-- for an ID / dmg (with placement info) - return the correct block (without the placment info embedded in the dmg)
-- for an ID / dmg (with placement info)
-- return the correct block (without the placment info embedded in the dmg)
function Blocks:getPlaceableBlock(id, dmg)
local p = placementDB:get({id, dmg})

View File

@@ -13,7 +13,7 @@ local convertNames = {
displayName = 'display_name',
maxDamage = 'max_dmg',
}
local keys = {
local keys = {
'damage',
'displayName',
'maxCount',
@@ -31,7 +31,7 @@ local function safeString(text)
local newText = {}
for i = 4, #text do
local val = text:byte(i)
val = text:byte(i)
newText[i - 3] = (val > 31 and val < 127) and val or 63
end
return string.char(unpack(newText))
@@ -65,11 +65,11 @@ function ChestAdapter:init(args)
Util.merge(self, chest)
end
end
function ChestAdapter:isValid()
return not not self.getAllStacks
end
function ChestAdapter:refresh(throttle)
return self:listItems(throttle)
end
@@ -109,12 +109,11 @@ function ChestAdapter:getItemInfo(item)
local key = table.concat({ item.name, item.damage, item.nbtHash }, ':')
return self.cache[key]
end
function ChestAdapter:craft(id, dmg, qty)
return false
function ChestAdapter:craft()
end
function ChestAdapter:craftItems(items)
function ChestAdapter:craftItems()
end
function ChestAdapter:provide(item, qty, slot, direction)
@@ -144,7 +143,7 @@ end
function ChestAdapter:insert(slot, qty)
local s, m = pcall(function() self.pullItem(self.direction, slot, qty) end)
if not s and m then
sleep(1)
os.sleep(1)
pcall(function() self.pullItem(self.direction, slot, qty) end)
end
end

View File

@@ -5,7 +5,7 @@ local Peripheral = require('peripheral')
local ChestAdapter = class()
local keys = Util.transpose({
local keys = Util.transpose({
'damage',
'displayName',
'maxCount',
@@ -22,7 +22,7 @@ function ChestAdapter:init(args)
}
Util.merge(self, defaults)
Util.merge(self, args)
local chest = Peripheral.getBySide(self.wrapSide)
if not chest then
chest = Peripheral.getByMethod('list')
@@ -106,10 +106,10 @@ function ChestAdapter:getItemInfo(item)
return self.cache[key]
end
function ChestAdapter:craft(name, damage, qty)
function ChestAdapter:craft()
end
function ChestAdapter:craftItems(items)
function ChestAdapter:craftItems()
end
function ChestAdapter:provide(item, qty, slot, direction)

View File

@@ -3,7 +3,8 @@ local itemDB = require('itemDB')
local Peripheral = require('peripheral')
local Util = require('util')
local MEAdapter = class()
local os = _G.os
local peripheral = _G.peripheral
local convertNames = {
name = 'id',
@@ -13,7 +14,7 @@ local convertNames = {
displayName = 'display_name',
maxDamage = 'max_dmg',
}
local keys = {
local keys = {
'damage',
'displayName',
'maxCount',
@@ -31,7 +32,7 @@ local function safeString(text)
local newText = {}
for i = 4, #text do
local val = text:byte(i)
val = text:byte(i)
newText[i - 3] = (val > 31 and val < 127) and val or 63
end
return string.char(unpack(newText))
@@ -48,6 +49,8 @@ local function convertItem(item)
item.displayName = safeString(item.displayName)
end
local MEAdapter = class()
function MEAdapter:init(args)
local defaults = {
items = { },
@@ -72,7 +75,7 @@ function MEAdapter:init(args)
end
end
end
function MEAdapter:isValid()
return self.getAvailableItems and self.getAvailableItems()
end
@@ -102,9 +105,9 @@ function MEAdapter:listItems()
self:refresh()
return self.items
end
function MEAdapter:getItemInfo(item)
for key,i in pairs(self.items) do
for _,i in pairs(self.items) do
if item.name == i.name and item.damage == i.damage and item.nbtHash == i.nbtHash then
return i
end
@@ -123,7 +126,7 @@ function MEAdapter:isCPUAvailable()
end
end
return available
end
end
function MEAdapter:craft(item, count)
@@ -133,7 +136,7 @@ function MEAdapter:craft(item, count)
self:refresh()
local item = self:getItemInfo(item)
item = self:getItemInfo(item)
if item and item.is_craftable then
local cpus = self.getCraftingCPUs() or { }
@@ -186,8 +189,8 @@ end
function MEAdapter:isCrafting(item)
for _,v in pairs(self:getJobList()) do
if v.name == item.name and
v.damage == item.damage and
if v.name == item.name and
v.damage == item.damage and
v.nbtHash == item.nbtHash then
return true
end
@@ -220,7 +223,7 @@ function MEAdapter:provide(item, count, slot, direction)
return pcall(function()
while count > 0 do
local qty = math.min(count, 64)
local s, m = self.exportItem({
local s = self.exportItem({
id = item.name,
dmg = item.damage
}, direction or self.direction, qty, slot)
@@ -232,18 +235,14 @@ function MEAdapter:provide(item, count, slot, direction)
end
end)
end
function MEAdapter:insert(slot, count)
local s, m = pcall(function() self.pullItem(self.direction, slot, count) end)
if not s and m then
print('MEAdapter:pullItem')
print(m)
sleep(1)
os.sleep(1)
s, m = pcall(function() self.pullItem(self.direction, slot, count) end)
if not s and m then
print('MEAdapter:pullItem')
print(m)
read()
error(m)
end
end
end

View File

@@ -12,7 +12,7 @@ function nameDB:load()
end
for strId, block in pairs(blocks) do
local strId = 'minecraft:' .. strId
strId = 'minecraft:' .. strId
if type(block.name) == 'string' then
self.data[strId .. ':0'] = block.name
else

View File

@@ -5,7 +5,7 @@ local itemDB = require('itemDB')
local RefinedAdapter = class()
local keys = {
local keys = {
'damage',
'displayName',
'maxCount',
@@ -109,8 +109,8 @@ end
function RefinedAdapter:isCrafting(item)
for _,task in pairs(self.getCraftingTasks()) do
local output = task.getPattern().outputs[1]
if output.name == item.name and
output.damage == item.damage and
if output.name == item.name and
output.damage == item.damage and
output.nbtHash == item.nbtHash then
return true
end
@@ -125,18 +125,18 @@ function RefinedAdapter:craft(item, qty)
end
end
function RefinedAdapter:craftItems(items)
function RefinedAdapter:craftItems()
return false
end
function RefinedAdapter:provide(item, qty, slot)
function RefinedAdapter:provide()
end
function RefinedAdapter:extract(slot, qty)
function RefinedAdapter:extract()
-- self.pushItems(self.direction, slot, qty)
end
function RefinedAdapter:insert(slot, qty)
function RefinedAdapter:insert()
-- self.pullItems(self.direction, slot, qty)
end

View File

@@ -4,6 +4,11 @@ local DEFLATE = require('deflatelua')
local UI = require('ui')
local Point = require('point')
local bit = _G.bit
local fs = _G.fs
local term = _G.term
local turtle = _G.turtle
--[[
Loading and manipulating a schematic
--]]
@@ -24,7 +29,7 @@ end
--[[
Credit to Orwell for the schematic file reader code
http://www.computercraft.info/forums2/index.php?/topic/1949-turtle-schematic-file-builder/
Some parts of the file reader code was modified from the original
--]]
@@ -52,7 +57,7 @@ function Schematic:readname(h)
local c = h:readbyte(h)
if c == nil then
return
end
end
str = str .. string.char(c)
end
return str
@@ -218,11 +223,11 @@ function DiskFile:close()
end
local MemoryFile = class()
function MemoryFile:init(args)
function MemoryFile:init()
self.s = { }
self.i = 1
end
function MemoryFile:open(filename)
function MemoryFile:open()
self.i = 1
end
function MemoryFile:close() end
@@ -247,7 +252,7 @@ function Schematic:decompress(ifname, spinner)
local mh = MemoryFile()
DEFLATE.gunzip({
input=function(...) spinner:spin() return ifh.read() end,
input=function() spinner:spin() return ifh.read() end,
output=function(b) mh:write(b) end,
disable_crc=true
})
@@ -310,7 +315,7 @@ end
function Schematic:load(filename)
local cursorX, cursorY = term.getCursorPos()
local _, cursorY = term.getCursorPos()
local spinner = UI.Spinner({
x = UI.term.width,
y = cursorY - 1
@@ -757,7 +762,7 @@ function Schematic:determineBlockPlacement(y)
-- otherwise, the turtle must place the block from the same plane
-- against another block
-- if no block to place against (from side) then the turtle must place from
-- the other side
-- the other side
--
-- Stair bug in 1.7 - placing a stair southward doesn't respect the turtle's direction
-- all other directions are fine
@@ -843,8 +848,6 @@ end
-- set the order for block dependencies
function Schematic:setPlacementOrder(spinner, placementChains)
local cursorX, cursorY = term.getCursorPos()
-- optimize for overlapping check
for _,chain in pairs(placementChains) do
for index,_ in pairs(chain.keys) do
@@ -917,9 +920,9 @@ function Schematic:setPlacementOrder(spinner, placementChains)
]]--
local masterChain = table.remove(chains)
--[[ it's something like this:
A chain B chain result
1 1
2 -------- 2 2
@@ -1040,12 +1043,10 @@ v.info = 'Unplaceable'
end
term.clearLine()
return t
end
function Schematic:optimizeRoute(spinner, y)
local function getNearestNeighbor(p, pt, maxDistance)
local key, block, heading
local moves = maxDistance
@@ -1146,7 +1147,6 @@ function Schematic:optimizeRoute(spinner, y)
local maxDistance = self.width*self.length
local plane, doors = extractPlane(y)
spinner:spin(percent)
pt.index = 0
for i = 1, #plane do
local b = getNearestNeighbor(plane, pt, maxDistance)

View File

@@ -11,14 +11,14 @@ function TableDB:init(args)
Util.merge(defaults, args)
Util.merge(self, defaults)
end
function TableDB:load()
local t = Util.readTable(self.fileName)
if t then
self.data = t.data or t
end
end
function TableDB:add(key, entry)
if type(key) == 'table' then
key = table.concat(key, ':')
@@ -26,19 +26,19 @@ function TableDB:add(key, entry)
self.data[key] = entry
self.dirty = true
end
function TableDB:get(key)
if type(key) == 'table' then
key = table.concat(key, ':')
end
return self.data[key]
end
function TableDB:remove(key)
self.data[key] = nil
self.dirty = true
end
function TableDB:flush()
if self.dirty then
Util.writeTable(self.fileName, self.data)