Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- _G ['i'] = {
- ['files'] = {
- ['_url'] = '_blank',
- ['_data'] = {
- ['class/map.lua'] = [[
- local data = {
- ['_path'] = '/.map',
- ['_data'] = false,
- ['_init'] = function ( self )
- if self._data == false then
- if fs.exists ( self._path ) == true then
- local f = fs.open ( self._path, 'r' )
- local content = f.readAll ()
- f.close ()
- self._data = textutils.unserialize ( content )
- if type ( self._data ) ~= 'table' then
- self._data = {}
- end
- else
- self._data = {}
- end
- end
- end,
- ['get'] = function ( self, key )
- self:_init ()
- return self._data [key]
- end,
- ['set'] = function ( self, key, value )
- self:_init ()
- self._data [key] = value
- local content = textutils.serialize ( self._data )
- local f = fs.open ( self._path, 'w' )
- f.write ( content )
- f.close ()
- return self
- end,
- }
- local map = {}
- map = {
- ['_raw'] = {},
- ['blocks'] = nil,
- ['get'] = function ( self, node )
- if node.x == nil then error ( 'X missing' ) end
- if node.y == nil then error ( 'Y missing' ) end
- if node.z == nil then error ( 'Z missing' ) end
- local bind = function ( node, block )
- for k,v in pairs ( node ) do block [k] = v end
- if block ['solid'] == nil then
- block ['solid'] = function ( self )
- if self._solid == true then return true end
- if self.id == nil then return false end
- if self.id == 1 then return false end
- local block = map.blocks [ self.id ]
- if block == nil then return false end
- if block.solid == nil then return false end
- if block.solid == true then return true end
- return block.solid
- end
- end
- if block ['neighbors'] == nil then
- block ['neighbors'] = function ( self )
- local nodes = {}
- for x = -1, 1, 1 do
- for y = -1, 1, 1 do
- for z = -1, 1, 1 do
- local c = 0
- if x == 0 then c = c + 1 end
- if y == 0 then c = c + 1 end
- if z == 0 then c = c + 1 end
- if c == 2 then
- table.insert ( nodes, {
- ['x'] = self.x + x,
- ['y'] = self.y + y,
- ['z'] = self.z + z,
- } )
- end
- end
- end
- end
- return nodes
- end
- end
- if block ['east'] == nil then
- block ['east'] = function ( self )
- if self._east == nil then
- self._east = map:get ({ ['x'] = self.x + 1, ['y'] = self.y, ['z'] = self.z, })
- self._east._west = self
- end
- return self._east
- end
- end
- if block ['west'] == nil then
- block ['west'] = function ( self )
- if self._west == nil then
- self._west = map:get ({ ['x'] = self.x - 1, ['y'] = self.y, ['z'] = self.z, })
- self._west._east = self
- end
- return self._west
- end
- end
- if block ['north'] == nil then
- block ['north'] = function ( self )
- if self._north == nil then
- self._north = map:get ({ ['x'] = self.x, ['y'] = self.y, ['z'] = self.z - 1, })
- self._north._south = self
- end
- return self._north
- end
- end
- if block ['south'] == nil then
- block ['south'] = function ( self )
- if self._south == nil then
- self._south = map:get ({ ['x'] = self.x, ['y'] = self.y, ['z'] = self.z + 1, })
- self._south._north = self
- end
- return self._south
- end
- end
- if block ['up'] == nil then
- block ['up'] = function ( self )
- if self._up == nil then
- self._up = map:get ({ ['x'] = self.x, ['y'] = self.y + 1, ['z'] = self.z, })
- self._up._down = self
- end
- return self._up
- end
- end
- if block ['down'] == nil then
- block ['down'] = function ( self )
- if self._down == nil then
- self._down = map:get ({ ['x'] = self.x, ['y'] = self.y - 1, ['z'] = self.z, })
- self._down._up = self
- end
- return self._down
- end
- end
- return block
- end
- if self._raw [node.x] == nil then
- self._raw [node.x] = { [node.y] = { [node.z] = { ['x'] = node.x, ['y'] = node.y, ['z'] = node.z } } }
- elseif self._raw [node.x][node.y] == nil then
- self._raw [node.x][node.y] = { [node.z] = { ['x'] = node.x, ['y'] = node.y, ['z'] = node.z } }
- elseif self._raw [node.x][node.y][node.z] == nil then
- self._raw [node.x][node.y][node.z] = { ['x'] = node.x, ['y'] = node.y, ['z'] = node.z }
- end
- return bind ( self._raw [node.x][node.y][node.z], node )
- end,
- ['set'] = function ( self, node, value )
- if node.x == nil then error ( 'X missing' ) end
- if node.y == nil then error ( 'Y missing' ) end
- if node.z == nil then error ( 'Z missing' ) end
- if self._raw [node.x] == nil then
- self._raw [node.x] = { [node.y] = { [node.z] = value } }
- return self
- end
- if self._raw [node.x][node.y] == nil then
- self._raw [node.x][node.y] = { [node.z] = value }
- return self
- end
- if self._raw [node.x][node.y][node.z] == nil then
- self._raw [node.x][node.y][node.z] = value
- return self
- end
- for k,v in pairs ( value ) do
- if type (v) ~= 'function' then
- self._raw [node.x][node.y][node.z][k] = v
- end
- end
- return self
- end,
- ['save'] = function ( self )
- local _data = {}
- local ignore = {
- ['x'] = true,
- ['y'] = true,
- ['z'] = true
- }
- for x in pairs ( self._raw ) do
- for y in pairs ( self._raw [x] ) do
- for z in pairs ( self._raw [x][y] ) do
- local save = false
- for k in pairs ( self._raw [x][y][z] ) do
- if ignore [k] == nil then
- save = true
- break
- end
- end
- if save == true then
- if _data [x] == nil then _data [x] = {} end
- if _data [x][y] == nil then _data [x][y] = {} end
- if _data [x][y][z] == nil then _data [x][y][z] = {} end
- for k,v in pairs ( self._raw [x][y][z] ) do
- if ignore [k] ~= true and type (v) ~= 'function' then
- _data [x][y][z][k] = v
- end
- end
- end
- end
- end
- end
- data:set ( 'map', _data )
- end,
- }
- local _data = data:get ( 'map' )
- if _data ~= nil then
- for x in pairs ( _data ) do
- for y in pairs ( _data [x] ) do
- for z in pairs ( _data [x][y] ) do
- if map._raw [x] == nil then map._raw [x] = {} end
- if map._raw [x][y] == nil then map._raw [x][y] = {} end
- if map._raw [x][y][z] == nil then map._raw [x][y][z] = {} end
- map._raw [x][y][z] = _data [x][y][z]
- map._raw [x][y][z].x = x
- map._raw [x][y][z].y = y
- map._raw [x][y][z].z = z
- end
- end
- end
- end
- return map
- ]],
- ['class/turtle.lua'] = [[
- local data = {
- ['_path'] = '/.turtle',
- ['_data'] = false,
- ['_init'] = function ( self )
- if self._data == false then
- if fs.exists ( self._path ) == true then
- local f = fs.open ( self._path, 'r' )
- local content = f.readAll ()
- f.close ()
- self._data = textutils.unserialize ( content )
- if type ( self._data ) ~= 'table' then
- self._data = {}
- end
- else
- self._data = {}
- end
- end
- end,
- ['get'] = function ( self, key )
- self:_init ()
- return self._data [key]
- end,
- ['set'] = function ( self, key, value )
- self:_init ()
- self._data [key] = value
- local content = textutils.serialize ( self._data )
- local f = fs.open ( self._path, 'w' )
- f.write ( content )
- f.close ()
- return self
- end,
- }
- local names = {
- ['east'] = 1,
- ['north'] = 2,
- ['west'] = 3,
- ['south'] = 4,
- [1] = 'east',
- [2] = 'north',
- [3] = 'west',
- [4] = 'south',
- }
- local custom = {}
- custom = {
- ['inventory'] = i.files:run ( 'class/turtle.inventory.lua' ),
- ['location'] = {
- ['x'] = data:get ( 'x' ) or 0,
- ['y'] = data:get ( 'y' ) or 0,
- ['z'] = data:get ( 'z' ) or 0,
- },
- ['direction'] = {
- ['_parent'] = nil,
- ['forward'] = function ( self )
- return self._parent:face ()
- --return 'cake'
- end,
- ['back'] = function ( self )
- local f = custom.facing + 2
- if f > 4 then f = f - 4 end
- return names [f]
- end,
- ['left'] = function ( self )
- local f = custom.facing + 1
- if f > 4 then f = f - 4 end
- return names [f]
- end,
- ['right'] = function ( self )
- local f = custom.facing - 1
- if f > 4 then f = f - 4 end
- return names [f]
- end,
- },
- ['facing'] = data:get ( 'facing' ) or 2,
- ['face'] = function ( self, direction )
- if type ( direction ) == 'string' then direction = names [direction] end
- if direction == nil then return names [self.facing] end
- if direction == self.facing then return true end
- local diff = direction - self.facing
- if direction > self.facing then
- local diff = direction - self.facing
- if diff > 2 then
- self:right ( 1 )
- else
- self:left ( diff )
- end
- else
- local diff = self.facing - direction
- if diff > 2 then
- self:left ( 1 )
- else
- self:right ( diff )
- end
- end
- self:update ()
- end,
- ['__update'] = function ( self )
- data:set ( 'x', self.location.x )
- data:set ( 'y', self.location.y )
- data:set ( 'z', self.location.z )
- if data:get ( 'facing' ) ~= self.facing then
- data:set ( 'facing', self.facing )
- end
- end,
- ['_update'] = nil,
- ['update'] = function ( self, func )
- if func == nil then
- self:__update ()
- if type ( self._update ) == 'function' then
- self:_update ()
- return self
- else
- return false
- end
- end
- if type ( func ) ~= 'function' then
- error ( 'Argument supplied is not a function' )
- end
- self._update = func
- return self
- end,
- ['forward'] = function ( self, amount )
- if amount == nil then amount = 1 end
- if amount > 0 and turtle.getFuelLevel () == 0 then return 0, 'Out of fuel' end
- local moved = 0
- for i = 1, amount do
- local state, reason = turtle.forward ()
- if state == false then
- return moved, reason
- end
- if self.facing == 2 then
- self.location.z = self.location.z - 1
- elseif self.facing == 4 then
- self.location.z = self.location.z + 1
- elseif self.facing == 1 then
- self.location.x = self.location.x + 1
- elseif self.facing == 3 then
- self.location.x = self.location.x - 1
- end
- self:update ()
- moved = moved + 1
- end
- return moved
- end,
- ['back'] = function ( self, amount )
- if amount == nil then amount = 1 end
- if amount > 0 and turtle.getFuelLevel () == 0 then return 0, 'Out of fuel' end
- local moved = 0
- for i = 1, amount do
- local state, reason = turtle.back ()
- if state == false then return moved, reason end
- if self.facing == 2 then
- self.location.z = self.location.z + 1
- elseif self.facing == 4 then
- self.location.z = self.location.z - 1
- elseif self.facing == 1 then
- self.location.x = self.location.x - 1
- elseif self.facing == 3 then
- self.location.x = self.location.x + 1
- end
- self:update ()
- moved = moved + 1
- end
- return moved
- end,
- ['up'] = function ( self, amount )
- if amount == nil then amount = 1 end
- if amount > 0 and turtle.getFuelLevel () == 0 then return 0, 'Out of fuel' end
- local moved = 0
- for i = 1, amount do
- local state, reason = turtle.up ()
- if state == false then return moved, reason end
- self.location.y = self.location.y + 1
- self:update ()
- moved = moved + 1
- end
- return moved
- end,
- ['down'] = function ( self, amount )
- if amount == nil then amount = 1 end
- if amount > 0 and turtle.getFuelLevel () == 0 then return 0, 'Out of fuel' end
- local moved = 0
- for i = 1, amount do
- local state, reason = turtle.down ()
- if state == false then return moved, reason end
- self.location.y = self.location.y - 1
- self:update ()
- moved = moved + 1
- end
- return moved
- end,
- ['left'] = function ( self, amount )
- if amount == nil then amount = 1 end
- local moved = 0
- for i = 1, amount do
- local state, reason = turtle.turnLeft ()
- if state == false then return false, reason end
- self.facing = self.facing + 1
- if self.facing > 4 then self.facing = 1 end
- self:update ()
- moved = moved + 1
- end
- return moved
- end,
- ['right'] = function ( self, amount )
- if amount == nil then amount = 1 end
- local moved = 0
- for i = 1, amount do
- local state, reason = turtle.turnRight ()
- if state == false then return false, reason end
- self.facing = self.facing - 1
- if self.facing < 1 then self.facing = 4 end
- self:update ()
- moved = moved + 1
- end
- return moved
- end,
- ['goto'] = function ( self, position )
- if position.x == self.location.x and position.y == self.location.y and position.z == self.location.z then return true end
- -- Y
- local diff = position.y - self.location.y
- if diff ~= 0 then
- if diff > 0 then
- local response, message = self:up ( diff )
- if response ~= diff then return false, message end
- else
- diff = 0 - diff
- local response, message = self:down ( diff )
- if response ~= diff then return false, message end
- end
- end
- -- X
- local diff = position.x - self.location.x
- if diff ~= 0 then
- if diff > 0 then
- if self:face () ~= 'east' then
- self:face ( 'east' )
- end
- local response, message = self:forward ( diff )
- if response ~= diff then return false, message end
- else
- if self:face () ~= 'west' then
- self:face ( 'west' )
- end
- diff = 0 - diff
- local response, message = self:forward ( diff )
- if response ~= diff then return false, message end
- end
- end
- -- Z
- local diff = position.z - self.location.z
- if diff ~= 0 then
- if diff > 0 then
- if self:face () ~= 'south' then
- self:face ( 'south' )
- end
- local response, message = self:forward ( diff )
- if response ~= diff then return false, message end
- else
- if self:face () ~= 'north' then
- self:face ( 'north' )
- end
- diff = 0 - diff
- local response, message = self:forward ( diff )
- if response ~= diff then return false, message end
- end
- end
- return true
- end,
- ['refuel'] = function ( self )
- if self.inventory.select:fuel () == false then
- return false
- end
- turtle.refuel ( 1 )
- return true
- end,
- }
- custom.direction._parent = custom
- setmetatable ( custom.location, {
- ['__call'] = function ( self )
- if i ~= nil and i.map ~= nil then return i.map:get ( { ['x'] = self.x, ['y'] = self.y, ['z'] = self.z, } ) end
- return {
- ['x'] = self.x,
- ['y'] = self.y,
- ['z'] = self.z,
- }
- end,
- } )
- local x,y,z = gps.locate (0.5)
- if x and y and z then
- custom.location.x = x
- custom.location.y = y
- custom.location.z = z
- custom._hasGPS = true
- end
- return custom
- ]],
- ['class/turtle.inventory.lua'] = [[
- local inventory = {}
- inventory = {
- ['_fuels'] = {
- ['has'] = function ( self, details )
- if details == nil then return false end
- for _, item in ipairs ( self ) do
- if item.damage ~= nil then
- if item.name == details.name and item.damage == details.damage then
- return item.fuel
- end
- else
- if item.name == details.name then
- return item.fuel
- end
- end
- end
- return false
- end,
- ['add'] = function ( self, details, fuel )
- table.insert ( self, { ['name'] = details.name, ['damage'] = details.damage, ['fuel'] = fuel, } )
- return self
- end,
- },
- ['_data'] = {},
- ['scan'] = function ( self )
- for i = 1, 16 do
- if turtle.getItemCount (i) > 0 then
- self._data [ i ] = self:details ( i )
- else
- self._data [ i ] = nil
- end
- end
- return self
- end,
- ['snapshot'] = function ( self )
- local inventory = {
- ['_parent'] = self,
- ['compare'] = {
- ['_parent'] = self,
- ['current'] = function ( self )
- return self._parent:compare ( self._parent._parent:snapshot () )
- end,
- },
- ['each'] = function ( self, method )
- for i = 1,16 do
- if self [i] ~= nil then
- if method ( i, self [i] ) == false then
- break
- end
- end
- end
- return self
- end,
- }
- inventory.compare._parent = inventory
- setmetatable ( inventory.compare, {
- ['__call'] = function ( self, _, current )
- local before = self._parent
- for slot = 1, 16 do
- if before [slot] ~= nil then
- if current [slot] ~= nil then
- current [slot].count = current [slot].count - before [slot].count
- if current [slot].count == 0 then
- current [slot] = nil
- end
- else
- current [slot] = before [slot]
- current [slot].count = 0 - current [slot].count
- end
- end
- end
- return current
- end,
- } )
- self:scan ()
- for slot, entry in pairs ( self._data ) do
- inventory [slot] = entry
- end
- return inventory
- end,
- ['details'] = function ( self, slot )
- local data = turtle.getItemDetail ( slot )
- if data ~= nil then
- data.stackSize = data.count + turtle.getItemSpace ( slot )
- end
- return data
- end,
- ['select'] = {
- ['_parent'] = nil,
- ['empty'] = function ( self )
- self:scan ()
- for slot = 1, 16 do
- local item = self._data [slot]
- if item == nil then
- turtle.select ( slot )
- return true
- end
- end
- return true
- end,
- ['fuel'] = function ( self )
- local items = {
- ['_fuels'] = self._parent._fuels,
- ['first'] = function ( self )
- local entry = self [1]
- if entry == nil then return false end
- turtle.select ( entry.slot )
- return true
- end,
- ['last'] = function ( self )
- local entry = self [ #self ]
- if entry == nil then return false end
- turtle.select ( entry.slot )
- return true
- end,
- ['best'] = function ( self )
- if #self == 0 then return false end
- local score,best = 0 - 1/0,nil
- for slot, entry in ipairs ( self ) do
- local _score = self._fuels:has ( entry.item )
- if _score > score then
- score = _score
- best = entry
- end
- end
- turtle.select ( best.slot )
- return true
- end,
- ['worst'] = function ( self )
- if #self == 0 then return false end
- local score,worst = 1/0,nil
- for slot, entry in ipairs ( self ) do
- local _score = self._fuels:has ( entry.item )
- if _score < score then
- score = _score
- worst = entry
- end
- end
- turtle.select ( worst.slot )
- return true
- end,
- ['least'] = function ( self )
- if #self == 0 then return false end
- local score,least = 1/0,nil
- for slot, entry in ipairs ( self ) do
- local _score = entry.item.count
- if _score < score then
- score = _score
- least = entry
- end
- end
- turtle.select ( least.slot )
- return true
- end,
- ['most'] = function ( self )
- if #self == 0 then return false end
- local score,most = 0 - 1/0,nil
- for slot, entry in ipairs ( self ) do
- local _score = entry.item.count
- if _score > score then
- score = _score
- most = entry
- end
- end
- turtle.select ( most.slot )
- return true
- end,
- }
- self._parent:scan ()
- local selected = false
- for slot = 1, 16 do
- local item = self._parent._data [slot]
- if item ~= nil then
- local fuel = self._parent._fuels:has ( item )
- if fuel ~= false then
- table.insert ( items, {
- ['slot'] = slot,
- ['fuel'] = fuel,
- ['item'] = item,
- } )
- end
- end
- end
- if #items == 0 then
- return false
- end
- items:first ()
- return items
- end,
- },
- ['stack'] = function ( self )
- local items = {}
- for i = 1, 16, 1 do items [i] = turtle.getItemDetail ( i ) end
- for i = 1, 16, 1 do
- if items [i] ~= nil then
- for slot = 16, 1, -1 do
- local item = items [slot]
- local stackSize = turtle.getItemSpace ( i ) + items [i].count
- if slot ~= i and item ~= nil and items [i].name == item.name and items [i].damage == item.damage and turtle.getItemSpace ( i ) > 0 and item.count < stackSize then
- turtle.select ( slot )
- turtle.transferTo ( i )
- items [slot] = turtle.getItemDetail ( slot )
- items [i] = turtle.getItemDetail ( i )
- end
- end
- end
- end
- return self
- end,
- }
- setmetatable ( inventory.select, {
- ['__call'] = function ( self, _, search, sel )
- if search == nil then error ( 'Search is nil' ) end
- self._parent:scan ()
- for slot = 1, 16 do
- local item = self._parent._data [slot]
- if item ~= nil then
- if i ~= nil and i.items ~= nil then item = i.items:has ( item ) end
- if type ( search ) == 'string' and tostring ( item.name ):lower ():sub ( 1, #search ) == search:lower () then
- if sel ~= false then
- turtle.select ( slot )
- end
- return item
- elseif type ( search ) == 'table' then
- if i ~= nil and i.items ~= nil then search = i.items:has ( search ) end
- local accept = true
- for k, v in pairs ( search ) do
- if k ~= 'count' and k ~= 'stackSize' then
- if item [k] ~= v then
- accept = false
- end
- end
- end
- if accept == true then
- if sel ~= false then
- turtle.select ( slot )
- end
- return item
- end
- end
- end
- end
- return false
- end,
- } )
- inventory._fuels:add ( {
- ['name'] = 'minecraft:coal',
- ['damage'] = 0,
- }, 80 )
- inventory._fuels:add ( {
- ['name'] = 'minecraft:coal',
- ['damage'] = 1,
- }, 80 )
- inventory._fuels:add ( {
- ['name'] = 'minecraft:coal_block',
- ['damage'] = 0,
- }, 800 )
- inventory._fuels:add ( {
- ['name'] = 'minecraft:lava_bucket',
- ['damage'] = 0,
- }, 1000 )
- inventory.select._parent = inventory
- return inventory:scan ()
- ]],
- ['class/items.lua'] = [[
- local items = {
- ['has'] = {
- ['_parent'] = nil,
- ['category'] = function ( self, category )
- local items = { ['has'] = self._parent ['has'] }
- for _, item in ipairs ( self._parent ) do
- if type ( item.category ) == 'table' then
- for _, cat in ipairs ( item.category ) do
- --print ( cat ..'='.. category )
- --os.sleep ( 0.1 )
- if cat == category then
- table.insert ( items, item )
- end
- end
- end
- end
- items.has ['_parent'] = items
- return items
- end,
- },
- -- ITEMS
- {
- ['match'] = {
- ['name'] = 'ComputerCraft:CC-Peripheral',
- ['damage'] = 0,
- },
- ['mod'] = 'Computercraft',
- ['category'] = { [1] = 'peripheral', },
- ['name'] = 'Disk Drive',
- },
- {
- ['match'] = {
- ['name'] = 'ComputerCraft:CC-Peripheral',
- ['damage'] = 1,
- },
- ['mod'] = 'Computercraft',
- ['category'] = { [1] = 'peripheral', },
- ['name'] = 'Wireless modem',
- },
- {
- ['match'] = {
- ['name'] = 'ComputerCraft:CC-Computer',
- ['damage'] = 0,
- },
- ['mod'] = 'Computercraft',
- ['category'] = { [1] = 'computer', },
- ['name'] = 'Computer',
- },
- {
- ['match'] = {
- ['name'] = 'ComputerCraft:CC-Computer',
- ['damage'] = 16384,
- },
- ['mod'] = 'Computercraft',
- ['category'] = { [1] = 'computer', },
- ['name'] = 'Advanced Computer',
- },
- {
- ['match'] = {
- ['name'] = 'ComputerCraft:command_computer',
- ['damage'] = 0,
- },
- ['mod'] = 'Computercraft',
- ['category'] = { [1] = 'computer', },
- ['name'] = 'Command Computer',
- },
- {
- ['match'] = {
- ['name'] = 'ComputerCraft:disk',
- },
- ['mod'] = 'Computercraft',
- ['category'] = { [1] = 'disk', },
- ['name'] = 'Floppy Disk',
- },
- {
- ['match'] = {
- ['name'] = 'ComputerCraft:diskExpanded',
- },
- ['mod'] = 'Computercraft',
- ['category'] = { [1] = 'computer', },
- ['name'] = 'Floppy Disk - Expanded',
- },
- {
- ['match'] = {
- ['name'] = 'minecraft:diamond_pickaxe',
- },
- ['mod'] = 'vanilla',
- ['category'] = { [1] = 'tool', },
- ['name'] = 'Diamond Pickaxe',
- },
- }
- items.has._parent = items
- setmetatable ( items ['has'], {
- ['__call'] = function ( self, _, item )
- for _, entry in ipairs ( self._parent ) do
- if entry.match ~= nil then
- local accept = true
- for k, v in pairs ( entry.match ) do
- if item [k] == nil or item [k] ~= v then
- --error ( 'failed on: ' .. k .. ' ' .. tostring ( item [k] ) .. ' ~= ' .. v )
- accept = false
- end
- end
- if accept == true then
- local _newEntry = {}
- _newEntry._name = item.name
- for k,v in pairs ( entry ) do
- if k ~= 'match' then
- _newEntry [k] = v
- end
- end
- for k,v in pairs ( item ) do
- if _newEntry [k] == nil then
- _newEntry [k] = v
- end
- end
- return _newEntry
- end
- end
- end
- return item
- end
- } )
- return items
- ]],
- ['class/timer.lua'] = [[
- local timer = {}
- timer = {
- ['__event'] = nil,
- ['__data'] = {},
- ['init'] = function ( self )
- self.__event = _G ['_event']
- end,
- ['start'] = function ( self, time, name, payload )
- if payload == nil then
- payload = name
- name = nil
- end
- if self.__event ['timer'] == nil then
- self.__event ['timer'] = {}
- end
- local load = {
- ['_name'] = name or #self.__data,
- ['name'] = function ( self, name )
- if name == nil then return self._name end
- self._name = name
- return self
- end,
- ['time'] = time + os.clock (),
- ['_payload'] = payload,
- ['payload'] = function ( self, payload )
- if payload == nil then return self._payload end
- if type ( payload ) ~= 'function' then self._payload = nil end
- self._payload = payload
- return self
- end,
- }
- setmetatable ( load, {
- ['__call'] = function ( self )
- local payload = self:payload ()
- if type (payload) == 'function' then
- self:payload ( false )
- return payload ()
- end
- return false
- end,
- } )
- table.insert ( self.__data, load )
- self.__event ['timer'][os.startTimer (time)] = function () timer:check () end
- end,
- ['interval'] = function ( self, time, name, payload )
- if payload == nil then
- payload = name
- name = nil
- end
- if self.__event ['timer'] == nil then
- self.__event ['timer'] = {}
- end
- local load = {
- ['_name'] = name or #self.__data,
- ['name'] = function ( self, name )
- if name == nil then return self._name end
- self._name = name
- return self
- end,
- ['_interval'] = time,
- ['interval'] = function ( self, time )
- if time == nil then return self._interval end
- if type ( time ) ~= 'number' then self._interval = nil end
- self._interval = time
- return self
- end,
- ['time'] = time + os.clock (),
- ['_payload'] = payload,
- ['payload'] = function ( self, payload )
- if payload == nil then return self._payload end
- if type ( payload ) ~= 'function' then self._payload = nil end
- self._payload = payload
- return self
- end,
- ['trigger'] = function ( self )
- if type ( self._payload ) == 'function' then self:payload () () end
- return self
- end,
- }
- setmetatable ( load, {
- ['__call'] = function ( self )
- local payload = self:payload ()
- if type (payload) == 'function' then
- return payload ()
- end
- return false
- end,
- } )
- table.insert ( self.__data, load )
- self.__event ['timer'][os.startTimer (time)] = function () timer:check () end
- end,
- ['get'] = function ( self, name )
- for _, entry in ipairs ( self.__data ) do
- if entry:name () == name then
- return entry
- end
- end
- return false
- end,
- ['check'] = function ( self )
- local clock = os.clock ()
- for i = #self.__data, 1, -1 do
- local entry = self.__data [i]
- if clock >= entry.time - 0.05 then
- entry ()
- if entry.interval ~= nil then
- if self.__event ['timer'] == nil then
- self.__event ['timer'] = {}
- end
- entry.time = math.max ( entry.time, clock ) + entry:interval ()
- self.__event ['timer'][os.startTimer (entry:interval ())] = function () timer:check () end
- else
- table.remove ( self.__data, i )
- end
- end
- end
- end,
- ['sleep'] = function ( self, time )
- local abort = false
- self:start ( time, function ()
- abort = true
- end )
- while abort ~= true do
- local event = ({os.pullEvent ()})
- local e = table.remove ( event, 1 )
- local success = false
- if _G ['_event'] ~= nil and _G ['_event'][e] ~= nil then
- if success == false and _G ['_event'] [e][ event[1] ] ~= nil then
- if _G ['_event'] [e][ event[1] ] ( self, event ) == true then
- success = true
- end
- end
- if success == false and _G ['_event'] [e]['*'] ~= nil then
- if _G ['_event'] [e]['*'] ( self, event ) == true then
- success = true
- end
- end
- end
- end
- return self
- end,
- }
- return timer
- ]],
- ['class/menu.basic.lua'] = [[
- local data = {
- ['_path'] = '/.menu',
- ['_data'] = false,
- ['_init'] = function ( self )
- if self._data == false then
- if fs.exists ( self._path ) == true then
- local f = fs.open ( self._path, 'r' )
- local content = f.readAll ()
- f.close ()
- self._data = textutils.unserialize ( content )
- if type ( self._data ) ~= 'table' then
- self._data = {}
- end
- else
- self._data = {}
- end
- end
- end,
- ['get'] = function ( self, key )
- self:_init ()
- return self._data [key]
- end,
- ['set'] = function ( self, key, value )
- self:_init ()
- self._data [key] = value
- local content = textutils.serialize ( self._data )
- local f = fs.open ( self._path, 'w' )
- f.write ( content )
- f.close ()
- return self
- end,
- }
- local width, height = term.getSize ()
- local sortId = 1
- return {
- ['_name'] = 'menu',
- ['name'] = function ( self, name )
- if name == nil then
- return self._name
- end
- self._name = name
- return self
- end,
- ['_abort'] = false,
- ['abort'] = function ( self )
- self._abort = true
- return self
- end,
- ['_verifyQuit'] = false,
- ['verifyQuit'] = function ( self, bool )
- self._verifyQuit = bool
- return self
- end,
- ['_options'] = {
- ['sort'] = function ( self )
- local keys = {}
- local copy = {}
- for _, opt in ipairs ( self ) do
- local sort = opt.__sortId
- if sort == nil then sort = opt:name () end
- table.insert ( keys, sort )
- table.insert ( copy, opt )
- end
- self:clear ()
- table.sort ( keys )
- for _, sort in ipairs ( keys ) do
- for _, opt in ipairs ( copy ) do
- if sort == opt.__sortId or opt:name () == sort then
- table.insert ( self, opt )
- end
- end
- end
- return self
- end,
- ['clear'] = function ( self )
- for i = #self, 1, -1 do
- table.remove ( self, i )
- end
- return self
- end,
- },
- ['option'] = function ( self, id )
- if id == nil then return self._options end
- if self._options [id] == false then return false end
- return self._options [id]
- end,
- ['clear'] = function ( self )
- self:option ():clear ()
- return self
- end,
- ['_select'] = 1,
- ['_offset'] = 0,
- ['select'] = function ( self, id )
- if id == nil then return self._select end
- local options = self:option ()
- local config = self:settings ()
- if id < 1 then id = 1 end
- if id > #options then id = #options end
- if id > (height - config.offset()) + self._offset then
- self._offset = id - (height - config.offset ())
- elseif id <= self._offset then
- self._offset = id - 1
- end
- if self._offset < 0 then self._offset = 0 end
- self._select = id
- if self:option (id) ~= nil and type ( self:option ( id )._selected ) == 'function' then
- self:option (id):_selected ()
- end
- end,
- ['_search'] = false,
- ['_searchStatus'] = '',
- ['_searchHidden'] = {},
- ['search'] = function ( self, search )
- if search ~= nil then
- if self._search == false and search == ' ' then
- search = ''
- end
- if search == '' then
- self._search = false
- else
- if self._search == false then
- self._searchStatus = self._status
- end
- self._search = search
- end
- end
- local options = {}
- for _, opt in ipairs ( self._options ) do table.insert ( options, opt ) end
- for _, opt in ipairs ( self._searchHidden ) do table.insert ( options, opt ) end
- self._searchHidden = {}
- self:option ():clear ()
- if self._search ~= false then
- self:status ( 'Search:' .. self._search )
- for _, opt in ipairs ( options ) do
- if self._search == '' or tostring ( opt:name () ):lower():match ( self._search:lower() ) then
- table.insert ( self._options, opt )
- else
- table.insert ( self._searchHidden, opt )
- end
- end
- else
- for _, opt in ipairs ( options ) do table.insert ( self._options, opt ) end
- self:status ( self._searchStatus )
- end
- self:option ():sort ()
- self:select ( self:select() )
- end,
- ['_option'] = {
- ['__sortId'] = 1/0,
- ['_parent'] = false,
- ['parent'] = function ( self, parent )
- if parent == nil then return self._parent end
- self._parent = parent
- return self
- end,
- ['_name'] = 'menu:option',
- ['name'] = function ( self, name )
- if name == nil then
- return self._name
- end
- self._name = name
- return self
- end,
- ['_type'] = 'basic',
- ['type'] = function ( self, name )
- if name == nil then return self._type end
- local data = {}
- if name ~= 'basic' then
- data = i.files:run ( 'class/menu.basic/' .. name .. '.lua' )
- end
- self._type = name
- local remove = {}
- for k,_ in pairs ( self ) do
- if self._parent._option [k] == nil then
- table.insert ( remove, k )
- else
- if k:sub ( 1,1 ) ~= '_' then
- self [k] = self._parent._option [k]
- end
- end
- end
- for _, key in ipairs ( remove ) do self [key] = nil end
- remove = nil
- local d = function () end
- d = function ( self, data )
- for k,v in pairs ( data ) do
- if type ( self [k] ) == 'table' and type ( data [k] ) == 'table' then
- self [k] = d ( self [k], data [k] )
- else
- self [k] = data [k]
- end
- end
- return self
- end
- self = d ( self, data )
- self.type = self._parent._option.type
- return self
- end,
- ['_update'] = false,
- ['update'] = function ( self, func )
- if func == nil then return self._update end
- if type(func) ~= 'function' then return false end
- self._update = func
- return self
- end,
- ['event'] = false,
- ['toString'] = function ( self )
- return string.rep ( ' ', self._parent:settings ().options.indent ) .. self:name ()
- end,
- ['_selected'] = nil,
- ['selected'] = function ( self, func )
- if func == nil then return self._selected end
- self._selected = func
- return self
- end,
- },
- ['create'] = function ( self, name )
- local opt = {}
- for k,v in pairs ( self._option ) do opt [k] = v end
- opt:parent ( self )
- opt:name ( name )
- opt.__sortId = sortId
- sortId = sortId + 1
- table.insert ( self._options, opt )
- self:option ():sort ()
- return opt
- end,
- ['_status'] = '[Enter][Backspace] - [Up]/[Down]',
- ['status'] = function ( self, message )
- if message ~= nil then
- self._status = message
- end
- local config = self:settings ()
- if config.status () == false then return end
- term.setBackgroundColor ( config.status.background )
- term.setTextColor ( config.status.text )
- term.setCursorPos ( 1, height )
- term.clearLine ()
- term.write ( self._status )
- if message == nil then
- return self._status
- end
- end,
- ['event'] = {
- ['key'] = {
- ['*'] = function ( self, event )
- --self:status ( 'key: ' .. tostring ( event [1] ) )
- end,
- [59] = function ( self ) -- F1
- self:help ()
- return true
- end,
- [62] = function ( self )
- self:setup ()
- end,
- [88] = function ( self )
- os.reboot ()
- return true
- end,
- [199] = function ( self ) -- [Home]
- self:select ( 1 )
- return true
- end,
- [207] = function ( self ) -- [End]
- self:select ( #self:option() )
- return true
- end,
- [201] = function ( self ) -- [Page up]
- self:select ( self:select() - (height - self:settings ().offset ()) )
- return true
- end,
- [209] = function ( self ) -- [Page down]
- self:select ( self:select() + (height - self:settings ().offset ()) )
- return true
- end,
- [200] = function ( self ) -- [Up]
- self:select ( self:select () - 1 )
- return true
- end,
- [208] = function ( self ) -- [Down]
- self:select ( self:select () + 1 )
- return true
- end,
- [14] = function ( self, event )
- local search = self._search
- if search == false then
- if self._verifyQuit == true then
- local status = self._status
- self:status ( 'Confirm quit, [Backspace] again' )
- local _, key = os.pullEvent ( 'key' )
- if key == event [1] then
- self:abort ()
- end
- self:status ( status )
- else
- self:abort ()
- end
- else
- if search == '' then
- self:search ( false )
- else
- search = search:sub ( 1, #search - 1 )
- self:search ( search )
- end
- end
- return true
- end,
- },
- ['char'] = {
- ['*'] = function ( self, event )
- local search = self._search
- if search == false then search = '' end
- if search == '' and event [1] == ' ' then event [1] = '' end
- if event [1]:match ( '[A-Za-z0-9 ]' ) then
- self:search ( search .. event [1] )
- end
- return true
- end,
- },
- },
- ['run'] = function ( self )
- if i ~= nil and data ~= nil then
- if data:get ( 'menu.tutorial.show' ) ~= false then
- self:help ()
- data:set ( 'menu.tutorial.show', false )
- end
- end
- local time = 0
- self:select ( self:select () )
- while self._abort ~= true do
- if time + 0.05 < os.clock () then
- self:draw ()
- time = os.clock ()
- end
- local event = ({os.pullEvent ()})
- local e = table.remove ( event, 1 )
- local success = false
- local opt = self:option ( self:select() )
- if opt ~= nil and opt.event ~= false and opt.event [e] ~= nil then
- if success == false and opt ~= false and event [1] ~= nil and opt.event [e][ event[1] ] ~= nil then
- if opt.event [e][ event[1] ] ( opt, event ) == true then
- success = true
- end
- end
- if success == false and opt ~= false and opt.event [e]['*'] ~= nil then
- if opt.event [e]['*'] ( opt, event ) == true then
- success = true
- end
- end
- end
- opt = nil
- if self.event [e] ~= nil then
- if success == false and self.event [e][ event[1] ] ~= nil then
- if self.event [e][ event[1] ] ( self, event ) == true then
- success = true
- end
- end
- if success == false and self.event [e]['*'] ~= nil then
- if self.event [e]['*'] ( self, event ) == true then
- success = true
- end
- end
- end
- if _G ['_event'] ~= nil and _G ['_event'][e] ~= nil then
- if success == false and _G ['_event'] [e][ event[1] ] ~= nil then
- if _G ['_event'] [e][ event[1] ] ( self, event ) == true then
- success = true
- end
- end
- if success == false and _G ['_event'] [e]['*'] ~= nil then
- if _G ['_event'] [e]['*'] ( self, event ) == true then
- success = true
- end
- end
- end
- end
- self._abort = false
- term.setBackgroundColor ( colors.black )
- term.setTextColor ( colors.white )
- term.setCursorPos ( 1,1 )
- term.clear ()
- end,
- ['draw'] = function ( self )
- local config = self:settings ()
- term.setBackgroundColor ( config.options.background )
- term.setTextColor ( config.options.text )
- term.clear ()
- if config.header ~= false then
- term.setBackgroundColor ( config.header.background )
- term.setTextColor ( config.header.text )
- term.setCursorPos ( 3,1 )
- term.clearLine ()
- term.setCursorPos ( 3,2 )
- term.clearLine ()
- term.write ( self._name )
- end
- for i = 1, height - config.offset () do
- term.setBackgroundColor ( config.options.background )
- term.setTextColor ( config.options.text )
- term.setCursorPos ( 4, config.offset.top + i )
- term.clearLine ()
- if self._offset + i == self:select () then
- term.setBackgroundColor ( config.selection.background )
- term.setTextColor ( config.selection.text )
- end
- local opt = self:option ( self._offset + i )
- if opt ~= nil then
- if opt.draw ~= nil then
- opt:draw ()
- else
- local str = tostring ( opt:toString () )
- str = str:sub ( 1, width - 7 )
- str = str .. string.rep ( ' ', math.max ( 0, width - #str - 7) )
- term.write ( str )
- end
- end
- end
- self:status ()
- end,
- ['_help'] = {
- {
- '',
- ' Help (Keybinds)',
- '',
- ' [Enter] Executes the selected option',
- ' [Backspace] Goes back a step',
- ' [Up] Selects the menu option above ',
- ' [Down] Selects the menu option below ',
- ' [F1] Opens this help screen',
- ' [F4] Setup (May be disabled)',
- },
- {
- '',
- ' Help (Keybinds)',
- '',
- ' [Page up] Goes up a page',
- ' [Page down] Goes down a page',
- ' [Home] Goes to first option',
- ' [End] Goes to last option',
- '',
- ' Do note that various custom options',
- ' may have their own keybinds, and as',
- ' such, they are not shown here',
- },
- {
- '',
- ' Search',
- ' The menu options can be searched in',
- ' simply by typing whichever you wish ',
- ' to search for, to stop searching ',
- ' repeat press backspace until the ',
- ' search is gone.',
- },
- },
- ['help'] = function ( self, page )
- if type ( page ) == 'boolean' then self._help = false end
- if self._help == false then return end
- term.setBackgroundColor ( colors.black )
- term.setTextColor ( colors.white )
- local s = function ( page, lines )
- if lines == nil then
- lines = page
- page = nil
- end
- term.clear ()
- for i, message in ipairs ( lines ) do
- term.setCursorPos ( 1, i )
- term.write ( message )
- end
- term.setCursorPos ( 1, height )
- local message = 'Press any key to continue'
- if page ~= nil then
- local status = page ..'/' .. #self._help
- message = message .. string.rep ( ' ', width - #status - 25 ) .. status
- end
- term.write ( message )
- os.pullEvent ( 'key' )
- end
- if type ( page ) == 'table' then
- s ( page )
- return self
- end
- for page, lines in ipairs ( self._help ) do
- s ( page, lines )
- end
- return self
- end,
- ['_settings'] = false,
- ['settings'] = function ( self )
- if self._settings ~= false then
- return self._settings
- end
- local config = {
- ['offset'] = {
- ['top'] = 1,
- ['bottom'] = 1,
- },
- ['status'] = {
- ['_status'] = true,
- },
- ['header'] = {
- ['_header'] = true,
- },
- ['options'] = {
- },
- ['selection'] = {
- },
- }
- setmetatable ( config ['offset'], {
- ['__call'] = function ( self )
- return self.top + self.bottom
- end,
- } )
- setmetatable ( config ['header'], {
- ['__call'] = function ( self, value )
- if value == nil then return self._header end
- self._header = value
- end,
- } )
- setmetatable ( config ['status'], {
- ['__call'] = function ( self, value )
- if value == nil then return self._status end
- self._status = value
- end,
- } )
- config.width,config.height = term.getSize ()
- if data:get ( 'menu.' .. self:name () .. '.setup.header' ) == false then
- config.header ( false )
- else
- config.header ( true )
- config.offset.top = config.offset.top + 2
- end
- if data:get ( 'menu.' .. self:name () .. '.setup.status' ) == false then
- config.status ( false )
- else
- config.status ( true )
- config.offset.bottom = config.offset.bottom + 1
- end
- config.status.background = data:get ( 'menu.' .. self:name () .. '.setup.status.background' )
- if type ( config.status.background ) ~= 'number' then
- config.status.background = colors.white
- end
- config.status.text = data:get ( 'menu.' .. self:name () .. '.setup.status.text' )
- if type ( config.status.text ) ~= 'number' then
- config.status.text = colors.black
- end
- config.header.background = data:get ( 'menu.' .. self:name () .. '.setup.header.background' )
- if type ( config.header.background ) ~= 'number' then
- config.header.background = colors.black
- end
- config.header.text = data:get ( 'menu.' .. self:name () .. '.setup.header.text' )
- if type ( config.header.text ) ~= 'number' then
- config.header.text = colors.white
- end
- config.options.background = data:get ( 'menu.' .. self:name () .. '.setup.options.background' )
- if type ( config.options.background ) ~= 'number' then
- config.options.background = colors.black
- end
- config.options.text = data:get ( 'menu.' .. self:name () .. '.setup.options.text' )
- if type ( config.options.text ) ~= 'number' then
- config.options.text = colors.white
- end
- config.selection.background = data:get ( 'menu.' .. self:name () .. '.setup.selection.background' )
- if type ( config.selection.background ) ~= 'number' then
- config.selection.background = colors.white
- end
- config.selection.text = data:get ( 'menu.' .. self:name () .. '.setup.selection.text' )
- if type ( config.selection.text ) ~= 'number' then
- config.selection.text = colors.black
- end
- config.options.indent = data:get ( 'menu.' .. self:name () .. '.setup.options.indent' )
- if type ( config.options.indent ) ~= 'number' then
- config.options.indent = 0
- end
- self._settings = config
- return config
- end,
- ['_setup'] = true,
- ['setup'] = function ( self, bool )
- if type ( bool ) == 'boolean' then
- self._setup = bool
- return self
- end
- if self._setup ~= true then return self end
- local menu = i.files:run ( 'class/menu.basic.lua' )
- menu.name = function () return self:name () end
- menu._name = 'Menu setup for: ' .. menu:name ()
- menu:setup ( false )
- local opt = menu:create ( 'Display: Header' )
- opt:type ( 'bool' )
- opt:bool ( data:get ( 'menu.' .. self:name () .. '.setup.header' ) )
- opt:update ( function ( opt )
- data:set ( 'menu.' .. self:name () .. '.setup.header', opt:bool () )
- self._settings = false
- menu._settings = false
- end )
- local opt = menu:create ( 'Display: Status' )
- opt:type ( 'bool' )
- opt:bool ( data:get ( 'menu.' .. self:name () .. '.setup.status' ) )
- opt:update ( function ( opt )
- data:set ( 'menu.' .. self:name () .. '.setup.status', opt:bool () )
- menu._settings = false
- end )
- local opt = menu:create ( 'Header: Background' )
- opt:type ( 'color' )
- opt:color ( data:get ( 'menu.' .. self:name () .. '.setup.header.background' ) or colors.black )
- opt:update ( function ( opt )
- data:set ( 'menu.' .. self:name () .. '.setup.header.background', opt:color () )
- menu._settings = false
- end )
- local opt = menu:create ( 'Header: Text' )
- opt:type ( 'color' )
- opt:color ( data:get ( 'menu.' .. self:name () .. '.setup.header.text' ) or colors.white )
- opt:update ( function ( opt )
- data:set ( 'menu.' .. self:name () .. '.setup.header.text', opt:color () )
- menu._settings = false
- end )
- local opt = menu:create ( 'Status: Background' )
- opt:type ( 'color' )
- opt:color ( data:get ( 'menu.' .. self:name () .. '.setup.status.background' ) or colors.white )
- opt:update ( function ( opt )
- data:set ( 'menu.' .. self:name () .. '.setup.status.background', opt:color () )
- menu._settings = false
- end )
- local opt = menu:create ( 'Status: Text' )
- opt:type ( 'color' )
- opt:color ( data:get ( 'menu.' .. self:name () .. '.setup.status.text' ) or colors.black )
- opt:update ( function ( opt )
- data:set ( 'menu.' .. self:name () .. '.setup.status.text', opt:color () )
- menu._settings = false
- end )
- local opt = menu:create ( 'Selection: Indent' )
- opt:type ( 'number' )
- opt:number ( data:get ( 'menu.' .. self:name () .. '.setup.options.indent' ) or 0 )
- opt:min ( 0 ):max ( 10 )
- opt:update ( function ( opt )
- data:set ( 'menu.' .. self:name () .. '.setup.options.indent', opt:number () )
- menu._settings = false
- end )
- local opt = menu:create ( 'Selection: Background' )
- opt:type ( 'color' )
- opt:color ( data:get ( 'menu.' .. self:name () .. '.setup.selection.background' ) or colors.white )
- opt:update ( function ( opt )
- data:set ( 'menu.' .. self:name () .. '.setup.selection.background', opt:color () )
- menu._settings = false
- end )
- local opt = menu:create ( 'Selection: Text' )
- opt:type ( 'color' )
- opt:color ( data:get ( 'menu.' .. self:name () .. '.setup.selection.text' ) or colors.black )
- opt:update ( function ( opt )
- data:set ( 'menu.' .. self:name () .. '.setup.selection.text', opt:color () )
- menu._settings = false
- end )
- local opt = menu:create ( 'Options: Background' )
- opt:type ( 'color' )
- opt:color ( data:get ( 'menu.' .. self:name () .. '.setup.options.background' ) or colors.black )
- opt:update ( function ( opt )
- data:set ( 'menu.' .. self:name () .. '.setup.options.background', opt:color () )
- menu._settings = false
- end )
- local opt = menu:create ( 'Options: Text' )
- opt:type ( 'color' )
- opt:color ( data:get ( 'menu.' .. self:name () .. '.setup.options.text' ) or colors.white )
- opt:update ( function ( opt )
- data:set ( 'menu.' .. self:name () .. '.setup.options.text', opt:color () )
- menu._settings = false
- end )
- menu:run ()
- self._settings = false
- menu = nil
- return true
- end,
- }
- ]],
- ['class/menu.basic/bool.lua'] = [[
- local width, height = term.getSize ()
- return {
- ['_selected'] = function ( self )
- end,
- ['_bool'] = true,
- ['bool'] = function ( self, bool )
- if bool == nil then return self._bool end
- if bool == true then
- self._bool = true
- else
- self._bool = false
- end
- if type ( self._update ) == 'function' then self._update ( self ) end
- return self
- end,
- ['_readonly'] = false,
- ['readonly'] = function ( self, bool )
- if bool == nil then return self._bool end
- if bool == true then
- self._bool = true
- else
- self._bool = false
- end
- return self
- end,
- ['event'] = {
- ['key'] = {
- [205] = function ( self )
- self:bool ( true )
- return true
- end,
- [203] = function ( self )
- self:bool ( false )
- return true
- end,
- }
- },
- ['toString'] = function ( self )
- local str = string.rep ( ' ', self._parent:settings ().options.indent ) .. self:name ()
- if #str > math.max ( 0, width - 7 - #str - (#tostring ( self:bool() ) + 2 )) or true then
- str:sub ( 1, math.max ( 0, width - 7 - #str - (#tostring ( self:bool() ) + 2 )) )
- end
- return str .. string.rep ( ' ', math.max ( 0, width - 7 - #str - (#tostring ( self:bool() ) + 2 )) ) ..' '.. tostring ( self:bool() )
- end,
- }
- ]],
- ['class/menu.basic/color.lua'] = [[
- return {
- ['_selected'] = function ( self )
- if i.settings:get ( 'menu.tutorial.color.show' ) ~= false then
- self._parent:help ( {
- '',
- ' Help (Menu option selection)',
- '',
- ' Color selector',
- ' Use [Left]/[Right] to change color',
- } )
- i.settings:set ( 'menu.tutorial.color.show', false )
- end
- end,
- ['__colors'] = {
- [colors.white] = true,
- [colors.orange] = false,
- [colors.magenta] = false,
- [colors.lightBlue] = false,
- [colors.yellow] = false,
- [colors.lime] = false,
- [colors.pink] = false,
- [colors.gray] = true,
- [colors.lightGray] = true,
- [colors.cyan] = false,
- [colors.purple] = false,
- [colors.blue] = false,
- [colors.brown] = false,
- [colors.green] = false,
- [colors.red] = false,
- [colors.black] = true,
- },
- ['_color'] = colors.white,
- ['color'] = function ( self, color )
- if color == nil then return self._color end
- if self.__colors [color] == nil then return false end
- if term.isColor () == false and self.__colors [color] == false then return false end
- self._color = color
- if type ( self._update ) == 'function' then self._update ( self ) end
- return self
- end,
- ['event'] = {
- ['key'] = {
- [205] = function ( self )
- local current = self:color ()
- local _next = false
- for color in pairs ( self.__colors ) do
- if term.isColor () == false then
- if self.__colors [color] == true then
- if _next == true then
- self:color ( color )
- break
- end
- if current == color then
- _next = true
- end
- end
- else
- if _next == true then
- self:color ( color )
- break
- end
- if current == color then
- _next = true
- end
- end
- end
- return true
- end,
- [203] = function ( self )
- local current = self:color ()
- local _prev = false
- for color in pairs ( self.__colors ) do
- if term.isColor () == false then
- if self.__colors [color] == true then
- if current == color then
- self:color ( _prev )
- break
- end
- _prev = color
- end
- else
- if current == color then
- self:color ( _prev )
- break
- end
- _prev = color
- end
- end
- return true
- end,
- }
- },
- ['draw'] = function ( self )
- local width = self._parent:settings ().width
- local str = string.rep ( ' ', self._parent:settings ().options.indent ) .. self:toString ()
- str = str:sub ( 1, width - 14 )
- if #str < width - 12 then
- str = str .. string.rep ( ' ', width - #str - 13 )
- end
- local color = term.getBackgroundColor ()
- term.write ( str .. '[' )
- term.setBackgroundColor ( self:color () )
- term.write ( ' ' )
- term.setBackgroundColor ( color )
- term.write ( ']' )
- end,
- ['toString'] = function ( self )
- return self:name ()
- end,
- }
- ]],
- ['class/menu.basic/execute.lua'] = [[
- return {
- ['_run'] = false,
- ['run'] = function ( self, input )
- if input == nil then return self._run end
- self._run = input
- return self
- end,
- ['event'] = {
- ['key'] = {
- [28] = function ( self, event ) -- [Enter]
- local run = self:run ()
- if run == false or run == nil then return true end
- if type ( run ) == 'function' then
- run ( self, event )
- elseif type ( run ) == 'string' then
- if run:sub ( 1, 4 ) == 'http' then
- i.files:run ( run )
- elseif fs.exists ( run ) == true then
- loadfile ( run ) ()
- end
- end
- return true
- end,
- }
- }
- }
- ]],
- ['class/menu.basic/number.lua'] = [[
- local width, height = term.getSize ()
- return {
- ['_selected'] = function ( self )
- if i.settings:get ( 'menu.tutorial.number.show' ) ~= false then
- self._parent:help ( {
- '',
- ' Help (Menu option selection)',
- '',
- ' Number selector',
- ' Use [Left] to select false',
- ' Use [Right] to select true',
- } )
- i.settings:set ( 'menu.tutorial.number.show', false )
- end
- end,
- ['_number'] = 1,
- ['number'] = function ( self, number )
- if number == nil then return self._number end
- if type(number) ~= 'number' then return false end
- if number > self:max () then
- number = self:max ()
- elseif number < self:min () then
- number = self:min ()
- end
- self._number = number
- if type ( self._update ) == 'function' then self._update ( self ) end
- return self
- end,
- ['_step'] = 1,
- ['step'] = function ( self, number )
- if number == nil then return self._step end
- if type(number) ~= 'number' then return false end
- self._step = number
- return self
- end,
- ['_max'] = 1/0,
- ['max'] = function ( self, number )
- if number == nil then return self._max end
- if type(number) ~= 'number' then return false end
- self._max = number
- if self:number () > number then
- self:number ( number )
- end
- return self
- end,
- ['_min'] = 0 - 1/0,
- ['min'] = function ( self, number )
- if number == nil then return self._min end
- if type(number) ~= 'number' then return false end
- self._min = number
- if self:number () < number then
- self:number ( number )
- end
- return self
- end,
- ['_readonly'] = false,
- ['readonly'] = function ( self, bool )
- if bool == nil then return self._readonly end
- if bool == true then
- self._readonly = true
- else
- self._readonly = false
- end
- return self
- end,
- ['_shift'] = false,
- ['_ctrl'] = false,
- ['event'] = {
- ['key'] = {
- [205] = function ( self )
- if self:readonly () == false then
- local multiplier = 1
- if self._shift == true then multiplier = multiplier * 10 end
- if self._ctrl == true then multiplier = multiplier * 100 end
- self:number ( self:number () + (self:step () * multiplier) )
- end
- end,
- [203] = function ( self )
- if self:readonly () == false then
- local multiplier = 1
- if self._shift == true then multiplier = multiplier * 10 end
- if self._ctrl == true then multiplier = multiplier * 100 end
- self:number ( self:number () - (self:step () * multiplier) )
- end
- end,
- [211] = function ( self )
- if self:readonly () == false then
- self:number ( math.max ( self:min (), 1 ) )
- end
- end,
- [42] = function ( self )
- self._shift = true
- end,
- [29] = function ( self )
- self._ctrl = true
- end,
- },
- ['key_up'] = {
- [42] = function ( self )
- self._shift = false
- end,
- [29] = function ( self )
- self._ctrl = false
- end,
- }
- },
- ['toString'] = function ( self )
- local str = string.rep ( ' ', self._parent:settings ().options.indent ) .. self:name ()
- if #str > math.max ( 0, width - 7 - #str - (#tostring ( self:number() ) + 2 )) or true then
- str:sub ( 1, math.max ( 0, width - 7 - #str - (#tostring ( self:number() ) + 2 )) )
- end
- return str .. string.rep ( ' ', math.max ( 0, width - 7 - #str - (#tostring ( self:number() ) + 2 )) ) ..' '.. self:number()
- end,
- }
- ]],
- },
- ['get'] = function ( self, file )
- if file == nil then
- error ( 'files.get, no file name provided' )
- return false
- end
- if self._data [file] == nil then
- local h = http.get ( self._url .. file )
- if h == nil then
- error ( 'files.run, file not found (' .. file ..')' )
- return false
- end
- self._data [file] = h.readAll ()
- end
- return self._data [file]
- end,
- ['run'] = function ( self, file )
- if file == nil then
- error ( 'files.run, no file name provided' )
- return false
- end
- local content = self:get ( file )
- if content == false then
- error ( 'files.run, file not found' )
- return false
- end
- local func, message = assert ( load ( content, '=' .. file, 't', _G ) )
- return func ()
- end,
- ['clear'] = function ( self, file )
- self._data [file] = nil
- end,
- },
- ['settings'] = {
- ['_path'] = '/.settings',
- ['_data'] = false,
- ['_init'] = function ( self )
- if self._data == false then
- if fs.exists ( self._path ) == true then
- local f = fs.open ( self._path, 'r' )
- local content = f.readAll ()
- f.close ()
- self._data = textutils.unserialize ( content )
- if type ( self._data ) ~= 'table' then
- self._data = {}
- end
- else
- self._data = {}
- end
- end
- end,
- ['get'] = function ( self, key )
- self:_init ()
- return self._data [key]
- end,
- ['set'] = function ( self, key, value )
- self:_init ()
- self._data [key] = value
- local content = textutils.serialize ( self._data )
- local f = fs.open ( self._path, 'w' )
- f.write ( content )
- f.close ()
- return self
- end,
- },
- }
- _G ['_event'] = {}
- i.map = i.files:run ( 'class/map.lua' )
- i.turtle = i.files:run ( 'class/turtle.lua' )
- i.items = i.files:run ( 'class/items.lua' )
- i.timer = i.files:run ( 'class/timer.lua' )
- i.timer:init ( _G ['_event'] )
- local menu = i.files:run ( 'class/menu.basic.lua' )
- menu:name ( 'GPS Tower builder' )
- menu:verifyQuit ( true )
- menu:settings ().options.indent = 1
- menu:create ( 'Current Position:' )
- menu:create ( ' x' ):type ( 'number' ):number ( i.turtle.location.x ):selected ( function () menu:status ( '' ) end )
- menu:create ( ' y' ):type ( 'number' ):number ( i.turtle.location.y ):selected ( function () menu:status ( '' ) end )
- menu:create ( ' z' ):type ( 'number' ):number ( i.turtle.location.z ):selected ( function () menu:status ( '' ) end )
- menu:create ( '' ):selected ( function () menu:status ( '' ) end )
- menu:create ( 'Place tower at' ):type ( 'number' ):min ( -1 ):number ( -1 ):selected ( function ()
- menu:status ( '-1 for max height possibly' )
- end )
- menu:create ( 'Dig if needed' ):type ( 'bool' ):bool ( true ):selected ( function ()
- menu:status ( '[Left] False, [Right] True' )
- end )
- menu:create ( 'Start building' ):type ( 'execute' ):selected ( function () menu:status ( '' ) end ):run ( function ()
- local x = menu:option (2):number ()
- local y = menu:option (3):number ()
- local z = menu:option (4):number ()
- local height = menu:option (6):number ()
- local digAllowed = menu:option (7):bool ()
- local startY = y
- local menu = i.files:run ( 'class/menu.basic.lua' )
- menu:settings ().options.indent = 1
- menu:name ( 'Checking inventory' )
- menu:create ( ' - Can dig' )
- menu:create ( ' - Fuel' )
- menu:create ( ' - Disk Drive' ):type ( 'number' ):number ( 1 )
- menu:create ( ' - Computer' ):type ( 'number' ):number ( 4 )
- menu:create ( ' - Wireless modem' ):type ( 'number' ):number ( 4 )
- menu:create ( ' - Floppy disk' ):type ( 'number' ):number ( 1 )
- menu:draw ()
- i.turtle.inventory:stack ()
- menu:option (1):type ( 'bool' ):bool ( false )
- local snapshot = i.turtle.inventory:snapshot ()
- local state, message = turtle.digUp ()
- if state == true then
- snapshot.compare:current ():each ( function ( slot )
- turtle.select ( slot )
- turtle.placeUp ()
- end )
- menu:option (1):type ( 'bool' ):bool ( digAllowed )
- if digAllowed == false then
- menu:option (3):number (4)
- menu:status ( 'Blocks in the way, please clear up' )
- menu:run ()
- return
- end
- else
- if message == 'No tool to dig with' then
- menu:option (1):type ( 'bool' ):bool ( false )
- else
- menu:option (1):type ( 'bool' ):bool ( true )
- end
- end
- if menu:option (1):bool () == false then
- local item = i.turtle.inventory:select ( 'Diamond Pickaxe' )
- if item ~= false then
- if turtle.equipLeft () == false then
- if turtle.equipRight () ~= false then
- menu:option (1):bool ( true )
- end
- else
- menu:option (1):bool ( true )
- end
- end
- end
- if menu:option (1):bool () == false then
- menu:option (1):bool ( true )
- menu:option (3):number (4)
- end
- local digCan = menu:option (1):bool () -- Giggle, digCan... its late,leave me alone
- menu:option (2):type ( 'bool' ):bool ( true )
- if i.turtle.inventory.select:fuel () == false then
- if turtle.getFuelLevel () ~= 'unlimited' and turtle.getFuelLevel () < 800 then
- menu:option (2):type ( 'bool' ):bool ( false )
- else
- menu:option (2):bool ( true )
- end
- else
- if turtle.getFuelLevel () == 'unlimited' then
- menu:option (2):type ( 'bool' ):bool ( true )
- else
- menu:option (2):type ( 'number' ):number ( turtle.getFuelLevel () )
- while i.turtle.inventory.select:fuel () ~= false do
- turtle.refuel (1)
- menu:option (2):type ( 'number' ):number ( math.max ( 0, 800 - turtle.getFuelLevel () ) )
- menu:draw ()
- if turtle.getFuelLevel () > 800 then
- break
- end
- end
- if turtle.getFuelLevel () <= 800 then
- menu:option (2):type ( 'bool' ):bool ( false )
- else
- menu:option (2):type ( 'bool' ):bool ( true )
- end
- end
- end
- local item = i.turtle.inventory:select ( 'Disk Drive', false )
- if item ~= false then
- menu:option (3):number ( math.max ( 0, menu:option (3):number () - item.count ) )
- end
- local item = i.turtle.inventory:select ( 'Computer', false )
- if item ~= false then
- menu:option (4):number ( math.max ( 0, menu:option (4):number () - item.count ) )
- end
- local item = i.turtle.inventory:select ( 'Advanced Computer', false )
- if item ~= false then
- menu:option (4):number ( math.max ( 0, menu:option (4):number () - item.count ) )
- end
- local item = i.turtle.inventory:select ( 'Wireless modem', false )
- if item ~= false then
- menu:option (5):number ( math.max ( 0, menu:option (5):number () - item.count ) )
- end
- local item = i.turtle.inventory:select ( 'Floppy disk', false )
- if item ~= false then
- menu:option (6):number ( math.max ( 0, menu:option (6):number () - item.count ) )
- end
- local item = i.turtle.inventory:select ( 'Floppy disk - Expanded', false )
- if item ~= false then
- menu:option (6):number ( math.max ( 0, menu:option (6):number () - item.count ) )
- end
- if menu:option (6):number () == 0 then table.remove ( menu:option (), 6 ) end
- if menu:option (5):number () == 0 then table.remove ( menu:option (), 5 ) end
- if menu:option (4):number () == 0 then table.remove ( menu:option (), 4 ) end
- if menu:option (3):number () == 0 then table.remove ( menu:option (), 3 ) end
- if menu:option (2):bool () == true then table.remove ( menu:option (), 2 ) end
- if menu:option (1):bool () == true then table.remove ( menu:option (), 1 ) end
- if #menu:option () > 0 then
- menu:name ( 'Missing items')
- for i = 1, #menu:option () do
- menu:option (i):readonly ( true )
- end
- i.timer:start ( 5, function ()
- menu:status ( 'Press [Backspace] to try again.' )
- end )
- menu:run ()
- return
- end
- i.turtle.location.x = x
- i.turtle.location.y = y
- i.turtle.location.z = z
- local selected = false
- menu:clear ()
- menu:name ( 'The turtle is facing' )
- menu:create ( 'East' ):type ( 'execute' ):run ( function ()
- i.turtle.facing = 1
- selected = true
- menu:abort ()
- end )
- menu:create ( 'North' ):type ( 'execute' ):run ( function ()
- i.turtle.facing = 2
- selected = true
- menu:abort ()
- end )
- menu:create ( 'West' ):type ( 'execute' ):run ( function ()
- i.turtle.facing = 3
- selected = true
- menu:abort ()
- end )
- menu:create ( 'South' ):type ( 'execute' ):run ( function ()
- i.turtle.facing = 4
- selected = true
- menu:abort ()
- end )
- menu:select ( i.turtle.facing or 2 )
- while selected == false do menu:run () end
- menu:clear ()
- menu:name ( 'Moving' )
- if height == -1 then
- menu:create ( 'Detecting max height' )
- else
- menu:create ( 'Moving to height' )
- end
- menu:create ( 'Y' ):type ( 'number' ):number ( i.turtle.location.y )
- menu:draw ()
- local placeGuide = {
- -1,
- -1,
- }
- i.turtle:face ( 'south' )
- local node = i.turtle:location ()
- local nodes = {
- [node.x ..','.. node.y ..','.. node.z] = node,
- }
- while true do
- if height ~= -1 and i.turtle.location.y >= height then
- break
- end
- if digAllowed == true then
- if turtle.detectUp () == true then
- local snapshot = i.turtle.inventory:snapshot ()
- if turtle.getSelectedSlot () ~= 1 then turtle.select (1) end
- turtle.digUp ()
- snapshot.compare:current ():each ( function ( slot, item )
- node:up ().item = item
- return true
- end )
- end
- end
- local moves, message = i.turtle:up ()
- if moves ~= 0 then
- node = node:up ()
- nodes [ node.x ..','.. node.y ..','.. node.z ] = node
- end
- menu:option (2):number ( i.turtle.location.y )
- menu:draw ()
- if digAllowed == true then
- local item = node:down ().item
- if item ~= nil then
- i.turtle.inventory:select ( item )
- turtle.placeDown ()
- end
- end
- if message == 'Movement obstructed' then break end
- if message == 'Too high to move' then
- i.turtle:down ()
- node = node:down ()
- break
- end
- end
- nodes [ node.x ..','.. node.y ..','.. node.z ] = node
- menu:name ( 'Deploying' )
- menu:clear ()
- menu:create ( 'Computer 1' ):type ( 'bool' ):bool ( false )
- menu:create ( 'Computer 2' ):type ( 'bool' ):bool ( false )
- menu:create ( 'Computer 3' ):type ( 'bool' ):bool ( false )
- menu:create ( 'Computer 4' ):type ( 'bool' ):bool ( false )
- for t = 1,4 do
- menu:select ( t )
- menu:draw ()
- if t == 1 then
- i.turtle:face ( 'south' )
- elseif t == 2 then
- i.turtle:face ( 'north' )
- elseif t == 3 then
- local node = i.turtle:location ()
- node = nodes [ node.x ..','.. node.y ..','.. node.z ]
- for a = 1,3 do
- if digAllowed == true then
- if turtle.detectDown () == true then
- local snapshot = i.turtle.inventory:snapshot ()
- if turtle.getSelectedSlot () ~= 1 then turtle.select (1) end
- turtle.digDown ()
- snapshot.compare:current ():each ( function ( slot, item )
- node:down ().item = item
- return true
- end )
- end
- end
- local moves, message = i.turtle:down ()
- if moves ~= 0 then
- node = node:down ()
- nodes [ node.x ..','.. node.y ..','.. node.z ] = node
- end
- if digAllowed == true then
- local item = node:up ().item
- if item ~= nil then
- i.turtle.inventory:select ( item )
- turtle.placeUp ()
- end
- end
- end
- i.turtle:face ( 'east' )
- elseif t == 4 then
- i.turtle:face ( 'west' )
- end
- local node = i.turtle:location ()
- node = nodes [ node.x ..','.. node.y ..','.. node.z ]
- for a = 1,2 do
- node = node [ i.turtle.direction:forward () ] ( node )
- nodes [ node.x ..','.. node.y ..','.. node.z ] = node
- if digAllowed == true then
- if turtle.detect () == true then
- local snapshot = i.turtle.inventory:snapshot ()
- if turtle.getSelectedSlot () ~= 1 then turtle.select ( 1 ) end
- local _, message = turtle.dig ()
- if message == 'Unbreakable block detected' then error ( 'Well this fucking sucks, i dont even....' ) end
- snapshot.compare:current ():each ( function ( slot, item )
- node.item = item
- return true
- end )
- end
- end
- i.turtle:forward ()
- end
- local coordNode = node [ i.turtle.direction:forward () ] ( node )
- local wirelessNode = node
- if turtle.detect () == true then
- local snapshot = i.turtle.inventory:snapshot ()
- if turtle.getSelectedSlot () ~= 1 then turtle.select ( 1 ) end
- turtle.dig ()
- snapshot.compare:current ():each ( function ( slot, item )
- turtle.select ( slot )
- turtle.drop ( item.count )
- end )
- end
- if i.turtle.inventory:select ( 'Computer' ) == false then
- i.turtle.inventory:select ( 'Advanced Computer' )
- end
- turtle.place ()
- if turtle.detectDown () == true then
- local snapshot = i.turtle.inventory:snapshot ()
- if turtle.getSelectedSlot () ~= 1 then turtle.select ( 1 ) end
- turtle.digDown ()
- local node = node:down ()
- nodes [ node.x ..','.. node.y ..','.. node.z ] = node
- snapshot.compare:current ():each ( function ( slot, item )
- node.item = item
- return true
- end )
- end
- i.turtle:down ()
- node = node:down ()
- if turtle.detect () == true then
- local snapshot = i.turtle.inventory:snapshot ()
- if turtle.getSelectedSlot () ~= 1 then turtle.select ( 1 ) end
- turtle.dig ()
- local node = node [ i.turtle.direction:forward () ] ( node )
- nodes [ node.x ..','.. node.y ..','.. node.z ] = node
- snapshot.compare:current ():each ( function ( slot, item )
- node.item = item
- return true
- end )
- end
- i.turtle.inventory:select ( 'Disk Drive' )
- turtle.place ()
- if i.turtle.inventory:select ( 'Floppy Disk' ) == false then
- i.turtle.inventory:select ( 'Floppy Disk - Extended' )
- end
- turtle.drop ()
- local file = fs.open ( 'disk/startup', 'w' )
- file.write ([[
- -- Inspired by http://www.computercraft.info/forums2/index.php?/topic/9528-gps-deploy-11-updated-04012014/
- -- Also, there's not really that many ways of doing this
- fs.delete ( 'startup' )
- fs.copy ('/disk/install', 'startup' )
- if fs.exists ( 'disk/custom' ) == true then
- fs.copy ( 'disk/custom', 'custom' )
- end
- term.clear ()
- term.setCursorPos ( 3,3 )
- term.write ( 'Sleeping...' )
- os.sleep (5)
- os.reboot ()
- ]])
- file.close ()
- fs.delete ( 'disk/install' )
- local file = fs.open ( 'disk/install', 'w' )
- file.write ([[
- -- Hi, http://www.computercraft.info/forums2/index.php?/topic/9528-gps-deploy-11-updated-04012014/
- term.clear ()
- if fs.exists ( 'custom' ) == true then
- shell.run ( 'custom', 'host', ]] .. coordNode.x ..',' .. coordNode.y ..','.. coordNode.z .. [[ )
- else
- shell.run ( 'gps', 'host', ]] .. coordNode.x ..',' .. coordNode.y ..','.. coordNode.z .. [[ )
- end
- ]])
- file.close ()
- i.turtle:up ()
- local wrap = peripheral.wrap ( 'front' )
- if wrap.isOn () == true then wrap.shutdown () end
- wrap.turnOn ()
- i.turtle:down ()
- if turtle.getSelectedSlot () ~= 1 then turtle.select ( 1 ) end
- turtle.suck ()
- turtle.dig ()
- local item = node [ i.turtle.direction:forward () ] ( node ).item
- if item ~= nil then
- i.turtle.inventory:select ( item )
- turtle.place ()
- end
- i.turtle:up ()
- local item = node.item
- if item ~= nil then
- i.turtle.inventory:select ( item )
- turtle.placeDown ()
- end
- node = coordNode [ i.turtle.direction:back () ] ( coordNode )
- for a = 1,2 do
- i.turtle:back ()
- if a == 1 then
- i.turtle.inventory:select ( 'Wireless modem' )
- turtle.place ()
- menu:option (t):bool ( true )
- menu:draw ()
- end
- if digAllowed == true then
- if node.item ~= nil then
- i.turtle.inventory:select ( node.item )
- if turtle.place () == false then
- turtle.drop (1)
- end
- end
- node = node [ i.turtle.direction:back () ] ( node )
- end
- end
- end
- i.turtle.inventory:stack ()
- menu:clear ()
- menu:name ( 'Moving back to start position' )
- menu:create ( 'Y' ):type ( 'number' ):number ( i.turtle.location.y )
- while true do
- if i.turtle.location.y <= startY then break end
- if digAllowed == true then
- if turtle.detectDown () == true then
- local snapshot = i.turtle.inventory:snapshot ()
- if turtle.getSelectedSlot () ~= 1 then turtle.select (1) end
- turtle.digDown ()
- snapshot.compare:current ():each ( function ( slot, item )
- node:down ().item = item
- return true
- end )
- end
- end
- local moves, message = i.turtle:down ()
- if moves ~= 0 then
- node = node:down ()
- nodes [ node.x ..','.. node.y ..','.. node.z ] = node
- end
- menu:option (1):number ( i.turtle.location.y )
- menu:draw ()
- if digAllowed == true then
- local item = node:up ().item
- if item ~= nil then
- i.turtle.inventory:select ( item )
- turtle.placeUp ()
- end
- end
- if message == 'Movement obstructed' then break end
- end
- end )
- menu:run ()
Advertisement
Add Comment
Please, Sign In to add comment