builder starting point

This commit is contained in:
kepler155c
2017-10-22 01:29:42 -04:00
parent 5e80591160
commit e0cac06c2a
7 changed files with 174 additions and 269 deletions

View File

@@ -6,42 +6,10 @@ local JSON = require('json')
-- see https://github.com/Khroki/MCEdit-Unified/blob/master/pymclevel/minecraft.yaml
-- see https://github.com/Khroki/MCEdit-Unified/blob/master/Items/minecraft/blocks.json
--[[-- nameDB --]]--
local nameDB = TableDB({
fileName = 'blocknames.db'
})
function nameDB:load(dir, blockDB)
self.fileName = fs.combine(dir, self.fileName)
if fs.exists(self.fileName) then
TableDB.load(self)
end
self.blockDB = blockDB
end
function nameDB:getName(id, dmg)
return self:lookupName(id, dmg) or id .. ':' .. dmg
end
function nameDB:lookupName(id, dmg)
-- is it in the name db ?
local name = self:get({ id, dmg })
if name then
return name
end
-- is it in the block db ?
for _,v in pairs(self.blockDB.data) do
if v.strId == id and v.dmg == dmg then
return v.name
end
end
end
--[[-- blockDB --]]--
local blockDB = TableDB()
function blockDB:load()
local blocks = JSON.decodeFromFile('usr/etc/blocks.json')
if not blocks then
@@ -85,19 +53,6 @@ end
local placementDB = TableDB()
function placementDB:load(sbDB, btDB)
for k,blockType in pairs(sbDB.data) do
local bt = btDB.data[blockType]
if not bt then
error('missing block type: ' .. blockType)
end
local id, dmg = string.match(k, '(%d+):*(%d+)')
self:addSubsForBlockType(tonumber(id), tonumber(dmg), bt)
end
end
function placementDB:load2(sbDB, btDB)
for k,v in pairs(sbDB.data) do
if v.place then
local bt = btDB.data[v.place]
@@ -113,7 +68,6 @@ function placementDB:load2(sbDB, btDB)
self:addSubsForBlockType(155, 2, btDB.data['quartz-pillar'])
end
function placementDB:addSubsForBlockType(id, dmg, bt)
for _,sub in pairs(bt) do
local odmg = sub.odmg
@@ -178,7 +132,6 @@ function blockTypeDB:addTemp(blockType, subs)
end
function blockTypeDB:load()
blockTypeDB:addTemp('stairs', {
{ 0, nil, 0, 'east-up' },
{ 1, nil, 0, 'west-up' },
@@ -564,21 +517,17 @@ end
local Blocks = class()
function Blocks:init(args)
Util.merge(self, args)
self.blockDB = blockDB
self.nameDB = nameDB
blockDB:load()
blockTypeDB:load()
nameDB:load(self.dir, blockDB)
placementDB:load2(blockDB, blockTypeDB)
placementDB:load(blockDB, blockTypeDB)
end
-- 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})
if p then
return Util.shallowCopy(p)

View File

@@ -235,7 +235,7 @@ function Schematic:isCompressed(filename)
end
local magic = h.read() * 256 + h.read()
debug({ magic, gzipMagic })
h.close()
return magic == gzipMagic
@@ -1160,8 +1160,8 @@ function Schematic:optimizeRoute(spinner, y)
return block
end
local pt = Util.shallowCopy(self.cache[y - 1] or turtle.point)
local t = {}
local pt = Util.shallowCopy(self.cache[y - 1] or { x = -1, y = 0, z = -1, heading = 0 })
local t = { }
local ri = self.rowIndex[y]
local blockCount = ri.e - ri.s + 1

View File

@@ -1,6 +1,8 @@
local Point = require('point')
local Util = require('util')
local turtle = _G.turtle
local checkedNodes = { }
local nodes = { }
local box = { }
@@ -11,7 +13,6 @@ local function toKey(pt)
end
local function addNode(node)
for i = 0, 5 do
local hi = turtle.getHeadingInfo(i)
local testNode = { x = node.x + hi.xd, y = node.y + hi.yd, z = node.z + hi.zd }
@@ -26,14 +27,13 @@ local function addNode(node)
end
local function dig(action)
local directions = {
top = 'up',
bottom = 'down',
}
-- convert to up, down, north, south, east, west
local direction = directions[action.side] or
local direction = directions[action.side] or
turtle.getHeadingInfo(turtle.point.heading).direction
local hi = turtle.getHeadingInfo(direction)
@@ -75,7 +75,7 @@ end
-- find the closest block
-- * favor same plane
-- * going backwards only if the dest is above or below
function closestPoint(reference, pts)
local function closestPoint(reference, pts)
local lpt, lm -- lowest
for _,pt in pairs(pts) do
local m = Point.turtleDistance(reference, pt)
@@ -114,7 +114,6 @@ local function getAdjacentPoint(pt)
end
return function(startPt, endPt, firstPt, verbose)
checkedNodes = { }
nodes = { }
box = { }
@@ -126,6 +125,10 @@ return function(startPt, endPt, firstPt, verbose)
box.ey = math.max(startPt.y, endPt.y)
box.ez = math.max(startPt.z, endPt.z)
if not Point.inBox(firstPt, box) then
error('Starting point is not in leveling area')
end
if not turtle.pathfind(firstPt) then
error('failed to reach starting point')
end