Zum Inhalt

CC: Tweaked


Introduction

With CC: Tweaked you can read and control the reactor, every turbine and the heat exchanger with Lua computers. Some knowledge in Lua or CC: Tweaked is recommended.

Place a computer or a wired modem next to any block of an assembled multiblock and use peripheral.find. This page lists all peripherals and every function with an example.




Overview

Reactor

Peripheral thorium_reactor: state, scram, rods, fluids, temperature and all turbines by id.

Turbine

Peripheral thorium_turbine: every turbine can be controlled directly: activation, coils, flow, speed, energy and steam.

Heat exchanger

Peripheral thorium_thermal: temperature, rates, produced steam and the tanks.


Peripherals

Peripheral Blocks Use
thorium_reactor Reactor Casing, Reactor Glass, Reactor Controller, rod controllers, core and moderators of an assembled reactor Reactor functions
thorium_turbine Turbine Casing, Glass, Vent, Coil, Rotor, Rotation Mount and Controller of an assembled turbine Turbine functions
thorium_thermal Casing, Conductor, Heat Sink and Controller of an assembled heat exchanger Heat exchanger functions

The valves and the power port are no peripherals of the mod: they keep the normal fluid, item and energy peripherals of CC: Tweaked (for example energy_storage), so you can read their contents with the standard functions. The same is true for all machines, tanks and pipes.

local reactor = peripheral.find("thorium_reactor")
local turbine = peripheral.find("thorium_turbine")
local thermal = peripheral.find("thorium_thermal")

With more than one turbine use the name of the peripheral to pick one: peripheral.wrap("turbine_0") for a wired modem network, or peripheral.find("thorium_turbine", function(name, t) return t.getHeight() == 9 end).


Good to know

  • One call instead of many: getInfo() of the turbine and the heat exchanger and getReactorInfo() / getTurbines() of the reactor return all values in one table. That is faster and the values belong together.
  • Errors: a function that needs an assembled multiblock throws a clear error message ("The turbine is not assembled") if it is not, and the turbine functions of the reactor tell you the valid ids ("Invalid turbine id 5, the ids go from 0 to 2"). Use pcall or check isAssembled() first.
  • Turbine ids of the reactor start at 0, see getTurbinePositions().
  • Values are limited: setters ignore or limit wrong values (rods 0 to 100, flow 0 to the maximum of the turbine).
  • All functions run on the main thread of the server, so they always show the real state.
  • Events: every computer next to the reactor or turbine receives thorium_scram (event, side, notification) when the reactor is scrammed and thorium_turbine_warning (event, side, warning) when a turbine gets a warning. Use os.pullEvent("thorium_scram") instead of polling.
  • The Wireless Reactor Interface is the in-game alternative to control the reactor from far away.

Dashboard Script

A complete dashboard for up to five monitors, ready to use. It shows and controls the reactor and the turbines:

  • Reactor: temperature, load, fuel, control rods, integrity, salt tanks and contamination, plus the core as in the game (9x9 fuel rods in green and 8x8 control rods in blue between them, turned by 45 degrees, with small gaps between the rows). Buttons: START, RUN, STOP, SCRAM / RESET (press START, then RUN once the start up is finished, the reactor only produces in the RUN state), fuel load and control rods. Touch a blue control rod to select it, the rod buttons then only change this rod, touch it again to control all rods.
  • Turbines: every turbine as a portrait card with animated blades, state, rpm, flow, generation and warnings. Buttons per turbine: ON / OFF, coils and flow -/+, and ALL ON / ALL OFF / ALL flow for all turbines.
  • Heat exchangers: every exchanger as a card with vertical gauges for temperature, salt, water and steam, the produced steam, the rates and animated flames while it works.
  • The screens are buffered, only the rows that changed are redrawn, so nothing flickers.

  • Automatic: monitor 1 shows the reactor, the last monitor the heat exchangers and all monitors in between the turbines. The turbines (up to 16) are spread over the turbine monitors, every monitor shows the next ones. On one monitor up to 10 turbine cards fit next to each other. With fewer than 3 monitors the views switch every few seconds.

  • Your own choice: in CONFIG.monitors you set which monitor shows what, several monitors for the turbines are a list: monitors = { reactor = "monitor_0", turbines = { "monitor_1", "monitor_2", "monitor_3" }, thermal = "monitor_4" }. Use peripheral.getNames() to see the names.
  • The turbines are read through the reactor, the heat exchangers are found automatically: place a wired modem on a block of every heat exchanger and connect everything with cables.
  • Use advanced monitors (3x3 or bigger is recommended, the reactor screen fits best on 4x3 or bigger) and touch the buttons. The text size and the steps of the buttons are set in the CONFIG table at the top.

Download thorium_dashboard.lua

Show Script
thorium_dashboard.lua
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
-- Thorium Reactors dashboard for CC: Tweaked
--
-- Shows and controls the reactor, all turbines (up to 16) and all heat exchangers on advanced monitors.
-- Needs: one advanced computer, a wired modem network (or direct contact) with
--   * a block of the reactor (thorium_reactor), the turbines are controlled through the reactor
--   * a block of every heat exchanger (thorium_thermal)
--   * 1 to 5 advanced monitors (3x3 or bigger, touch them to use the buttons)
--
-- Automatic: monitor 1 = reactor, the last monitor = heat exchangers, all monitors in between = turbines.
-- The turbines are spread over all turbine monitors (a turbine card is 14 characters wide, up to 10 per row).
-- With less than 3 monitors the views switch automatically every few seconds.
-- To choose what every monitor shows use CONFIG.monitors below.
-- Start the reactor with START, then press RUN as soon as the start up is finished (RUN is ignored before that).
-- Save it as "startup.lua" or run it with "thorium_dashboard".

local CONFIG = {
    -- Which monitor shows what. nil = automatic. Use the names of the monitors ("monitor_4", see
    -- peripheral.getNames()), several monitors for the turbines are given as a list:
    --   monitors = { reactor = "monitor_0", turbines = { "monitor_1", "monitor_2", "monitor_3" }, thermal = "monitor_4" }
    monitors = {
        reactor = nil,
        turbines = nil,
        thermal = nil,
    },
    maxMonitors = 5,        -- how many monitors are used automatically
    maxTurbinesPerRow = 10, -- turbine cards next to each other on one monitor
    textScale = 0.5,   -- 0.5 = a lot of space, 1 = bigger text
    refresh = 1,       -- seconds between two updates (the screen only redraws what changed)
    rotate = 8,        -- seconds per view if there are less than 3 monitors
    flowStep = 50,     -- mB/t per click of the flow buttons of the turbines
    loadStep = 5,      -- % per click of the fuel load buttons
    rodStep = 10,      -- % per click of the control rod buttons
}

-- ---------------------------------------------------------------- helpers

local function fmt(n)
    n = tonumber(n) or 0
    local a = math.abs(n)
    if a >= 1e9 then return string.format("%.2fG", n / 1e9) end
    if a >= 1e6 then return string.format("%.2fM", n / 1e6) end
    if a >= 1e4 then return string.format("%.1fk", n / 1e3) end
    if a == math.floor(a) then return string.format("%d", n) end
    return string.format("%.1f", n)
end

local function frac(value, max)
    value, max = tonumber(value) or 0, tonumber(max) or 0
    if max <= 0 then return 0 end
    return math.max(0, math.min(1, value / max))
end

-- green when f is high ("good"), red when it is low. invert = true: red when high
local function traffic(f, invert)
    if invert then f = 1 - f end
    if f > 0.6 then return colors.green end
    if f > 0.3 then return colors.yellow end
    return colors.red
end

local function duration(ticks)
    ticks = tonumber(ticks) or -1
    if ticks < 0 then return "-" end
    local s = math.floor(ticks / 20)
    return string.format("%dh %02dm %02ds", math.floor(s / 3600), math.floor(s / 60) % 60, s % 60)
end

local function call(fn, ...)
    local ok, a = pcall(fn, ...)
    if ok then return a end
    return nil
end

local function clamp(v, lo, hi) return math.max(lo, math.min(hi, v)) end

-- ---------------------------------------------------------------- canvas
-- Everything is drawn into a buffer first. Only the rows that really changed are sent to
-- the monitor, so nothing flickers.

local function newCanvas(mon, name)
    local c = { mon = mon, name = name, buttons = {}, frame = 0 }
    local ch, fg, bg, prev = {}, {}, {}, {}

    local function reset()
        c.w, c.h = mon.getSize()
        ch, fg, bg, prev = {}, {}, {}, {}
        for y = 1, c.h do ch[y], fg[y], bg[y] = {}, {}, {} end
    end
    reset()

    -- call before drawing a new frame
    function c.begin()
        local w, h = mon.getSize()
        if w ~= c.w or h ~= c.h then reset() end
        for y = 1, c.h do
            local a, b, d = ch[y], fg[y], bg[y]
            for x = 1, c.w do a[x], b[x], d[x] = " ", colors.white, colors.black end
        end
        c.buttons = {}
        c.frame = c.frame + 1
    end

    function c.text(x, y, str, fgc, bgc)
        if y < 1 or y > c.h then return end
        str = tostring(str)
        for i = 1, #str do
            local px = x + i - 1
            if px >= 1 and px <= c.w then
                ch[y][px] = str:sub(i, i)
                fg[y][px] = fgc or colors.white
                if bgc then bg[y][px] = bgc end
            end
        end
    end

    function c.fill(x, y, w, bgc, h)
        for yy = y, y + (h or 1) - 1 do
            if yy >= 1 and yy <= c.h then
                for px = math.max(1, x), math.min(c.w, x + w - 1) do
                    ch[yy][px], bg[yy][px] = " ", bgc
                end
            end
        end
    end

    -- a bar with a text in the middle
    function c.bar(x, y, w, f, color, label)
        if w < 1 then return end
        label = tostring(label or "")
        if #label > w then label = label:sub(1, w) end
        local pad = math.floor((w - #label) / 2)
        label = string.rep(" ", pad) .. label .. string.rep(" ", w - #label - pad)
        local n = math.floor(w * f + 0.5)
        for i = 1, w do
            c.text(x + i - 1, y, label:sub(i, i), colors.white, i <= n and color or colors.gray)
        end
    end

    -- a touch button, h rows high, the action is called when it is touched
    function c.button(x, y, w, h, label, color, action)
        c.fill(x, y, w, color, h)
        label = tostring(label):sub(1, w)
        local lx = x + math.floor((w - #label) / 2)
        c.text(lx, y + math.floor((h - 1) / 2), label, colors.white, color)
        c.buttons[#c.buttons + 1] = { x = x, y = y, w = w, h = h, action = action }
    end

    -- an invisible touch area
    function c.area(x, y, w, h, action)
        c.buttons[#c.buttons + 1] = { x = x, y = y, w = w, h = h, action = action }
    end

    function c.header(title, right, color)
        color = color or colors.green
        c.fill(1, 1, c.w, color)
        c.text(2, 1, title, colors.white, color)
        if right then c.text(c.w - #right, 1, right, colors.white, color) end
    end

    function c.hit(x, y)
        for i = #c.buttons, 1, -1 do
            local b = c.buttons[i]
            if x >= b.x and x < b.x + b.w and y >= b.y and y < b.y + b.h then return b end
        end
    end

    -- sends the changed rows to the monitor
    function c.flush()
        for y = 1, c.h do
            local t, f, b = {}, {}, {}
            for x = 1, c.w do
                t[x] = ch[y][x]
                f[x] = colors.toBlit(fg[y][x])
                b[x] = colors.toBlit(bg[y][x])
            end
            local row = table.concat(t) .. "|" .. table.concat(f) .. "|" .. table.concat(b)
            if prev[y] ~= row then
                prev[y] = row
                mon.setCursorPos(1, y)
                mon.blit(table.concat(t), table.concat(f), table.concat(b))
            end
        end
    end

    return c
end

-- ---------------------------------------------------------------- view: reactor

-- a rod is drawn with two block characters that leave a small gap at the bottom of the row
local ROD = "\143\143"
local selectedRod = nil   -- 0 based index of the selected control rod, nil = all rods

local function drawCore(c, x, y, rods, spacing)
    -- The core as in the game: 9x9 fuel rods and 8x8 control rods between them, turned by 45 degrees.
    -- A fuel rod (row r, column c) sits at x = spacing * (c - r), y = r + c,
    -- the control rod at the corner between four fuel rods one row lower.
    local mid = spacing * 8
    for r = 0, 8 do
        for col = 0, 8 do
            local v = rods.fuel[r * 9 + col + 1] or 0
            local color = colors.gray
            if v > 0 then color = v >= 60 and colors.lime or (v >= 30 and colors.yellow or colors.orange) end
            c.text(x + mid + spacing * (col - r), y + r + col, ROD, color, colors.black)
        end
    end
    for r = 0, 7 do
        for col = 0, 7 do
            local index = r * 8 + col
            local v = rods.control[index + 1] or 0
            local color = v >= 50 and colors.blue or (v > 0 and colors.cyan or colors.lightBlue)
            local px, py = x + mid + spacing * (col - r), y + r + col + 1
            c.text(px, py, ROD, selectedRod == index and colors.white or color, colors.black)
            c.area(px, py, 2, 1, function() selectedRod = (selectedRod ~= index) and index or nil end)
        end
    end
end

local function viewReactor(c, reactor)
    local info = reactor and call(reactor.getReactorInfo) or nil
    if not info then
        c.header("Reactor", "no connection", colors.red)
        c.text(2, 3, "No thorium_reactor found.", colors.red)
        return
    end
    if not info.assembled then
        c.header("Reactor", "NOT ASSEMBLED", colors.red)
        c.text(2, 3, "The reactor is not assembled.", colors.red)
        return
    end

    local stateColor = ({ running = colors.green, starting = colors.yellow, stop = colors.red })[info.state] or colors.gray
    c.header("Thorium Reactor", string.upper(info.state) .. (info.scrammed and "  SCRAM" or ""), info.scrammed and colors.red or stateColor)

    local spacing = (c.w >= 100) and 3 or 2
    local mapW = spacing * 16 + 2
    local sideMap = c.w >= mapW + 24
    local bw = sideMap and (c.w - mapW - 4) or (c.w - 3)
    bw = clamp(bw, 20, 44)

    local y = 3
    if info.notification and info.notification ~= "" then
        c.text(2, y, info.notification, colors.orange)
    else
        c.text(2, y, "Running for " .. duration(info.runningSince), colors.lightGray)
    end
    y = y + 2

    local function row(label, f, color, text)
        c.bar(2, y, bw, f, color, label .. "  " .. text)
        y = y + 1
    end
    row("Temp", frac(info.temperature - 22, 949), traffic(frac(info.temperature - 22, 949), true), string.format("%.0f/%.0f C", info.temperature, info.targetTemperature))
    row("Load", info.load / 100, colors.orange, string.format("%.0f %%", info.load))
    row("Fuel", info.fuel / 100, colors.lime, string.format("%.1f %%", info.fuel))
    row("Control", info.controlRods / 100, colors.blue, string.format("%.1f %%", info.controlRods))
    row("Integrity", info.status / 100, traffic(info.status / 100, false), string.format("%.1f %%", info.status))
    row("Salt", frac(info.fluidIn.amount, info.fluidIn.capacity), colors.cyan, fmt(info.fluidIn.amount) .. "/" .. fmt(info.fluidIn.capacity))
    row("Hot salt", frac(info.fluidOut.amount, info.fluidOut.capacity), colors.red, fmt(info.fluidOut.amount) .. "/" .. fmt(info.fluidOut.capacity))
    y = y + 1
    c.text(2, y, "Contamination " .. fmt(info.contamination) .. " uSv/h", info.contamination > 0 and colors.red or colors.green)
    c.text(2, y + 1, "Turbines " .. info.turbineCount, colors.lightGray)
    y = y + 3

    -- controls
    local function buttonRow(labels, h)
        local n = #labels
        local gap = 1
        local w = math.floor((bw - gap * (n - 1)) / n)
        for i, b in ipairs(labels) do
            c.button(2 + (i - 1) * (w + gap), y, w, h, b[1], b[2], b[3])
        end
        y = y + h + 1
    end

    buttonRow({
        { "START", colors.yellow, function() reactor.setReactorState("starting") end },
        { "RUN", colors.green, function() reactor.setReactorState("running") end },
        { "STOP", colors.orange, function() reactor.setReactorState("stop") end },
    }, 3)
    buttonRow({
        { info.scrammed and "RESET SCRAM" or "SCRAM", colors.red, function() reactor.setReactorScrammed(not info.scrammed) end },
    }, 3)

    c.text(2, y, "Fuel load: " .. info.targetLoad .. " %", colors.lightGray); y = y + 1
    buttonRow({
        { "-" .. CONFIG.loadStep, colors.gray, function() reactor.setReactorTargetLoadSet(clamp(info.targetLoad - CONFIG.loadStep, 0, 100)) end },
        { "+" .. CONFIG.loadStep, colors.gray, function() reactor.setReactorTargetLoadSet(clamp(info.targetLoad + CONFIG.loadStep, 0, 100)) end },
    }, 3)

    local rods = call(reactor.getRods)
    local label = "Control rods: all"
    local current = nil
    if selectedRod and rods then
        current = rods.targetControl[selectedRod + 1] or 0
        label = "Control rod #" .. (selectedRod + 1) .. ": " .. current .. " %"
    end
    c.text(2, y, label, selectedRod and colors.cyan or colors.lightGray); y = y + 1
    local function setRods(value)
        value = clamp(value, 0, 100)
        if selectedRod then reactor.setTargetControlRodStatus(selectedRod, value)
        else reactor.setAllTargetControlRodStatus(value) end
    end
    local base = current or info.controlRods
    buttonRow({
        { "-" .. CONFIG.rodStep, colors.blue, function() setRods(math.floor(base) - CONFIG.rodStep) end },
        { "+" .. CONFIG.rodStep, colors.blue, function() setRods(math.floor(base) + CONFIG.rodStep) end },
        { "0", colors.gray, function() setRods(0) end },
        { "100", colors.gray, function() setRods(100) end },
    }, 3)

    -- the core map
    if rods then
        if sideMap then
            local x = bw + 4
            c.text(x, 3, "Core (touch a blue rod to select it)", colors.lightGray)
            drawCore(c, x, 5, rods, spacing)
            c.text(x, 23, "Fuel", colors.lime)
            c.text(x + 6, 23, "Control", colors.blue)
        elseif c.h >= y + 18 then
            drawCore(c, 2, y + 1, rods, spacing)
        end
    end
end

-- ---------------------------------------------------------------- view: turbines (portrait cards)

local CARD_W, BODY = 14, 8

local function drawTurbine(c, x, y, t, reactor, flowStep)
    local color, state = colors.gray, "NOT BUILT"
    if t.assembled then
        if t.warning and t.warning ~= "" then color, state = colors.red, "WARNING"
        elseif t.active and t.coilsEngaged then color, state = colors.green, "RUNNING"
        elseif t.active then color, state = colors.yellow, "NO COILS"
        else color, state = colors.orange, "STOPPED" end
    end
    c.fill(x, y, CARD_W, color)
    c.text(x + 1, y, "#" .. t.turbineId .. " " .. state, colors.white, color)
    if not t.assembled then return end

    -- the turbine from the side: casing, rotor and blades (the blades move when it turns)
    local spinning = (t.speed or 0) > 1
    local phase = spinning and (c.frame % 2) or 0
    local blade = frac(t.speed, 2000)
    local bladeColor = blade > 0.66 and colors.cyan or (blade > 0.2 and colors.lightBlue or colors.blue)
    for r = 1, BODY do
        local by = y + r
        c.fill(x, by, 1, colors.gray)
        c.fill(x + CARD_W - 1, by, 1, colors.gray)
        c.fill(x + 1, by, CARD_W - 2, colors.black)
        c.fill(x + 6, by, 2, colors.lightGray)          -- rotor
        if r > 1 and r < BODY and r % 2 == 0 then          -- blades
            local pattern = ((r / 2 + phase) % 2 == 0) and "/\\/\\/" or "\\/\\/\\"
            c.text(x + 1, by, pattern, bladeColor, colors.black)
            c.text(x + 8, by, pattern, bladeColor, colors.black)
        end
    end
    c.fill(x, y + BODY + 1, CARD_W, colors.gray)

    local ry = y + BODY + 2
    c.bar(x, ry, CARD_W, frac(t.speed, 2000), colors.blue, string.format("%.0f rpm", t.speed))
    c.bar(x, ry + 1, CARD_W, frac(t.currentFlow, t.maxFlow), colors.cyan, string.format("%.0f/%.0f", t.currentFlow, t.targetFlow))
    c.text(x, ry + 2, fmt(t.generation) .. " FE/t", colors.yellow)
    c.text(x + 9, ry + 2, "h" .. (t.height or 0), colors.gray)
    if t.warning and t.warning ~= "" then
        c.text(x, ry + 3, t.warning, colors.red)
    else
        c.text(x, ry + 3, string.format("max %d mB/t", t.maxFlow or 0), colors.gray)
    end

    local id = t.turbineId
    c.button(x, ry + 4, 6, 2, t.active and "OFF" or "ON", t.active and colors.orange or colors.green, function() reactor.setTurbineActive(id, not t.active) end)
    c.button(x + 7, ry + 4, 7, 2, t.coilsEngaged and "COIL ON" or "COIL OFF", t.coilsEngaged and colors.green or colors.gray, function() reactor.setTurbineCoilsEngaged(id, not t.coilsEngaged) end)
    c.button(x, ry + 6, 6, 2, "-" .. flowStep, colors.blue, function() reactor.setTurbineTargetFlow(id, clamp(t.targetFlow - flowStep, 0, t.maxFlow)) end)
    c.button(x + 7, ry + 6, 7, 2, "+" .. flowStep, colors.blue, function() reactor.setTurbineTargetFlow(id, clamp(t.targetFlow + flowStep, 0, t.maxFlow)) end)
end

local CARD_H = BODY + 10

-- how many turbine cards fit on a canvas
local function turbineLayout(c)
    local perRow = clamp(math.floor((c.w - 1) / (CARD_W + 2)), 1, CONFIG.maxTurbinesPerRow)
    local rows = c.h >= 6 + CARD_H and math.floor((c.h - 6 - CARD_H) / (CARD_H + 1)) + 1 or 0
    return perRow, math.max(0, rows)
end

local function turbineCapacity(c)
    local perRow, rows = turbineLayout(c)
    return perRow * rows
end

local function viewTurbines(c, reactor, ctx)
    local list = reactor and call(reactor.getTurbines) or nil
    if not list then
        c.header("Turbines", "no connection", colors.red)
        c.text(2, 3, "No thorium_reactor found.", colors.red)
        return
    end
    local skip = ctx and ctx.skip or 0
    local perRow, rows = turbineLayout(c)
    local cap = perRow * rows
    local first, last = skip + 1, math.min(#list, skip + cap)

    local total, active = 0, 0
    for _, t in ipairs(list) do
        if t.assembled and t.coilsEngaged then total = total + (t.generation or 0) end
        if t.assembled and t.active then active = active + 1 end
    end
    local range = (#list > cap or skip > 0) and (" #" .. (first - 1) .. "-" .. (last - 1)) or ""
    c.header("Turbines " .. active .. "/" .. #list .. " active" .. range, fmt(total) .. " FE/t")

    -- buttons for all turbines
    local bw = math.floor((c.w - 2 - 3) / 4)
    c.button(2, 3, bw, 3, "ALL ON", colors.green, function() reactor.setAllTurbinesActive(true) end)
    c.button(2 + (bw + 1), 3, bw, 3, "ALL OFF", colors.orange, function() reactor.setAllTurbinesActive(false) end)
    local step = CONFIG.flowStep
    c.button(2 + 2 * (bw + 1), 3, bw, 3, "ALL -" .. step, colors.blue, function()
        for _, t in ipairs(list) do if t.assembled then reactor.setTurbineTargetFlow(t.turbineId, clamp(t.targetFlow - step, 0, t.maxFlow)) end end
    end)
    c.button(2 + 3 * (bw + 1), 3, bw, 3, "ALL +" .. step, colors.blue, function()
        for _, t in ipairs(list) do if t.assembled then reactor.setTurbineTargetFlow(t.turbineId, clamp(t.targetFlow + step, 0, t.maxFlow)) end end
    end)

    if #list == 0 then c.text(2, 7, "The reactor has no turbines.", colors.orange) return end
    if cap == 0 then c.text(2, 7, "The monitor is too small for a turbine.", colors.orange) return end
    if first > #list then c.text(2, 7, "No more turbines for this monitor.", colors.gray) return end
    if ctx and ctx.lastMonitor and #list > skip + cap then
        c.text(2, 6, (#list - skip - cap) .. " more turbines do not fit, add a monitor.", colors.orange)
    end

    local x0 = 2 + math.floor((c.w - 1 - perRow * (CARD_W + 2) + 2) / 2)
    for i = first, last do
        local n = i - skip - 1
        local col, rowN = n % perRow, math.floor(n / perRow)
        drawTurbine(c, x0 + col * (CARD_W + 2), 7 + rowN * (CARD_H + 1), list[i], reactor, step)
    end
end

-- ---------------------------------------------------------------- view: heat exchangers

local function findThermals()
    local found, seen = {}, {}
    for _, name in ipairs(peripheral.getNames()) do
        if peripheral.hasType(name, "thorium_thermal") then
            local p = peripheral.wrap(name)
            local info = p and call(p.getInfo)
            if info and info.assembled then
                local key = info.position.x .. "," .. info.position.y .. "," .. info.position.z
                if not seen[key] then seen[key] = true; found[#found + 1] = info end
            end
        end
    end
    table.sort(found, function(a, b) return a.position.x .. a.position.y .. a.position.z < b.position.x .. b.position.y .. b.position.z end)
    return found
end

local THERMAL_W, GAUGE_H = 20, 10

-- a vertical gauge that fills from the bottom
local function gauge(c, x, y, f, color, label, value)
    local filled = math.floor(GAUGE_H * f + 0.5)
    for r = 1, GAUGE_H do
        c.fill(x + 1, y + r - 1, 3, (GAUGE_H - r) < filled and color or colors.gray)
    end
    c.text(x + math.floor((5 - #label) / 2), y + GAUGE_H, label, colors.lightGray)
    value = tostring(value)
    c.text(x + math.floor((5 - #value) / 2), y + GAUGE_H + 1, value, colors.white)
end

local function drawThermal(c, x, y, i, n)
    local color = i.working and colors.green or colors.orange
    c.fill(x, y, THERMAL_W, color)
    c.text(x + 1, y, string.format("#%d %s %s", n, string.upper(i.size), i.working and "WORKING" or "IDLE"), colors.white, color)
    local gy = y + 1
    local tf = frac(i.temperature, i.heatCapacity)
    gauge(c, x, gy, tf, traffic(tf, true), "TEMP", i.temperature .. "C")
    gauge(c, x + 5, gy, frac(i.salt.amount, i.salt.capacity), colors.red, "SALT", fmt(i.salt.amount))
    gauge(c, x + 10, gy, frac(i.water.amount, i.water.capacity), colors.blue, "WATER", fmt(i.water.amount))
    gauge(c, x + 15, gy, frac(i.steam.amount, i.steam.capacity), colors.lightGray, "STEAM", fmt(i.steam.amount))
    local iy = gy + GAUGE_H + 2
    c.text(x, iy, fmt(i.produced) .. " mB/t steam", colors.yellow)
    c.text(x, iy + 1, "salt " .. fmt(i.saltRate) .. "  water " .. fmt(i.waterRate), colors.lightGray)
    c.text(x, iy + 2, string.format("%d, %d, %d", i.position.x, i.position.y, i.position.z), colors.gray)
    -- flames under the exchanger while it works
    if i.working then
        for k = 0, THERMAL_W - 1 do
            local on = (k + c.frame) % 3 ~= 0
            c.text(x + k, iy + 3, on and "^" or " ", (k + c.frame) % 2 == 0 and colors.orange or colors.red)
        end
    end
end

local function viewThermals(c)
    local list = findThermals()
    local produced = 0
    for _, i in ipairs(list) do produced = produced + (i.produced or 0) end
    c.header("Heat exchangers (" .. #list .. ")", fmt(produced) .. " mB/t steam")
    if #list == 0 then
        c.text(2, 3, "No assembled thorium_thermal found.", colors.red)
        return
    end

    local perRow = math.max(1, math.floor((c.w - 1) / (THERMAL_W + 2)))
    local x0 = 2 + math.floor((c.w - 1 - perRow * (THERMAL_W + 2) + 2) / 2)
    for n, i in ipairs(list) do
        local col, rowN = (n - 1) % perRow, math.floor((n - 1) / perRow)
        local y = 3 + rowN * (GAUGE_H + 8)
        if y + GAUGE_H + 7 <= c.h + 1 then drawThermal(c, x0 + col * (THERMAL_W + 2), y, i, n) end
    end
end

-- ---------------------------------------------------------------- main

local views = {
    { name = "reactor", draw = viewReactor },
    { name = "turbines", draw = viewTurbines },
    { name = "thermal", draw = viewThermals },
}

local function toList(v)
    if v == nil then return {} end
    if type(v) == "string" then return { v } end
    return v
end

local function setupMonitors()
    local names = {}
    for _, name in ipairs(peripheral.getNames()) do
        if peripheral.hasType(name, "monitor") then names[#names + 1] = name end
    end
    table.sort(names)
    local list = {}
    for _, name in ipairs(names) do
        local m = peripheral.wrap(name)
        m.setTextScale(CONFIG.textScale)
        m.setBackgroundColor(colors.black)
        m.clear()
        list[#list + 1] = { name = name, canvas = newCanvas(m, name) }
    end
    return list
end

local monitors = setupMonitors()
if #monitors == 0 then error("No monitor found. Place an advanced monitor next to the computer or the wired modem.", 0) end
local reactor = peripheral.find("thorium_reactor")
local startTime = os.clock()
local shown = {}   -- monitor name -> view that is shown at the moment

local function findMonitor(name)
    for _, m in ipairs(monitors) do if m.name == name then return m end end
end

-- returns a list of { m = monitor, v = view }
local function assign()
    local page = math.floor((os.clock() - startTime) / CONFIG.rotate)
    local used, assignment, open = {}, {}, {}
    for _, v in ipairs(views) do
        local any = false
        for _, name in ipairs(toList(CONFIG.monitors[v.name])) do
            local m = findMonitor(name)
            if m and not used[name] then used[name] = true; any = true; assignment[#assignment + 1] = { m = m, v = v } end
        end
        if not any then open[#open + 1] = v end
    end
    local free = {}
    for _, m in ipairs(monitors) do
        if not used[m.name] and #free < CONFIG.maxMonitors then free[#free + 1] = m end
    end
    if #free >= #open then
        -- reactor first, heat exchangers last, everything in between shows turbines
        local ordered = {}
        for _, v in ipairs(open) do ordered[#ordered + 1] = v end
        local extra = #free - #open
        local k = 1
        for _, v in ipairs(ordered) do
            assignment[#assignment + 1] = { m = free[k], v = v }
            k = k + 1
            if v.name == "turbines" then
                for _ = 1, extra do assignment[#assignment + 1] = { m = free[k], v = v }; k = k + 1 end
                extra = 0
            end
        end
    elseif #open > 0 then
        -- not enough monitors: the views rotate
        for i, m in ipairs(free) do assignment[#assignment + 1] = { m = m, v = open[((i - 1) + page) % #open + 1] } end
    end
    return assignment
end

local function redraw()
    if not reactor then reactor = peripheral.find("thorium_reactor") end
    local list = assign()
    -- the turbine monitors share the turbines: every monitor shows the next ones
    local skip, turbineMonitors = 0, {}
    for _, a in ipairs(list) do if a.v.name == "turbines" then turbineMonitors[#turbineMonitors + 1] = a end end
    for i, a in ipairs(turbineMonitors) do
        a.ctx = { skip = skip, lastMonitor = (i == #turbineMonitors) }
        skip = skip + turbineCapacity(a.m.canvas)
    end
    for _, a in ipairs(list) do
        local c = a.m.canvas
        c.begin()
        local ok, err = pcall(a.v.draw, c, reactor, a.ctx)
        if not ok then c.text(1, 1, "Error: " .. tostring(err), colors.red) end
        c.flush()
        shown[a.m.name] = c
    end
end

local function touch(name, x, y)
    local c = shown[name]
    local b = c and c.hit(x, y)
    if b then pcall(b.action) end
end

-- a failing redraw (monitor or peripheral gone, chunk unloaded...) must never stop the dashboard
local function safeRedraw()
    local ok = pcall(redraw)
    if not ok then
        -- look everything up again, it is tried again at the next refresh
        pcall(function() monitors = setupMonitors() end)
        reactor = nil
    end
end

print("Thorium dashboard started with " .. #monitors .. " monitor(s). Hold Ctrl+T to stop.")
safeRedraw()
local timer = os.startTimer(CONFIG.refresh)
while true do
    local ev, a, b, d = os.pullEvent()
    if ev == "timer" and a == timer then
        safeRedraw()
        timer = os.startTimer(CONFIG.refresh)   -- always started again, also after an error
    elseif ev == "monitor_touch" then
        touch(a, b, d)
        safeRedraw()
    elseif ev == "peripheral" or ev == "peripheral_detach" then
        pcall(function() monitors = setupMonitors() end)
        reactor = nil
        safeRedraw()
    elseif ev == "thorium_scram" or ev == "thorium_turbine_warning" then
        safeRedraw()   -- show alarms immediately
    end
end

Example Script

Computer Example Script

Show Script
startup.lua
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
reactor = peripheral.find("thorium_reactor")
monitor = peripheral.find("monitor")

monitor.clear()

monitor.setCursorPos(15,1)
monitor.write("Turbine")
monitor.setCursorPos(1,2)
monitor.write("Turbines: " .. reactor.getTurbineCount())

offset = 3
for i=reactor.getTurbineCount() - 1,0,-1 do
    monitor.setCursorPos(1,offset)
    monitor.write("Turbine #" .. i)
    monitor.setCursorPos(20,offset)
    monitor.write("x:" .. reactor.getTurbinePosition(i).x .. " y:" .. reactor.getTurbinePosition(i).y .. " z:" .. reactor.getTurbinePosition(i).z)
    monitor.setCursorPos(20,offset + 1)
    monitor.write(tostring(reactor.isTurbineActive(i) and "Active" or "Inactive"))
    monitor.setCursorPos(30,offset + 1)
    monitor.write(tostring(reactor.isTurbineAssembled(i) and "Assembled" or "Incomplete"))
    monitor.setCursorPos(20,offset + 2)
    monitor.write(string.format("%.1f", reactor.getTurbineGeneration(i)) .. "FE/t")
    monitor.setCursorPos(20,offset + 3)
    monitor.write(string.format("%.1f", reactor.getTurbineSpeed(i)) .. "RPM")
    monitor.setCursorPos(30,offset + 3)
    monitor.write(string.format("%.1f", reactor.getTurbineHeight(i)) .. "B")
    monitor.setCursorPos(20,offset + 4)
    monitor.write(tostring(reactor.getTurbineCurrentFlow(i)) .. " / " .. tostring(reactor.getTurbineTargetFlow(i)) .. "mB/t")
    offset = offset + 5
end

offset = offset + 1
monitor.setCursorPos(15,offset)
monitor.write("Reactor")
monitor.setCursorPos(1,offset + 1)
monitor.write(reactor.isAssembled() and "Assembled" or "Incomplete")
monitor.setCursorPos(30,offset + 1)
monitor.write(string.upper(reactor.getReactorState()))
monitor.setCursorPos(1,offset + 2)
monitor.write("Temperature: " .. string.format("%.1f", reactor.getReactorCurrentTemperature()) .. " / " .. string.format("%.1f", reactor.getReactorTargetTemperature()) .. "°C")
monitor.setCursorPos(1,offset + 3) 
monitor.write("Molten Salt: " .. tostring(reactor.getReactorFluidAmountIn()) .. " / " .. tostring(reactor.getReactorFluidCapacityIn()) .. "mB")
monitor.setCursorPos(1,offset + 4) 
monitor.write("Heated Molten Salt: " .. tostring(reactor.getReactorFluidAmountOut()) .. " / " .. tostring(reactor.getReactorFluidCapacityOut()) .. "mB")


Reactor functions

Peripheral name thorium_reactor, example: local reactor = peripheral.find("thorium_reactor")

isAssembled()

Description

Returns true or false whether the reactor is assembled or not!

Method
isAssembled() -> boolean
Example
example.lua
1
2
3
local reactor = peripheral.find("thorium_reactor")

print("Assembled? " .. tostring(reactor.isAssembled()))

getReactorState()

Description

Returns the current operating mode of the reactor as a string.

Method
getReactorState() -> string

return: "starting", "running", "stop" (or "undefined" when there is no assembled reactor)
Example
example.lua
1
2
3
local reactor = peripheral.find("thorium_reactor")

print("Currently in " .. tostring(reactor.getReactorState() .. " mode!"))

setReactorState()

Description

Set the reactor operating state! When an invalid mode is passed, the reactor will use "stop" as default. "running" is ignored while the reactor cannot run yet (the startup is not finished).

Method
setReactorState(string mode)

mode: "starting", "running", "stop"
Example
example.lua
1
2
3
local reactor = peripheral.find("thorium_reactor")

reactor.setReactorState("starting")

getReactorFluidAmountOut()

Description

Returns the amount of heated molten salt in the reactor tank!

Method
getReactorFluidAmountOut() -> Integer
Example
example.lua
1
2
3
local reactor = peripheral.find("thorium_reactor")

print("Heated Molten Salt: " .. tostring(reactor.getReactorFluidAmountOut()) .. " mB")

getReactorFluidCapacityOut()

Description

Returns the capacity of the reactor output tank! (Heated Molten Salt)

Method
getReactorFluidCapacityOut() -> Integer
Example
example.lua
1
2
3
local reactor = peripheral.find("thorium_reactor")

print("Capacity Out: " .. tostring(reactor.getReactorFluidCapacityOut()) .. " mB")

getReactorFluidAmountIn()

Description

Returns the amount of molten salt in the reactor tank!

Method
getReactorFluidAmountIn() -> Integer
Example
example.lua
1
2
3
local reactor = peripheral.find("thorium_reactor")

print("Molten Salt: " .. tostring(reactor.getReactorFluidAmountIn()) .. " mB")

getReactorFluidCapacityIn()

Description

Returns the capacity of the reactor input tank! (Molten Salt)

Method
getReactorFluidCapacityIn() -> Integer
Example
example.lua
1
2
3
local reactor = peripheral.find("thorium_reactor")

print("Capacity In: " .. tostring(reactor.getReactorFluidCapacityIn()) .. " mB")

getReactorCapacity()

Description

Returns the total capacity of the reactor!

Method
getReactorCapacity() -> Integer
Example
example.lua
1
2
3
local reactor = peripheral.find("thorium_reactor")

print("Capacity: " .. tostring(reactor.getReactorCapacity()) .. " mB")

getReactorCurrentLoadSet()

Description

Returns the value of current fueled uranium in percent!

Method
getReactorCurrentLoadSet() -> Float
Example
example.lua
1
2
3
local reactor = peripheral.find("thorium_reactor")

print("Uranium Fuel: " .. tostring(reactor.getReactorCurrentLoadSet()) .. "%")

getReactorTargetLoadSet()

Description

Returns the set/wanted uranium fuel fill level in percent!

Method
getReactorTargetLoadSet() -> Float
Example
example.lua
1
2
3
local reactor = peripheral.find("thorium_reactor")

print("Uranium Fuel: " .. tostring(reactor.getReactorTargetLoadSet()) .. "%")

setReactorTargetLoadSet()

Description

Set the wanted uranium fuel fill level in percent!

Method
setReactorTargetLoadSet(Integer rate)

rate: 0 - 100
Example
example.lua
1
2
3
local reactor = peripheral.find("thorium_reactor")

reactor.setReactorTargetLoadSet(100)

getReactorStatusPercent()

Description

Returns the current health rate of the reactor in percent!

Method
getReactorStatusPercent() -> Float
Example
example.lua
1
2
3
local reactor = peripheral.find("thorium_reactor")

print("Health: " .. tostring(reactor.getReactorStatusPercent()) .. "%")

getReactorContamination()

Description

Returns the radiation the reactor currently gives off (the contamination around the controller)!

Method
getReactorContamination() -> Float
Example
example.lua
1
2
3
local reactor = peripheral.find("thorium_reactor")

print("Contamination: " .. tostring(reactor.getReactorContamination()))

isReactorScrammed()

Description

Returns whether the reactor is scrammed or not!

Method
isReactorScrammed() -> boolean
Example
example.lua
1
2
3
local reactor = peripheral.find("thorium_reactor")

print("Scrammed? " .. tostring(reactor.isReactorScrammed()))

setReactorScrammed()

Description

Set the reactor operating state! When an invalid mode is passed, the reactor will use "stop" as default.

Method
setReactorScrammed(boolean state)

state: true, false
Example
example.lua
1
2
3
local reactor = peripheral.find("thorium_reactor")

reactor.setReactorScrammed(true)

getReactorRunningSince()

Description

Returns the time the reactor has run until last startup! Format: 5 seconds = 5 seconds * 20 ticks = 100

Method
getReactorRunningSince() -> Long
Example
example.lua
1
2
3
local reactor = peripheral.find("thorium_reactor")

print("Time lasted: " .. tostring(reactor.getReactorRunningSince() / 20))

getReactorCurrentTemperature()

Description

Returns the reactors current temperature in degree Celsius!

Method
getReactorCurrentTemperature() -> Float
Example
example.lua
1
2
3
local reactor = peripheral.find("thorium_reactor")

print("Current Temp: " .. tostring(reactor.getReactorCurrentTemperature()) .. "°C")

getReactorTargetTemperature()

Description

Returns the reactors target temperature in degree Celsius!

Method
getReactorTargetTemperature() -> Float
Example
example.lua
1
2
3
local reactor = peripheral.find("thorium_reactor")

print("Target Temp: " .. tostring(reactor.getReactorTargetTemperature()) .. "°C")

getReactorNotification()

Description

Returns the current notification of the reactor! For example when the reactor gets scrammed!

Method
getReactorNotification() -> String
Example
example.lua
1
2
3
local reactor = peripheral.find("thorium_reactor")

print("Warning: " .. reactor.getReactorNotification())

getReactorLoad()

Description

Returns the load of the reactor in percent (derived from the current temperature, 100 means the maximum temperature of the design)!

Method
getReactorLoad() -> Float
Example
example.lua
1
2
3
local reactor = peripheral.find("thorium_reactor")

print("Warning: " .. toString(reactor.getReactorLoad()))

getFuelRodStatus()

Description

Returns the fuel level of the given fuel rod in percent!

Method
getFuelRodStatus(Integer index) -> Float

index: 0 - 80

getFuelRodStatusMap()

Description

Returns the fuel level of the given fuel rod in percent in a lua table!

Method
getFuelRodStatusMap() -> Table: Int, Int
Example
example.lua
1
2
3
4
5
local reactor = peripheral.find("thorium_reactor")

for k, v in pairs(reactor.getFuelRodStatusMap()) do
    print("Fuel #: " .. k .. " has " .. v .. "% fuel")
end
Added In

ThoriumReactors version 0.2b


getDepletedFuelRodStatus()

Description

Returns the depleted fuel level of the given fuel rod in percent!

Method
getDepletedFuelRodStatus(Integer index) -> Float

index: 0 - 80
Example
example.lua
1
2
3
local reactor = peripheral.find("thorium_reactor")

print("Depletion #55: " .. toString(reactor.getDepletedFuelRodStatus(55)) .. "%")

getDepletedFuelRodStatusMap()

Description

Returns the depleted fuel level of the given fuel rod in percent in a lua table!

Method
getDepletedFuelRodStatusMap() -> Table: Int, Int
Example
example.lua
1
2
3
4
5
local reactor = peripheral.find("thorium_reactor")

for k, v in pairs(reactor.getDepletedFuelRodStatusMap()) do
    print("Fuel #: " .. k .. " has " .. v .. "% depleted fuel")
end
Added In

ThoriumReactors version 0.2b


getCurrentControlRodStatus()

Description

Returns the current control rod insert value in percent!

Method
getCurrentControlRodStatus(Integer index) -> Float

index: 0 - 63
Example
example.lua
1
2
3
local reactor = peripheral.find("thorium_reactor")

print("Control #55: " .. toString(reactor.getCurrentControlRodStatus(70)) .. "%")

getCurrentControlRodStatusMap()

Description

Returns the depleted fuel level of the given fuel rod in percent in a lua table!

Method
getCurrentControlRodStatusMap() -> Table: Int, Int
Example
example.lua
1
2
3
4
5
local reactor = peripheral.find("thorium_reactor")

for k, v in pairs(reactor.getCurrentControlRodStatusMap()) do
    print("Rod #: " .. k .. " is " .. v .. "% inserted")
end
Added In

ThoriumReactors version 0.2b


getTargetControlRodStatus()

Description

Returns the target control rod insert value in percent!

Method
getTargetControlRodStatus(Integer index) -> Float

index: 0 - 63
Example
example.lua
1
2
3
local reactor = peripheral.find("thorium_reactor")

print("Control #70: " .. toString(reactor.getTargetControlRodStatus(70)) .. "%")

getTargetControlRodStatusMap()

Description

Returns the depleted fuel level of the given fuel rod in percent in a lua table!

Method
getTargetControlRodStatusMap() -> Table: Int, Int
Example
example.lua
1
2
3
4
5
local reactor = peripheral.find("thorium_reactor")

for k, v in pairs(reactor.getTargetControlRodStatusMap()) do
    print("Rod #: " .. k .. " will be " .. v .. "% inserted")
end
Added In

ThoriumReactors version 0.2b


setTargetControlRodStatus()

Description

Sets the target control rod insert value!

Method
setTargetControlRodStatus(Integer index, Integer value)

index: 0 - 63
value: 0 - 100
Example
example.lua
1
2
3
4
local reactor = peripheral.find("thorium_reactor")

-- Sets target control rod insert to 59% on rod #10
reactor.setTargetControlRodStatus(10, 59)

isTurbineActive()

Description

Returns true or false whether the turbine with the id is active.

Method
isTurbineActive(Integer index) -> boolean

index: 0 - ?
Example
example.lua
1
2
3
local reactor = peripheral.find("thorium_reactor")

print("Turbine on? " .. tostring(reactor.isTurbineActive(0)))

setTurbineActive()

Description

Sets the activation state of a turbine.

Method
setTurbineActive(Integer index, Boolean state)

index: 0 - ?
state: true - false
Example
example.lua
1
2
3
local reactor = peripheral.find("thorium_reactor")

reactor.setTurbineActive(0,true)

isTurbineCoilsEngaged()

Description

Returns true or false whether the turbine coils are engaged or not.

Method
isTurbineCoilsEngaged(Integer index) -> boolean

index: 0 - ?
Example
example.lua
1
2
3
local reactor = peripheral.find("thorium_reactor")

print("Coils engaged? " .. tostring(reactor.isTurbineCoilsEngaged(0)))

setTurbineCoilsEngaged()

Description

Sets the coil engage state of a turbine.

Method
setTurbineCoilsEngaged(Integer index, Boolean state)

index: 0 - ?
state: true - false
Example
example.lua
1
2
3
local reactor = peripheral.find("thorium_reactor")

reactor.setTurbineCoilsEngaged(0,true)

copyConfigurationToAllTurbines()

Description

Copy the settings from the given turbine to all others.

Method
copyConfigurationToAllTurbines(Integer index)

index: 0 - ?
Example
example.lua
1
2
3
4
local reactor = peripheral.find("thorium_reactor")

-- copies all settings from turbine 0 to all other saved!
reactor.copyConfigurationToAllTurbines(0)

isTurbineAssembled()

Description

Returns true or false whether the turbine is assembled or not.

Method
isTurbineAssembled(Integer index) -> boolean

index: 0 - ?
Example
example.lua
1
2
3
local reactor = peripheral.find("thorium_reactor")

print("Assembled? " .. tostring(reactor.isTurbineAssembled(0)))

getTurbineHeight()

Description

Returns the total height of the turbine.

Method
getTurbineHeight(Integer index) -> Integer

index: 0 - ?
Example
example.lua
1
2
3
local reactor = peripheral.find("thorium_reactor")

print("Height: " .. tostring(reactor.getTurbineHeight(0)))

getTurbineCurrentFlow()

Description

Returns the actual flow rate of the turbine.

Method
getTurbineCurrentFlow(Integer index) -> Integer

index: 0 - ?
Example
example.lua
1
2
3
local reactor = peripheral.find("thorium_reactor")

print("Flow rate: " .. tostring(reactor.getTurbineCurrentFlow(0)) "mB/t")

getTurbineTargetFlow()

Description

Returns the target flow rate of the turbine.

Method
getTurbineTargetFlow(Integer index) -> Integer

index: 0 - ?
Example
example.lua
1
2
3
local reactor = peripheral.find("thorium_reactor")

print("Flow rate: " .. tostring(reactor.getTurbineTargetFlow(0)) .. "mB/t")

setTurbineTargetFlow()

Description

Sets the target flow rate of the turbine.

Method
setTurbineTargetFlow(Integer index, Integer flowrate)

index: 0 - ?
flowrate: 0 - the maximum flow of the turbine (values above are clamped, the maximum depends on the height)
Example
example.lua
1
2
3
local reactor = peripheral.find("thorium_reactor")

reactor.setTurbineTargetFlow(0,2000)

getTurbineGeneration()

Description

Returns the current energy generation of the turbine in FE/t.

Method
getTurbineGeneration(Integer index) -> Float

index: 0 - ?
Example
example.lua
1
2
3
local reactor = peripheral.find("thorium_reactor")

print("Gen: " .. tostring(reactor.getTurbineGeneration(0)) .. " FE/t")

getTurbineSpeed()

Description

Returns the current turbine speed of the turbine.

Method
getTurbineSpeed(Integer index) -> Float

index: 0 - ?
Example
example.lua
1
2
3
local reactor = peripheral.find("thorium_reactor")

print("Speed: " .. tostring(reactor.getTurbineSpeed(0)) .. " RPM")

getTurbineEnergyModifier()

Description

Returns the energy modifier of the turbine (the factor of its moderator blocks).

Method
getTurbineEnergyModifier(Integer index) -> Float

index: 0 - ?
Example
example.lua
1
2
3
local reactor = peripheral.find("thorium_reactor")

print("Energy Modifier: " .. tostring(reactor.getTurbineEnergyModifier(0)) .. "x")

getTurbinePosition()

Description

Returns the turbines position in a table.

Method
getTurbinePosition(Integer index) -> Table

Table:
{
    "x": -127,
    "y": 80,
    "z": 322
}

index: 0 - ?
Example
example.lua
1
2
3
local reactor = peripheral.find("thorium_reactor")

print("Position: x:" .. reactor.getTurbinePosition(0).x .. " y:" .. reactor.getTurbinePosition(0).y .. " z:" .. reactor.getTurbinePosition(0).z)

getTurbinePositionString()

Description

Returns the turbines position in a string.

Method
getTurbinePosition(Integer index) -> String

index: 0 - ?
Example
example.lua
1
2
3
local reactor = peripheral.find("thorium_reactor")

print("Position: " + getTurbinePositionString())

getTurbinePositions()

Description

Returns the positions of all saved turbines in a table.

Method
getTurbinePositions() -> Table

Table:
{
    {
        "x": -127,
        "y": 80,
        "z": 322
        "turbineId": 0
    },
    {
        "x": -127,
        "y": 80,
        "z": 322
        "turbineId": 1
    }
}

index: 0 - ?
Example
example.lua
1
2
3
4
5
6
7
local reactor = peripheral.find("thorium_reactor")

local positions = reactor.getTurbinePositions()

for k, v in pairs(positions) do
    print(v.x .. " " .. v.y .. " " .. v.z .. " " .. v.turbineId)
end

getTurbineCount()

Description

Returns the amount of all turbines.

Method
getTurbineCount() -> Integer
Example
example.lua
1
2
3
local reactor = peripheral.find("thorium_reactor")

print("Turbines: " + reactor.getTurbineCount())

getReactorInfo()

Description

Returns all values of the reactor in one table: assembled, state, scrammed, notification, temperature, targetTemperature, load, status, contamination, runningSince, fuel, controlRods, targetLoad, fluidIn and fluidOut (each with amount and capacity) and turbineCount. One call instead of many, so scripts are faster and the values fit together. If the reactor is not assembled the table only contains assembled = false.

Method
getReactorInfo() -> table
Example
example.lua
1
2
3
4
5
6
7
local reactor = peripheral.find("thorium_reactor")

local info = reactor.getReactorInfo()
if info.assembled then
    print(info.state .. " at " .. info.temperature .. " C, load " .. info.load .. "%")
    print("Salt: " .. info.fluidIn.amount .. " / " .. info.fluidIn.capacity .. " mB")
end

getRods()

Description

Returns all rods of the core in one call as a table with the lists fuel and depleted (81 values each) and control and targetControl (64 values each). Every value is between 0 and 100 and the lists start at index 1. Perfect to draw a map of the core, see the dashboard script. If the reactor is not assembled the lists are empty.

Method
getRods() -> table
Example
example.lua
1
2
3
4
5
local reactor = peripheral.find("thorium_reactor")

local rods = reactor.getRods()
print("Fuel rod 1: " .. rods.fuel[1] .. " %")
print("Control rod 1: " .. rods.control[1] .. " % (target " .. rods.targetControl[1] .. " %)")

setAllTargetControlRodStatus()

Description

Sets the target of all 64 control rods at once. Throws an error if the value is not between 0 and 100.

Method
setAllTargetControlRodStatus(int value)

value: 0 - 100
Example
example.lua
1
2
3
local reactor = peripheral.find("thorium_reactor")

reactor.setAllTargetControlRodStatus(50)

getTurbineInfo()

Description

Returns all values of one turbine in one table: turbineId, assembled, position, active, coilsEngaged, height, speed, currentFlow, targetFlow, maxFlow, generation, energyModifier and warning.

Method
getTurbineInfo(int id) -> table
Example
example.lua
1
2
3
4
local reactor = peripheral.find("thorium_reactor")

local t = reactor.getTurbineInfo(0)
print(t.speed .. " rpm, " .. t.generation .. " FE/t")

getTurbines()

Description

Returns a list with the info tables of all turbines of the reactor, see getTurbineInfo().

Method
getTurbines() -> table
Example
example.lua
1
2
3
4
5
local reactor = peripheral.find("thorium_reactor")

for _, t in ipairs(reactor.getTurbines()) do
    print("Turbine " .. t.turbineId .. ": " .. (t.speed or 0) .. " rpm")
end

setAllTurbinesActive()

Description

Activates or stops all turbines of the reactor at once.

Method
setAllTurbinesActive(boolean state)
Example
example.lua
1
2
3
local reactor = peripheral.find("thorium_reactor")

reactor.setAllTurbinesActive(true)

setAllTurbinesTargetFlow()

Description

Sets the target steam flow of all turbines at once. The value is limited between 0 and the maximum of every turbine.

Method
setAllTurbinesTargetFlow(number flowrate)
Example
example.lua
1
2
3
local reactor = peripheral.find("thorium_reactor")

reactor.setAllTurbinesTargetFlow(500)

getTurbineMaxFlow()

Description

Returns the maximum steam flow of the turbine in mB/t, which depends on its height.

Method
getTurbineMaxFlow(int id) -> Integer
Example
example.lua
1
2
3
local reactor = peripheral.find("thorium_reactor")

print(reactor.getTurbineMaxFlow(0))

getTurbineWarning()

Description

Returns the warning of the turbine as text (an empty text if there is none).

Method
getTurbineWarning(int id) -> string
Example
example.lua
1
2
3
local reactor = peripheral.find("thorium_reactor")

print(reactor.getTurbineWarning(0))

getTurbineEnergy()

Description

Returns the energy in the power port of the turbine in FE.

Method
getTurbineEnergy(int id) -> int
Example
example.lua
1
2
3
local reactor = peripheral.find("thorium_reactor")

print(reactor.getTurbineEnergy(0) .. " / " .. reactor.getTurbineEnergyCapacity(0))

getTurbineEnergyCapacity()

Description

Returns the capacity of the power port of the turbine in FE.

Method
getTurbineEnergyCapacity(int id) -> int
Example
example.lua
1
2
3
local reactor = peripheral.find("thorium_reactor")

print(reactor.getTurbineEnergyCapacity(0))

getTurbineSteam()

Description

Returns the steam in the valve of the turbine in mB.

Method
getTurbineSteam(int id) -> int
Example
example.lua
1
2
3
local reactor = peripheral.find("thorium_reactor")

print(reactor.getTurbineSteam(0))

Turbine functions

Peripheral name thorium_turbine, example: local turbine = peripheral.find("thorium_turbine"). These functions work on every turbine directly, you do not need the reactor.

isAssembled()

Description

Returns whether the turbine this block belongs to is assembled. Works on every block of the turbine, also when it is not assembled (all other functions throw an error then).

Method
isAssembled() -> boolean
Example
example.lua
1
2
3
local turbine = peripheral.find("thorium_turbine")

print(turbine.isAssembled())

getInfo()

Description

Returns all values of the turbine in one table: assembled, active, coilsEngaged, height, speed, currentFlow, targetFlow, maxFlow, generation, energyModifier, warning, position, energy (amount, capacity) and steam (fluid, amount, capacity).

Method
getInfo() -> table
Example
example.lua
1
2
3
4
local turbine = peripheral.find("thorium_turbine")

local i = turbine.getInfo()
print(i.speed .. " rpm, " .. i.generation .. " FE/t")

isActive()

Description

Returns whether the turbine is activated.

Method
isActive() -> boolean
Example
example.lua
1
2
3
local turbine = peripheral.find("thorium_turbine")

print(turbine.isActive())

setActive()

Description

Activates or stops the turbine.

Method
setActive(boolean state)
Example
example.lua
1
2
3
local turbine = peripheral.find("thorium_turbine")

turbine.setActive(true)

isCoilsEngaged()

Description

Returns whether the coils are engaged (the turbine produces energy).

Method
isCoilsEngaged() -> boolean
Example
example.lua
1
2
3
local turbine = peripheral.find("thorium_turbine")

print(turbine.isCoilsEngaged())

setCoilsEngaged()

Description

Engages or disengages the coils.

Method
setCoilsEngaged(boolean state)
Example
example.lua
1
2
3
local turbine = peripheral.find("thorium_turbine")

turbine.setCoilsEngaged(true)

getHeight()

Description

Returns the height of the turbine in blocks.

Method
getHeight() -> int
Example
example.lua
1
2
3
local turbine = peripheral.find("thorium_turbine")

print(turbine.getHeight())

getSpeed()

Description

Returns the speed of the rotor in rpm.

Method
getSpeed() -> number
Example
example.lua
1
2
3
local turbine = peripheral.find("thorium_turbine")

print(turbine.getSpeed())

getCurrentFlow()

Description

Returns the steam flow of the turbine in mB/t at the moment.

Method
getCurrentFlow() -> number
Example
example.lua
1
2
3
local turbine = peripheral.find("thorium_turbine")

print(turbine.getCurrentFlow())

getTargetFlow()

Description

Returns the target steam flow in mB/t.

Method
getTargetFlow() -> number
Example
example.lua
1
2
3
local turbine = peripheral.find("thorium_turbine")

print(turbine.getTargetFlow())

setTargetFlow()

Description

Sets the target steam flow in mB/t. Values below 0 or above the maximum flow are limited.

Method
setTargetFlow(number flow)
Example
example.lua
1
2
3
local turbine = peripheral.find("thorium_turbine")

turbine.setTargetFlow(turbine.getMaxFlow())

getMaxFlow()

Description

Returns the maximum steam flow in mB/t, which depends on the height.

Method
getMaxFlow() -> int
Example
example.lua
1
2
3
local turbine = peripheral.find("thorium_turbine")

print(turbine.getMaxFlow())

getGeneration()

Description

Returns the energy that is generated in FE per tick (0 while the coils are disengaged).

Method
getGeneration() -> number
Example
example.lua
1
2
3
local turbine = peripheral.find("thorium_turbine")

print(turbine.getGeneration() .. " FE/t")

getEnergyModifier()

Description

Returns the efficiency factor of the moderator blocks (nickel x0.75, niob x1.0, stainless steel x1.25, molybdenum x1.5, chrome-moly steel x1.75, hastelloy N x2.0, inconel x2.25).

Method
getEnergyModifier() -> number
Example
example.lua
1
2
3
local turbine = peripheral.find("thorium_turbine")

print(turbine.getEnergyModifier())

getWarning()

Description

Returns the warning of the turbine as text, an empty text if there is none.

Method
getWarning() -> string
Example
example.lua
1
2
3
local turbine = peripheral.find("thorium_turbine")

print(turbine.getWarning())

getEnergy()

Description

Returns the energy in the power port in FE.

Method
getEnergy() -> int
Example
example.lua
1
2
3
local turbine = peripheral.find("thorium_turbine")

print(turbine.getEnergy() .. " / " .. turbine.getEnergyCapacity())

getEnergyCapacity()

Description

Returns the capacity of the power port in FE.

Method
getEnergyCapacity() -> int
Example
example.lua
1
2
3
local turbine = peripheral.find("thorium_turbine")

print(turbine.getEnergyCapacity())

getSteamAmount()

Description

Returns the steam in the valve in mB.

Method
getSteamAmount() -> int
Example
example.lua
1
2
3
local turbine = peripheral.find("thorium_turbine")

print(turbine.getSteamAmount() .. " / " .. turbine.getSteamCapacity())

getSteamCapacity()

Description

Returns the capacity of the valve in mB.

Method
getSteamCapacity() -> int
Example
example.lua
1
2
3
local turbine = peripheral.find("thorium_turbine")

print(turbine.getSteamCapacity())

getPosition()

Description

Returns the position of the turbine controller as table with x, y and z.

Method
getPosition() -> table
Example
example.lua
1
2
3
4
local turbine = peripheral.find("thorium_turbine")

local p = turbine.getPosition()
print(p.x, p.y, p.z)

Heat exchanger functions

Peripheral name thorium_thermal, example: local thermal = peripheral.find("thorium_thermal")

isAssembled()

Description

Returns whether the heat exchanger this block belongs to is assembled. All other functions throw an error while it is not.

Method
isAssembled() -> boolean
Example
example.lua
1
2
3
local thermal = peripheral.find("thorium_thermal")

print(thermal.isAssembled())

getInfo()

Description

Returns all values of the heat exchanger in one table: assembled, working, size, temperature, saltRate, waterRate, heatPerWater, heatCost, heatCapacity, valveCapacity, converted, evaporated, produced, water (amount, capacity), steam (amount, capacity), salt (fluid, amount, capacity) and position.

Method
getInfo() -> table
Example
example.lua
1
2
3
4
local thermal = peripheral.find("thorium_thermal")

local i = thermal.getInfo()
print(i.size .. ": " .. i.temperature .. " C, " .. i.produced .. " mB/t steam")

isWorking()

Description

Returns whether the heat exchanger is working.

Method
isWorking() -> boolean
Example
example.lua
1
2
3
local thermal = peripheral.find("thorium_thermal")

print(thermal.isWorking())

getSize()

Description

Returns the size of the heat exchanger.

Method
getSize() -> string

return: "small", "medium" or "large"
Example
example.lua
1
2
3
local thermal = peripheral.find("thorium_thermal")

print(thermal.getSize())

getTemperature()

Description

Returns the temperature in degrees Celsius.

Method
getTemperature() -> int
Example
example.lua
1
2
3
local thermal = peripheral.find("thorium_thermal")

print(thermal.getTemperature())

getSaltRate()

Description

Returns how much heated molten salt is used per tick in mB.

Method
getSaltRate() -> int
Example
example.lua
1
2
3
local thermal = peripheral.find("thorium_thermal")

print(thermal.getSaltRate())

getWaterRate()

Description

Returns how much water is used per tick in mB.

Method
getWaterRate() -> int
Example
example.lua
1
2
3
local thermal = peripheral.find("thorium_thermal")

print(thermal.getWaterRate())

getHeatPerWater()

Description

Returns the heat that is needed to evaporate the water.

Method
getHeatPerWater() -> int
Example
example.lua
1
2
3
local thermal = peripheral.find("thorium_thermal")

print(thermal.getHeatPerWater())

getHeatCost()

Description

Returns the heat cost of the current evaporation.

Method
getHeatCost() -> int
Example
example.lua
1
2
3
local thermal = peripheral.find("thorium_thermal")

print(thermal.getHeatCost())

getHeatCapacity()

Description

Returns the heat capacity of the heat exchanger.

Method
getHeatCapacity() -> int
Example
example.lua
1
2
3
local thermal = peripheral.find("thorium_thermal")

print(thermal.getHeatCapacity())

getValveCapacity()

Description

Returns the capacity of the valves.

Method
getValveCapacity() -> int
Example
example.lua
1
2
3
local thermal = peripheral.find("thorium_thermal")

print(thermal.getValveCapacity())

getConverted()

Description

Returns how much salt was converted in the last operation in mB.

Method
getConverted() -> int
Example
example.lua
1
2
3
local thermal = peripheral.find("thorium_thermal")

print(thermal.getConverted())

getEvaporated()

Description

Returns how much water was evaporated in the last operation in mB.

Method
getEvaporated() -> int
Example
example.lua
1
2
3
local thermal = peripheral.find("thorium_thermal")

print(thermal.getEvaporated())

getProduced()

Description

Returns the steam that is produced per tick in mB.

Method
getProduced() -> int
Example
example.lua
1
2
3
local thermal = peripheral.find("thorium_thermal")

print(thermal.getProduced())

getWaterAmount()

Description

Returns the water in the heat exchanger in mB.

Method
getWaterAmount() -> int
Example
example.lua
1
2
3
local thermal = peripheral.find("thorium_thermal")

print(thermal.getWaterAmount() .. " / " .. thermal.getWaterCapacity())

getWaterCapacity()

Description

Returns the water capacity in mB.

Method
getWaterCapacity() -> int
Example
example.lua
1
2
3
local thermal = peripheral.find("thorium_thermal")

print(thermal.getWaterCapacity())

getSteamAmount()

Description

Returns the steam in the heat exchanger in mB.

Method
getSteamAmount() -> int
Example
example.lua
1
2
3
local thermal = peripheral.find("thorium_thermal")

print(thermal.getSteamAmount() .. " / " .. thermal.getSteamCapacity())

getSteamCapacity()

Description

Returns the steam capacity in mB.

Method
getSteamCapacity() -> int
Example
example.lua
1
2
3
local thermal = peripheral.find("thorium_thermal")

print(thermal.getSteamCapacity())

getSaltAmount()

Description

Returns the heated molten salt in the heat exchanger in mB.

Method
getSaltAmount() -> int
Example
example.lua
1
2
3
local thermal = peripheral.find("thorium_thermal")

print(thermal.getSaltAmount() .. " / " .. thermal.getSaltCapacity())

getSaltCapacity()

Description

Returns the capacity for heated molten salt in mB.

Method
getSaltCapacity() -> int
Example
example.lua
1
2
3
local thermal = peripheral.find("thorium_thermal")

print(thermal.getSaltCapacity())

getPosition()

Description

Returns the position of the heat exchanger controller as table with x, y and z.

Method
getPosition() -> table
Example
example.lua
1
2
3
4
local thermal = peripheral.find("thorium_thermal")

local p = thermal.getPosition()
print(p.x, p.y, p.z)