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

View File

@@ -6,6 +6,7 @@ _G.requireInjector()
local Blocks = require('blocks')
local Event = require('event')
local GPS = require('gps')
local itemDB = require('itemDB')
local MEAdapter = require('meAdapter')
local Message = require('message')
@@ -37,12 +38,11 @@ local blocks = Blocks({ dir = BUILDER_DIR })
local supplyPage, substitutionPage
local pistonFacings
local SUPPLIES_PT = { x = -1, z = -1, y = 0 }
local Builder = {
version = '1.71',
isCommandComputer = not turtle,
slots = { },
loc = { },
index = 1,
mode = 'build',
fuelItem = { id = 'minecraft:coal', dmg = 0 },
@@ -76,7 +76,6 @@ local function convertSingleBack(item)
item.qty = item.count
item.max_size = item.maxCount
item.display_name = item.displayName
--item.name = item.displayName
end
return item
end
@@ -233,7 +232,6 @@ function Builder:getBlockCounts()
end
function Builder:selectItem(id, dmg)
for k,s in ipairs(self.slots) do
if s.qty > 0 and s.id == id and s.dmg == dmg then
-- check to see if someone pulled items from inventory
@@ -251,7 +249,6 @@ function Builder:selectItem(id, dmg)
end
function Builder:getAirResupplyList(blockIndex)
local slots = { }
if self.mode == 'destroy' then
@@ -289,7 +286,6 @@ function Builder:getAirResupplyList(blockIndex)
end
function Builder:getSupplyList(blockIndex)
local slots, lastBlock = self:getGenericSupplyList(blockIndex)
slots[15] = {
@@ -316,7 +312,6 @@ function Builder:getSupplyList(blockIndex)
end
function Builder:getGenericSupplyList(blockIndex)
local slots = { }
for i = 1, self.resourceSlots do
@@ -370,7 +365,6 @@ function Builder:getGenericSupplyList(blockIndex)
end
function Builder:substituteBlocks(throttle)
for _,b in pairs(schematic.blocks) do
-- replace schematic block type with substitution
@@ -389,7 +383,6 @@ function Builder:substituteBlocks(throttle)
end
function Builder:dumpInventory()
local success = true
for i = 1, 16 do
@@ -407,7 +400,6 @@ function Builder:dumpInventory()
end
function Builder:dumpInventoryWithCheck()
while not self:dumpInventory() do
print('Storage is full or missing - make space or replace')
print('Press enter to continue')
@@ -437,7 +429,6 @@ function Builder:autocraft(supplies)
end
function Builder:getSupplies()
self.itemAdapter:refresh()
local t = { }
@@ -560,7 +551,6 @@ function Builder:inAirDropoff()
end
function Builder:inAirResupply()
if not device.wireless_modem then
return false
end
@@ -633,7 +623,6 @@ function Builder:inAirResupply()
end
function Builder:sendSupplyRequest(lastBlock)
if device.wireless_modem then
local slots = self:getAirResupplyList(lastBlock)
self.slotUid = os.clock()
@@ -642,8 +631,32 @@ function Builder:sendSupplyRequest(lastBlock)
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
os.queueEvent('build')
return
@@ -652,8 +665,7 @@ function Builder:resupply()
turtle.status = 'resupplying'
self:log('Resupplying')
turtle.gotoYlast(SUPPLIES_PT)
os.sleep(.1) -- random 'Computer is not connected' error...
Builder:gotoSupplyPoint()
self:dumpInventoryWithCheck()
self:refuel()
local lastBlock = self:getSupplyList(self.index)
@@ -795,7 +807,6 @@ function Builder:wrenchBlock(side, facing, cache)
end
function Builder:rotateBlock(side, facing)
local s = Builder:getWrenchSlot()
if not s then
@@ -807,32 +818,10 @@ function Builder:rotateBlock(side, facing)
end
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
-- place piston, wrench piston to face downward, extend, remove piston
function Builder:placePiston(b)
local ps = Builder:selectItem('minecraft:piston', 0)
local ws = Builder:getWrenchSlot()
@@ -1140,7 +1129,7 @@ end
function Builder:saveProgress(index)
Util.writeTable(
fs.combine(BUILDER_DIR, schematic.filename .. '.progress'),
{ index = index, facing = Builder.facing }
{ index = index, facing = Builder.facing, loc = Builder.loc }
)
end
@@ -1152,12 +1141,12 @@ function Builder:loadProgress(filename)
Builder.index = 1
end
Builder.facing = progress.facing or 'south'
Builder.loc = progress.loc
end
end
-- find the highest y in the last 2 planes
function Builder:findTravelPlane(index)
local travelPlane
for i = index, 1, -1 do
@@ -1184,7 +1173,6 @@ function Builder:gotoTravelPlane(travelPlane)
end
function Builder:build()
local direction = 1
local last = #schematic.blocks
local travelPlane = 0
@@ -1200,6 +1188,12 @@ function Builder:build()
turtle.status = 'building'
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')
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.getFuelLevel() < minFuel or not self:inAirDropoff() then
turtle.gotoPoint(SUPPLIES_PT)
os.sleep(.1) -- random 'Computer is not connected' error...
Builder:gotoSupplyPoint()
self:dumpInventoryWithCheck()
self:refuel()
end
@@ -1277,9 +1270,7 @@ function Builder:build()
local slot = Builder:selectItem(b.id, b.dmg)
if not slot or turtle.getFuelLevel() < minFuel then
if turtle.getPoint().x > -1 or turtle.getPoint().z > -1 then
self:gotoTravelPlane(travelPlane)
end
self:gotoTravelPlane(travelPlane)
self:resupply()
return
end
@@ -1324,12 +1315,12 @@ function Builder:build()
if turtle.abort then
turtle.status = 'aborting'
turtle.abort = false
self:gotoTravelPlane(travelPlane)
turtle.gotoPoint(SUPPLIES_PT)
Builder:gotoSupplyPoint()
turtle.setHeading(0)
Builder:dumpInventory()
Event.exitPullEvents()
UI.term:reset()
print('Aborted')
return
end
@@ -1340,7 +1331,7 @@ function Builder:build()
end
if not self.isCommandComputer then
self:gotoTravelPlane(travelPlane)
turtle.gotoPoint(SUPPLIES_PT)
Builder:gotoSupplyPoint()
turtle.setHeading(0)
Builder:dumpInventory()
@@ -1394,7 +1385,6 @@ function selectSubstitutionPage:enable()
end
function selectSubstitutionPage:eventHandler(event)
if event.type == 'grid_select' then
substitutionPage.sub = event.selected
UI:setPage(substitutionPage)
@@ -1446,7 +1436,6 @@ substitutionPage.menuBar:add({
})
function substitutionPage.info:draw()
local sub = self.parent.sub
local inName = itemDB:getName({ name = sub.id, damage = sub.dmg })
local outName = ''
@@ -1462,7 +1451,6 @@ function substitutionPage.info:draw()
end
function substitutionPage:enable()
self.allItems = convertBack(Builder.itemAdapter:refresh())
self.grid.values = self.allItems
for _,item in pairs(self.grid.values) do
@@ -1488,7 +1476,6 @@ function substitutionPage:applySubstitute(id, dmg)
end
function substitutionPage:eventHandler(event)
if event.type == 'grid_focus_row' then
local s = string.format('%s:%d',
event.selected.id,
@@ -1498,11 +1485,6 @@ function substitutionPage:eventHandler(event)
self.statusBar:draw()
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.info:draw()
@@ -1594,21 +1576,6 @@ supplyPage = UI.Page {
}
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
Builder:build()
@@ -1721,7 +1688,6 @@ function listingPage:enable(throttle)
end
function listingPage:eventHandler(event)
if event.type == 'craft' then
local s = self.grid:getSelected()
local item = convertSingleBack(Builder.itemAdapter:getItemInfo({
@@ -1785,7 +1751,6 @@ function listingPage.grid:getRowTextColor(row, selected)
end
function listingPage:refresh(throttle)
local supplyList = Builder:getBlockCounts()
Builder.itemAdapter:refresh(throttle)
@@ -1799,12 +1764,6 @@ function listingPage:refresh(throttle)
}))
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.qty = item.qty
b.is_craftable = item.is_craftable
@@ -1816,7 +1775,6 @@ function listingPage:refresh(throttle)
throttle()
end
end
--blocks.nameDB:flush()
if self.fullList then
self.grid:setValues(supplyList)
@@ -1833,7 +1791,6 @@ function listingPage:refresh(throttle)
end
function listingPage:manageBlock(selected)
local substitutes = subDB:lookupBlocksForSub(selected.id, selected.dmg)
if Util.empty(substitutes) then
@@ -1888,6 +1845,7 @@ local startPage = UI.Page {
menuItems = {
{ prompt = 'Set starting level', event = 'startLevel' },
{ prompt = 'Set starting block', event = 'startBlock' },
{ prompt = 'Set starting point', event = 'startPoint' },
{ prompt = 'Supply list', event = 'assignBlocks' },
{ prompt = 'Toggle mode', event = 'toggleMode' },
{ prompt = 'Begin', event = 'begin' },
@@ -1921,7 +1879,6 @@ function startPage:enable()
end
function startPage:eventHandler(event)
if event.type == 'startLevel' then
local dialog = UI.Dialog({
title = 'Enter Starting Level',
@@ -1993,6 +1950,69 @@ function startPage:eventHandler(event)
dialog:setFocus(dialog.form.textEntry)
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
-- this might be an approximation of the blocks needed
-- as the current level's route may or may not have been
@@ -2021,26 +2041,38 @@ function startPage:eventHandler(event)
turtle.status = 'thinking'
print('Reloading schematic')
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: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
pistonFacings = {
down = { },
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
UI.term:reset()
@@ -2126,12 +2158,10 @@ UI:setPages({
UI:setPage('start')
if Builder.isCommandComputer then
Event.pullEvents()
UI:pullEvents()
else
turtle.run(function()
turtle.setPolicy(turtle.policies.digAttack)
turtle.setPoint(SUPPLIES_PT)
turtle.point.heading = 0
turtle.heading = 0
UI:pullEvents()
end)
end

View File

@@ -15,7 +15,7 @@ local turtle = _G.turtle
multishell.setTitle(multishell.getCurrent(), 'Crafter')
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 RECIPES_FILE = 'usr/etc/recipes2.db'
@@ -262,7 +262,7 @@ local function findMachines()
local _
_, machine = turtle.inspectDown()
end
if machine then
if machine and type(machine) == 'table' then
local name = machine.name
local i = 1
while t[name] do

View File

@@ -159,6 +159,13 @@
[ 7 ] = "minecraft:stained_glass:8",
},
},
[ "minecraft:carpet:1" ] = {
count = 3,
ingredients = {
"minecraft:wool:1",
"minecraft:wool:1",
},
},
[ "minecraft:wooden_slab:2" ] = {
count = 6,
ingredients = {
@@ -181,13 +188,6 @@
[ 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" ] = {
count = 1,
ingredients = {
@@ -195,15 +195,11 @@
[ 6 ] = "minecraft:stone_slab:7",
},
},
[ "minecraft:stained_glass_pane:9" ] = {
count = 16,
[ "minecraft:light_weighted_pressure_plate:0" ] = {
count = 1,
ingredients = {
"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:gold_ingot:0",
"minecraft:gold_ingot:0",
},
},
[ "minecraft:dye:11" ] = {
@@ -219,10 +215,15 @@
[ 6 ] = "minecraft:wool:7",
},
},
[ "minecraft:planks:2" ] = {
count = 4,
[ "minecraft:stained_glass_pane:9" ] = {
count = 16,
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" ] = {
@@ -321,11 +322,10 @@
[ 7 ] = "minecraft:brick_block:0",
},
},
[ "minecraft:carpet:1" ] = {
count = 3,
[ "minecraft:planks:2" ] = {
count = 4,
ingredients = {
"minecraft:wool:1",
"minecraft:wool:1",
[ 6 ] = "minecraft:log:2",
},
},
[ "minecraft:cobblestone_wall:0" ] = {
@@ -895,6 +895,14 @@
[ 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" ] = {
count = 3,
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)