Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Sterilization functions. Most assume defaults are correctly formatted to save ovehead.
- --If you want <function> to sterilize its default, add default=<function>(default)
- function nForm(n, default) --integers
- if type(default) ~= 'number' then default = 0 end
- n = tonumber(n) or default
- n = math.floor(n)
- return n
- end
- function slotForm(s, keepNil, default) --turtle slots, keepNil for no change in slot
- default = nForm(default, 1)
- if s ~= nil or not keepNil then
- s = tonumber(s) or default
- s = s % 16
- if s == 0 then s = 16 end
- end
- return s
- end
- function faceForm(face, default) --orthogonal directions
- local facelist = {'front', 'right', 'back', 'left', 'up', 'down'}
- if type(default) == 'number' then
- default = facelist[default + 1]
- end
- if type(default) ~= 'string' then
- default = {'front'}
- end
- if type(face) == 'number' then
- face = math.floor(face)
- if face < 0 or face > 5 then
- face = default
- else
- face = facelist[face + 1]
- end
- elseif type(face) == 'string' then
- local b = false
- for i, v in ipairs(facelist) do
- if face == v then
- b = true
- end
- end
- if b == false then
- print('Invalid face arguament, using default.')
- face = default
- end
- else
- face = default
- end
- return face
- end
- function vForm(v, default) --integer vectors
- if type(default) ~= 'table' then
- default = {0, 0, 0}
- end
- if type(v) ~= 'table' then v = {} end
- for i = 1, 3 do
- v[i] = nForm(v[i], default[i])
- end
- return v
- end
- function posForm(pos, default) --integer vectors w/ direction
- if type(default) ~= 'table' then
- default = {0, 0, 0, 3}
- end
- if type(pos) ~= 'table' then pos = {} end
- for i=1,4 do
- pos[i] = nForm(pos[i], default[i])
- end
- pos[4] = pos[4] % 4
- return pos
- end
- --Abstract functions
- function corners(v1, v2) --Stores volume info
- v1 = vForm(v1)
- v2 = vForm(v2)
- local c = {}
- for i=1,3 do
- c[i] = {}
- c[i][1] = math.min(v1[i], v2[i])
- c[i][2] = math.max(v1[i], v2[i])
- end
- return c
- end
- function faceInv(face) --Reflects face
- face = faceForm(face)
- if face == 'right' then face = 'left'
- elseif face == 'left' then face = 'right'
- end
- return face
- end
- function transpose(n, face)
- n = tonumber(n)
- if face ~= 'top' and face ~= 'bottom' then
- face = sUtil.faceForm(face)
- end
- if redstone.getOutput(face) then
- error('Redstone signal in facing is currently on')
- end
- for i=1,n do
- redstone.setOutput(face, true)
- sleep(0.1)
- redstone.setOutput(face, false)
- sleep(0.2)
- end
- return true
- end
- function redPulse(faces, pLength, sterile)
- faces = faces or {'back'}
- pLength = pLength or 0.1
- pLength = tonumber(pLength)
- for i, v in ipairs(faces) do
- if sterile ~= true then v = strl.faceForm(v) end
- redstone.setOutput(v, true)
- end
- sleep(pLength)
- for i, v in ipairs(faces) do
- redstone.setOutput(v, false)
- end
- end
- --Same functionality as a redpower2 timer by default,
- --with options to change clock and pulse length, and
- --define input (disable) and output faces.
- function redClock(length, outFaces, pLength, inFaces)
- --input sterilization
- length = length or 10
- length = tonumber(length)
- if outFaces ~= nil then
- for i, v in ipairs(outFaces) do
- v = strl.faceForm(v)
- end
- else
- outFaces = {'left', 'right', 'back'}
- end
- pLength = pLength or 0.1
- pLength = tonumber(pLength)
- if inFaces ~= nil then
- for i, v in ipairs(outFaces) do
- v = strl.faceForm(v)
- end
- else
- inFaces = {'front'}
- end
- --clock functionality
- while true do
- local disable = false
- for i, v in ipairs(inFaces) do
- if redstone.getInput(v) then disable = true end
- end
- if not(disable) then
- sleep(length - pLength)
- redPulse(pLength, faces, true)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment