proxy apis over wireless
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
local Blocks = require('blocks')
|
local Blocks = require('blocks')
|
||||||
|
local class = require('class')
|
||||||
local Message = require('message')
|
local Message = require('message')
|
||||||
local Util = require('util')
|
local Util = require('util')
|
||||||
|
|
||||||
@@ -6,7 +7,8 @@ local device = _G.device
|
|||||||
local fs = _G.fs
|
local fs = _G.fs
|
||||||
local turtle = _G.turtle
|
local turtle = _G.turtle
|
||||||
|
|
||||||
local Builder = {
|
local Builder = class()
|
||||||
|
Util.merge(Builder, {
|
||||||
isCommandComputer = not turtle,
|
isCommandComputer = not turtle,
|
||||||
slots = { },
|
slots = { },
|
||||||
loc = { },
|
loc = { },
|
||||||
@@ -15,9 +17,7 @@ local Builder = {
|
|||||||
fuelItem = { id = 'minecraft:coal', dmg = 0 },
|
fuelItem = { id = 'minecraft:coal', dmg = 0 },
|
||||||
resourceSlots = 14,
|
resourceSlots = 14,
|
||||||
facing = 'south',
|
facing = 'south',
|
||||||
wrenchSucks = false,
|
})
|
||||||
stairBug = false,
|
|
||||||
}
|
|
||||||
|
|
||||||
local BUILDER_DIR = 'usr/builder'
|
local BUILDER_DIR = 'usr/builder'
|
||||||
|
|
||||||
@@ -26,26 +26,6 @@ local blockInfo = Blocks()
|
|||||||
function Builder:getBlockCounts()
|
function Builder:getBlockCounts()
|
||||||
local blocks = { }
|
local blocks = { }
|
||||||
|
|
||||||
-- add a couple essential items to the supply list to allow replacements
|
|
||||||
if not self.isCommandComputer then
|
|
||||||
local wrench = self.subDB:getSubstitutedItem('SubstituteAWrench', 0)
|
|
||||||
wrench.qty = 0
|
|
||||||
wrench.need = 1
|
|
||||||
blocks[wrench.id .. ':' .. wrench.dmg] = wrench
|
|
||||||
|
|
||||||
local fuel = self.subDB:getSubstitutedItem(Builder.fuelItem.id, Builder.fuelItem.dmg)
|
|
||||||
fuel.qty = 0
|
|
||||||
fuel.need = 1
|
|
||||||
blocks[fuel.id .. ':' .. fuel.dmg] = fuel
|
|
||||||
|
|
||||||
blocks['minecraft:piston:0'] = {
|
|
||||||
id = 'minecraft:piston',
|
|
||||||
dmg = 0,
|
|
||||||
qty = 0,
|
|
||||||
need = 1,
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
for k = self.index, #self.schematic.blocks do
|
for k = self.index, #self.schematic.blocks do
|
||||||
local b = self.schematic.blocks[k]
|
local b = self.schematic.blocks[k]
|
||||||
local key = tostring(b.id) .. ':' .. b.dmg
|
local key = tostring(b.id) .. ':' .. b.dmg
|
||||||
@@ -107,19 +87,19 @@ end
|
|||||||
function Builder:saveProgress(index)
|
function Builder:saveProgress(index)
|
||||||
Util.writeTable(
|
Util.writeTable(
|
||||||
fs.combine(BUILDER_DIR, self.schematic.filename .. '.progress'),
|
fs.combine(BUILDER_DIR, self.schematic.filename .. '.progress'),
|
||||||
{ index = index, facing = Builder.facing, loc = Builder.loc }
|
{ index = index, facing = self.facing, loc = self.loc }
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Builder:loadProgress(filename)
|
function Builder:loadProgress(filename)
|
||||||
local progress = Util.readTable(fs.combine(BUILDER_DIR, filename))
|
local progress = Util.readTable(fs.combine(BUILDER_DIR, filename))
|
||||||
if progress then
|
if progress then
|
||||||
Builder.index = progress.index
|
self.index = progress.index
|
||||||
if Builder.index > #self.schematic.blocks then
|
if self.index > #self.schematic.blocks then
|
||||||
Builder.index = 1
|
self.index = 1
|
||||||
end
|
end
|
||||||
Builder.facing = progress.facing or 'south'
|
self.facing = progress.facing or 'south'
|
||||||
Builder.loc = progress.loc or { }
|
self.loc = progress.loc or { }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
|
local Adapter = require('inventoryAdapter')
|
||||||
local Builder = require('builder.builder')
|
local Builder = require('builder.builder')
|
||||||
|
local class = require('class')
|
||||||
local Event = require('event')
|
local Event = require('event')
|
||||||
local itemDB = require('itemDB')
|
local itemDB = require('itemDB')
|
||||||
local Message = require('message')
|
local Message = require('message')
|
||||||
local Point = require('point')
|
local Point = require('point')
|
||||||
local TableDB = require('tableDB')
|
|
||||||
local UI = require('ui')
|
local UI = require('ui')
|
||||||
local Util = require('util')
|
local Util = require('util')
|
||||||
|
|
||||||
@@ -14,14 +15,7 @@ local read = _G.read
|
|||||||
local rs = _G.rs
|
local rs = _G.rs
|
||||||
local turtle = _G.turtle
|
local turtle = _G.turtle
|
||||||
|
|
||||||
local BUILDER_DIR = 'usr/builder'
|
local TurtleBuilder = class(Builder)
|
||||||
|
|
||||||
local pistonFacings
|
|
||||||
|
|
||||||
local ChestAdapter = require('chestAdapter')
|
|
||||||
if Util.checkMinecraftVersion(1.8) then
|
|
||||||
ChestAdapter = require('chestAdapter18')
|
|
||||||
end
|
|
||||||
|
|
||||||
-- 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)
|
||||||
@@ -92,10 +86,10 @@ local supplyPage = UI.Page {
|
|||||||
|
|
||||||
function supplyPage:eventHandler(event)
|
function supplyPage:eventHandler(event)
|
||||||
if event.type == 'build' then
|
if event.type == 'build' then
|
||||||
Builder:build()
|
self.builder:build()
|
||||||
|
|
||||||
elseif event.type == 'menu' then
|
elseif event.type == 'menu' then
|
||||||
Builder:dumpInventory()
|
self.builder:dumpInventory()
|
||||||
--Builder.status = 'idle'
|
--Builder.status = 'idle'
|
||||||
UI:setPage('start')
|
UI:setPage('start')
|
||||||
turtle.status = 'idle'
|
turtle.status = 'idle'
|
||||||
@@ -111,16 +105,15 @@ function supplyPage:eventHandler(event)
|
|||||||
return UI.Page.eventHandler(self, event)
|
return UI.Page.eventHandler(self, event)
|
||||||
end
|
end
|
||||||
|
|
||||||
function supplyPage:enable()
|
function supplyPage:enable(builder)
|
||||||
|
self.builder = builder
|
||||||
self.grid:setIndex(1)
|
self.grid:setIndex(1)
|
||||||
self.statusBar:setValue('fuel',
|
self.statusBar:setValue('fuel',
|
||||||
string.format('Fuel: %dk', math.floor(turtle.getFuelLevel() / 1024)))
|
string.format('Fuel: %dk', math.floor(turtle.getFuelLevel() / 1024)))
|
||||||
-- self.statusBar:setValue('block',
|
|
||||||
-- string.format('Block: %d', Builder.index))
|
|
||||||
|
|
||||||
Event.addNamedTimer('supplyRefresh', 6, true, function()
|
Event.addNamedTimer('supplyRefresh', 6, true, function()
|
||||||
if self.enabled then
|
if self.enabled then
|
||||||
Builder:autocraft(Builder:getSupplies())
|
self.builder:autocraft(self.builder:getSupplies())
|
||||||
self:refresh()
|
self:refresh()
|
||||||
self.statusBar:timedStatus('Refreshed ', 2)
|
self.statusBar:timedStatus('Refreshed ', 2)
|
||||||
self:sync()
|
self:sync()
|
||||||
@@ -152,26 +145,41 @@ end
|
|||||||
|
|
||||||
function supplyPage:refresh()
|
function supplyPage:refresh()
|
||||||
self.statusBar:timedStatus('Refreshed ', 3)
|
self.statusBar:timedStatus('Refreshed ', 3)
|
||||||
local supplies = Builder:getSupplies()
|
local supplies = self.builder:getSupplies()
|
||||||
if #supplies == 0 then
|
if #supplies == 0 then
|
||||||
Builder:build()
|
self.builder:build()
|
||||||
else
|
else
|
||||||
self:setSupplies(supplies)
|
self:setSupplies(supplies)
|
||||||
self.grid:draw()
|
self.grid:draw()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[-- maxStackDB --]]--
|
--[[-- Builder --]]--
|
||||||
local maxStackDB = TableDB({
|
function TurtleBuilder:getBlockCounts()
|
||||||
fileName = fs.combine(BUILDER_DIR, 'maxstack.db'),
|
local blocks = Builder.getBlockCounts(self)
|
||||||
})
|
|
||||||
|
|
||||||
function maxStackDB:get(id, dmg)
|
-- add a couple essential items to the supply list to allow replacements
|
||||||
return self.data[id .. ':' .. dmg] or 64
|
local wrench = self.subDB:getSubstitutedItem('SubstituteAWrench', 0)
|
||||||
|
wrench.qty = 0
|
||||||
|
wrench.need = 1
|
||||||
|
blocks[wrench.id .. ':' .. wrench.dmg] = wrench
|
||||||
|
|
||||||
|
local fuel = self.subDB:getSubstitutedItem(Builder.fuelItem.id, Builder.fuelItem.dmg)
|
||||||
|
fuel.qty = 0
|
||||||
|
fuel.need = 1
|
||||||
|
blocks[fuel.id .. ':' .. fuel.dmg] = fuel
|
||||||
|
|
||||||
|
blocks['minecraft:piston:0'] = {
|
||||||
|
id = 'minecraft:piston',
|
||||||
|
dmg = 0,
|
||||||
|
qty = 0,
|
||||||
|
need = 1,
|
||||||
|
}
|
||||||
|
|
||||||
|
return blocks
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[-- Builder --]]--
|
function TurtleBuilder: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
|
||||||
@@ -188,7 +196,7 @@ function Builder:selectItem(id, dmg)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Builder:getAirResupplyList(blockIndex)
|
function TurtleBuilder:getAirResupplyList(blockIndex)
|
||||||
local slots = { }
|
local slots = { }
|
||||||
|
|
||||||
if self.mode == 'destroy' then
|
if self.mode == 'destroy' then
|
||||||
@@ -203,10 +211,10 @@ function Builder:getAirResupplyList(blockIndex)
|
|||||||
slots = self:getGenericSupplyList(blockIndex)
|
slots = self:getGenericSupplyList(blockIndex)
|
||||||
end
|
end
|
||||||
|
|
||||||
local fuel = self.subDB:getSubstitutedItem(Builder.fuelItem.id, Builder.fuelItem.dmg)
|
local fuel = self.subDB:getSubstitutedItem(self.fuelItem.id, self.fuelItem.dmg)
|
||||||
|
|
||||||
slots[15] = {
|
slots[15] = {
|
||||||
id = 'minecraft:chest', --'ironchest:BlockIronChest', --
|
id = 'minecraft:chest',
|
||||||
dmg = 0,
|
dmg = 0,
|
||||||
qty = 0,
|
qty = 0,
|
||||||
need = 1,
|
need = 1,
|
||||||
@@ -216,7 +224,6 @@ function Builder:getAirResupplyList(blockIndex)
|
|||||||
slots[16] = {
|
slots[16] = {
|
||||||
id = fuel.id,
|
id = fuel.id,
|
||||||
dmg = fuel.dmg,
|
dmg = fuel.dmg,
|
||||||
wrench = true,
|
|
||||||
qty = 0,
|
qty = 0,
|
||||||
need = 64,
|
need = 64,
|
||||||
index = 16,
|
index = 16,
|
||||||
@@ -225,7 +232,7 @@ function Builder:getAirResupplyList(blockIndex)
|
|||||||
return slots
|
return slots
|
||||||
end
|
end
|
||||||
|
|
||||||
function Builder:getSupplyList(blockIndex)
|
function TurtleBuilder:getSupplyList(blockIndex)
|
||||||
local slots, lastBlock = self:getGenericSupplyList(blockIndex)
|
local slots, lastBlock = self:getGenericSupplyList(blockIndex)
|
||||||
|
|
||||||
slots[15] = {
|
slots[15] = {
|
||||||
@@ -240,7 +247,6 @@ function Builder:getSupplyList(blockIndex)
|
|||||||
slots[16] = {
|
slots[16] = {
|
||||||
id = wrench.id,
|
id = wrench.id,
|
||||||
dmg = wrench.dmg,
|
dmg = wrench.dmg,
|
||||||
wrench = true,
|
|
||||||
qty = 0,
|
qty = 0,
|
||||||
need = 1,
|
need = 1,
|
||||||
index = 16,
|
index = 16,
|
||||||
@@ -251,7 +257,7 @@ function Builder:getSupplyList(blockIndex)
|
|||||||
return lastBlock
|
return lastBlock
|
||||||
end
|
end
|
||||||
|
|
||||||
function Builder:getGenericSupplyList(blockIndex)
|
function TurtleBuilder:getGenericSupplyList(blockIndex)
|
||||||
local slots = { }
|
local slots = { }
|
||||||
|
|
||||||
for i = 1, self.resourceSlots do
|
for i = 1, self.resourceSlots do
|
||||||
@@ -264,7 +270,7 @@ function Builder:getGenericSupplyList(blockIndex)
|
|||||||
|
|
||||||
local function getSlot(id, dmg)
|
local function getSlot(id, dmg)
|
||||||
-- find matching slot
|
-- find matching slot
|
||||||
local maxStack = maxStackDB:get(id, dmg)
|
local maxStack = itemDB:getMaxCount({ name = id, damage = dmg })
|
||||||
for _, s in ipairs(slots) do
|
for _, s in ipairs(slots) do
|
||||||
if s.id == id and s.dmg == dmg and s.need < maxStack then
|
if s.id == id and s.dmg == dmg and s.need < maxStack then
|
||||||
return s
|
return s
|
||||||
@@ -304,7 +310,7 @@ function Builder:getGenericSupplyList(blockIndex)
|
|||||||
return slots, lastBlock
|
return slots, lastBlock
|
||||||
end
|
end
|
||||||
|
|
||||||
function Builder:dumpInventory()
|
function TurtleBuilder:dumpInventory()
|
||||||
local success = true
|
local success = true
|
||||||
|
|
||||||
for i = 1, 16 do
|
for i = 1, 16 do
|
||||||
@@ -321,7 +327,7 @@ function Builder:dumpInventory()
|
|||||||
return success
|
return success
|
||||||
end
|
end
|
||||||
|
|
||||||
function Builder:dumpInventoryWithCheck()
|
function TurtleBuilder: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')
|
||||||
@@ -330,7 +336,7 @@ function Builder:dumpInventoryWithCheck()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Builder:autocraft(supplies)
|
function TurtleBuilder:autocraft(supplies)
|
||||||
local t = { }
|
local t = { }
|
||||||
|
|
||||||
for _,s in pairs(supplies) do
|
for _,s in pairs(supplies) do
|
||||||
@@ -350,7 +356,7 @@ function Builder:autocraft(supplies)
|
|||||||
self.itemAdapter:craftItems(convertForward(t))
|
self.itemAdapter:craftItems(convertForward(t))
|
||||||
end
|
end
|
||||||
|
|
||||||
function Builder:getSupplies()
|
function TurtleBuilder:getSupplies()
|
||||||
self.itemAdapter:refresh()
|
self.itemAdapter:refresh()
|
||||||
|
|
||||||
local t = { }
|
local t = { }
|
||||||
@@ -367,9 +373,6 @@ function Builder:getSupplies()
|
|||||||
local qty = math.min(s.need - s.qty, item.qty)
|
local qty = math.min(s.need - s.qty, item.qty)
|
||||||
|
|
||||||
if qty + s.qty > item.max_size then
|
if qty + s.qty > item.max_size then
|
||||||
maxStackDB:add({ s.id, s.dmg }, item.max_size)
|
|
||||||
maxStackDB.dirty = true
|
|
||||||
maxStackDB:flush()
|
|
||||||
qty = item.max_size
|
qty = item.max_size
|
||||||
s.need = qty
|
s.need = qty
|
||||||
end
|
end
|
||||||
@@ -389,7 +392,7 @@ function Builder:getSupplies()
|
|||||||
return t
|
return t
|
||||||
end
|
end
|
||||||
|
|
||||||
function Builder:refuel()
|
function TurtleBuilder:refuel()
|
||||||
while turtle.getFuelLevel() < 4000 do
|
while turtle.getFuelLevel() < 4000 do
|
||||||
print('Refueling')
|
print('Refueling')
|
||||||
turtle.select(1)
|
turtle.select(1)
|
||||||
@@ -408,7 +411,7 @@ function Builder:refuel()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Builder:inAirDropoff()
|
function TurtleBuilder:inAirDropoff()
|
||||||
if not device.wireless_modem then
|
if not device.wireless_modem then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
@@ -434,9 +437,9 @@ function Builder:inAirDropoff()
|
|||||||
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 = Adapter.wrap({ direction = 'down', wrapSide = 'top' })
|
||||||
|
|
||||||
if not chestAdapter:isValid() then
|
if not chestAdapter then
|
||||||
self:log('Chests above is not valid')
|
self:log('Chests above is not valid')
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
@@ -468,7 +471,7 @@ function Builder:inAirDropoff()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Builder:inAirResupply()
|
function TurtleBuilder:inAirResupply()
|
||||||
if not device.wireless_modem then
|
if not device.wireless_modem then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
@@ -496,9 +499,9 @@ function Builder:inAirResupply()
|
|||||||
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 = Adapter.wrap({ direction = 'down', wrapSide = 'top' })
|
||||||
|
|
||||||
if not chestAdapter:isValid() then
|
if not chestAdapter then
|
||||||
Util.print('not valid')
|
Util.print('not valid')
|
||||||
read()
|
read()
|
||||||
end
|
end
|
||||||
@@ -540,7 +543,7 @@ function Builder:inAirResupply()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Builder:sendSupplyRequest(lastBlock)
|
function TurtleBuilder: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()
|
||||||
@@ -577,32 +580,30 @@ local function closestEdgePoint(pt, pts, rpt)
|
|||||||
return cpt
|
return cpt
|
||||||
end
|
end
|
||||||
|
|
||||||
function Builder:getBuildingCorner()
|
function TurtleBuilder:getBuildingCorner()
|
||||||
local pts = {
|
local pts = {
|
||||||
{ x = -1, z = -1, y = 0 },
|
{ x = -1, z = -1, y = 0 },
|
||||||
{ x = -1, z = self.schematic.length, y = 0 },
|
{ x = -1, z = self.schematic.length, y = 0 },
|
||||||
{ x = self.schematic.width, z = -1, y = 0 },
|
{ x = self.schematic.width, z = -1, y = 0 },
|
||||||
{ x = self.schematic.width, z = self.schematic.length, y = 0 },
|
{ x = self.schematic.width, z = self.schematic.length, y = 0 },
|
||||||
}
|
}
|
||||||
-- local supplyPoint = Util.shallowCopy(self.supplyPoint)
|
return closestEdgePoint(self.supplyPoint, pts, turtle.getPoint())
|
||||||
-- supplyPoint.heading = turtle.point.heading
|
|
||||||
return closestEdgePoint(self.supplyPoint, pts, turtle.point)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function Builder:gotoSupplyPoint()
|
function TurtleBuilder:gotoSupplyPoint()
|
||||||
if not Point.same(turtle.point, self.supplyPoint) then
|
if not Point.same(turtle.getPoint(), self.supplyPoint) then
|
||||||
-- so we don't end up pathfinding through a building
|
-- so we don't end up pathfinding through a building
|
||||||
-- go to the corner closest to the supplies point
|
-- go to the corner closest to the supplies point
|
||||||
-- pathfind the rest of the way
|
-- pathfind the rest of the way
|
||||||
local pt = self:getBuildingCorner()
|
local pt = self:getBuildingCorner()
|
||||||
turtle._goto(pt.x, pt.z)
|
turtle._goto(pt.x, pt.z)
|
||||||
turtle.setPolicy(turtle.policies.none)
|
turtle.setPolicy('none')
|
||||||
turtle.pathfind(self.supplyPoint)
|
turtle.pathfind(self.supplyPoint)
|
||||||
os.sleep(.1) -- random 'Computer is not connected' error...
|
os.sleep(.1) -- random 'Computer is not connected' error...
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Builder:resupply()
|
function TurtleBuilder:resupply()
|
||||||
if self.slotUid and self:inAirResupply() then
|
if self.slotUid and self:inAirResupply() then
|
||||||
os.queueEvent('build')
|
os.queueEvent('build')
|
||||||
return
|
return
|
||||||
@@ -629,29 +630,29 @@ function Builder:resupply()
|
|||||||
turtle.setHeading(0)
|
turtle.setHeading(0)
|
||||||
self:autocraft(supplies)
|
self:autocraft(supplies)
|
||||||
supplyPage:setSupplies(supplies)
|
supplyPage:setSupplies(supplies)
|
||||||
UI:setPage(supplyPage)
|
UI:setPage(supplyPage, self)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Builder:placeDown(slot)
|
function TurtleBuilder:placeDown(slot)
|
||||||
return turtle.placeDown(slot.index)
|
return turtle.placeDown(slot.index)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Builder:placeUp(slot)
|
function TurtleBuilder:placeUp(slot)
|
||||||
return turtle.placeUp(slot.index)
|
return turtle.placeUp(slot.index)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Builder:place(slot)
|
function TurtleBuilder:place(slot)
|
||||||
return turtle.place(slot.index)
|
return turtle.place(slot.index)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Builder:getWrenchSlot()
|
function TurtleBuilder:getWrenchSlot()
|
||||||
local wrench = self.subDB:getSubstitutedItem('SubstituteAWrench', 0)
|
local wrench = self.subDB:getSubstitutedItem('SubstituteAWrench', 0)
|
||||||
return self:selectItem(wrench.id, wrench.dmg)
|
return self: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 TurtleBuilder:getTurtleFacing()
|
||||||
local directions = { -- reversed directions
|
local directions = { -- reversed directions
|
||||||
[5] = 'west',
|
[5] = 'west',
|
||||||
[3] = 'north',
|
[3] = 'north',
|
||||||
@@ -699,14 +700,14 @@ function Builder:getTurtleFacing()
|
|||||||
self.facing = directions[bi2.metadata]
|
self.facing = directions[bi2.metadata]
|
||||||
end
|
end
|
||||||
|
|
||||||
function Builder:wrenchBlock(side, facing, cache)
|
function TurtleBuilder:wrenchBlock(side, facing, cache)
|
||||||
local s = self:getWrenchSlot()
|
local s = self:getWrenchSlot()
|
||||||
|
|
||||||
if not s then
|
if not s then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
local key = turtle.point.heading .. '-' .. facing
|
local key = turtle.getPoint().heading .. '-' .. facing
|
||||||
if cache then
|
if cache then
|
||||||
local count = cache[side][key]
|
local count = cache[side][key]
|
||||||
|
|
||||||
@@ -752,7 +753,7 @@ function Builder:wrenchBlock(side, facing, cache)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
function Builder:rotateBlock(side, facing)
|
function TurtleBuilder:rotateBlock(side, facing)
|
||||||
local s = self:getWrenchSlot()
|
local s = self:getWrenchSlot()
|
||||||
|
|
||||||
if not s then
|
if not s then
|
||||||
@@ -767,7 +768,7 @@ function Builder:rotateBlock(side, facing)
|
|||||||
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 TurtleBuilder:placePiston(b)
|
||||||
local ps = self:selectItem('minecraft:piston', 0)
|
local ps = self:selectItem('minecraft:piston', 0)
|
||||||
local ws = self:getWrenchSlot()
|
local ws = self:getWrenchSlot()
|
||||||
|
|
||||||
@@ -789,7 +790,8 @@ function Builder:placePiston(b)
|
|||||||
turtle.turnLeft()
|
turtle.turnLeft()
|
||||||
end
|
end
|
||||||
|
|
||||||
local success = self:wrenchBlock('forward', 'down', pistonFacings) --wrench piston to point downwards
|
--wrench piston to point downwards
|
||||||
|
local success = self:wrenchBlock('forward', 'down', self.pistonFacings)
|
||||||
|
|
||||||
rs.setOutput('front', true)
|
rs.setOutput('front', true)
|
||||||
os.sleep(.25)
|
os.sleep(.25)
|
||||||
@@ -806,7 +808,7 @@ function Builder:placePiston(b)
|
|||||||
return success
|
return success
|
||||||
end
|
end
|
||||||
|
|
||||||
function Builder:_goto(x, z, y, heading)
|
function TurtleBuilder:_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')
|
||||||
@@ -818,14 +820,15 @@ end
|
|||||||
|
|
||||||
-- goto used when turtle could be below travel plane
|
-- goto used when turtle could be below travel plane
|
||||||
-- if the distance is no more than 1 block, there's no need to pop back to the travel plane
|
-- if the distance is no more than 1 block, there's no need to pop back to the travel plane
|
||||||
function Builder:gotoEx(x, z, y, h, travelPlane)
|
function TurtleBuilder:gotoEx(x, z, y, h, travelPlane)
|
||||||
local distance = math.abs(turtle.getPoint().x - x) + math.abs(turtle.getPoint().z - z)
|
local pt = turtle.getPoint()
|
||||||
|
local distance = math.abs(pt.x - x) + math.abs(pt.z - z)
|
||||||
|
|
||||||
-- following code could be better
|
-- following code could be better
|
||||||
if distance == 0 then
|
if distance == 0 then
|
||||||
turtle.gotoY(y)
|
turtle.gotoY(y)
|
||||||
elseif distance == 1 then
|
elseif distance == 1 then
|
||||||
if turtle.point.y < y then
|
if pt.y < y then
|
||||||
turtle.gotoY(y)
|
turtle.gotoY(y)
|
||||||
end
|
end
|
||||||
elseif distance > 1 then
|
elseif distance > 1 then
|
||||||
@@ -834,7 +837,7 @@ function Builder:gotoEx(x, z, y, h, travelPlane)
|
|||||||
self:_goto(x, z, y, h)
|
self:_goto(x, z, y, h)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Builder:placeDirectionalBlock(b, slot, travelPlane)
|
function TurtleBuilder:placeDirectionalBlock(b, slot, travelPlane)
|
||||||
local d = b.direction
|
local d = b.direction
|
||||||
|
|
||||||
local function getAdjacentPoint(pt, direction)
|
local function getAdjacentPoint(pt, direction)
|
||||||
@@ -912,12 +915,13 @@ function Builder:placeDirectionalBlock(b, slot, travelPlane)
|
|||||||
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)
|
||||||
if self:placeUp(slot) then
|
if self:placeUp(slot) then
|
||||||
turtle.goback()
|
turtle.goback()
|
||||||
turtle.gotoY(turtle.point.y + 2)
|
turtle.gotoY(turtle.getPoint().y + 2)
|
||||||
b.placed = self:placePiston(b)
|
b.placed = self:placePiston(b)
|
||||||
turtle.down()
|
turtle.down()
|
||||||
b.placed = self:placePiston(b)
|
b.placed = self:placePiston(b)
|
||||||
|
|
||||||
b.heading = turtle.point.heading -- stop debug message below since we are pointing in wrong direction
|
-- stop debug message below since we are pointing in wrong direction
|
||||||
|
b.heading = turtle.getPoint().heading
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
local hi = turtle.getHeadingInfo(stairUpDirections[d])
|
local hi = turtle.getHeadingInfo(stairUpDirections[d])
|
||||||
@@ -961,7 +965,7 @@ function Builder:placeDirectionalBlock(b, slot, travelPlane)
|
|||||||
if pistonDirections[d] then
|
if pistonDirections[d] then
|
||||||
-- why are pistons so broke in cc 1.7 ??????????????????????
|
-- why are pistons so broke in cc 1.7 ??????????????????????
|
||||||
|
|
||||||
local ws = Builder:getWrenchSlot()
|
local ws = self:getWrenchSlot()
|
||||||
|
|
||||||
if not ws then
|
if not ws then
|
||||||
b.needResupply = true
|
b.needResupply = true
|
||||||
@@ -980,12 +984,12 @@ function Builder:placeDirectionalBlock(b, slot, travelPlane)
|
|||||||
self:gotoEx(b.x, b.z, b.y, nil, travelPlane)
|
self:gotoEx(b.x, b.z, b.y, nil, travelPlane)
|
||||||
|
|
||||||
local heading = rotatedPistonDirections[d]
|
local heading = rotatedPistonDirections[d]
|
||||||
if heading and turtle.point.heading % 2 ~= heading % 2 then
|
if heading and turtle.getPoint().heading % 2 ~= heading % 2 then
|
||||||
turtle.setHeading(heading)
|
turtle.setHeading(heading)
|
||||||
end
|
end
|
||||||
|
|
||||||
if self:placeDown(slot) then
|
if self:placeDown(slot) then
|
||||||
b.placed = self:wrenchBlock('down', pistonDirections[d], pistonFacings)
|
b.placed = self:wrenchBlock('down', pistonDirections[d], self.pistonFacings)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -1051,7 +1055,7 @@ 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 TurtleBuilder:findTravelPlane(index)
|
||||||
local travelPlane
|
local travelPlane
|
||||||
|
|
||||||
for i = index, 1, -1 do
|
for i = index, 1, -1 do
|
||||||
@@ -1071,13 +1075,13 @@ function Builder:findTravelPlane(index)
|
|||||||
return travelPlane or 0
|
return travelPlane or 0
|
||||||
end
|
end
|
||||||
|
|
||||||
function Builder:gotoTravelPlane(travelPlane)
|
function TurtleBuilder:gotoTravelPlane(travelPlane)
|
||||||
if travelPlane > turtle.point.y then
|
if travelPlane > turtle.getPoint().y then
|
||||||
turtle.gotoY(travelPlane)
|
turtle.gotoY(travelPlane)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Builder:build()
|
function TurtleBuilder:build()
|
||||||
local direction = 1
|
local direction = 1
|
||||||
local last = #self.schematic.blocks
|
local last = #self.schematic.blocks
|
||||||
local travelPlane = 0
|
local travelPlane = 0
|
||||||
@@ -1095,7 +1099,7 @@ function Builder:build()
|
|||||||
|
|
||||||
local pt = self:getBuildingCorner()
|
local pt = self:getBuildingCorner()
|
||||||
turtle.pathfind({ x = pt.x, z = pt.z, y = travelPlane })
|
turtle.pathfind({ x = pt.x, z = pt.z, y = travelPlane })
|
||||||
turtle.setPolicy(turtle.policies.digAttack)
|
turtle.setPolicy('digAttack')
|
||||||
|
|
||||||
for i = self.index, last, direction do
|
for i = self.index, last, direction do
|
||||||
self.index = i
|
self.index = i
|
||||||
@@ -1204,30 +1208,28 @@ function Builder:build()
|
|||||||
Event.exitPullEvents()
|
Event.exitPullEvents()
|
||||||
end
|
end
|
||||||
|
|
||||||
function Builder:begin()
|
function TurtleBuilder:begin()
|
||||||
if self.loc.x then
|
if self.loc.x then
|
||||||
self.supplyPoint = {
|
self.supplyPoint = {
|
||||||
x = Builder.loc.x - Builder.loc.rx - 1,
|
x = self.loc.x - self.loc.rx - 1,
|
||||||
y = Builder.loc.y - Builder.loc.ry,
|
y = self.loc.y - self.loc.ry,
|
||||||
z = Builder.loc.z - Builder.loc.rz - 1,
|
z = self.loc.z - self.loc.rz - 1,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
self.supplyPoint = { x = -1, y = 0, z = -1 }
|
self.supplyPoint = { x = -1, y = 0, z = -1 }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
turtle.reset()
|
||||||
self:dumpInventory()
|
self:dumpInventory()
|
||||||
self:refuel()
|
self:refuel()
|
||||||
|
self:getTurtleFacing()
|
||||||
|
|
||||||
if self.mode == 'build' then
|
local facing = turtle.getHeadingInfo(self.facing).heading
|
||||||
self:getTurtleFacing()
|
|
||||||
end
|
|
||||||
|
|
||||||
local facing = turtle.getHeadingInfo(Builder.facing).heading
|
|
||||||
Point.rotate(self.supplyPoint, facing)
|
Point.rotate(self.supplyPoint, facing)
|
||||||
turtle.setPoint(self.supplyPoint)
|
turtle.setPoint(self.supplyPoint)
|
||||||
|
|
||||||
-- reset piston cache in case wrench was substituted
|
-- reset piston cache in case wrench was substituted
|
||||||
pistonFacings = {
|
self.pistonFacings = {
|
||||||
down = { },
|
down = { },
|
||||||
forward = { },
|
forward = { },
|
||||||
}
|
}
|
||||||
@@ -1244,10 +1246,4 @@ function Builder:begin()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
maxStackDB:load()
|
return TurtleBuilder
|
||||||
|
|
||||||
Event.on('build', function()
|
|
||||||
Builder:build()
|
|
||||||
end)
|
|
||||||
|
|
||||||
return Builder
|
|
||||||
|
|||||||
24
apis/inventoryAdapter.lua
Normal file
24
apis/inventoryAdapter.lua
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
local ChestAdapter = require('chestAdapter')
|
||||||
|
local ChestAdapter18 = require('chestAdapter18')
|
||||||
|
local MEAdapter = require('meAdapter')
|
||||||
|
|
||||||
|
local Adapter = { }
|
||||||
|
|
||||||
|
function Adapter.wrap(args)
|
||||||
|
local adapter = ChestAdapter18(args)
|
||||||
|
if adapter:isValid() then
|
||||||
|
return adapter
|
||||||
|
end
|
||||||
|
|
||||||
|
adapter = MEAdapter(args)
|
||||||
|
if adapter:isValid() then
|
||||||
|
return adapter
|
||||||
|
end
|
||||||
|
|
||||||
|
adapter = ChestAdapter(args)
|
||||||
|
if adapter:isValid() then
|
||||||
|
return adapter
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return Adapter
|
||||||
@@ -9,7 +9,6 @@ function itemDB:makeKey(item)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function itemDB:splitKey(key, item)
|
function itemDB:splitKey(key, item)
|
||||||
|
|
||||||
item = item or { }
|
item = item or { }
|
||||||
|
|
||||||
local t = Util.split(key, '(.-):')
|
local t = Util.split(key, '(.-):')
|
||||||
@@ -23,7 +22,6 @@ function itemDB:splitKey(key, item)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function itemDB:get(key)
|
function itemDB:get(key)
|
||||||
|
|
||||||
local item = TableDB.get(self, key)
|
local item = TableDB.get(self, key)
|
||||||
|
|
||||||
if item then
|
if item then
|
||||||
@@ -42,7 +40,6 @@ function itemDB:get(key)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function itemDB:add(key, item)
|
function itemDB:add(key, item)
|
||||||
|
|
||||||
if item.maxDamage > 0 then
|
if item.maxDamage > 0 then
|
||||||
key = { key[1], 0, key[3] }
|
key = { key[1], 0, key[3] }
|
||||||
end
|
end
|
||||||
@@ -51,7 +48,6 @@ end
|
|||||||
|
|
||||||
-- Accepts: "minecraft:stick:0" or { name = 'minecraft:stick', damage = 0 }
|
-- Accepts: "minecraft:stick:0" or { name = 'minecraft:stick', damage = 0 }
|
||||||
function itemDB:getName(item)
|
function itemDB:getName(item)
|
||||||
|
|
||||||
if type(item) == 'string' then
|
if type(item) == 'string' then
|
||||||
item = self:splitKey(item)
|
item = self:splitKey(item)
|
||||||
end
|
end
|
||||||
@@ -65,8 +61,20 @@ function itemDB:getName(item)
|
|||||||
return nameDB:getName(item.name .. ':' .. item.damage)
|
return nameDB:getName(item.name .. ':' .. item.damage)
|
||||||
end
|
end
|
||||||
|
|
||||||
function itemDB:load()
|
function itemDB:getMaxCount(item)
|
||||||
|
if type(item) == 'string' then
|
||||||
|
item = self:splitKey(item)
|
||||||
|
end
|
||||||
|
|
||||||
|
local detail = self:get(self:makeKey(item))
|
||||||
|
if detail then
|
||||||
|
return detail.maxCount
|
||||||
|
end
|
||||||
|
|
||||||
|
return 64
|
||||||
|
end
|
||||||
|
|
||||||
|
function itemDB:load()
|
||||||
TableDB.load(self)
|
TableDB.load(self)
|
||||||
|
|
||||||
for key,item in pairs(self.data) do
|
for key,item in pairs(self.data) do
|
||||||
|
|||||||
@@ -4,10 +4,10 @@ end
|
|||||||
|
|
||||||
_G.requireInjector()
|
_G.requireInjector()
|
||||||
|
|
||||||
|
local Adapter = require('inventoryAdapter')
|
||||||
local Event = require('event')
|
local Event = require('event')
|
||||||
local GPS = require('gps')
|
local GPS = require('gps')
|
||||||
local itemDB = require('itemDB')
|
local itemDB = require('itemDB')
|
||||||
local MEAdapter = require('meAdapter')
|
|
||||||
local Schematic = require('schematic')
|
local Schematic = require('schematic')
|
||||||
local TableDB = require('tableDB')
|
local TableDB = require('tableDB')
|
||||||
local UI = require('ui')
|
local UI = require('ui')
|
||||||
@@ -18,11 +18,6 @@ local fs = _G.fs
|
|||||||
local multishell = _ENV.multishell
|
local multishell = _ENV.multishell
|
||||||
local turtle = _G.turtle
|
local turtle = _G.turtle
|
||||||
|
|
||||||
local ChestAdapter = require('chestAdapter')
|
|
||||||
if Util.checkMinecraftVersion(1.8) then
|
|
||||||
ChestAdapter = require('chestAdapter18')
|
|
||||||
end
|
|
||||||
|
|
||||||
local BUILDER_DIR = 'usr/builder'
|
local BUILDER_DIR = 'usr/builder'
|
||||||
|
|
||||||
local substitutionPage
|
local substitutionPage
|
||||||
@@ -34,25 +29,9 @@ else
|
|||||||
Builder = require('builder.turtle')
|
Builder = require('builder.turtle')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Builder = Builder()
|
||||||
Builder.schematic = Schematic()
|
Builder.schematic = Schematic()
|
||||||
|
|
||||||
-- Temp functions until conversion to new adapters is complete
|
|
||||||
local function convertSingleForward(item)
|
|
||||||
item.displayName = item.display_name
|
|
||||||
item.name = item.id
|
|
||||||
item.damage = item.dmg
|
|
||||||
item.count = item.qty
|
|
||||||
item.maxCount = item.max_size
|
|
||||||
return item
|
|
||||||
end
|
|
||||||
|
|
||||||
local function convertForward(t)
|
|
||||||
for _,v in pairs(t) do
|
|
||||||
convertSingleForward(v)
|
|
||||||
end
|
|
||||||
return t
|
|
||||||
end
|
|
||||||
|
|
||||||
local function convertSingleBack(item)
|
local function convertSingleBack(item)
|
||||||
if item then
|
if item then
|
||||||
item.id = item.name
|
item.id = item.name
|
||||||
@@ -283,10 +262,6 @@ function substitutionPage:enable()
|
|||||||
UI.Page.enable(self)
|
UI.Page.enable(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
--function substitutionPage:focusFirst()
|
|
||||||
-- self.menuBar.filter:focus()
|
|
||||||
--end
|
|
||||||
|
|
||||||
function substitutionPage:applySubstitute(id, dmg)
|
function substitutionPage:applySubstitute(id, dmg)
|
||||||
self.sub.sid = id
|
self.sub.sid = id
|
||||||
self.sub.sdmg = dmg
|
self.sub.sdmg = dmg
|
||||||
@@ -317,7 +292,6 @@ function substitutionPage:eventHandler(event)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
--self.grid:adjustWidth()
|
|
||||||
self.grid:update()
|
self.grid:update()
|
||||||
self.grid:setIndex(1)
|
self.grid:setIndex(1)
|
||||||
self.grid:draw()
|
self.grid:draw()
|
||||||
@@ -766,12 +740,9 @@ if #args < 1 then
|
|||||||
error('supply file name')
|
error('supply file name')
|
||||||
end
|
end
|
||||||
|
|
||||||
Builder.itemAdapter = MEAdapter()
|
Builder.itemAdapter = Adapter.wrap()
|
||||||
if not Builder.itemAdapter:isValid() then
|
if not Builder.itemAdapter then
|
||||||
Builder.itemAdapter = ChestAdapter()
|
error('A chest or ME interface must be below turtle')
|
||||||
if not Builder.itemAdapter:isValid() then
|
|
||||||
error('A chest or ME interface must be below turtle')
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
multishell.setTitle(multishell.getCurrent(), 'Builder')
|
multishell.setTitle(multishell.getCurrent(), 'Builder')
|
||||||
@@ -792,6 +763,10 @@ end
|
|||||||
|
|
||||||
Builder:loadProgress(Builder.schematic.filename .. '.progress')
|
Builder:loadProgress(Builder.schematic.filename .. '.progress')
|
||||||
|
|
||||||
|
Event.on('build', function()
|
||||||
|
Builder:build()
|
||||||
|
end)
|
||||||
|
|
||||||
UI:setPages({
|
UI:setPages({
|
||||||
listing = listingPage,
|
listing = listingPage,
|
||||||
start = startPage,
|
start = startPage,
|
||||||
@@ -803,8 +778,9 @@ UI:setPage('start')
|
|||||||
if Builder.isCommandComputer then
|
if Builder.isCommandComputer then
|
||||||
UI:pullEvents()
|
UI:pullEvents()
|
||||||
else
|
else
|
||||||
turtle.run(function()
|
UI:pullEvents()
|
||||||
turtle.point.heading = 0
|
-- turtle.run(function()
|
||||||
UI:pullEvents()
|
-- turtle.reset()
|
||||||
end)
|
-- UI:pullEvents()
|
||||||
|
-- end)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,53 +0,0 @@
|
|||||||
_G.requireInjector()
|
|
||||||
|
|
||||||
local Socket = require('socket')
|
|
||||||
|
|
||||||
if not ... then
|
|
||||||
local turtle = _G.turtle
|
|
||||||
|
|
||||||
while true do
|
|
||||||
print('hijack: waiting for connections')
|
|
||||||
local socket = Socket.server(188)
|
|
||||||
|
|
||||||
print('hijack: connection from ' .. socket.dhost)
|
|
||||||
|
|
||||||
local methods = { }
|
|
||||||
for k,v in pairs(turtle) do
|
|
||||||
if type(v) == 'function' then
|
|
||||||
table.insert(methods, k)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
socket:write(methods)
|
|
||||||
|
|
||||||
while true do
|
|
||||||
local data = socket:read()
|
|
||||||
if not data then
|
|
||||||
break
|
|
||||||
end
|
|
||||||
socket:write({ turtle[data.fn](unpack(data.args)) })
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
else
|
|
||||||
local remoteId = ({ ... })[1]
|
|
||||||
local socket, msg = Socket.connect(remoteId, 188)
|
|
||||||
|
|
||||||
if not socket then
|
|
||||||
error(msg)
|
|
||||||
end
|
|
||||||
|
|
||||||
local methods = socket:read()
|
|
||||||
|
|
||||||
local turtle = { }
|
|
||||||
for _,method in pairs(methods) do
|
|
||||||
turtle[method] = function(...)
|
|
||||||
socket:write({ fn = method, args = { ... } })
|
|
||||||
local resp = socket:read()
|
|
||||||
return table.unpack(resp)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
_G.turtle = turtle
|
|
||||||
os.pullEventRaw('terminate')
|
|
||||||
socket:close()
|
|
||||||
end
|
|
||||||
Reference in New Issue
Block a user