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/pymclevel/minecraft.yaml
-- see https://github.com/Khroki/MCEdit-Unified/blob/master/Items/minecraft/blocks.json -- 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 --]]-- --[[-- blockDB --]]--
local blockDB = TableDB() local blockDB = TableDB()
function blockDB:load() function blockDB:load()
local blocks = JSON.decodeFromFile('usr/etc/blocks.json') local blocks = JSON.decodeFromFile('usr/etc/blocks.json')
if not blocks then if not blocks then
@@ -85,19 +53,6 @@ end
local placementDB = TableDB() local placementDB = TableDB()
function placementDB:load(sbDB, btDB) 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 for k,v in pairs(sbDB.data) do
if v.place then if v.place then
local bt = btDB.data[v.place] local bt = btDB.data[v.place]
@@ -113,7 +68,6 @@ function placementDB:load2(sbDB, btDB)
self:addSubsForBlockType(155, 2, btDB.data['quartz-pillar']) self:addSubsForBlockType(155, 2, btDB.data['quartz-pillar'])
end end
function placementDB:addSubsForBlockType(id, dmg, bt) function placementDB:addSubsForBlockType(id, dmg, bt)
for _,sub in pairs(bt) do for _,sub in pairs(bt) do
local odmg = sub.odmg local odmg = sub.odmg
@@ -178,7 +132,6 @@ function blockTypeDB:addTemp(blockType, subs)
end end
function blockTypeDB:load() function blockTypeDB:load()
blockTypeDB:addTemp('stairs', { blockTypeDB:addTemp('stairs', {
{ 0, nil, 0, 'east-up' }, { 0, nil, 0, 'east-up' },
{ 1, nil, 0, 'west-up' }, { 1, nil, 0, 'west-up' },
@@ -564,21 +517,17 @@ end
local Blocks = class() local Blocks = class()
function Blocks:init(args) function Blocks:init(args)
Util.merge(self, args) Util.merge(self, args)
self.blockDB = blockDB self.blockDB = blockDB
self.nameDB = nameDB
blockDB:load() blockDB:load()
blockTypeDB:load() blockTypeDB:load()
nameDB:load(self.dir, blockDB) placementDB:load(blockDB, blockTypeDB)
placementDB:load2(blockDB, blockTypeDB)
end end
-- for an ID / dmg (with placement info) -- for an ID / dmg (with placement info)
-- return the correct block (without the placment info embedded in the dmg) -- return the correct block (without the placment info embedded in the dmg)
function Blocks:getPlaceableBlock(id, dmg) function Blocks:getPlaceableBlock(id, dmg)
local p = placementDB:get({id, dmg}) local p = placementDB:get({id, dmg})
if p then if p then
return Util.shallowCopy(p) return Util.shallowCopy(p)

View File

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

View File

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

View File

@@ -6,6 +6,7 @@ _G.requireInjector()
local Blocks = require('blocks') local Blocks = require('blocks')
local Event = require('event') local Event = require('event')
local GPS = require('gps')
local itemDB = require('itemDB') local itemDB = require('itemDB')
local MEAdapter = require('meAdapter') local MEAdapter = require('meAdapter')
local Message = require('message') local Message = require('message')
@@ -37,12 +38,11 @@ local blocks = Blocks({ dir = BUILDER_DIR })
local supplyPage, substitutionPage local supplyPage, substitutionPage
local pistonFacings local pistonFacings
local SUPPLIES_PT = { x = -1, z = -1, y = 0 }
local Builder = { local Builder = {
version = '1.71', version = '1.71',
isCommandComputer = not turtle, isCommandComputer = not turtle,
slots = { }, slots = { },
loc = { },
index = 1, index = 1,
mode = 'build', mode = 'build',
fuelItem = { id = 'minecraft:coal', dmg = 0 }, fuelItem = { id = 'minecraft:coal', dmg = 0 },
@@ -76,7 +76,6 @@ local function convertSingleBack(item)
item.qty = item.count item.qty = item.count
item.max_size = item.maxCount item.max_size = item.maxCount
item.display_name = item.displayName item.display_name = item.displayName
--item.name = item.displayName
end end
return item return item
end end
@@ -233,7 +232,6 @@ function Builder:getBlockCounts()
end end
function Builder:selectItem(id, dmg) function Builder:selectItem(id, dmg)
for k,s in ipairs(self.slots) do for k,s in ipairs(self.slots) do
if s.qty > 0 and s.id == id and s.dmg == dmg then if s.qty > 0 and s.id == id and s.dmg == dmg then
-- check to see if someone pulled items from inventory -- check to see if someone pulled items from inventory
@@ -251,7 +249,6 @@ function Builder:selectItem(id, dmg)
end end
function Builder:getAirResupplyList(blockIndex) function Builder:getAirResupplyList(blockIndex)
local slots = { } local slots = { }
if self.mode == 'destroy' then if self.mode == 'destroy' then
@@ -289,7 +286,6 @@ function Builder:getAirResupplyList(blockIndex)
end end
function Builder:getSupplyList(blockIndex) function Builder:getSupplyList(blockIndex)
local slots, lastBlock = self:getGenericSupplyList(blockIndex) local slots, lastBlock = self:getGenericSupplyList(blockIndex)
slots[15] = { slots[15] = {
@@ -316,7 +312,6 @@ function Builder:getSupplyList(blockIndex)
end end
function Builder:getGenericSupplyList(blockIndex) function Builder:getGenericSupplyList(blockIndex)
local slots = { } local slots = { }
for i = 1, self.resourceSlots do for i = 1, self.resourceSlots do
@@ -370,7 +365,6 @@ function Builder:getGenericSupplyList(blockIndex)
end end
function Builder:substituteBlocks(throttle) function Builder:substituteBlocks(throttle)
for _,b in pairs(schematic.blocks) do for _,b in pairs(schematic.blocks) do
-- replace schematic block type with substitution -- replace schematic block type with substitution
@@ -389,7 +383,6 @@ function Builder:substituteBlocks(throttle)
end end
function Builder:dumpInventory() function Builder:dumpInventory()
local success = true local success = true
for i = 1, 16 do for i = 1, 16 do
@@ -407,7 +400,6 @@ function Builder:dumpInventory()
end end
function Builder:dumpInventoryWithCheck() function Builder:dumpInventoryWithCheck()
while not self:dumpInventory() do while not self:dumpInventory() do
print('Storage is full or missing - make space or replace') print('Storage is full or missing - make space or replace')
print('Press enter to continue') print('Press enter to continue')
@@ -437,7 +429,6 @@ function Builder:autocraft(supplies)
end end
function Builder:getSupplies() function Builder:getSupplies()
self.itemAdapter:refresh() self.itemAdapter:refresh()
local t = { } local t = { }
@@ -560,7 +551,6 @@ function Builder:inAirDropoff()
end end
function Builder:inAirResupply() function Builder:inAirResupply()
if not device.wireless_modem then if not device.wireless_modem then
return false return false
end end
@@ -633,7 +623,6 @@ function Builder:inAirResupply()
end end
function Builder:sendSupplyRequest(lastBlock) function Builder:sendSupplyRequest(lastBlock)
if device.wireless_modem then if device.wireless_modem then
local slots = self:getAirResupplyList(lastBlock) local slots = self:getAirResupplyList(lastBlock)
self.slotUid = os.clock() self.slotUid = os.clock()
@@ -642,8 +631,32 @@ function Builder:sendSupplyRequest(lastBlock)
end end
end end
function Builder:resupply() function Builder:getBuildingCorner()
local pts = {
{ x = -1, z = -1, y = 0 },
{ x = -1, z = schematic.length, y = 0 },
{ x = schematic.width, z = -1, y = 0 },
{ x = schematic.width, z = schematic.length, y = 0 },
}
local supplyPoint = Util.shallowCopy(self.supplyPoint)
supplyPoint.heading = turtle.point.heading
return Point.closest(supplyPoint, pts)
end
function Builder:gotoSupplyPoint()
if not Point.same(turtle.point, self.supplyPoint) then
-- so we don't end up pathfinding through a building
-- go to the corner closest to the supplies point
-- pathfind the rest of the way
local pt = self:getBuildingCorner()
turtle._goto(pt.x, pt.z)
turtle.setPolicy(turtle.policies.none)
turtle.pathfind(self.supplyPoint)
os.sleep(.1) -- random 'Computer is not connected' error...
end
end
function Builder:resupply()
if self.slotUid and self:inAirResupply() then if self.slotUid and self:inAirResupply() then
os.queueEvent('build') os.queueEvent('build')
return return
@@ -652,8 +665,7 @@ function Builder:resupply()
turtle.status = 'resupplying' turtle.status = 'resupplying'
self:log('Resupplying') self:log('Resupplying')
turtle.gotoYlast(SUPPLIES_PT) Builder:gotoSupplyPoint()
os.sleep(.1) -- random 'Computer is not connected' error...
self:dumpInventoryWithCheck() self:dumpInventoryWithCheck()
self:refuel() self:refuel()
local lastBlock = self:getSupplyList(self.index) local lastBlock = self:getSupplyList(self.index)
@@ -795,7 +807,6 @@ function Builder:wrenchBlock(side, facing, cache)
end end
function Builder:rotateBlock(side, facing) function Builder:rotateBlock(side, facing)
local s = Builder:getWrenchSlot() local s = Builder:getWrenchSlot()
if not s then if not s then
@@ -807,32 +818,10 @@ function Builder:rotateBlock(side, facing)
end end
return true return true
--[[
local origFacing
while true do
local _, bi = turtle.getAction(side).inspect()
-- spin until it repeats
if not origFacing then
origFacing = bi.metadata
elseif bi.metadata == origFacing then
return false
end
if facing == bi.metadata then
return true
end
turtle.getAction(side).place()
end
return false
]]--
end end
-- place piston, wrench piston to face downward, extend, remove piston -- place piston, wrench piston to face downward, extend, remove piston
function Builder:placePiston(b) function Builder:placePiston(b)
local ps = Builder:selectItem('minecraft:piston', 0) local ps = Builder:selectItem('minecraft:piston', 0)
local ws = Builder:getWrenchSlot() local ws = Builder:getWrenchSlot()
@@ -1140,7 +1129,7 @@ end
function Builder:saveProgress(index) function Builder:saveProgress(index)
Util.writeTable( Util.writeTable(
fs.combine(BUILDER_DIR, schematic.filename .. '.progress'), fs.combine(BUILDER_DIR, schematic.filename .. '.progress'),
{ index = index, facing = Builder.facing } { index = index, facing = Builder.facing, loc = Builder.loc }
) )
end end
@@ -1152,12 +1141,12 @@ function Builder:loadProgress(filename)
Builder.index = 1 Builder.index = 1
end end
Builder.facing = progress.facing or 'south' Builder.facing = progress.facing or 'south'
Builder.loc = progress.loc
end end
end end
-- find the highest y in the last 2 planes -- find the highest y in the last 2 planes
function Builder:findTravelPlane(index) function Builder:findTravelPlane(index)
local travelPlane local travelPlane
for i = index, 1, -1 do for i = index, 1, -1 do
@@ -1184,7 +1173,6 @@ function Builder:gotoTravelPlane(travelPlane)
end end
function Builder:build() function Builder:build()
local direction = 1 local direction = 1
local last = #schematic.blocks local last = #schematic.blocks
local travelPlane = 0 local travelPlane = 0
@@ -1200,6 +1188,12 @@ function Builder:build()
turtle.status = 'building' turtle.status = 'building'
end end
if not self.isCommandComputer then
local pt = self:getBuildingCorner()
turtle.pathfind({ x = pt.x, z = pt.z, y = travelPlane })
turtle.setPolicy(turtle.policies.digAttack)
end
UI:setPage('blank') UI:setPage('blank')
for i = self.index, last, direction do for i = self.index, last, direction do
@@ -1264,8 +1258,7 @@ function Builder:build()
if turtle.getItemCount(self.resourceSlots) > 0 or turtle.getFuelLevel() < minFuel then if turtle.getItemCount(self.resourceSlots) > 0 or turtle.getFuelLevel() < minFuel then
if turtle.getFuelLevel() < minFuel or not self:inAirDropoff() then if turtle.getFuelLevel() < minFuel or not self:inAirDropoff() then
turtle.gotoPoint(SUPPLIES_PT) Builder:gotoSupplyPoint()
os.sleep(.1) -- random 'Computer is not connected' error...
self:dumpInventoryWithCheck() self:dumpInventoryWithCheck()
self:refuel() self:refuel()
end end
@@ -1277,9 +1270,7 @@ function Builder:build()
local slot = Builder:selectItem(b.id, b.dmg) local slot = Builder:selectItem(b.id, b.dmg)
if not slot or turtle.getFuelLevel() < minFuel then if not slot or turtle.getFuelLevel() < minFuel then
if turtle.getPoint().x > -1 or turtle.getPoint().z > -1 then self:gotoTravelPlane(travelPlane)
self:gotoTravelPlane(travelPlane)
end
self:resupply() self:resupply()
return return
end end
@@ -1324,12 +1315,12 @@ function Builder:build()
if turtle.abort then if turtle.abort then
turtle.status = 'aborting' turtle.status = 'aborting'
turtle.abort = false
self:gotoTravelPlane(travelPlane) self:gotoTravelPlane(travelPlane)
turtle.gotoPoint(SUPPLIES_PT) Builder:gotoSupplyPoint()
turtle.setHeading(0) turtle.setHeading(0)
Builder:dumpInventory() Builder:dumpInventory()
Event.exitPullEvents() Event.exitPullEvents()
UI.term:reset()
print('Aborted') print('Aborted')
return return
end end
@@ -1340,7 +1331,7 @@ function Builder:build()
end end
if not self.isCommandComputer then if not self.isCommandComputer then
self:gotoTravelPlane(travelPlane) self:gotoTravelPlane(travelPlane)
turtle.gotoPoint(SUPPLIES_PT) Builder:gotoSupplyPoint()
turtle.setHeading(0) turtle.setHeading(0)
Builder:dumpInventory() Builder:dumpInventory()
@@ -1394,7 +1385,6 @@ function selectSubstitutionPage:enable()
end end
function selectSubstitutionPage:eventHandler(event) function selectSubstitutionPage:eventHandler(event)
if event.type == 'grid_select' then if event.type == 'grid_select' then
substitutionPage.sub = event.selected substitutionPage.sub = event.selected
UI:setPage(substitutionPage) UI:setPage(substitutionPage)
@@ -1446,7 +1436,6 @@ substitutionPage.menuBar:add({
}) })
function substitutionPage.info:draw() function substitutionPage.info:draw()
local sub = self.parent.sub local sub = self.parent.sub
local inName = itemDB:getName({ name = sub.id, damage = sub.dmg }) local inName = itemDB:getName({ name = sub.id, damage = sub.dmg })
local outName = '' local outName = ''
@@ -1462,7 +1451,6 @@ function substitutionPage.info:draw()
end end
function substitutionPage:enable() function substitutionPage:enable()
self.allItems = convertBack(Builder.itemAdapter:refresh()) self.allItems = convertBack(Builder.itemAdapter:refresh())
self.grid.values = self.allItems self.grid.values = self.allItems
for _,item in pairs(self.grid.values) do for _,item in pairs(self.grid.values) do
@@ -1488,7 +1476,6 @@ function substitutionPage:applySubstitute(id, dmg)
end end
function substitutionPage:eventHandler(event) function substitutionPage:eventHandler(event)
if event.type == 'grid_focus_row' then if event.type == 'grid_focus_row' then
local s = string.format('%s:%d', local s = string.format('%s:%d',
event.selected.id, event.selected.id,
@@ -1498,11 +1485,6 @@ function substitutionPage:eventHandler(event)
self.statusBar:draw() self.statusBar:draw()
elseif event.type == 'grid_select' then elseif event.type == 'grid_select' then
-- if not item:lookupName(event.selected.id, event.selected.dmg) then
-- blocks.nameDB:add({event.selected.id, event.selected.dmg}, event.selected.name)
-- blocks.nameDB:flush()
-- end
self:applySubstitute(event.selected.id, event.selected.dmg) self:applySubstitute(event.selected.id, event.selected.dmg)
self.info:draw() self.info:draw()
@@ -1594,21 +1576,6 @@ supplyPage = UI.Page {
} }
function supplyPage:eventHandler(event) function supplyPage:eventHandler(event)
--[[
if event.type == 'craft' then
local s = self.grid:getSelected()
if Builder.itemAdapter:craftItems({{ name = s.id, damage = s.dmg, nbtHash = s.nbt_hash }}, s.need-s.qty) then
local name = s.display_name or ''
self.statusBar:timedStatus('Requested ' .. s.need-s.qty .. ' ' .. name, 3)
else
self.statusBar:timedStatus('Unable to craft')
end
elseif event.type == 'refresh' then
self:refresh()
]]
if event.type == 'build' then if event.type == 'build' then
Builder:build() Builder:build()
@@ -1721,7 +1688,6 @@ function listingPage:enable(throttle)
end end
function listingPage:eventHandler(event) function listingPage:eventHandler(event)
if event.type == 'craft' then if event.type == 'craft' then
local s = self.grid:getSelected() local s = self.grid:getSelected()
local item = convertSingleBack(Builder.itemAdapter:getItemInfo({ local item = convertSingleBack(Builder.itemAdapter:getItemInfo({
@@ -1785,7 +1751,6 @@ function listingPage.grid:getRowTextColor(row, selected)
end end
function listingPage:refresh(throttle) function listingPage:refresh(throttle)
local supplyList = Builder:getBlockCounts() local supplyList = Builder:getBlockCounts()
Builder.itemAdapter:refresh(throttle) Builder.itemAdapter:refresh(throttle)
@@ -1799,12 +1764,6 @@ function listingPage:refresh(throttle)
})) }))
if item then if item then
-- local block = blocks.blockDB:lookup(b.id, b.dmg)
-- if not block then
-- blocks.nameDB:add({b.id, b.dmg}, item.display_name)
-- elseif not block.name and item.display_name then
-- blocks.nameDB:add({b.id, b.dmg}, item.display_name)
-- end
b.display_name = item.display_name b.display_name = item.display_name
b.qty = item.qty b.qty = item.qty
b.is_craftable = item.is_craftable b.is_craftable = item.is_craftable
@@ -1816,7 +1775,6 @@ function listingPage:refresh(throttle)
throttle() throttle()
end end
end end
--blocks.nameDB:flush()
if self.fullList then if self.fullList then
self.grid:setValues(supplyList) self.grid:setValues(supplyList)
@@ -1833,7 +1791,6 @@ function listingPage:refresh(throttle)
end end
function listingPage:manageBlock(selected) function listingPage:manageBlock(selected)
local substitutes = subDB:lookupBlocksForSub(selected.id, selected.dmg) local substitutes = subDB:lookupBlocksForSub(selected.id, selected.dmg)
if Util.empty(substitutes) then if Util.empty(substitutes) then
@@ -1888,6 +1845,7 @@ local startPage = UI.Page {
menuItems = { menuItems = {
{ prompt = 'Set starting level', event = 'startLevel' }, { prompt = 'Set starting level', event = 'startLevel' },
{ prompt = 'Set starting block', event = 'startBlock' }, { prompt = 'Set starting block', event = 'startBlock' },
{ prompt = 'Set starting point', event = 'startPoint' },
{ prompt = 'Supply list', event = 'assignBlocks' }, { prompt = 'Supply list', event = 'assignBlocks' },
{ prompt = 'Toggle mode', event = 'toggleMode' }, { prompt = 'Toggle mode', event = 'toggleMode' },
{ prompt = 'Begin', event = 'begin' }, { prompt = 'Begin', event = 'begin' },
@@ -1921,7 +1879,6 @@ function startPage:enable()
end end
function startPage:eventHandler(event) function startPage:eventHandler(event)
if event.type == 'startLevel' then if event.type == 'startLevel' then
local dialog = UI.Dialog({ local dialog = UI.Dialog({
title = 'Enter Starting Level', title = 'Enter Starting Level',
@@ -1993,6 +1950,69 @@ function startPage:eventHandler(event)
dialog:setFocus(dialog.form.textEntry) dialog:setFocus(dialog.form.textEntry)
UI:setPage(dialog) UI:setPage(dialog)
elseif event.type == 'startPoint' then
local loc = Util.shallowCopy(Builder.loc)
if not loc.x then
local pt = GPS.getPoint()
if pt then
loc.x = pt.x
loc.y = pt.y
loc.z = pt.z
end
end
local dialog = UI.Dialog {
title = 'Set starting point',
height = 11,
width = 30,
form = UI.Form {
y = 2, x = 2, ey = -2,
values = loc,
text1 = UI.Text {
x = 1, y = 2, value = 'Turtle location' },
xLoc = UI.TextEntry {
x = 1, y = 3, formKey = 'x', width = 7, limit = 16, shadowText = 'x', required = true },
yLoc = UI.TextEntry {
x = 9, y = 3, formKey = 'y', width = 7, limit = 16, shadowText = 'y', required = true },
zLoc = UI.TextEntry {
x = 17, y = 3, formKey = 'z', width = 7, limit = 16, shadowText = 'z', required = true },
text2 = UI.Text {
x = 1, y = 5, value = 'Starting Point' },
xrLoc = UI.TextEntry {
x = 1, y = 6, formKey = 'rx', width = 7, limit = 16, shadowText = 'x', required = true },
yrLoc = UI.TextEntry {
x = 9, y = 6, formKey = 'ry', width = 7, limit = 16, shadowText = 'y', required = true },
zrLoc = UI.TextEntry {
x = 17, y = 6, formKey = 'rz', width = 7, limit = 16, shadowText = 'z', required = true },
revert = UI.Button {
x = 1, y = -2, text = 'Revert', event = 'revert' },
},
statusBar = UI.StatusBar({ values = 'Optional start point'}),
}
function dialog:eventHandler(event)
if event.type == 'form_complete' then
for k,v in pairs(loc) do
Builder.loc[k] = tonumber(v)
end
Builder:saveProgress(Builder.index)
UI:setPreviousPage()
elseif event.type == 'revert' then
Builder.loc = { }
Builder:saveProgress(Builder.index)
UI:setPreviousPage()
elseif event.type == 'form_invalid' then
self.statusBar:setStatus(event.message)
elseif event.type == 'form_cancel' or event.type == 'cancel' then
UI:setPreviousPage()
else
return UI.Dialog.eventHandler(self, event)
end
return true
end
UI:setPage(dialog)
elseif event.type == 'assignBlocks' then elseif event.type == 'assignBlocks' then
-- this might be an approximation of the blocks needed -- this might be an approximation of the blocks needed
-- as the current level's route may or may not have been -- as the current level's route may or may not have been
@@ -2021,26 +2041,38 @@ function startPage:eventHandler(event)
turtle.status = 'thinking' turtle.status = 'thinking'
print('Reloading schematic') print('Reloading schematic')
Builder:reloadSchematic(Util.throttle()) Builder:reloadSchematic(Util.throttle())
if Builder.loc.x then
Builder.supplyPoint = {
x = Builder.loc.x - Builder.loc.rx - 1,
y = Builder.loc.y - Builder.loc.ry,
z = Builder.loc.z - Builder.loc.rz - 1,
}
else
Builder.supplyPoint = { x = -1, y = 0, z = -1 }
end
turtle.setPoint(Builder.supplyPoint)
Builder:dumpInventory() Builder:dumpInventory()
Builder:refuel() Builder:refuel()
if Builder.mode == 'destroy' then
if device.wireless_modem then
Message.broadcast('supplyList', { uid = 1, slots = Builder:getAirResupplyList() })
end
print('Beginning destruction')
else
print('Starting build')
Builder:getTurtleFacing()
end
-- reset piston cache in case wrench was substituted -- reset piston cache in case wrench was substituted
pistonFacings = { pistonFacings = {
down = { }, down = { },
forward = { }, forward = { },
} }
Builder:build() if Builder.mode == 'destroy' then
if device.wireless_modem then
Message.broadcast('supplyList', { uid = 1, slots = Builder:getAirResupplyList() })
end
print('Beginning destruction')
Builder:build()
else
print('Starting build')
Builder:getTurtleFacing()
Builder:resupply()
end
elseif event.type == 'quit' then elseif event.type == 'quit' then
UI.term:reset() UI.term:reset()
@@ -2126,12 +2158,10 @@ UI:setPages({
UI:setPage('start') UI:setPage('start')
if Builder.isCommandComputer then if Builder.isCommandComputer then
Event.pullEvents() UI:pullEvents()
else else
turtle.run(function() turtle.run(function()
turtle.setPolicy(turtle.policies.digAttack) turtle.heading = 0
turtle.setPoint(SUPPLIES_PT)
turtle.point.heading = 0
UI:pullEvents() UI:pullEvents()
end) end)
end end

View File

@@ -15,7 +15,7 @@ local turtle = _G.turtle
multishell.setTitle(multishell.getCurrent(), 'Crafter') multishell.setTitle(multishell.getCurrent(), 'Crafter')
repeat until not turtle.forward() repeat until not turtle.forward()
local inventoryAdapter = ChestAdapter({ wrapSide = 'front', direction = 'north' }) local inventoryAdapter = ChestAdapter({ wrapSide = 'bottom', direction = 'up' })
local RESOURCE_FILE = 'usr/config/resources.db' local RESOURCE_FILE = 'usr/config/resources.db'
local RECIPES_FILE = 'usr/etc/recipes2.db' local RECIPES_FILE = 'usr/etc/recipes2.db'
@@ -262,7 +262,7 @@ local function findMachines()
local _ local _
_, machine = turtle.inspectDown() _, machine = turtle.inspectDown()
end end
if machine then if machine and type(machine) == 'table' then
local name = machine.name local name = machine.name
local i = 1 local i = 1
while t[name] do while t[name] do

View File

@@ -159,6 +159,13 @@
[ 7 ] = "minecraft:stained_glass:8", [ 7 ] = "minecraft:stained_glass:8",
}, },
}, },
[ "minecraft:carpet:1" ] = {
count = 3,
ingredients = {
"minecraft:wool:1",
"minecraft:wool:1",
},
},
[ "minecraft:wooden_slab:2" ] = { [ "minecraft:wooden_slab:2" ] = {
count = 6, count = 6,
ingredients = { ingredients = {
@@ -181,13 +188,6 @@
[ 7 ] = "minecraft:redstone:0", [ 7 ] = "minecraft:redstone:0",
}, },
}, },
[ "minecraft:light_weighted_pressure_plate:0" ] = {
count = 1,
ingredients = {
"minecraft:gold_ingot:0",
"minecraft:gold_ingot:0",
},
},
[ "minecraft:quartz_block:1" ] = { [ "minecraft:quartz_block:1" ] = {
count = 1, count = 1,
ingredients = { ingredients = {
@@ -195,15 +195,11 @@
[ 6 ] = "minecraft:stone_slab:7", [ 6 ] = "minecraft:stone_slab:7",
}, },
}, },
[ "minecraft:stained_glass_pane:9" ] = { [ "minecraft:light_weighted_pressure_plate:0" ] = {
count = 16, count = 1,
ingredients = { ingredients = {
"minecraft:stained_glass:9", "minecraft:gold_ingot:0",
"minecraft:stained_glass:9", "minecraft:gold_ingot:0",
"minecraft:stained_glass:9",
[ 5 ] = "minecraft:stained_glass:9",
[ 6 ] = "minecraft:stained_glass:9",
[ 7 ] = "minecraft:stained_glass:9",
}, },
}, },
[ "minecraft:dye:11" ] = { [ "minecraft:dye:11" ] = {
@@ -219,10 +215,15 @@
[ 6 ] = "minecraft:wool:7", [ 6 ] = "minecraft:wool:7",
}, },
}, },
[ "minecraft:planks:2" ] = { [ "minecraft:stained_glass_pane:9" ] = {
count = 4, count = 16,
ingredients = { ingredients = {
[ 6 ] = "minecraft:log:2", "minecraft:stained_glass:9",
"minecraft:stained_glass:9",
"minecraft:stained_glass:9",
[ 5 ] = "minecraft:stained_glass:9",
[ 6 ] = "minecraft:stained_glass:9",
[ 7 ] = "minecraft:stained_glass:9",
}, },
}, },
[ "minecraft:end_bricks:0" ] = { [ "minecraft:end_bricks:0" ] = {
@@ -321,11 +322,10 @@
[ 7 ] = "minecraft:brick_block:0", [ 7 ] = "minecraft:brick_block:0",
}, },
}, },
[ "minecraft:carpet:1" ] = { [ "minecraft:planks:2" ] = {
count = 3, count = 4,
ingredients = { ingredients = {
"minecraft:wool:1", [ 6 ] = "minecraft:log:2",
"minecraft:wool:1",
}, },
}, },
[ "minecraft:cobblestone_wall:0" ] = { [ "minecraft:cobblestone_wall:0" ] = {
@@ -895,6 +895,14 @@
[ 7 ] = "minecraft:hardened_clay:0", [ 7 ] = "minecraft:hardened_clay:0",
}, },
}, },
[ "minecraft:tripwire_hook:0" ] = {
count = 2,
ingredients = {
"minecraft:iron_ingot:0",
[ 9 ] = "minecraft:planks:0",
[ 5 ] = "minecraft:stick:0",
},
},
[ "minecraft:carpet:14" ] = { [ "minecraft:carpet:14" ] = {
count = 3, count = 3,
ingredients = { ingredients = {

View File

@@ -1,85 +0,0 @@
requireInjector(getfenv(1))
local Point = require('point')
local Util = require('util')
local checkedNodes = { }
local nodes = { }
local box = { x = 65, ex = 69, y = 65, ey = 70, z = -23, ez = -19 }
local function inBox(pt, box)
return pt.x >= box.x and
pt.y >= box.y and
pt.z >= box.z and
pt.x <= box.ex and
pt.y <= box.ey and
pt.z <= box.ez
end
local function toKey(pt)
return table.concat({ pt.x, pt.y, pt.z }, ':')
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 }
if inBox(testNode, box) then
local key = toKey(testNode)
if not checkedNodes[key] then
nodes[key] = testNode
end
end
end
end
local function dig(facing)
local direction = facing
if direction == 'forward' then
direction = turtle.getHeadingInfo(turtle.point.heading).direction
end
local hi = turtle.getHeadingInfo(direction)
local node = { x = turtle.point.x + hi.xd, y = turtle.point.y + hi.yd, z = turtle.point.z + hi.zd }
if inBox(node, box) then
if turtle.getAction(facing).dig() then
addNode(node)
end
end
end
local function level()
repeat
local node = { x = turtle.point.x, y = turtle.point.y, z = turtle.point.z }
local key = toKey(node)
checkedNodes[key] = true
nodes[key] = nil
dig('down')
dig('up')
dig('forward')
print(string.format('%d nodes remaining', Util.size(nodes)))
if Util.size(nodes) == 0 then
break
end
local node = Point.closest(turtle.point, nodes)
if not turtle.gotoPoint(node) then
break
end
until turtle.abort
end
local pt = Util.shallowCopy(turtle.point)
turtle.setPolicy(turtle.policies.none)
if turtle.pathfind({ x = 65, y = 70, z = -23 }) then
--turtle.reset()
turtle.setPolicy(turtle.policies.digOnly)
level()
end
turtle.pathfind(pt)
--local s, m = turtle.run(level)