1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-06-18 22:44:12 +00:00

The big massive reformat

- Normalise all line endings to be LF rather than CLRF
 - Trim all trailing whitespace
 - Remove any tabs
This commit is contained in:
SquidDev 2018-12-17 17:22:15 +00:00
parent e6850ab644
commit 86569533e9
154 changed files with 3684 additions and 3717 deletions

View File

@ -1,19 +0,0 @@
/*
* This file is part of ComputerCraft - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2017. Do not distribute without permission.
* Send enquiries to dratcliffe@gmail.com
*/
package dan200.computercraft.client.gui.widgets;
public class MousePos
{
public int x;
public int y;
public MousePos( int x, int y )
{
this.x = x;
this.y = y;
}
}

View File

@ -1,6 +1,5 @@
{ {
"variants": { "variants": {
"advanced=false,facing=north,state=off": { "model": "computercraft:computer_off" }, "advanced=false,facing=north,state=off": { "model": "computercraft:computer_off" },
"advanced=false,facing=south,state=off": { "model": "computercraft:computer_off", "y": 180 }, "advanced=false,facing=south,state=off": { "model": "computercraft:computer_off", "y": 180 },
"advanced=false,facing=west,state=off": { "model": "computercraft:computer_off", "y": 270 }, "advanced=false,facing=west,state=off": { "model": "computercraft:computer_off", "y": 270 },

View File

@ -3,85 +3,85 @@ local function isDrive( name )
if type( name ) ~= "string" then if type( name ) ~= "string" then
error( "bad argument #1 (expected string, got " .. type( name ) .. ")", 3 ) error( "bad argument #1 (expected string, got " .. type( name ) .. ")", 3 )
end end
return peripheral.getType( name ) == "drive" return peripheral.getType( name ) == "drive"
end end
function isPresent( name ) function isPresent( name )
if isDrive( name ) then if isDrive( name ) then
return peripheral.call( name, "isDiskPresent" ) return peripheral.call( name, "isDiskPresent" )
end end
return false return false
end end
function getLabel( name ) function getLabel( name )
if isDrive( name ) then if isDrive( name ) then
return peripheral.call( name, "getDiskLabel" ) return peripheral.call( name, "getDiskLabel" )
end end
return nil return nil
end end
function setLabel( name, label ) function setLabel( name, label )
if isDrive( name ) then if isDrive( name ) then
peripheral.call( name, "setDiskLabel", label ) peripheral.call( name, "setDiskLabel", label )
end end
end end
function hasData( name ) function hasData( name )
if isDrive( name ) then if isDrive( name ) then
return peripheral.call( name, "hasData" ) return peripheral.call( name, "hasData" )
end end
return false return false
end end
function getMountPath( name ) function getMountPath( name )
if isDrive( name ) then if isDrive( name ) then
return peripheral.call( name, "getMountPath" ) return peripheral.call( name, "getMountPath" )
end end
return nil return nil
end end
function hasAudio( name ) function hasAudio( name )
if isDrive( name ) then if isDrive( name ) then
return peripheral.call( name, "hasAudio" ) return peripheral.call( name, "hasAudio" )
end end
return false return false
end end
function getAudioTitle( name ) function getAudioTitle( name )
if isDrive( name ) then if isDrive( name ) then
return peripheral.call( name, "getAudioTitle" ) return peripheral.call( name, "getAudioTitle" )
end end
return nil return nil
end end
function playAudio( name ) function playAudio( name )
if isDrive( name ) then if isDrive( name ) then
peripheral.call( name, "playAudio" ) peripheral.call( name, "playAudio" )
end end
end end
function stopAudio( name ) function stopAudio( name )
if not name then if not name then
for n,sName in ipairs( peripheral.getNames() ) do for n,sName in ipairs( peripheral.getNames() ) do
stopAudio( sName ) stopAudio( sName )
end end
else else
if isDrive( name ) then if isDrive( name ) then
peripheral.call( name, "stopAudio" ) peripheral.call( name, "stopAudio" )
end end
end end
end end
function eject( name ) function eject( name )
if isDrive( name ) then if isDrive( name ) then
peripheral.call( name, "ejectDisk" ) peripheral.call( name, "ejectDisk" )
end end
end end
function getID( name ) function getID( name )
if isDrive( name ) then if isDrive( name ) then
return peripheral.call( name, "getDiskID" ) return peripheral.call( name, "getDiskID" )
end end
return nil return nil
end end

View File

@ -1,58 +1,57 @@
CHANNEL_GPS = 65534 CHANNEL_GPS = 65534
local function trilaterate( A, B, C ) local function trilaterate( A, B, C )
local a2b = B.vPosition - A.vPosition local a2b = B.vPosition - A.vPosition
local a2c = C.vPosition - A.vPosition local a2c = C.vPosition - A.vPosition
if math.abs( a2b:normalize():dot( a2c:normalize() ) ) > 0.999 then if math.abs( a2b:normalize():dot( a2c:normalize() ) ) > 0.999 then
return nil return nil
end end
local d = a2b:length() local d = a2b:length()
local ex = a2b:normalize( ) local ex = a2b:normalize( )
local i = ex:dot( a2c ) local i = ex:dot( a2c )
local ey = (a2c - (ex * i)):normalize() local ey = (a2c - (ex * i)):normalize()
local j = ey:dot( a2c ) local j = ey:dot( a2c )
local ez = ex:cross( ey ) local ez = ex:cross( ey )
local r1 = A.nDistance local r1 = A.nDistance
local r2 = B.nDistance local r2 = B.nDistance
local r3 = C.nDistance local r3 = C.nDistance
local x = (r1*r1 - r2*r2 + d*d) / (2*d) local x = (r1*r1 - r2*r2 + d*d) / (2*d)
local y = (r1*r1 - r3*r3 - x*x + (x-i)*(x-i) + j*j) / (2*j) local y = (r1*r1 - r3*r3 - x*x + (x-i)*(x-i) + j*j) / (2*j)
local result = A.vPosition + (ex * x) + (ey * y) local result = A.vPosition + (ex * x) + (ey * y)
local zSquared = r1*r1 - x*x - y*y local zSquared = r1*r1 - x*x - y*y
if zSquared > 0 then if zSquared > 0 then
local z = math.sqrt( zSquared ) local z = math.sqrt( zSquared )
local result1 = result + (ez * z) local result1 = result + (ez * z)
local result2 = result - (ez * z) local result2 = result - (ez * z)
local rounded1, rounded2 = result1:round( 0.01 ), result2:round( 0.01 ) local rounded1, rounded2 = result1:round( 0.01 ), result2:round( 0.01 )
if rounded1.x ~= rounded2.x or rounded1.y ~= rounded2.y or rounded1.z ~= rounded2.z then if rounded1.x ~= rounded2.x or rounded1.y ~= rounded2.y or rounded1.z ~= rounded2.z then
return rounded1, rounded2 return rounded1, rounded2
else else
return rounded1 return rounded1
end end
end end
return result:round( 0.01 ) return result:round( 0.01 )
end end
local function narrow( p1, p2, fix ) local function narrow( p1, p2, fix )
local dist1 = math.abs( (p1 - fix.vPosition):length() - fix.nDistance ) local dist1 = math.abs( (p1 - fix.vPosition):length() - fix.nDistance )
local dist2 = math.abs( (p2 - fix.vPosition):length() - fix.nDistance ) local dist2 = math.abs( (p2 - fix.vPosition):length() - fix.nDistance )
if math.abs(dist1 - dist2) < 0.01 then if math.abs(dist1 - dist2) < 0.01 then
return p1, p2 return p1, p2
elseif dist1 < dist2 then elseif dist1 < dist2 then
return p1:round( 0.01 ) return p1:round( 0.01 )
else else
return p2:round( 0.01 ) return p2:round( 0.01 )
end end
end end
function locate( _nTimeout, _bDebug ) function locate( _nTimeout, _bDebug )
@ -67,56 +66,56 @@ function locate( _nTimeout, _bDebug )
return commands.getBlockPosition() return commands.getBlockPosition()
end end
-- Find a modem -- Find a modem
local sModemSide = nil local sModemSide = nil
for n,sSide in ipairs( rs.getSides() ) do for n,sSide in ipairs( rs.getSides() ) do
if peripheral.getType( sSide ) == "modem" and peripheral.call( sSide, "isWireless" ) then if peripheral.getType( sSide ) == "modem" and peripheral.call( sSide, "isWireless" ) then
sModemSide = sSide sModemSide = sSide
break break
end end
end end
if sModemSide == nil then if sModemSide == nil then
if _bDebug then if _bDebug then
print( "No wireless modem attached" ) print( "No wireless modem attached" )
end end
return nil return nil
end end
if _bDebug then if _bDebug then
print( "Finding position..." ) print( "Finding position..." )
end end
-- Open a channel -- Open a channel
local modem = peripheral.wrap( sModemSide ) local modem = peripheral.wrap( sModemSide )
local bCloseChannel = false local bCloseChannel = false
if not modem.isOpen( os.getComputerID() ) then if not modem.isOpen( os.getComputerID() ) then
modem.open( os.getComputerID() ) modem.open( os.getComputerID() )
bCloseChannel = true bCloseChannel = true
end end
-- Send a ping to listening GPS hosts -- Send a ping to listening GPS hosts
modem.transmit( CHANNEL_GPS, os.getComputerID(), "PING" ) modem.transmit( CHANNEL_GPS, os.getComputerID(), "PING" )
-- Wait for the responses -- Wait for the responses
local tFixes = {} local tFixes = {}
local pos1, pos2 = nil, nil local pos1, pos2 = nil, nil
local timeout = os.startTimer( _nTimeout or 2 ) local timeout = os.startTimer( _nTimeout or 2 )
while true do while true do
local e, p1, p2, p3, p4, p5 = os.pullEvent() local e, p1, p2, p3, p4, p5 = os.pullEvent()
if e == "modem_message" then if e == "modem_message" then
-- We received a reply from a modem -- We received a reply from a modem
local sSide, sChannel, sReplyChannel, tMessage, nDistance = p1, p2, p3, p4, p5 local sSide, sChannel, sReplyChannel, tMessage, nDistance = p1, p2, p3, p4, p5
if sSide == sModemSide and sChannel == os.getComputerID() and sReplyChannel == CHANNEL_GPS and nDistance then if sSide == sModemSide and sChannel == os.getComputerID() and sReplyChannel == CHANNEL_GPS and nDistance then
-- Received the correct message from the correct modem: use it to determine position -- Received the correct message from the correct modem: use it to determine position
if type(tMessage) == "table" and #tMessage == 3 and tonumber(tMessage[1]) and tonumber(tMessage[2]) and tonumber(tMessage[3]) then if type(tMessage) == "table" and #tMessage == 3 and tonumber(tMessage[1]) and tonumber(tMessage[2]) and tonumber(tMessage[3]) then
local tFix = { vPosition = vector.new( tMessage[1], tMessage[2], tMessage[3] ), nDistance = nDistance } local tFix = { vPosition = vector.new( tMessage[1], tMessage[2], tMessage[3] ), nDistance = nDistance }
if _bDebug then if _bDebug then
print( tFix.nDistance.." metres from "..tostring( tFix.vPosition ) ) print( tFix.nDistance.." metres from "..tostring( tFix.vPosition ) )
end end
if tFix.nDistance == 0 then if tFix.nDistance == 0 then
pos1, pos2 = tFix.vPosition, nil pos1, pos2 = tFix.vPosition, nil
else else
table.insert( tFixes, tFix ) table.insert( tFixes, tFix )
if #tFixes >= 3 then if #tFixes >= 3 then
if not pos1 then if not pos1 then
@ -126,43 +125,43 @@ function locate( _nTimeout, _bDebug )
end end
end end
end end
if pos1 and not pos2 then if pos1 and not pos2 then
break break
end end
end end
end end
elseif e == "timer" then elseif e == "timer" then
-- We received a timeout -- We received a timeout
local timer = p1 local timer = p1
if timer == timeout then if timer == timeout then
break break
end end
end end
end end
-- Close the channel, if we opened one -- Close the channel, if we opened one
if bCloseChannel then if bCloseChannel then
modem.close( os.getComputerID() ) modem.close( os.getComputerID() )
end end
-- Return the response -- Return the response
if pos1 and pos2 then if pos1 and pos2 then
if _bDebug then if _bDebug then
print( "Ambiguous position" ) print( "Ambiguous position" )
print( "Could be "..pos1.x..","..pos1.y..","..pos1.z.." or "..pos2.x..","..pos2.y..","..pos2.z ) print( "Could be "..pos1.x..","..pos1.y..","..pos1.z.." or "..pos2.x..","..pos2.y..","..pos2.z )
end end
return nil return nil
elseif pos1 then elseif pos1 then
if _bDebug then if _bDebug then
print( "Position is "..pos1.x..","..pos1.y..","..pos1.z ) print( "Position is "..pos1.x..","..pos1.y..","..pos1.z )
end end
return pos1.x, pos1.y, pos1.z return pos1.x, pos1.y, pos1.z
else else
if _bDebug then if _bDebug then
print( "Could not determine position" ) print( "Could not determine position" )
end end
return nil return nil
end end
end end

View File

@ -2,64 +2,64 @@
local sPath = "/rom/help" local sPath = "/rom/help"
function path() function path()
return sPath return sPath
end end
function setPath( _sPath ) function setPath( _sPath )
if type( _sPath ) ~= "string" then if type( _sPath ) ~= "string" then
error( "bad argument #1 (expected string, got " .. type( _sPath ) .. ")", 2 ) error( "bad argument #1 (expected string, got " .. type( _sPath ) .. ")", 2 )
end end
sPath = _sPath sPath = _sPath
end end
function lookup( _sTopic ) function lookup( _sTopic )
if type( _sTopic ) ~= "string" then if type( _sTopic ) ~= "string" then
error( "bad argument #1 (expected string, got " .. type( _sTopic ) .. ")", 2 ) error( "bad argument #1 (expected string, got " .. type( _sTopic ) .. ")", 2 )
end end
-- Look on the path variable -- Look on the path variable
for sPath in string.gmatch(sPath, "[^:]+") do for sPath in string.gmatch(sPath, "[^:]+") do
sPath = fs.combine( sPath, _sTopic ) sPath = fs.combine( sPath, _sTopic )
if fs.exists( sPath ) and not fs.isDir( sPath ) then if fs.exists( sPath ) and not fs.isDir( sPath ) then
return sPath return sPath
elseif fs.exists( sPath..".txt" ) and not fs.isDir( sPath..".txt" ) then elseif fs.exists( sPath..".txt" ) and not fs.isDir( sPath..".txt" ) then
return sPath..".txt" return sPath..".txt"
end end
end end
-- Not found -- Not found
return nil return nil
end end
function topics() function topics()
-- Add index -- Add index
local tItems = { local tItems = {
[ "index" ] = true [ "index" ] = true
} }
-- Add topics from the path -- Add topics from the path
for sPath in string.gmatch(sPath, "[^:]+") do for sPath in string.gmatch(sPath, "[^:]+") do
if fs.isDir( sPath ) then if fs.isDir( sPath ) then
local tList = fs.list( sPath ) local tList = fs.list( sPath )
for n,sFile in pairs( tList ) do for n,sFile in pairs( tList ) do
if string.sub( sFile, 1, 1 ) ~= "." then if string.sub( sFile, 1, 1 ) ~= "." then
if not fs.isDir( fs.combine( sPath, sFile ) ) then if not fs.isDir( fs.combine( sPath, sFile ) ) then
if #sFile > 4 and sFile:sub(-4) == ".txt" then if #sFile > 4 and sFile:sub(-4) == ".txt" then
sFile = sFile:sub(1,-5) sFile = sFile:sub(1,-5)
end end
tItems[ sFile ] = true tItems[ sFile ] = true
end end
end end
end end
end end
end end
-- Sort and return -- Sort and return
local tItemList = {} local tItemList = {}
for sItem, b in pairs( tItems ) do for sItem, b in pairs( tItems ) do
table.insert( tItemList, sItem ) table.insert( tItemList, sItem )
end end
table.sort( tItemList ) table.sort( tItemList )
return tItemList return tItemList
end end
function completeTopic( sText ) function completeTopic( sText )
@ -74,7 +74,5 @@ function completeTopic( sText )
table.insert( tResults, string.sub( sTopic, #sText + 1 ) ) table.insert( tResults, string.sub( sTopic, #sText + 1 ) )
end end
end end
return tResults return tResults
end end

View File

@ -3,54 +3,54 @@
-- See http://www.minecraftwiki.net/wiki/Key_codes for more info -- See http://www.minecraftwiki.net/wiki/Key_codes for more info
local tKeys = { local tKeys = {
nil, "one", "two", "three", "four", -- 1 nil, "one", "two", "three", "four", -- 1
"five", "six", "seven", "eight", "nine", -- 6 "five", "six", "seven", "eight", "nine", -- 6
"zero", "minus", "equals", "backspace","tab", -- 11 "zero", "minus", "equals", "backspace","tab", -- 11
"q", "w", "e", "r", "t", -- 16 "q", "w", "e", "r", "t", -- 16
"y", "u", "i", "o", "p", -- 21 "y", "u", "i", "o", "p", -- 21
"leftBracket","rightBracket","enter","leftCtrl","a", -- 26 "leftBracket","rightBracket","enter","leftCtrl","a", -- 26
"s", "d", "f", "g", "h", -- 31 "s", "d", "f", "g", "h", -- 31
"j", "k", "l", "semiColon","apostrophe", -- 36 "j", "k", "l", "semiColon","apostrophe", -- 36
"grave", "leftShift","backslash","z", "x", -- 41 "grave", "leftShift","backslash","z", "x", -- 41
"c", "v", "b", "n", "m", -- 46 "c", "v", "b", "n", "m", -- 46
"comma", "period", "slash", "rightShift","multiply", -- 51 "comma", "period", "slash", "rightShift","multiply", -- 51
"leftAlt", "space", "capsLock", "f1", "f2", -- 56 "leftAlt", "space", "capsLock", "f1", "f2", -- 56
"f3", "f4", "f5", "f6", "f7", -- 61 "f3", "f4", "f5", "f6", "f7", -- 61
"f8", "f9", "f10", "numLock", "scrollLock", -- 66 "f8", "f9", "f10", "numLock", "scrollLock", -- 66
"numPad7", "numPad8", "numPad9", "numPadSubtract","numPad4", -- 71 "numPad7", "numPad8", "numPad9", "numPadSubtract","numPad4", -- 71
"numPad5", "numPad6", "numPadAdd","numPad1", "numPad2", -- 76 "numPad5", "numPad6", "numPadAdd","numPad1", "numPad2", -- 76
"numPad3", "numPad0", "numPadDecimal",nil, nil, -- 81 "numPad3", "numPad0", "numPadDecimal",nil, nil, -- 81
nil, "f11", "f12", nil, nil, -- 86 nil, "f11", "f12", nil, nil, -- 86
nil, nil, nil, nil, nil, -- 91 nil, nil, nil, nil, nil, -- 91
nil, nil, nil, nil, "f13", -- 96 nil, nil, nil, nil, "f13", -- 96
"f14", "f15", nil, nil, nil, -- 101 "f14", "f15", nil, nil, nil, -- 101
nil, nil, nil, nil, nil, -- 106 nil, nil, nil, nil, nil, -- 106
nil, "kana", nil, nil, nil, -- 111 nil, "kana", nil, nil, nil, -- 111
nil, nil, nil, nil, nil, -- 116 nil, nil, nil, nil, nil, -- 116
"convert", nil, "noconvert",nil, "yen", -- 121 "convert", nil, "noconvert",nil, "yen", -- 121
nil, nil, nil, nil, nil, -- 126 nil, nil, nil, nil, nil, -- 126
nil, nil, nil, nil, nil, -- 131 nil, nil, nil, nil, nil, -- 131
nil, nil, nil, nil, nil, -- 136 nil, nil, nil, nil, nil, -- 136
"numPadEquals",nil, nil, "circumflex","at", -- 141 "numPadEquals",nil, nil, "circumflex","at", -- 141
"colon", "underscore","kanji", "stop", "ax", -- 146 "colon", "underscore","kanji", "stop", "ax", -- 146
nil, nil, nil, nil, nil, -- 151 nil, nil, nil, nil, nil, -- 151
"numPadEnter","rightCtrl",nil, nil, nil, -- 156 "numPadEnter","rightCtrl",nil, nil, nil, -- 156
nil, nil, nil, nil, nil, -- 161 nil, nil, nil, nil, nil, -- 161
nil, nil, nil, nil, nil, -- 166 nil, nil, nil, nil, nil, -- 166
nil, nil, nil, nil, nil, -- 171 nil, nil, nil, nil, nil, -- 171
nil, nil, nil, "numPadComma",nil, -- 176 nil, nil, nil, "numPadComma",nil, -- 176
"numPadDivide",nil, nil, "rightAlt", nil, -- 181 "numPadDivide",nil, nil, "rightAlt", nil, -- 181
nil, nil, nil, nil, nil, -- 186 nil, nil, nil, nil, nil, -- 186
nil, nil, nil, nil, nil, -- 191 nil, nil, nil, nil, nil, -- 191
nil, "pause", nil, "home", "up", -- 196 nil, "pause", nil, "home", "up", -- 196
"pageUp", nil, "left", nil, "right", -- 201 "pageUp", nil, "left", nil, "right", -- 201
nil, "end", "down", "pageDown", "insert", -- 206 nil, "end", "down", "pageDown", "insert", -- 206
"delete" -- 211 "delete" -- 211
} }
local keys = _ENV local keys = _ENV
for nKey, sKey in pairs( tKeys ) do for nKey, sKey in pairs( tKeys ) do
keys[sKey] = nKey keys[sKey] = nKey
end end
keys["return"] = keys.enter keys["return"] = keys.enter
--backwards compatibility to earlier, typo prone, versions --backwards compatibility to earlier, typo prone, versions
@ -61,5 +61,5 @@ function getName( _nKey )
if type( _nKey ) ~= "number" then if type( _nKey ) ~= "number" then
error( "bad argument #1 (expected number, got " .. type( _nKey ) .. ")", 2 ) error( "bad argument #1 (expected number, got " .. type( _nKey ) .. ")", 2 )
end end
return tKeys[ _nKey ] return tKeys[ _nKey ]
end end

View File

@ -21,37 +21,37 @@ local function runUntilLimit( _routines, _limit )
local tFilters = {} local tFilters = {}
local eventData = { n = 0 } local eventData = { n = 0 }
while true do while true do
for n=1,count do for n=1,count do
local r = _routines[n] local r = _routines[n]
if r then if r then
if tFilters[r] == nil or tFilters[r] == eventData[1] or eventData[1] == "terminate" then if tFilters[r] == nil or tFilters[r] == eventData[1] or eventData[1] == "terminate" then
local ok, param = coroutine.resume( r, table.unpack( eventData, 1, eventData.n ) ) local ok, param = coroutine.resume( r, table.unpack( eventData, 1, eventData.n ) )
if not ok then if not ok then
error( param, 0 ) error( param, 0 )
else else
tFilters[r] = param tFilters[r] = param
end end
if coroutine.status( r ) == "dead" then if coroutine.status( r ) == "dead" then
_routines[n] = nil _routines[n] = nil
living = living - 1 living = living - 1
if living <= _limit then if living <= _limit then
return n return n
end end
end end
end end
end end
end end
for n=1,count do for n=1,count do
local r = _routines[n] local r = _routines[n]
if r and coroutine.status( r ) == "dead" then if r and coroutine.status( r ) == "dead" then
_routines[n] = nil _routines[n] = nil
living = living - 1 living = living - 1
if living <= _limit then if living <= _limit then
return n return n
end end
end end
end end
eventData = table.pack( os.pullEventRaw() ) eventData = table.pack( os.pullEventRaw() )
end end
end end
@ -62,5 +62,5 @@ end
function waitForAll( ... ) function waitForAll( ... )
local routines = create( ... ) local routines = create( ... )
runUntilLimit( routines, 0 ) runUntilLimit( routines, 0 )
end end

View File

@ -1,70 +1,70 @@
local native = peripheral local native = peripheral
function getNames() function getNames()
local tResults = {} local tResults = {}
for n,sSide in ipairs( rs.getSides() ) do for n,sSide in ipairs( rs.getSides() ) do
if native.isPresent( sSide ) then if native.isPresent( sSide ) then
table.insert( tResults, sSide ) table.insert( tResults, sSide )
if native.getType( sSide ) == "modem" and not native.call( sSide, "isWireless" ) then if native.getType( sSide ) == "modem" and not native.call( sSide, "isWireless" ) then
local tRemote = native.call( sSide, "getNamesRemote" ) local tRemote = native.call( sSide, "getNamesRemote" )
for n,sName in ipairs( tRemote ) do for n,sName in ipairs( tRemote ) do
table.insert( tResults, sName ) table.insert( tResults, sName )
end end
end end
end end
end end
return tResults return tResults
end end
function isPresent( _sSide ) function isPresent( _sSide )
if type( _sSide ) ~= "string" then if type( _sSide ) ~= "string" then
error( "bad argument #1 (expected string, got " .. type( _sSide ) .. ")", 2 ) error( "bad argument #1 (expected string, got " .. type( _sSide ) .. ")", 2 )
end end
if native.isPresent( _sSide ) then if native.isPresent( _sSide ) then
return true return true
end end
for n,sSide in ipairs( rs.getSides() ) do for n,sSide in ipairs( rs.getSides() ) do
if native.getType( sSide ) == "modem" and not native.call( sSide, "isWireless" ) then if native.getType( sSide ) == "modem" and not native.call( sSide, "isWireless" ) then
if native.call( sSide, "isPresentRemote", _sSide ) then if native.call( sSide, "isPresentRemote", _sSide ) then
return true return true
end end
end end
end end
return false return false
end end
function getType( _sSide ) function getType( _sSide )
if type( _sSide ) ~= "string" then if type( _sSide ) ~= "string" then
error( "bad argument #1 (expected string, got " .. type( _sSide ) .. ")", 2 ) error( "bad argument #1 (expected string, got " .. type( _sSide ) .. ")", 2 )
end end
if native.isPresent( _sSide ) then if native.isPresent( _sSide ) then
return native.getType( _sSide ) return native.getType( _sSide )
end end
for n,sSide in ipairs( rs.getSides() ) do for n,sSide in ipairs( rs.getSides() ) do
if native.getType( sSide ) == "modem" and not native.call( sSide, "isWireless" ) then if native.getType( sSide ) == "modem" and not native.call( sSide, "isWireless" ) then
if native.call( sSide, "isPresentRemote", _sSide ) then if native.call( sSide, "isPresentRemote", _sSide ) then
return native.call( sSide, "getTypeRemote", _sSide ) return native.call( sSide, "getTypeRemote", _sSide )
end end
end end
end end
return nil return nil
end end
function getMethods( _sSide ) function getMethods( _sSide )
if type( _sSide ) ~= "string" then if type( _sSide ) ~= "string" then
error( "bad argument #1 (expected string, got " .. type( _sSide ) .. ")", 2 ) error( "bad argument #1 (expected string, got " .. type( _sSide ) .. ")", 2 )
end end
if native.isPresent( _sSide ) then if native.isPresent( _sSide ) then
return native.getMethods( _sSide ) return native.getMethods( _sSide )
end end
for n,sSide in ipairs( rs.getSides() ) do for n,sSide in ipairs( rs.getSides() ) do
if native.getType( sSide ) == "modem" and not native.call( sSide, "isWireless" ) then if native.getType( sSide ) == "modem" and not native.call( sSide, "isWireless" ) then
if native.call( sSide, "isPresentRemote", _sSide ) then if native.call( sSide, "isPresentRemote", _sSide ) then
return native.call( sSide, "getMethodsRemote", _sSide ) return native.call( sSide, "getMethodsRemote", _sSide )
end end
end end
end end
return nil return nil
end end
function call( _sSide, _sMethod, ... ) function call( _sSide, _sMethod, ... )
@ -74,34 +74,34 @@ function call( _sSide, _sMethod, ... )
if type( _sSide ) ~= "string" then if type( _sSide ) ~= "string" then
error( "bad argument #2 (expected string, got " .. type( _sMethod ) .. ")", 2 ) error( "bad argument #2 (expected string, got " .. type( _sMethod ) .. ")", 2 )
end end
if native.isPresent( _sSide ) then if native.isPresent( _sSide ) then
return native.call( _sSide, _sMethod, ... ) return native.call( _sSide, _sMethod, ... )
end end
for n,sSide in ipairs( rs.getSides() ) do for n,sSide in ipairs( rs.getSides() ) do
if native.getType( sSide ) == "modem" and not native.call( sSide, "isWireless" ) then if native.getType( sSide ) == "modem" and not native.call( sSide, "isWireless" ) then
if native.call( sSide, "isPresentRemote", _sSide ) then if native.call( sSide, "isPresentRemote", _sSide ) then
return native.call( sSide, "callRemote", _sSide, _sMethod, ... ) return native.call( sSide, "callRemote", _sSide, _sMethod, ... )
end end
end end
end end
return nil return nil
end end
function wrap( _sSide ) function wrap( _sSide )
if type( _sSide ) ~= "string" then if type( _sSide ) ~= "string" then
error( "bad argument #1 (expected string, got " .. type( _sSide ) .. ")", 2 ) error( "bad argument #1 (expected string, got " .. type( _sSide ) .. ")", 2 )
end end
if peripheral.isPresent( _sSide ) then if peripheral.isPresent( _sSide ) then
local tMethods = peripheral.getMethods( _sSide ) local tMethods = peripheral.getMethods( _sSide )
local tResult = {} local tResult = {}
for n,sMethod in ipairs( tMethods ) do for n,sMethod in ipairs( tMethods ) do
tResult[sMethod] = function( ... ) tResult[sMethod] = function( ... )
return peripheral.call( _sSide, sMethod, ... ) return peripheral.call( _sSide, sMethod, ... )
end end
end end
return tResult return tResult
end end
return nil return nil
end end
function find( sType, fnFilter ) function find( sType, fnFilter )
@ -111,14 +111,14 @@ function find( sType, fnFilter )
if fnFilter ~= nil and type( fnFilter ) ~= "function" then if fnFilter ~= nil and type( fnFilter ) ~= "function" then
error( "bad argument #2 (expected function, got " .. type( fnFilter ) .. ")", 2 ) error( "bad argument #2 (expected function, got " .. type( fnFilter ) .. ")", 2 )
end end
local tResults = {} local tResults = {}
for n,sName in ipairs( peripheral.getNames() ) do for n,sName in ipairs( peripheral.getNames() ) do
if peripheral.getType( sName ) == sType then if peripheral.getType( sName ) == sType then
local wrapped = peripheral.wrap( sName ) local wrapped = peripheral.wrap( sName )
if fnFilter == nil or fnFilter( sName, wrapped ) then if fnFilter == nil or fnFilter( sName, wrapped ) then
table.insert( tResults, wrapped ) table.insert( tResults, wrapped )
end end
end end
end end
return table.unpack( tResults ) return table.unpack( tResults )
end end

View File

@ -3,9 +3,9 @@ local native = (term.native and term.native()) or term
local redirectTarget = native local redirectTarget = native
local function wrap( _sFunction ) local function wrap( _sFunction )
return function( ... ) return function( ... )
return redirectTarget[ _sFunction ]( ... ) return redirectTarget[ _sFunction ]( ... )
end end
end end
local term = {} local term = {}
@ -17,18 +17,18 @@ term.redirect = function( target )
if target == term then if target == term then
error( "term is not a recommended redirect target, try term.current() instead", 2 ) error( "term is not a recommended redirect target, try term.current() instead", 2 )
end end
for k,v in pairs( native ) do for k,v in pairs( native ) do
if type( k ) == "string" and type( v ) == "function" then if type( k ) == "string" and type( v ) == "function" then
if type( target[k] ) ~= "function" then if type( target[k] ) ~= "function" then
target[k] = function() target[k] = function()
error( "Redirect object is missing method "..k..".", 2 ) error( "Redirect object is missing method "..k..".", 2 )
end end
end end
end end
end end
local oldRedirectTarget = redirectTarget local oldRedirectTarget = redirectTarget
redirectTarget = target redirectTarget = target
return oldRedirectTarget return oldRedirectTarget
end end
term.current = function() term.current = function()
@ -43,14 +43,14 @@ term.native = function()
end end
for k,v in pairs( native ) do for k,v in pairs( native ) do
if type( k ) == "string" and type( v ) == "function" then if type( k ) == "string" and type( v ) == "function" then
if term[k] == nil then if term[k] == nil then
term[k] = wrap( k ) term[k] = wrap( k )
end end
end end
end end
local env = _ENV local env = _ENV
for k,v in pairs( term ) do for k,v in pairs( term ) do
env[k] = v env[k] = v
end end

View File

@ -1,6 +1,6 @@
if not turtle then if not turtle then
error( "Cannot load turtle API on computer", 2 ) error( "Cannot load turtle API on computer", 2 )
end end
native = turtle.native or turtle native = turtle.native or turtle
@ -28,7 +28,7 @@ for k,v in pairs( native ) do
return result, err return result, err
end end
else else
env[k] = v env[k] = v
end end
end end
addCraftMethod( env ) addCraftMethod( env )

View File

@ -24,4 +24,3 @@ else
table.sort( tList ) table.sort( tList )
textutils.pagedTabulate( tList ) textutils.pagedTabulate( tList )
end end

View File

@ -91,7 +91,7 @@ local function save( _sPath )
end end
-- Save -- Save
local file = nil local file, fileerr
local function innerSave() local function innerSave()
file, fileerr = fs.open( _sPath, "w" ) file, fileerr = fs.open( _sPath, "w" )
if file then if file then
@ -774,4 +774,3 @@ end
term.clear() term.clear()
term.setCursorBlink( false ) term.setCursorBlink( false )
term.setCursorPos( 1, 1 ) term.setCursorPos( 1, 1 )

View File

@ -405,4 +405,3 @@ term.setBackgroundColour(colours.black)
term.setTextColour(colours.white) term.setTextColour(colours.white)
term.clear() term.clear()
term.setCursorPos(1,1) term.setCursorPos(1,1)

View File

@ -285,5 +285,3 @@ until e == "char"
term.clear() term.clear()
term.setCursorPos(1,1) term.setCursorPos(1,1)

View File

@ -91,5 +91,4 @@ else
-- "gps somethingelse" -- "gps somethingelse"
-- Error -- Error
printUsage() printUsage()
end end

View File

@ -27,4 +27,3 @@ else
print( "The disk is labelled \""..label.."\"" ) print( "The disk is labelled \""..label.."\"" )
end end
end end

View File

@ -1,4 +1,3 @@
local function printUsage() local function printUsage()
print( "Usage: monitor <name> <program> <arguments>" ) print( "Usage: monitor <name> <program> <arguments>" )
return return
@ -64,4 +63,3 @@ term.redirect( previousTerm )
if not ok then if not ok then
printError( param ) printError( param )
end end

View File

@ -15,14 +15,14 @@ else
print( #tModems .. " modems found." ) print( #tModems .. " modems found." )
end end
function open( nChannel ) local function open( nChannel )
for n=1,#tModems do for n=1,#tModems do
local sModem = tModems[n] local sModem = tModems[n]
peripheral.call( sModem, "open", nChannel ) peripheral.call( sModem, "open", nChannel )
end end
end end
function close( nChannel ) local function close( nChannel )
for n=1,#tModems do for n=1,#tModems do
local sModem = tModems[n] local sModem = tModems[n]
peripheral.call( sModem, "close", nChannel ) peripheral.call( sModem, "close", nChannel )

View File

@ -34,5 +34,4 @@ while nArg <= #tArgs do
print( "Try: left, right" ) print( "Try: left, right" )
return return
end end
end end

View File

@ -7,7 +7,7 @@
}, },
"elements": [ "elements": [
{ {
"from": [ 6, 6, 2 ], "from": [ 6, 6, 2 ],
"to": [ 10, 10, 14 ], "to": [ 10, 10, 14 ],
"faces": { "faces": {
"down": { "uv": [ 6, 2, 10, 14 ], "texture": "#side" }, "down": { "uv": [ 6, 2, 10, 14 ], "texture": "#side" },

View File

@ -5,7 +5,7 @@
}, },
"elements": [ "elements": [
{ {
"from": [ 2, 2, 0 ], "from": [ 2, 2, 0 ],
"to": [ 14, 14, 3 ], "to": [ 14, 14, 3 ],
"faces": { "faces": {
"down": { "uv": [ 2, 13, 14, 16 ], "texture": "#front" }, "down": { "uv": [ 2, 13, 14, 16 ], "texture": "#front" },

View File

@ -5,7 +5,7 @@
}, },
"elements": [ "elements": [
{ {
"from": [ 2, 2, 2 ], "from": [ 2, 2, 2 ],
"to": [ 14, 14, 13 ], "to": [ 14, 14, 13 ],
"faces": { "faces": {
"down": { "uv": [ 2.75, 0, 5.75, 2.75 ], "texture": "#texture" }, "down": { "uv": [ 2.75, 0, 5.75, 2.75 ], "texture": "#texture" },

View File

@ -5,7 +5,7 @@
}, },
"elements": [ "elements": [
{ {
"from": [ 2, 2, 2 ], "from": [ 2, 2, 2 ],
"to": [ 14, 14, 13 ], "to": [ 14, 14, 13 ],
"faces": { "faces": {
"down": { "uv": [ 2.75, 0, 5.75, 2.75 ], "texture": "#texture" }, "down": { "uv": [ 2.75, 0, 5.75, 2.75 ], "texture": "#texture" },

View File

@ -5,7 +5,7 @@
}, },
"elements": [ "elements": [
{ {
"from": [ 0.5, 4.5, 3.5 ], "from": [ 0.5, 4.5, 3.5 ],
"to": [ 2, 12.5, 11.5 ], "to": [ 2, 12.5, 11.5 ],
"faces": { "faces": {
"down": { "uv": [ 13, 2, 16, 14 ], "texture": "#texture" }, "down": { "uv": [ 13, 2, 16, 14 ], "texture": "#texture" },

View File

@ -5,7 +5,7 @@
}, },
"elements": [ "elements": [
{ {
"from": [ 14, 4.5, 3.5 ], "from": [ 14, 4.5, 3.5 ],
"to": [ 15.5, 12.5, 11.5 ], "to": [ 15.5, 12.5, 11.5 ],
"faces": { "faces": {
"down": { "uv": [ 0, 2, 3, 14 ], "texture": "#texture" }, "down": { "uv": [ 0, 2, 3, 14 ], "texture": "#texture" },