compatibility improvements
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
local class = require('class')
|
local class = require('class')
|
||||||
local Util = require('util')
|
local Util = require('util')
|
||||||
local DEFLATE = require('deflatelua')
|
local DEFLATE = require('deflatelua')
|
||||||
local UI = require('ui')
|
|
||||||
local Point = require('point')
|
local Point = require('point')
|
||||||
|
|
||||||
local bit = _G.bit
|
local bit = _G.bit
|
||||||
@@ -16,6 +15,52 @@ local turtle = _G.turtle
|
|||||||
local schematicMagic = 0x0a00
|
local schematicMagic = 0x0a00
|
||||||
local gzipMagic = 0x1f8b
|
local gzipMagic = 0x1f8b
|
||||||
|
|
||||||
|
--[[-- Spinner --]]--
|
||||||
|
local Spinner = class()
|
||||||
|
function Spinner:init(args)
|
||||||
|
local defaults = {
|
||||||
|
timeout = .095,
|
||||||
|
c = os.clock(),
|
||||||
|
spinIndex = 0,
|
||||||
|
spinSymbols = { '-', '/', '|', '\\' }
|
||||||
|
}
|
||||||
|
defaults.x, defaults.y = term.getCursorPos()
|
||||||
|
defaults.startX = defaults.x
|
||||||
|
defaults.startY = defaults.y
|
||||||
|
|
||||||
|
Util.merge(self, defaults)
|
||||||
|
Util.merge(self, args)
|
||||||
|
end
|
||||||
|
|
||||||
|
function Spinner:spin(text)
|
||||||
|
local cc = os.clock()
|
||||||
|
if text then
|
||||||
|
self.text = text
|
||||||
|
end
|
||||||
|
if cc > self.c + self.timeout then
|
||||||
|
term.setCursorPos(self.x, self.y)
|
||||||
|
local str = self.spinSymbols[self.spinIndex % #self.spinSymbols + 1]
|
||||||
|
if self.text then
|
||||||
|
str = str .. ' ' .. self.text
|
||||||
|
self.text = nil
|
||||||
|
end
|
||||||
|
term.write(str)
|
||||||
|
self.spinIndex = self.spinIndex + 1
|
||||||
|
os.sleep(0)
|
||||||
|
self.c = os.clock()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function Spinner:stop(text)
|
||||||
|
term.setCursorPos(self.x, self.y)
|
||||||
|
local str = string.rep(' ', #self.spinSymbols)
|
||||||
|
if text then
|
||||||
|
str = str .. ' ' .. text
|
||||||
|
end
|
||||||
|
term.write(str)
|
||||||
|
term.setCursorPos(self.startX, self.startY)
|
||||||
|
end
|
||||||
|
|
||||||
local Schematic = class()
|
local Schematic = class()
|
||||||
function Schematic:init(args)
|
function Schematic:init(args)
|
||||||
self.blocks = { }
|
self.blocks = { }
|
||||||
@@ -281,7 +326,7 @@ function Schematic:loadpass(fh, spinner)
|
|||||||
|
|
||||||
fh:close()
|
fh:close()
|
||||||
|
|
||||||
print('Assigning coords ')
|
spinner.text = 'Assigning coords '
|
||||||
local index = 1
|
local index = 1
|
||||||
for _, b in ipairs(self.blocks) do
|
for _, b in ipairs(self.blocks) do
|
||||||
while index < b.index do
|
while index < b.index do
|
||||||
@@ -314,11 +359,10 @@ function Schematic:loadpass(fh, spinner)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Schematic:load(filename)
|
function Schematic:load(filename)
|
||||||
|
local _, cy = term.getCursorPos()
|
||||||
local _, cursorY = term.getCursorPos()
|
local spinner = Spinner({
|
||||||
local spinner = UI.Spinner({
|
x = 1,
|
||||||
x = UI.term.width,
|
y = cy,
|
||||||
y = cursorY - 1
|
|
||||||
})
|
})
|
||||||
local f
|
local f
|
||||||
|
|
||||||
@@ -327,7 +371,7 @@ function Schematic:load(filename)
|
|||||||
filename = originalFile .. '.uncompressed'
|
filename = originalFile .. '.uncompressed'
|
||||||
|
|
||||||
if not fs.exists(filename) then
|
if not fs.exists(filename) then
|
||||||
print('Decompressing')
|
spinner.text = 'Decompressing'
|
||||||
f = self:decompress(originalFile, spinner)
|
f = self:decompress(originalFile, spinner)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -340,7 +384,7 @@ function Schematic:load(filename)
|
|||||||
|
|
||||||
self:checkFileType(f)
|
self:checkFileType(f)
|
||||||
|
|
||||||
print('Loading blocks ')
|
spinner.text = 'Loading blocks '
|
||||||
self:loadpass(f, spinner)
|
self:loadpass(f, spinner)
|
||||||
|
|
||||||
self.rowIndex = { }
|
self.rowIndex = { }
|
||||||
@@ -357,7 +401,7 @@ function Schematic:load(filename)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Schematic:assignDamages(spinner)
|
function Schematic:assignDamages(spinner)
|
||||||
print('Assigning damages')
|
spinner.text = 'Assigning damages'
|
||||||
|
|
||||||
for _,b in pairs(self.blocks) do
|
for _,b in pairs(self.blocks) do
|
||||||
b.dmg = self.damages[b.index] or 0
|
b.dmg = self.damages[b.index] or 0
|
||||||
@@ -586,7 +630,7 @@ function Schematic:determineBlockPlacement(y)
|
|||||||
|
|
||||||
print('Processing level ' .. y)
|
print('Processing level ' .. y)
|
||||||
|
|
||||||
local spinner = UI.Spinner({
|
local spinner = Spinner({
|
||||||
x = 1,
|
x = 1,
|
||||||
spinSymbols = { 'o.....', '.o....', '..o...', '...o..', '....o.', '.....o' }
|
spinSymbols = { 'o.....', '.o....', '..o...', '...o..', '....o.', '.....o' }
|
||||||
})
|
})
|
||||||
|
|||||||
218
apps/builder.lua
218
apps/builder.lua
@@ -1,11 +1,10 @@
|
|||||||
if not turtle and not commands then
|
if not _G.turtle and not _G.commands then
|
||||||
error('Must be run on a turtle or a command computer')
|
error('Must be run on a turtle or a command computer')
|
||||||
end
|
end
|
||||||
|
|
||||||
requireInjector(getfenv(1))
|
_G.requireInjector()
|
||||||
|
|
||||||
local Blocks = require('blocks')
|
local Blocks = require('blocks')
|
||||||
local class = require('class')
|
|
||||||
local Event = require('event')
|
local Event = require('event')
|
||||||
local itemDB = require('itemDB')
|
local itemDB = require('itemDB')
|
||||||
local MEAdapter = require('meAdapter')
|
local MEAdapter = require('meAdapter')
|
||||||
@@ -16,8 +15,18 @@ local TableDB = require('tableDB')
|
|||||||
local UI = require('ui')
|
local UI = require('ui')
|
||||||
local Util = require('util')
|
local Util = require('util')
|
||||||
|
|
||||||
|
local commands = _G.commands
|
||||||
|
local colors = _G.colors
|
||||||
|
local device = _G.device
|
||||||
|
local fs = _G.fs
|
||||||
|
local multishell = _ENV.multishell
|
||||||
|
local os = _G.os
|
||||||
|
local read = _G.read
|
||||||
|
local rs = _G.rs
|
||||||
|
local turtle = _G.turtle
|
||||||
|
|
||||||
local ChestAdapter = require('chestAdapter')
|
local ChestAdapter = require('chestAdapter')
|
||||||
if Util.getVersion() == 1.8 then
|
if Util.checkMinecraftVersion(1.8) then
|
||||||
ChestAdapter = require('chestAdapter18')
|
ChestAdapter = require('chestAdapter18')
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -25,6 +34,8 @@ local BUILDER_DIR = 'usr/builder'
|
|||||||
|
|
||||||
local schematic = Schematic()
|
local schematic = Schematic()
|
||||||
local blocks = Blocks({ dir = BUILDER_DIR })
|
local blocks = Blocks({ dir = BUILDER_DIR })
|
||||||
|
local supplyPage, substitutionPage
|
||||||
|
local pistonFacings
|
||||||
|
|
||||||
local SUPPLIES_PT = { x = -1, z = -1, y = 0 }
|
local SUPPLIES_PT = { x = -1, z = -1, y = 0 }
|
||||||
|
|
||||||
@@ -37,12 +48,10 @@ local Builder = {
|
|||||||
fuelItem = { id = 'minecraft:coal', dmg = 0 },
|
fuelItem = { id = 'minecraft:coal', dmg = 0 },
|
||||||
resourceSlots = 14,
|
resourceSlots = 14,
|
||||||
facing = 'south',
|
facing = 'south',
|
||||||
confirmFacing = false,
|
|
||||||
wrenchSucks = false,
|
wrenchSucks = false,
|
||||||
|
stairBug = false,
|
||||||
}
|
}
|
||||||
|
|
||||||
local pistonFacings
|
|
||||||
|
|
||||||
-- Temp functions until conversion to new adapters is complete
|
-- Temp functions until conversion to new adapters is complete
|
||||||
local function convertSingleForward(item)
|
local function convertSingleForward(item)
|
||||||
item.displayName = item.display_name
|
item.displayName = item.display_name
|
||||||
@@ -80,7 +89,7 @@ local function convertBack(t)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--[[-- SubDB --]]--
|
--[[-- SubDB --]]--
|
||||||
subDB = TableDB({
|
local subDB = TableDB({
|
||||||
fileName = fs.combine(BUILDER_DIR, 'sub.db'),
|
fileName = fs.combine(BUILDER_DIR, 'sub.db'),
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -174,7 +183,7 @@ function subDB:lookupBlocksForSub(sid, sdmg)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--[[-- maxStackDB --]]--
|
--[[-- maxStackDB --]]--
|
||||||
maxStackDB = TableDB({
|
local maxStackDB = TableDB({
|
||||||
fileName = fs.combine(BUILDER_DIR, 'maxstack.db'),
|
fileName = fs.combine(BUILDER_DIR, 'maxstack.db'),
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -182,51 +191,6 @@ function maxStackDB:get(id, dmg)
|
|||||||
return self.data[id .. ':' .. dmg] or 64
|
return self.data[id .. ':' .. dmg] or 64
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[-- Spinner --]]--
|
|
||||||
UI.Spinner = class()
|
|
||||||
function UI.Spinner:init(args)
|
|
||||||
local defaults = {
|
|
||||||
UIElement = 'Spinner',
|
|
||||||
timeout = .095,
|
|
||||||
x = 1,
|
|
||||||
y = 1,
|
|
||||||
c = os.clock(),
|
|
||||||
spinIndex = 0,
|
|
||||||
spinSymbols = { '-', '/', '|', '\\' }
|
|
||||||
}
|
|
||||||
defaults.x, defaults.y = term.getCursorPos()
|
|
||||||
defaults.startX = defaults.x
|
|
||||||
defaults.startY = defaults.y
|
|
||||||
|
|
||||||
UI:setProperties(self, defaults)
|
|
||||||
UI:setProperties(self, args)
|
|
||||||
end
|
|
||||||
|
|
||||||
function UI.Spinner:spin(text)
|
|
||||||
local cc = os.clock()
|
|
||||||
if cc > self.c + self.timeout then
|
|
||||||
term.setCursorPos(self.x, self.y)
|
|
||||||
local str = self.spinSymbols[self.spinIndex % #self.spinSymbols + 1]
|
|
||||||
if text then
|
|
||||||
str = str .. ' ' .. text
|
|
||||||
end
|
|
||||||
term.write(str)
|
|
||||||
self.spinIndex = self.spinIndex + 1
|
|
||||||
os.sleep(0)
|
|
||||||
self.c = os.clock()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function UI.Spinner:stop(text)
|
|
||||||
term.setCursorPos(self.x, self.y)
|
|
||||||
local str = string.rep(' ', #self.spinSymbols)
|
|
||||||
if text then
|
|
||||||
str = str .. ' ' .. text
|
|
||||||
end
|
|
||||||
term.write(str)
|
|
||||||
term.setCursorPos(self.startX, self.startY)
|
|
||||||
end
|
|
||||||
|
|
||||||
--[[-- Builder --]]--
|
--[[-- Builder --]]--
|
||||||
function Builder:getBlockCounts()
|
function Builder:getBlockCounts()
|
||||||
local blocks = { }
|
local blocks = { }
|
||||||
@@ -299,13 +263,13 @@ function Builder:getAirResupplyList(blockIndex)
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
slots, _ = self:getGenericSupplyList(blockIndex)
|
slots = self:getGenericSupplyList(blockIndex)
|
||||||
end
|
end
|
||||||
|
|
||||||
local fuel = subDB:getSubstitutedItem(Builder.fuelItem.id, Builder.fuelItem.dmg)
|
local fuel = subDB:getSubstitutedItem(Builder.fuelItem.id, Builder.fuelItem.dmg)
|
||||||
|
|
||||||
slots[15] = {
|
slots[15] = {
|
||||||
id = 'minecraft:chest', --'ironchest:BlockIronChest', --
|
id = 'minecraft:chest', --'ironchest:BlockIronChest', --
|
||||||
dmg = 0,
|
dmg = 0,
|
||||||
qty = 0,
|
qty = 0,
|
||||||
need = 1,
|
need = 1,
|
||||||
@@ -455,7 +419,7 @@ end
|
|||||||
function Builder:autocraft(supplies)
|
function Builder:autocraft(supplies)
|
||||||
local t = { }
|
local t = { }
|
||||||
|
|
||||||
for i,s in pairs(supplies) do
|
for _,s in pairs(supplies) do
|
||||||
local key = s.id .. ':' .. s.dmg
|
local key = s.id .. ':' .. s.dmg
|
||||||
local item = t[key]
|
local item = t[key]
|
||||||
if not item then
|
if not item then
|
||||||
@@ -543,7 +507,7 @@ function Builder:inAirDropoff()
|
|||||||
self:log('Requesting air supply drop for supply #: ' .. 1)
|
self:log('Requesting air supply drop for supply #: ' .. 1)
|
||||||
while true do
|
while true do
|
||||||
Message.broadcast('needSupplies', { point = turtle.getPoint(), uid = 1 })
|
Message.broadcast('needSupplies', { point = turtle.getPoint(), uid = 1 })
|
||||||
local _, id, msg, _ = Message.waitForMessage('gotSupplies', 1)
|
local _, _, msg, _ = Message.waitForMessage('gotSupplies', 1)
|
||||||
|
|
||||||
if not msg or not msg.contents then
|
if not msg or not msg.contents then
|
||||||
Message.broadcast('supplyList', { uid = 1, slots = self:getAirResupplyList() })
|
Message.broadcast('supplyList', { uid = 1, slots = self:getAirResupplyList() })
|
||||||
@@ -558,7 +522,7 @@ function Builder:inAirDropoff()
|
|||||||
self:log('Received supply location')
|
self:log('Received supply location')
|
||||||
os.sleep(0)
|
os.sleep(0)
|
||||||
|
|
||||||
turtle.goto(pt.x, pt.z, pt.y)
|
turtle._goto(pt.x, pt.z, pt.y)
|
||||||
os.sleep(.1) -- random computer is not connected error
|
os.sleep(.1) -- random computer is not connected error
|
||||||
|
|
||||||
local chestAdapter = ChestAdapter({ direction = 'down', wrapSide = 'top' })
|
local chestAdapter = ChestAdapter({ direction = 'down', wrapSide = 'top' })
|
||||||
@@ -581,7 +545,7 @@ function Builder:inAirDropoff()
|
|||||||
|
|
||||||
Message.broadcast('thanks', { })
|
Message.broadcast('thanks', { })
|
||||||
|
|
||||||
for i = 1,12 do -- wait til supplier is idle before sending next request
|
for _ = 1,12 do -- wait til supplier is idle before sending next request
|
||||||
if turtle.detectUp() then
|
if turtle.detectUp() then
|
||||||
os.sleep(.25)
|
os.sleep(.25)
|
||||||
end
|
end
|
||||||
@@ -606,7 +570,7 @@ function Builder:inAirResupply()
|
|||||||
self:log('Requesting air supply drop for supply #: ' .. self.slotUid)
|
self:log('Requesting air supply drop for supply #: ' .. self.slotUid)
|
||||||
while true do
|
while true do
|
||||||
Message.broadcast('needSupplies', { point = turtle.getPoint(), uid = Builder.slotUid })
|
Message.broadcast('needSupplies', { point = turtle.getPoint(), uid = Builder.slotUid })
|
||||||
local _, id, msg, _ = Message.waitForMessage('gotSupplies', 1)
|
local _, _, msg, _ = Message.waitForMessage('gotSupplies', 1)
|
||||||
|
|
||||||
if not msg or not msg.contents then
|
if not msg or not msg.contents then
|
||||||
self.itemAdapter = oldAdapter
|
self.itemAdapter = oldAdapter
|
||||||
@@ -621,7 +585,7 @@ function Builder:inAirResupply()
|
|||||||
self:log('Received supply location')
|
self:log('Received supply location')
|
||||||
os.sleep(0)
|
os.sleep(0)
|
||||||
|
|
||||||
turtle.goto(pt.x, pt.z, pt.y)
|
turtle._goto(pt.x, pt.z, pt.y)
|
||||||
os.sleep(.1) -- random computer is not connected error
|
os.sleep(.1) -- random computer is not connected error
|
||||||
|
|
||||||
local chestAdapter = ChestAdapter({ direction = 'down', wrapSide = 'top' })
|
local chestAdapter = ChestAdapter({ direction = 'down', wrapSide = 'top' })
|
||||||
@@ -648,7 +612,7 @@ function Builder:inAirResupply()
|
|||||||
|
|
||||||
if #supplies == 0 then
|
if #supplies == 0 then
|
||||||
|
|
||||||
for i = 1,12 do -- wait til supplier is idle before sending next request
|
for _ = 1,12 do -- wait til supplier is idle before sending next request
|
||||||
if turtle.detectUp() then
|
if turtle.detectUp() then
|
||||||
os.sleep(.25)
|
os.sleep(.25)
|
||||||
end
|
end
|
||||||
@@ -724,40 +688,63 @@ function Builder:place(slot)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Builder:getWrenchSlot()
|
function Builder:getWrenchSlot()
|
||||||
|
|
||||||
local wrench = subDB:getSubstitutedItem('SubstituteAWrench', 0)
|
local wrench = subDB:getSubstitutedItem('SubstituteAWrench', 0)
|
||||||
return Builder:selectItem(wrench.id, wrench.dmg)
|
return Builder:selectItem(wrench.id, wrench.dmg)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- figure out our orientation in the world
|
-- figure out our orientation in the world
|
||||||
function Builder:getTurtleFacing()
|
function Builder:getTurtleFacing()
|
||||||
|
local directions = { -- reversed directions
|
||||||
|
[5] = 'west',
|
||||||
|
[3] = 'north',
|
||||||
|
[4] = 'east',
|
||||||
|
[2] = 'south',
|
||||||
|
}
|
||||||
|
|
||||||
if Util.getVersion() == 1.8 then
|
local function getItem(item)
|
||||||
|
turtle.select(1)
|
||||||
local directions = { -- reversed directions
|
local msg = false
|
||||||
[5] = 'west',
|
while true do
|
||||||
[3] = 'north',
|
self.itemAdapter:provide(item, 1, 1)
|
||||||
[4] = 'east',
|
if turtle.getItemCount(1) == 1 then
|
||||||
[2] = 'south',
|
break
|
||||||
}
|
end
|
||||||
|
if not msg then
|
||||||
if self:selectItem('minecraft:piston', 0) then
|
print('Place ' .. itemDB:getName(item) .. ' in supply chest')
|
||||||
turtle.placeUp()
|
msg = true
|
||||||
local _, bi = turtle.inspectUp()
|
end
|
||||||
turtle.digUp()
|
os.sleep(1)
|
||||||
return directions[bi.metadata]
|
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
getItem({ name = 'minecraft:piston', damage = 0 })
|
||||||
|
turtle.placeUp()
|
||||||
|
local _, bi = turtle.inspectUp()
|
||||||
|
turtle.digUp()
|
||||||
|
self:dumpInventoryWithCheck()
|
||||||
|
|
||||||
|
if directions[bi.metadata] then
|
||||||
|
self.facing = directions[bi.metadata]
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
return Builder.facing
|
|
||||||
|
-- if the piston faces up when placed above, then this version
|
||||||
|
-- has the stair bug
|
||||||
|
self.stairBug = true
|
||||||
|
|
||||||
|
getItem({ name = 'minecraft:chest', damage = 0 })
|
||||||
|
turtle.placeUp()
|
||||||
|
local _, bi2 = turtle.inspectUp()
|
||||||
|
turtle.digUp()
|
||||||
|
self:dumpInventoryWithCheck()
|
||||||
|
|
||||||
|
self.facing = directions[bi2.metadata]
|
||||||
end
|
end
|
||||||
|
|
||||||
function Builder:wrenchBlock(side, facing, cache)
|
function Builder:wrenchBlock(side, facing, cache)
|
||||||
|
|
||||||
local s = Builder:getWrenchSlot()
|
local s = Builder:getWrenchSlot()
|
||||||
|
|
||||||
if not s then
|
if not s then
|
||||||
b.needResupply = true
|
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -767,7 +754,7 @@ function Builder:wrenchBlock(side, facing, cache)
|
|||||||
|
|
||||||
if count then
|
if count then
|
||||||
turtle.select(s.index)
|
turtle.select(s.index)
|
||||||
for i = 1,count do
|
for _ = 1,count do
|
||||||
turtle.getAction(side).place()
|
turtle.getAction(side).place()
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
@@ -789,9 +776,9 @@ function Builder:wrenchBlock(side, facing, cache)
|
|||||||
facing = turtle.getHeadingInfo(offsetDirection).direction
|
facing = turtle.getHeadingInfo(offsetDirection).direction
|
||||||
end
|
end
|
||||||
|
|
||||||
count = 0
|
local count = 0
|
||||||
print('determining wrench count')
|
print('determining wrench count')
|
||||||
for i = 1, 6 do
|
for _ = 1, 6 do
|
||||||
local _, bi = turtle.getAction(side).inspect()
|
local _, bi = turtle.getAction(side).inspect()
|
||||||
|
|
||||||
if facing == directions[bi.metadata] then
|
if facing == directions[bi.metadata] then
|
||||||
@@ -812,11 +799,10 @@ function Builder:rotateBlock(side, facing)
|
|||||||
local s = Builder:getWrenchSlot()
|
local s = Builder:getWrenchSlot()
|
||||||
|
|
||||||
if not s then
|
if not s then
|
||||||
b.needResupply = true
|
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
for i = 1, facing do
|
for _ = 1, facing do
|
||||||
turtle.getAction(side).place()
|
turtle.getAction(side).place()
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -885,8 +871,8 @@ function Builder:placePiston(b)
|
|||||||
return success
|
return success
|
||||||
end
|
end
|
||||||
|
|
||||||
function Builder:goto(x, z, y, heading)
|
function Builder:_goto(x, z, y, heading)
|
||||||
if not turtle.goto(x, z, y, heading) then
|
if not turtle._goto(x, z, y, heading) then
|
||||||
print('stuck')
|
print('stuck')
|
||||||
print('Press enter to continue')
|
print('Press enter to continue')
|
||||||
os.sleep(1)
|
os.sleep(1)
|
||||||
@@ -910,7 +896,7 @@ function Builder:gotoEx(x, z, y, h, travelPlane)
|
|||||||
elseif distance > 1 then
|
elseif distance > 1 then
|
||||||
self:gotoTravelPlane(travelPlane)
|
self:gotoTravelPlane(travelPlane)
|
||||||
end
|
end
|
||||||
self:goto(x, z, y, h)
|
self:_goto(x, z, y, h)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Builder:placeDirectionalBlock(b, slot, travelPlane)
|
function Builder:placeDirectionalBlock(b, slot, travelPlane)
|
||||||
@@ -982,12 +968,11 @@ function Builder:placeDirectionalBlock(b, slot, travelPlane)
|
|||||||
local isSouth = (turtle.getHeadingInfo(Builder.facing).heading +
|
local isSouth = (turtle.getHeadingInfo(Builder.facing).heading +
|
||||||
turtle.getHeadingInfo(stairUpDirections[d]).heading) % 4 == 1
|
turtle.getHeadingInfo(stairUpDirections[d]).heading) % 4 == 1
|
||||||
|
|
||||||
if Util.getVersion() == 1.8 then
|
if not self.stairBug then
|
||||||
isSouth = false -- no stair bug in this version
|
isSouth = false
|
||||||
end
|
end
|
||||||
|
|
||||||
if isSouth then
|
if isSouth then
|
||||||
|
|
||||||
-- for some reason, the south facing stair doesn't place correctly
|
-- for some reason, the south facing stair doesn't place correctly
|
||||||
-- jump through some hoops to place it
|
-- jump through some hoops to place it
|
||||||
self:gotoEx(b.x, b.z, b.y, (turtle.getHeadingInfo(stairUpDirections[d]).heading + 2) % 4, travelPlane)
|
self:gotoEx(b.x, b.z, b.y, (turtle.getHeadingInfo(stairUpDirections[d]).heading + 2) % 4, travelPlane)
|
||||||
@@ -1213,13 +1198,6 @@ function Builder:build()
|
|||||||
elseif not self.isCommandComputer then
|
elseif not self.isCommandComputer then
|
||||||
travelPlane = self:findTravelPlane(self.index)
|
travelPlane = self:findTravelPlane(self.index)
|
||||||
turtle.status = 'building'
|
turtle.status = 'building'
|
||||||
if not self.confirmFacing then
|
|
||||||
local facing = self:getTurtleFacing()
|
|
||||||
if facing then
|
|
||||||
self.confirmFacing = true
|
|
||||||
self.facing = facing
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
UI:setPage('blank')
|
UI:setPage('blank')
|
||||||
@@ -1241,7 +1219,7 @@ function Builder:build()
|
|||||||
|
|
||||||
local function placeBlock(id, dmg, x, y, z)
|
local function placeBlock(id, dmg, x, y, z)
|
||||||
|
|
||||||
local cx, cy, cz = commands.getBlockPosition()
|
local cx, _, cz = commands.getBlockPosition()
|
||||||
|
|
||||||
local command = table.concat({
|
local command = table.concat({
|
||||||
"setblock",
|
"setblock",
|
||||||
@@ -1279,7 +1257,7 @@ function Builder:build()
|
|||||||
if b.y ~= turtle.getPoint().y then
|
if b.y ~= turtle.getPoint().y then
|
||||||
turtle.gotoY(b.y)
|
turtle.gotoY(b.y)
|
||||||
end
|
end
|
||||||
self:goto(b.x, b.z, b.y)
|
self:_goto(b.x, b.z, b.y)
|
||||||
turtle.digDown()
|
turtle.digDown()
|
||||||
|
|
||||||
-- if no supplier, then should fill all slots
|
-- if no supplier, then should fill all slots
|
||||||
@@ -1325,10 +1303,10 @@ function Builder:build()
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
self:gotoTravelPlane(travelPlane)
|
self:gotoTravelPlane(travelPlane)
|
||||||
self:goto(b.x, b.z, b.y)
|
self:_goto(b.x, b.z, b.y)
|
||||||
b.placed = self:placeDown(slot)
|
b.placed = self:placeDown(slot)
|
||||||
end
|
end
|
||||||
|
|
||||||
if b.placed then
|
if b.placed then
|
||||||
slot.qty = slot.qty - 1
|
slot.qty = slot.qty - 1
|
||||||
else
|
else
|
||||||
@@ -1366,7 +1344,7 @@ function Builder:build()
|
|||||||
turtle.setHeading(0)
|
turtle.setHeading(0)
|
||||||
Builder:dumpInventory()
|
Builder:dumpInventory()
|
||||||
|
|
||||||
for i = 1, 4 do
|
for _ = 1, 4 do
|
||||||
turtle.turnRight()
|
turtle.turnRight()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -1380,7 +1358,7 @@ function Builder:build()
|
|||||||
end
|
end
|
||||||
|
|
||||||
--[[-- blankPage --]]--
|
--[[-- blankPage --]]--
|
||||||
blankPage = UI.Page()
|
local blankPage = UI.Page()
|
||||||
function blankPage:draw()
|
function blankPage:draw()
|
||||||
self:clear(colors.black)
|
self:clear(colors.black)
|
||||||
self:setCursorPos(1, 1)
|
self:setCursorPos(1, 1)
|
||||||
@@ -1392,7 +1370,7 @@ function blankPage:enable()
|
|||||||
end
|
end
|
||||||
|
|
||||||
--[[-- selectSubstitutionPage --]]--
|
--[[-- selectSubstitutionPage --]]--
|
||||||
selectSubstitutionPage = UI.Page({
|
local selectSubstitutionPage = UI.Page({
|
||||||
titleBar = UI.TitleBar({
|
titleBar = UI.TitleBar({
|
||||||
title = 'Select a substitution',
|
title = 'Select a substitution',
|
||||||
previousPage = 'listing'
|
previousPage = 'listing'
|
||||||
@@ -1702,7 +1680,7 @@ function supplyPage:refresh()
|
|||||||
end
|
end
|
||||||
|
|
||||||
--[[-- ListingPage --]]--
|
--[[-- ListingPage --]]--
|
||||||
listingPage = UI.Page({
|
local listingPage = UI.Page({
|
||||||
titleBar = UI.TitleBar({
|
titleBar = UI.TitleBar({
|
||||||
title = 'Supply List',
|
title = 'Supply List',
|
||||||
previousPage = 'start'
|
previousPage = 'start'
|
||||||
@@ -1873,7 +1851,6 @@ function listingPage:manageBlock(selected)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--[[-- startPage --]]--
|
--[[-- startPage --]]--
|
||||||
|
|
||||||
local wy = 2
|
local wy = 2
|
||||||
local my = 3
|
local my = 3
|
||||||
|
|
||||||
@@ -1913,7 +1890,6 @@ local startPage = UI.Page {
|
|||||||
{ prompt = 'Set starting block', event = 'startBlock' },
|
{ prompt = 'Set starting block', event = 'startBlock' },
|
||||||
{ prompt = 'Supply list', event = 'assignBlocks' },
|
{ prompt = 'Supply list', event = 'assignBlocks' },
|
||||||
{ prompt = 'Toggle mode', event = 'toggleMode' },
|
{ prompt = 'Toggle mode', event = 'toggleMode' },
|
||||||
{ prompt = 'Toggle facing', event = 'toggleFacing' },
|
|
||||||
{ prompt = 'Begin', event = 'begin' },
|
{ prompt = 'Begin', event = 'begin' },
|
||||||
{ prompt = 'Quit', event = 'quit' }
|
{ prompt = 'Quit', event = 'quit' }
|
||||||
}
|
}
|
||||||
@@ -1926,16 +1902,10 @@ local startPage = UI.Page {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function startPage:draw()
|
function startPage:draw()
|
||||||
local fuel = turtle.getFuelLevel()
|
|
||||||
if fuel > 9999 then
|
|
||||||
fuel = string.format('%dk', math.floor(fuel/1024))
|
|
||||||
end
|
|
||||||
local t = {
|
local t = {
|
||||||
{ name = 'mode', value = Builder.mode },
|
{ name = 'mode', value = Builder.mode },
|
||||||
{ name = 'start', value = Builder.index },
|
{ name = 'start', value = Builder.index },
|
||||||
{ name = 'blocks', value = #schematic.blocks },
|
{ name = 'blocks', value = #schematic.blocks },
|
||||||
--{ name = 'fuel', value = fuel },
|
|
||||||
{ name = 'facing', value = Builder.facing },
|
|
||||||
{ name = 'length', value = schematic.length },
|
{ name = 'length', value = schematic.length },
|
||||||
{ name = 'width', value = schematic.width },
|
{ name = 'width', value = schematic.width },
|
||||||
{ name = 'height', value = schematic.height },
|
{ name = 'height', value = schematic.height },
|
||||||
@@ -1964,7 +1934,7 @@ function startPage:eventHandler(event)
|
|||||||
statusBar = UI.StatusBar(),
|
statusBar = UI.StatusBar(),
|
||||||
})
|
})
|
||||||
|
|
||||||
dialog.eventHandler = function(self, event)
|
function dialog:eventHandler(event)
|
||||||
if event.type == 'form_complete' then
|
if event.type == 'form_complete' then
|
||||||
local l = tonumber(self.form.textEntry.value)
|
local l = tonumber(self.form.textEntry.value)
|
||||||
if l and l < schematic.height and l >= 0 then
|
if l and l < schematic.height and l >= 0 then
|
||||||
@@ -2002,7 +1972,7 @@ function startPage:eventHandler(event)
|
|||||||
statusBar = UI.StatusBar(),
|
statusBar = UI.StatusBar(),
|
||||||
}
|
}
|
||||||
|
|
||||||
dialog.eventHandler = function(self, event)
|
function dialog:eventHandler(event)
|
||||||
if event.type == 'form_complete' then
|
if event.type == 'form_complete' then
|
||||||
local bn = tonumber(self.form.textEntry.value)
|
local bn = tonumber(self.form.textEntry.value)
|
||||||
if bn and bn < #schematic.blocks and bn >= 0 then
|
if bn and bn < #schematic.blocks and bn >= 0 then
|
||||||
@@ -2045,21 +2015,8 @@ function startPage:eventHandler(event)
|
|||||||
end
|
end
|
||||||
self:draw()
|
self:draw()
|
||||||
|
|
||||||
elseif event.type == 'toggleFacing' then
|
|
||||||
local directions = {
|
|
||||||
[ 'north' ] = 'east',
|
|
||||||
[ 'east' ] = 'south',
|
|
||||||
[ 'south' ] = 'west',
|
|
||||||
[ 'west' ] = 'north',
|
|
||||||
}
|
|
||||||
|
|
||||||
Builder.facing = directions[Builder.facing]
|
|
||||||
Builder:saveProgress(Builder.index)
|
|
||||||
self:draw()
|
|
||||||
|
|
||||||
elseif event.type == 'begin' then
|
elseif event.type == 'begin' then
|
||||||
UI:setPage('blank')
|
UI:setPage('blank')
|
||||||
--Builder.status = 'building'
|
|
||||||
|
|
||||||
turtle.status = 'thinking'
|
turtle.status = 'thinking'
|
||||||
print('Reloading schematic')
|
print('Reloading schematic')
|
||||||
@@ -2074,6 +2031,7 @@ function startPage:eventHandler(event)
|
|||||||
print('Beginning destruction')
|
print('Beginning destruction')
|
||||||
else
|
else
|
||||||
print('Starting build')
|
print('Starting build')
|
||||||
|
Builder:getTurtleFacing()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- reset piston cache in case wrench was substituted
|
-- reset piston cache in case wrench was substituted
|
||||||
|
|||||||
@@ -554,6 +554,7 @@ if not Util.getOptions(options, args) then
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- TODO: this won't work - need to Util.merge file into mining
|
||||||
mining.depth = options.depth.value
|
mining.depth = options.depth.value
|
||||||
mining.chunks = options.chunks.value
|
mining.chunks = options.chunks.value
|
||||||
|
|
||||||
@@ -619,7 +620,7 @@ turtle.run(function()
|
|||||||
unload()
|
unload()
|
||||||
status('mining')
|
status('mining')
|
||||||
|
|
||||||
local s, m = pcall(function() main() end)
|
local s, m = pcall(main)
|
||||||
if not s and m then
|
if not s and m then
|
||||||
_G.printError(m)
|
_G.printError(m)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user