mirror of
https://github.com/kepler155c/opus
synced 2025-01-12 08:40:26 +00:00
builder improvements
This commit is contained in:
parent
71cbf34ade
commit
3f66a9397c
@ -347,7 +347,7 @@ function standardBlockDB:seedDB()
|
||||
[ '163:0' ] = 'stairs',
|
||||
[ '164:0' ] = 'stairs',
|
||||
[ '167:0' ] = 'trapdoor',
|
||||
[ '170:0' ] = 'flatten',
|
||||
[ '170:0' ] = 'quartz-pillar', -- hay bale
|
||||
[ '175:0' ] = 'largeplant',
|
||||
[ '175:1' ] = 'largeplant',
|
||||
[ '175:2' ] = 'largeplant', -- double tallgrass - an alternative would be to use grass as the bottom part, bonemeal as top part
|
||||
|
@ -29,6 +29,7 @@ function ChestProvider:refresh()
|
||||
entry = self.cache[key]
|
||||
if not entry then
|
||||
local meta = self.p.getItemMeta(k) -- slow method.. cache for speed
|
||||
if meta then
|
||||
entry = {
|
||||
id = s.name,
|
||||
dmg = s.damage,
|
||||
@ -37,14 +38,18 @@ function ChestProvider:refresh()
|
||||
}
|
||||
self.cache[key] = entry
|
||||
end
|
||||
end
|
||||
if entry then
|
||||
entry = Util.shallowCopy(entry)
|
||||
self.items[key] = entry
|
||||
entry.qty = 0
|
||||
end
|
||||
|
||||
end
|
||||
if entry then
|
||||
entry.qty = entry.qty + s.count
|
||||
end
|
||||
end
|
||||
end
|
||||
return self.items
|
||||
end
|
||||
|
||||
|
@ -1,8 +1,6 @@
|
||||
local class = require('class')
|
||||
local DEFLATE = require('deflatelua')
|
||||
local UI = require('ui')
|
||||
local Logger = require('logger')
|
||||
local Profile = require('profile')
|
||||
local Point = require('point')
|
||||
|
||||
--[[
|
||||
@ -17,7 +15,6 @@ function Schematic:init(args)
|
||||
self.blocks = { }
|
||||
self.damages = { }
|
||||
self.originalBlocks = { }
|
||||
self.placementChains = { }
|
||||
self.x, self.y, self.z = 0, 0, 0
|
||||
self.height = 0
|
||||
self.index = 1
|
||||
@ -152,7 +149,6 @@ end
|
||||
-- end http://www.computercraft.info/forums2/index.php?/topic/1949-turtle-schematic-file-builder/
|
||||
|
||||
function Schematic:copyBlocks(iblocks, oblocks, spinner)
|
||||
Profile.start('copyBlocks')
|
||||
for k,b in ipairs(iblocks) do
|
||||
oblocks[k] = Util.shallowCopy(b)
|
||||
if spinner then
|
||||
@ -161,24 +157,15 @@ function Schematic:copyBlocks(iblocks, oblocks, spinner)
|
||||
end
|
||||
end
|
||||
end
|
||||
Profile.stop('copyBlocks')
|
||||
end
|
||||
|
||||
function Schematic:reload()
|
||||
self.placementChains = {}
|
||||
self.blocks = { }
|
||||
self:copyBlocks(self.originalBlocks, self.blocks)
|
||||
--[[
|
||||
self.planes = { }
|
||||
for i = 0, self.height - 1 do
|
||||
self.planes[i] = { }
|
||||
|
||||
for _,ri in pairs(self.rowIndex) do
|
||||
ri.loaded = false
|
||||
end
|
||||
for k,b in ipairs(self.blocks) do
|
||||
if not self.planes[b.y].start then
|
||||
self.planes[b.y].start = k
|
||||
end
|
||||
end
|
||||
--]]
|
||||
end
|
||||
|
||||
function Schematic:getMagic(fh)
|
||||
@ -253,8 +240,6 @@ end
|
||||
|
||||
function Schematic:decompress(ifname, spinner)
|
||||
|
||||
Profile.start('decompress')
|
||||
|
||||
local ifh = fs.open(ifname, "rb")
|
||||
if not ifh then
|
||||
error('Unable to open ' .. ifname)
|
||||
@ -271,15 +256,12 @@ function Schematic:decompress(ifname, spinner)
|
||||
ifh.close()
|
||||
|
||||
spinner:stop()
|
||||
Profile.stop('decompress')
|
||||
|
||||
return mh
|
||||
end
|
||||
|
||||
function Schematic:loadpass(fh, spinner)
|
||||
|
||||
Profile.start('load')
|
||||
|
||||
fh:open()
|
||||
|
||||
while true do
|
||||
@ -297,13 +279,11 @@ function Schematic:loadpass(fh, spinner)
|
||||
end
|
||||
|
||||
fh:close()
|
||||
Profile.stop('load')
|
||||
|
||||
self:assignDamages(spinner)
|
||||
self.damages = nil
|
||||
|
||||
self:copyBlocks(self.blocks, self.originalBlocks, spinner)
|
||||
Profile.display()
|
||||
|
||||
spinner:stop()
|
||||
end
|
||||
@ -335,28 +315,6 @@ function Schematic:load(filename)
|
||||
|
||||
self:checkFileType(f)
|
||||
|
||||
--[[
|
||||
local size = fs.getSize(filename)
|
||||
|
||||
local buffer = {
|
||||
h = h,
|
||||
i = 1,
|
||||
s = { },
|
||||
l = size,
|
||||
}
|
||||
|
||||
for i = 1,size do
|
||||
buffer.s[i] = h.read()
|
||||
end
|
||||
|
||||
function buffer:readbyte()
|
||||
--return self.h.read()
|
||||
local b = self.s[self.i]
|
||||
self.i = self.i + 1
|
||||
return b
|
||||
end
|
||||
]]--
|
||||
|
||||
print('Initial pass ')
|
||||
self:loadpass(f, spinner)
|
||||
|
||||
@ -365,7 +323,6 @@ function Schematic:load(filename)
|
||||
self.blocks = { }
|
||||
self.damages = { }
|
||||
self.originalBlocks = { }
|
||||
self.placementChains = { }
|
||||
self.x, self.y, self.z = 0, 0, 0
|
||||
self.height = 0
|
||||
self.index = 1
|
||||
@ -373,6 +330,18 @@ function Schematic:load(filename)
|
||||
print('Second pass ')
|
||||
self:loadpass(f, spinner)
|
||||
end
|
||||
|
||||
self.rowIndex = { }
|
||||
for k,b in ipairs(self.blocks) do
|
||||
local ri = self.rowIndex[b.y]
|
||||
if not ri then
|
||||
self.rowIndex[b.y] = { s = k, e = k }
|
||||
else
|
||||
ri.e = k
|
||||
end
|
||||
end
|
||||
|
||||
self.cache = Util.readTable('usr/builder/' .. self.filename .. '.cache') or { }
|
||||
end
|
||||
|
||||
function Schematic:assignCoord(i, id)
|
||||
@ -402,11 +371,9 @@ function Schematic:assignCoord(i, id)
|
||||
end
|
||||
|
||||
function Schematic:assignDamages(spinner)
|
||||
local i = 0
|
||||
|
||||
Profile.start('assignDamages')
|
||||
print('Assigning damages')
|
||||
|
||||
local i = 0
|
||||
for _,b in pairs(self.blocks) do
|
||||
b.dmg = self.damages[b.index] or 0
|
||||
i = i + 1
|
||||
@ -414,7 +381,6 @@ function Schematic:assignDamages(spinner)
|
||||
spinner:spin()
|
||||
end
|
||||
end
|
||||
Profile.stop('assignDamages')
|
||||
end
|
||||
|
||||
function Schematic:findIndexAt(x, z, y)
|
||||
@ -446,7 +412,7 @@ function Schematic:findBlockAtSide(b, side)
|
||||
end
|
||||
end
|
||||
|
||||
function Schematic:addPlacementChain(chain)
|
||||
function Schematic:addPlacementChain(chains, chain)
|
||||
local t = { }
|
||||
for _,v in ipairs(chain) do
|
||||
local k = self:findIndexAt(v.x, v.z, v.y)
|
||||
@ -461,14 +427,14 @@ function Schematic:addPlacementChain(chain)
|
||||
for _,b in pairs(t) do
|
||||
keys[b.index] = true
|
||||
end
|
||||
table.insert(self.placementChains, {
|
||||
table.insert(chains, {
|
||||
blocks = t,
|
||||
keys = keys
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
function Schematic:bestSide(b, ...)
|
||||
function Schematic:bestSide(b, chains, ...)
|
||||
local directions = { ... }
|
||||
local blocks = { }
|
||||
|
||||
@ -516,13 +482,13 @@ function Schematic:bestSide(b, ...)
|
||||
local hi = bestBlock.hi
|
||||
b.heading = hi.heading -- ?????????????????????????????????
|
||||
b.direction = bestBlock.d .. '-block'
|
||||
self:addPlacementChain({
|
||||
self:addPlacementChain(chains, {
|
||||
{ x = b.x, z = b.z, y = b.y },
|
||||
{ x = b.x - hi.xd, z = b.z - hi.zd, y = b.y }
|
||||
})
|
||||
end
|
||||
|
||||
function Schematic:bestOfTwoSides(b, side1, side2) -- could be better
|
||||
function Schematic:bestOfTwoSides(b, chains, side1, side2) -- could be better
|
||||
|
||||
local sb
|
||||
local fb = b -- first block
|
||||
@ -567,7 +533,7 @@ function Schematic:bestOfTwoSides(b, side1, side2) -- could be better
|
||||
b = self:findBlockAtSide(b, side2)
|
||||
end
|
||||
|
||||
self:addPlacementChain(pc)
|
||||
self:addPlacementChain(chains, pc)
|
||||
end
|
||||
|
||||
-- can we place the first block from the side (instead of using piston) ?
|
||||
@ -601,10 +567,12 @@ function Schematic:bestOfTwoSides(b, side1, side2) -- could be better
|
||||
end
|
||||
|
||||
-- Determine the best way to place each block
|
||||
function Schematic:determineBlockPlacement(row)
|
||||
function Schematic:determineBlockPlacement(y)
|
||||
|
||||
-- NOTE: blocks are evaluated top to bottom
|
||||
|
||||
print('Processing level ' .. y)
|
||||
|
||||
local spinner = UI.Spinner({
|
||||
x = 1,
|
||||
spinSymbols = { 'o.....', '.o....', '..o...', '...o..', '....o.', '.....o' }
|
||||
@ -652,18 +620,11 @@ function Schematic:determineBlockPlacement(row)
|
||||
|
||||
local dirtyBlocks = {}
|
||||
local dirtyBlocks2 = {}
|
||||
local chains = {}
|
||||
|
||||
self.rowIndex = { }
|
||||
for k,b in ipairs(self.blocks) do
|
||||
local ri = self.rowIndex[b.y]
|
||||
if not ri then
|
||||
self.rowIndex[b.y] = { s = k, e = k }
|
||||
else
|
||||
ri.e = k
|
||||
end
|
||||
end
|
||||
|
||||
for k,b in ipairs(self.blocks) do
|
||||
local ri = self.rowIndex[y]
|
||||
for k = ri.s, ri.e do
|
||||
local b = self.blocks[k]
|
||||
local d = b.direction
|
||||
|
||||
if d then
|
||||
@ -735,7 +696,7 @@ function Schematic:determineBlockPlacement(row)
|
||||
b.heading = hi.heading
|
||||
b.twoHigh = true
|
||||
|
||||
self:addPlacementChain({
|
||||
self:addPlacementChain(chains, {
|
||||
{ x = b.x, z = b.z, y = b.y },
|
||||
{ x = b.x - hi.xd, z = b.z - hi.zd, y = b.y },
|
||||
})
|
||||
@ -761,7 +722,7 @@ function Schematic:determineBlockPlacement(row)
|
||||
-- no block below, place from side
|
||||
|
||||
-- took care of all other cases above
|
||||
self:bestSide(b, 'east', 'south', 'west', 'north')
|
||||
self:bestSide(b, chains, 'east', 'south', 'west', 'north')
|
||||
|
||||
-- elseif not db.direction or db.direction ~= 'bottom' then
|
||||
-- not a slab below, ok to place from above
|
||||
@ -802,7 +763,7 @@ function Schematic:determineBlockPlacement(row)
|
||||
-- placing a block from the side
|
||||
local hi = turtle.getHeadingInfo(blockDirections[d])
|
||||
b.heading = hi.heading
|
||||
self:addPlacementChain({
|
||||
self:addPlacementChain(chains, {
|
||||
{ x = b.x + hi.xd, z = b.z + hi.zd, y = b.y }, -- block we are placing against
|
||||
{ x = b.x, z = b.z, y = b.y }, -- the block (or torch, etc)
|
||||
{ x = b.x - hi.xd, z = b.z - hi.zd, y = b.y } -- room for the turtle
|
||||
@ -818,26 +779,50 @@ function Schematic:determineBlockPlacement(row)
|
||||
spinner:spin(#dirtyBlocks2 .. ' blocks remaining ')
|
||||
|
||||
if d == 'east-west-block' then
|
||||
self:bestOfTwoSides(b, 'east', 'west')
|
||||
self:bestOfTwoSides(b, chains, 'east', 'west')
|
||||
elseif d == 'north-south-block' then
|
||||
self:bestOfTwoSides(b, 'north', 'south')
|
||||
self:bestOfTwoSides(b, chains, 'north', 'south')
|
||||
end
|
||||
end
|
||||
|
||||
spinner:stop()
|
||||
term.clearLine()
|
||||
|
||||
self:setPlacementOrder(spinner, chains)
|
||||
local plane = self:optimizeRoute(spinner, y)
|
||||
|
||||
spinner:stop()
|
||||
|
||||
for k,b in ipairs(plane) do
|
||||
self.blocks[ri.s + k - 1] = b
|
||||
end
|
||||
end
|
||||
|
||||
function Schematic:getComputedBlock(i)
|
||||
local b = self.blocks[i]
|
||||
|
||||
-- has this level been computed ?
|
||||
if not self.rowIndex[b.y].loaded then
|
||||
-- compute each level up til this one (unless saved in cache)
|
||||
for y = 0, b.y - 1 do
|
||||
if not self.cache[y] then
|
||||
self:determineBlockPlacement(y)
|
||||
end
|
||||
end
|
||||
self:determineBlockPlacement(b.y)
|
||||
-- get the block now at the computed location
|
||||
b = self.blocks[i]
|
||||
end
|
||||
|
||||
return b
|
||||
end
|
||||
|
||||
-- set the order for block dependencies
|
||||
function Schematic:setPlacementOrder()
|
||||
local cursorX, cursorY = term.getCursorPos()
|
||||
local spinner = UI.Spinner({
|
||||
x = 1
|
||||
})
|
||||
function Schematic:setPlacementOrder(spinner, placementChains)
|
||||
|
||||
local cursorX, cursorY = term.getCursorPos()
|
||||
|
||||
Profile.start('overlapping')
|
||||
-- optimize for overlapping check
|
||||
for _,chain in pairs(self.placementChains) do
|
||||
for _,chain in pairs(placementChains) do
|
||||
for index,_ in pairs(chain.keys) do
|
||||
if not chain.startRow or (index < chain.startRow) then
|
||||
chain.startRow = index
|
||||
@ -881,15 +866,14 @@ function Schematic:setPlacementOrder()
|
||||
|
||||
-- group together any placement chains with overlapping blocks
|
||||
local groupedChains = {}
|
||||
while #self.placementChains > 0 do
|
||||
while #placementChains > 0 do
|
||||
local groupedChain = {}
|
||||
local chain = table.remove(self.placementChains)
|
||||
local chain = table.remove(placementChains)
|
||||
table.insert(groupedChain, chain)
|
||||
table.insert(groupedChains, groupedChain)
|
||||
groupOverlappingChains(self.placementChains, groupedChain, chain, spinner)
|
||||
spinner:spin('chains: ' .. #groupedChains .. ' ' .. #self.placementChains .. ' ')
|
||||
groupOverlappingChains(placementChains, groupedChain, chain, spinner)
|
||||
spinner:spin('chains: ' .. #groupedChains .. ' ' .. #placementChains .. ' ')
|
||||
end
|
||||
Profile.stop('overlapping')
|
||||
|
||||
--Logger.log('schematic', 'groups: ' .. #groupedChains)
|
||||
--Logger.setFileLogging('chains')
|
||||
@ -985,13 +969,11 @@ function Schematic:setPlacementOrder()
|
||||
end
|
||||
|
||||
-- combine the individual overlapping placement chains into 1 long master chain
|
||||
Profile.start('masterchains')
|
||||
local masterChains = {}
|
||||
for _,group in pairs(groupedChains) do
|
||||
spinner:spin('chains: ' .. #masterChains)
|
||||
table.insert(masterChains, mergeChains(group))
|
||||
end
|
||||
Profile.stop('masterchains')
|
||||
|
||||
local function removeDuplicates(chain)
|
||||
for k,v in ipairs(chain) do
|
||||
@ -1006,7 +988,6 @@ v.info = 'Unplaceable'
|
||||
|
||||
-- any chains with duplicates cannot be placed correctly
|
||||
-- there are some cases where a turtle cannot place blocks the same as a player
|
||||
Profile.start('duplicates')
|
||||
for _,chain in pairs(masterChains) do
|
||||
removeDuplicates(chain.blocks)
|
||||
spinner:spin('chains: ' .. #masterChains)
|
||||
@ -1020,52 +1001,26 @@ v.info = 'Unplaceable'
|
||||
--]]
|
||||
|
||||
end
|
||||
Profile.stop('duplicates')
|
||||
term.clearLine()
|
||||
|
||||
-- adjust row indices as blocks are being moved
|
||||
Profile.start('reordering')
|
||||
-- set dependent blocks for optimize routine
|
||||
for k,chain in pairs(masterChains) do
|
||||
spinner:spin('chains: ' .. #masterChains - k)
|
||||
|
||||
local startBlock = table.remove(chain.blocks, 1)
|
||||
startBlock.movedBlocks = chain.blocks
|
||||
|
||||
for _,b in pairs(chain.blocks) do
|
||||
b.moved = true
|
||||
local prev
|
||||
for k,b in ipairs(chain.blocks) do
|
||||
b.prev = prev
|
||||
b.next = chain.blocks[k + 1]
|
||||
prev = b
|
||||
end
|
||||
end
|
||||
|
||||
local t = { }
|
||||
for k,b in ipairs(self.blocks) do
|
||||
|
||||
-- adjust y so the turtle travels above the two high blocks
|
||||
if b.twoHigh then
|
||||
b.y = b.y + 1
|
||||
end
|
||||
|
||||
spinner:spin('blocks: ' .. #self.blocks - k .. ' ')
|
||||
if not b.moved then
|
||||
table.insert(t, b)
|
||||
end
|
||||
if b.movedBlocks then
|
||||
for _,mb in ipairs(b.movedBlocks) do
|
||||
table.insert(t, mb)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
self.blocks = t
|
||||
|
||||
Profile.stop('reordering')
|
||||
|
||||
--Logger.setWirelessLogging()
|
||||
|
||||
term.clearLine()
|
||||
spinner:stop()
|
||||
|
||||
return t
|
||||
end
|
||||
|
||||
function Schematic:optimizeRoute()
|
||||
function Schematic:optimizeRoute(spinner, y)
|
||||
|
||||
local function getNearestNeighbor(p, pt, maxDistance)
|
||||
local key, block, heading
|
||||
@ -1086,13 +1041,23 @@ function Schematic:optimizeRoute()
|
||||
end
|
||||
end
|
||||
|
||||
local function blockReady(b)
|
||||
if b.u then
|
||||
return false
|
||||
end
|
||||
if b.prev and not b.prev.u then
|
||||
return false
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
local mid = pt.index
|
||||
local forward = mid + 1
|
||||
local backward = mid - 1
|
||||
while forward <= #p or backward > 0 do
|
||||
if forward <= #p then
|
||||
local b = p[forward]
|
||||
if not b.u then
|
||||
if blockReady(b) then
|
||||
getMoves(b, forward)
|
||||
if moves <= 1 then
|
||||
break
|
||||
@ -1105,7 +1070,7 @@ function Schematic:optimizeRoute()
|
||||
end
|
||||
if backward > 0 then
|
||||
local b = p[backward]
|
||||
if not b.u then
|
||||
if blockReady(b) then
|
||||
getMoves(b, backward)
|
||||
if moves <= 1 then
|
||||
break
|
||||
@ -1126,53 +1091,61 @@ function Schematic:optimizeRoute()
|
||||
return block
|
||||
end
|
||||
|
||||
local pt = { x = -1, z = -1, y = 0, heading = 0 }
|
||||
local pt = Util.shallowCopy(self.cache[y - 1] or turtle.point)
|
||||
local t = {}
|
||||
local cursorX, cursorY = term.getCursorPos()
|
||||
local spinner = UI.Spinner({
|
||||
x = 0,
|
||||
y = cursorY
|
||||
})
|
||||
local ri = self.rowIndex[y]
|
||||
local blockCount = ri.e - ri.s + 1
|
||||
|
||||
local function extractPlane(y)
|
||||
local function extractPlane()
|
||||
local t = {}
|
||||
local dt = {}
|
||||
for _, b in pairs(self.blocks) do
|
||||
if b.y == y then
|
||||
for i = ri.s, ri.e do
|
||||
local b = self.blocks[i]
|
||||
if b.twoHigh then
|
||||
b.last = true
|
||||
while b.next do
|
||||
b = b.next
|
||||
b.last = true
|
||||
end
|
||||
end
|
||||
end
|
||||
for i = ri.s, ri.e do
|
||||
local b = self.blocks[i]
|
||||
if b.last then
|
||||
table.insert(dt, b)
|
||||
else
|
||||
table.insert(t, b)
|
||||
end
|
||||
end
|
||||
end
|
||||
return t, dt
|
||||
end
|
||||
|
||||
local maxDistance = self.width*self.length
|
||||
Profile.start('optimize')
|
||||
for y = 0, self.height do
|
||||
local percent = math.floor(#t * 100 / #self.blocks) .. '%'
|
||||
spinner:spin(percent)
|
||||
local plane, doors = extractPlane(y)
|
||||
spinner:spin(percent)
|
||||
pt.index = 0
|
||||
for i = 1, #plane do
|
||||
local b = getNearestNeighbor(plane, pt, maxDistance)
|
||||
table.insert(t, b)
|
||||
spinner:spin(percent .. ' ' .. #plane - i .. ' ')
|
||||
local percent = math.floor(#t * 100 / blockCount) .. '%'
|
||||
spinner:spin(percent .. ' ' .. blockCount - i .. ' ')
|
||||
end
|
||||
-- all two high blocks are placed last on each plane
|
||||
pt.index = 0
|
||||
for i = 1, #doors do
|
||||
local b = getNearestNeighbor(doors, pt, maxDistance)
|
||||
table.insert(t, b)
|
||||
spinner:spin(percent .. ' ' .. #doors - i .. ' ')
|
||||
end
|
||||
local percent = math.floor(#t * 100 / blockCount) .. '%'
|
||||
spinner:spin(percent .. ' ' .. blockCount - #plane - i .. ' ')
|
||||
end
|
||||
|
||||
Profile.stop('optimize')
|
||||
self.blocks = t
|
||||
spinner:stop(' ')
|
||||
self.rowIndex[y].loaded = true
|
||||
if not self.cache[y] then
|
||||
self.cache[y] = Util.shallowCopy(pt)
|
||||
Util.writeTable('usr/builder/' .. self.filename .. '.cache', self.cache)
|
||||
end
|
||||
|
||||
return t
|
||||
end
|
||||
|
||||
return Schematic
|
||||
|
@ -9,7 +9,6 @@ local Message = require('message')
|
||||
local Logger = require('logger')
|
||||
local UI = require('ui')
|
||||
local Schematic = require('schematic')
|
||||
local Profile = require('profile')
|
||||
local TableDB = require('tableDB')
|
||||
local MEProvider = require('meProvider')
|
||||
local Blocks = require('blocks')
|
||||
@ -520,7 +519,7 @@ function Builder:getGenericSupplyList(blockIndex)
|
||||
local lastBlock = blockIndex
|
||||
for k = blockIndex, #schematic.blocks do
|
||||
lastBlock = k
|
||||
local b = schematic.blocks[k]
|
||||
local b = schematic:getComputedBlock(k)
|
||||
|
||||
if b.id ~= 'minecraft:air' then
|
||||
local slot = getSlot(b.id, b.dmg)
|
||||
@ -1164,16 +1163,8 @@ function Builder:placeDirectionalBlock(b, slot, travelPlane)
|
||||
}
|
||||
if doorDirections[d] then
|
||||
local hi = turtle.getHeadingInfo(doorDirections[d])
|
||||
self:gotoEx(b.x - hi.xd, b.z - hi.zd, b.y - 2, hi.heading, travelPlane)
|
||||
-- if not turtle.detectDown() then
|
||||
-- if turtle.down() then
|
||||
-- if not turtle.detectDown() then
|
||||
-- if turtle.down() then
|
||||
self:gotoEx(b.x - hi.xd, b.z - hi.zd, b.y - 1, hi.heading, travelPlane)
|
||||
b.placed = self:place(slot)
|
||||
-- end
|
||||
-- end
|
||||
-- end
|
||||
-- end
|
||||
end
|
||||
|
||||
local blockDirections = {
|
||||
@ -1251,15 +1242,19 @@ function Builder:findTravelPlane(index)
|
||||
for i = index, 1, -1 do
|
||||
local b = schematic.blocks[i]
|
||||
|
||||
if not travelPlane or b.y > travelPlane then
|
||||
local y = b.y
|
||||
if b.twoHigh then
|
||||
y = y + 1
|
||||
end
|
||||
if not travelPlane or y > travelPlane then
|
||||
-- if not b.twoHigh then
|
||||
travelPlane = b.y
|
||||
travelPlane = y
|
||||
|
||||
Logger.log('builder', 'adjusting travelPlane')
|
||||
Logger.log('builder', b)
|
||||
--read()
|
||||
-- end
|
||||
elseif travelPlane and travelPlane - b.y > 2 then
|
||||
elseif travelPlane and travelPlane - y > 2 then
|
||||
break
|
||||
end
|
||||
end
|
||||
@ -1300,11 +1295,12 @@ function Builder:build()
|
||||
|
||||
for i = self.index, last, direction do
|
||||
self.index = i
|
||||
local b = schematic.blocks[i]
|
||||
local b = schematic:getComputedBlock(i)
|
||||
|
||||
if b.id ~= 'minecraft:air' then
|
||||
|
||||
if self.mode == 'destroy' then
|
||||
|
||||
b.heading = nil -- don't make the supplier follow the block heading
|
||||
self:logBlock(self.index, b)
|
||||
if b.y ~= turtle.getPoint().y then
|
||||
@ -1337,8 +1333,12 @@ function Builder:build()
|
||||
self:resupply()
|
||||
return
|
||||
end
|
||||
if b.y > travelPlane then
|
||||
travelPlane = b.y
|
||||
local y = b.y
|
||||
if b.twoHigh then
|
||||
y = b.y + 1
|
||||
end
|
||||
if y > travelPlane then
|
||||
travelPlane = y
|
||||
end
|
||||
|
||||
self:logBlock(self.index, b)
|
||||
@ -1995,8 +1995,8 @@ function startPage:eventHandler(event)
|
||||
height = 7,
|
||||
form = UI.Form {
|
||||
y = 3, x = 2, height = 4,
|
||||
text = UI.Text { x = 5, y = 1, value = '1 - ' .. #schematic.blocks, textColor = colors.gray },
|
||||
textEntry = UI.TextEntry { x = 15, y = 1, value = tostring(Builder.index), width = 7 }
|
||||
text = UI.Text { x = 2, y = 1, value = '1 - ' .. #schematic.blocks, textColor = colors.gray },
|
||||
textEntry = UI.TextEntry { x = 16, y = 1, value = tostring(Builder.index), width = 10, limit = 8 }
|
||||
},
|
||||
statusBar = UI.StatusBar(),
|
||||
}
|
||||
@ -2023,6 +2023,9 @@ function startPage:eventHandler(event)
|
||||
UI:setPage(dialog)
|
||||
|
||||
elseif event.type == 'assignBlocks' then
|
||||
-- this might be an approximation of the blocks needed
|
||||
-- as the current level's route may or may not have been
|
||||
-- computed
|
||||
Builder:dumpInventory()
|
||||
UI:setPage('listing')
|
||||
|
||||
@ -2059,12 +2062,6 @@ function startPage:eventHandler(event)
|
||||
turtle.status = 'thinking'
|
||||
print('Reloading schematic')
|
||||
Builder:reloadSchematic()
|
||||
print('Determining block placement')
|
||||
schematic:determineBlockPlacement()
|
||||
print('Optimizing route (' .. #schematic.blocks .. ' blocks)')
|
||||
schematic:optimizeRoute()
|
||||
print('Adjusting route')
|
||||
schematic:setPlacementOrder()
|
||||
Builder:dumpInventory()
|
||||
Builder:refuel()
|
||||
|
||||
@ -2084,7 +2081,6 @@ function startPage:eventHandler(event)
|
||||
}
|
||||
|
||||
Builder:build()
|
||||
Profile.display()
|
||||
|
||||
elseif event.type == 'quit' then
|
||||
Event.exitPullEvents()
|
||||
@ -2098,9 +2094,6 @@ local args = {...}
|
||||
if #args < 1 then
|
||||
error('supply file name')
|
||||
end
|
||||
--if #args > 1 then
|
||||
Profile.enable()
|
||||
--end
|
||||
|
||||
if os.version() == 'CraftOS 1.7' then
|
||||
Builder.ccVersion = 1.7
|
||||
|
@ -6,6 +6,18 @@ local Point = require('point')
|
||||
local TableDB = require('tableDB')
|
||||
local MEProvider = require('meProvider')
|
||||
|
||||
--[[
|
||||
A supplier turtle for the builder turtle. For larger builds, use
|
||||
ender modems.
|
||||
|
||||
Setup:
|
||||
|
||||
1. chest or ME interface at level 0 (bottom of build area)
|
||||
2. builder turtle on top facing the build area
|
||||
3. If facing the build turtle, the supplier turtle is to the right
|
||||
pointing at the chest/interface
|
||||
]]--
|
||||
|
||||
local ChestProvider = require('chestProvider')
|
||||
if os.getVersion() == 1.8 then
|
||||
ChestProvider = require('chestProvider18')
|
||||
@ -70,7 +82,7 @@ function Builder:dumpInventoryWithCheck()
|
||||
Builder:log('Unable to dump inventory')
|
||||
print('Provider is full or missing - make space or replace')
|
||||
print('Press enter to continue')
|
||||
turtle.setHeading(0)
|
||||
--turtle.setHeading(0)
|
||||
self.ready = false
|
||||
read()
|
||||
end
|
||||
@ -397,9 +409,9 @@ if not Builder.itemProvider:isValid() then
|
||||
south = 'north',
|
||||
}
|
||||
|
||||
Builder.itemProvider = ChestProvider({ direction = sides[args[2]], wrapSide = args[2] })
|
||||
Builder.itemProvider = ChestProvider({ direction = sides[args[2]], wrapSide = 'front' })
|
||||
if not Builder.itemProvider:isValid() then
|
||||
error('A chest or ME interface must be below turtle')
|
||||
error('A chest or ME interface must be in front of turtle')
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user