Diesel Generators
The engines, burners, fermenters, distillation towers, pumpjacks and chemical turrets of Create: Diesel Generators, read and driven by a computer.
These blocks belong to Create: Diesel Generators. Without that mod, they do not exist, and peripheral.find("diesel_engine") returns nil.
Create: Diesel Generators turns oil into rotation. A pumpjack pumps crude oil, a distillation tower splits it into diesel and gasoline, a basin lid or a bulk fermenter makes ethanol, and diesel engines burn those fuels to drive a Create network. A computer connected to these blocks watches every step of the chain (fuel left, heat, progress, oil left in the chunk) and does what a player would: it starts, slows and stops engines, sets the way they turn, opens a basin lid, aims a chemical turret and fires it.
| Block (in game) | peripheral type | what it reads or sets |
|---|---|---|
| Diesel Engine | diesel_engine | fuel, throttle, the rotation it gives, the way it turns |
| Modular Diesel Engine | modular_diesel_engine | the same, for the whole engine |
| Huge Diesel Engine | huge_diesel_engine | the same, for the shaft it drives |
| Burner | burner | heat, flame, valve, redstone |
| Basin Lid | basin_lid | fermenting and its progress; opens and closes the lid |
| Bulk Fermenter | bulk_fermenter | fermenting, its progress, the heat under it |
| Distillation Tank | distillation_tank | distilling, its progress, the heat, full outputs |
| Pumpjack Hole | pumpjack_hole | the oil left in the chunk, the pipe, the oil it holds |
| Chemical Turret | chemical_turret | where it aims; turns it and sprays |
Against the computer, a block is called by its side ("left"...); on a Data Cable (Minicomputer and newer) it gets a name such as diesel_engine@12,64,-30. peripheral.find wants the exact type: peripheral.find("diesel_engine") finds no modular or huge engine. A block that is part of a bigger whole (a segment of a modular engine, any block of a bulk fermenter or of a distillation tower) answers for the whole.
local engine = peripheral.find("diesel_engine")
local f = engine.fuel()
print(engine.generated_speed() .. " RPM, " .. f.amount .. " mB of fuel")Every method reads the block again when it is called. When the block is gone, the call stops the program with its name and removed (diesel engine removed, modular diesel engine removed, huge diesel engine removed, burner removed, basin lid removed, bulk fermenter removed, distillation tank removed, pumpjack hole removed, chemical turret removed); when its chunk is not loaded, with peripheral is not loaded. A multiblock that is not assembled stops it with the modular diesel engine is not formed (or the bulk fermenter, the distillation tank). With another version of the mod, a method may stop it with this version of Create: Diesel Generators has no ....
Also kinetic blocks and tanks. The Diesel Engine, each segment of a Modular Diesel Engine, the Burner and the Chemical Turret are Create kinetic blocks, with the methods of Create kinetic blocks as well (the Basin Lid too, though it never turns). Their speed() is the speed the block turns at, 0 on an overstressed network, where generated_speed() is what the engine gives; capacity() is what the whole network can give, where stress_capacity() is the engine's own share. The Huge Diesel Engine is not a kinetic block: the Powered Engine Shaft it drives is. Blocks that hold fluids have tank.tanks() (Tanks), but only through the faces where the mod lets fluids in: the fuel port of an engine, every face of the burner but the top, the bottom of the turret, the sides of the pumpjack hole that a pipe connects to. That is why the engines have fuel() and the pumpjack hole stored(): they read the tank from any face. The Bulk Fermenter is also an inventory (Inventories) and a tank on every face, and each layer of a distillation tower is a tank holding its own fluid.
engine.active() | true while the engine runs: it has fuel, redstone does not stop it, and its network is not overstressed. A Huge Diesel Engine also needs its Powered Engine Shaft. All three engines have it. |
engine.fuel() | The engine's tank, like an entry of tank.tanks(): fluid is the fluid id ("createdieselgenerators:diesel"), nil when empty; amount and capacity are in mB. A Diesel Engine and a whole Modular Diesel Engine hold 1000 mB, a Huge Diesel Engine 100 mB. It works whatever face touches the computer or the cable, where tanks() exists only on the fuel port. |
engine.throttle() | How hard the engine runs, set by redstone: (15 - signal) / 15, rounded to 3 decimals. No signal gives 1, a signal of 5 gives 0.667, 15 gives 0. When the server turned analog control off, it is always 1 (a signal then stops the engine without changing it: read active()). |
engine.fuel_consumption() | With the default fuels, 1 mB per second at full throttle, 0.25 at the lowest (per segment for a modular engine): a full tank of 1000 mB lasts about 17 minutes. 0 while the engine is stopped: no fuel, a redstone signal of 15, an overstressed network, or a huge engine without its shaft. |
engine.generated_speed() | The speed the engine drives its network at: the speed of its fuel (see the table above) times the throttle, doubled by a turbocharger. The sign is the way it turns, as Create counts it. For a Huge Diesel Engine, it is the speed of its Powered Engine Shaft (the fastest of the engines that drive it), and 0 while this engine does not run. |
engine.stress_capacity() | The engine's own share of its network's capacity, what Engineer's Goggles show as the capacity it provides: with diesel at full throttle, 6144 SU for a Diesel Engine, 8192 per segment of a modular one, 16384 for a huge one. Not kinetic.capacity(), which is what all the sources of the network give together. |
engine.direction() | The way set on the engine's value box (Rotation Direction), as a player sets it. All three engines have it. |
engine.set_direction(way) | Sets the engine's value box, like a player. The change is made at the end of the tick, with the last value asked in that tick. Every segment of a Modular Diesel Engine takes it, and so does every Huge Diesel Engine that drives the same shaft. Any other text stops the program with bad argument #1 to 'set_direction' ("clockwise" or "counter_clockwise"). |
engine.upgrade() | The upgrade a player fitted on the engine. An Engine Silencer makes it quiet; an Engine Turbocharger doubles its speed and its stress capacity (server setting "Turbocharged Diesel Engine Speed Multiplier") and does not fit on a huge engine. A program cannot fit or remove one. |
burner.heat() | The heat the burner gives the block on top of it, with the names of Create's heat levels. |
burner.lit() | true while its flame burns: it holds fuel, and its valve is open or it gets redstone. A weak flame can burn while heat() reads "none": it then heats nothing. |
burner.valve() | How open the burner's valve is. A new burner starts at 0.2. A shaft at 64 RPM moves it from closed to fully open in about 4 seconds. |
burner.signal() | The strongest redstone signal around the burner. Any signal, even 1, burns it harder than its valve fully open. |
lid.running() | true while a recipe runs under the closed lid. |
lid.progress() | lua print(math.floor(lid.progress() * 100) .. " %") |
lid.open() | lua print(lid.open()) |
lid.set_open(open) | Opens or closes the lid, like a right click. The change is made at the end of the tick. Opening it stops the fermenting (the batch starts over once it is closed). The lid stays as the program left it until the redstone signal around it changes. Anything else than true or false stops the program with bad argument #1 to 'set_open' (boolean expected, got number) (or the type given). |
f.running() | lua local f = peripheral.find("bulk_fermenter") print(f.running(), f.progress(), f.heat()) |
f.progress() | lua print(math.floor(f.progress() * 100) .. " %") |
f.heat() | The hottest of the blocks under its bottom layer, with the names of Create's heat levels (see burner.heat()). A recipe that needs heat waits while this is too low. |
tower.running() | lua local tower = peripheral.find("distillation_tank") print(tower.running(), tower.progress()) |
tower.progress() | lua print(math.floor(tower.progress() * 100) .. " %") |
tower.heat() | The hottest of the blocks under the bottom layer. Crude oil needs "fading" or hotter; "seething" gives more, faster. |
tower.full() | true while a layer above has no room for its share of the batch: the tower waits, its progress held, until that layer is emptied. |
hole.oil() | The oil left in the chunk, as the hole read it at the pumpjack's last stroke: Engineer's Goggles show the same. math.huge for a chunk that never runs dry, nil while the pumpjack has never pumped. |
hole.connected() | true when an unbroken column of fluid pipes goes from the hole down to the bedrock. The hole checks it once a second. Without it, the pumpjack pumps nothing. |
hole.pipe_length() | lua print(hole.pipe_length() .. " blocks deep") |
hole.stored() | The hole's own tank (8000 mB), like an entry of tank.tanks(). It works from any face, where tanks() exists only on the sides a pipe connects to. |
turret.horizontal_rotation() | The angle the turret was asked to face, not where it points while it still turns. 0 to 359 when a program set it; a player or a mob controlling it may leave any angle, so take it % 360. |
turret.vertical_rotation() | lua print(turret.vertical_rotation()) |
turret.set_horizontal_rotation(degrees) | Turns the turret to that angle: it starts turning at its next tick. Any whole number works and is taken modulo 360 (-90 is 270). A number with decimals stops the program with bad argument #1 to 'set_horizontal_rotation' (number has no integer representation). A player or a mob controlling the turret aims it over the program. |
turret.set_vertical_rotation(degrees) | lua turret.set_vertical_rotation(-20) -- raise the barrel 20 degrees |
turret.spray() | One spray at the turret's next tick, where the barrel points then: wait for on_target() first. It returns false when the turret cannot spray, its cogwheel still or its tank empty. For a long spray, give it redstone instead. |
turret.on_target() | The test the turret makes itself before a mob in its seat fires. A turret that sweeps an arc, one spray every 15 degrees: |
turret.controlled() | true while a player controls it (until they crouch or move more than 3 blocks away), or while a mob sits on a Seat next to it. Their aim then replaces the program's angles (a mob's, while it has a target). |
Diesel engines
The three engines burn a liquid fuel and drive a Create network. All three have the methods below.
- Diesel Engine: one block, a tank of 1000 mB. Its fuel port is its bottom face when it lies down, two of its side faces when it stands up.
- Modular Diesel Engine: segments placed in a row (up to 21) make one engine, run by one of them, its controller. It turns at the speed of a single segment, but gives the stress capacity of all of them and burns the fuel of all of them, from a single tank of 1000 mB. Fuel goes in through the top of a segment (the pipe on top, which a wrench removes). Any segment can be wrapped: the methods read the controller.
- Huge Diesel Engine: drives a shaft placed two blocks in front of it, across its axis, which becomes a Powered Engine Shaft; several huge engines can drive the same shaft. Its tank holds 100 mB and takes fuel through every face but its front and back.
With the mod's default fuels (a data pack can change them), at full throttle:
| fuel | Diesel Engine | Modular, per segment | Huge |
|---|---|---|---|
| diesel | 96 RPM, 6144 SU | 96 RPM, 8192 SU | 224 RPM, 16384 SU |
| gasoline, biodiesel | 96 RPM, 4096 SU | 96 RPM, 6144 SU | 224 RPM, 12288 SU |
| ethanol | 96 RPM, 2048 SU | 96 RPM, 3072 SU | 192 RPM, 6144 SU |
| plant oil | 74 RPM, 2048 SU | 74 RPM, 2560 SU | 192 RPM, 4096 SU |
Each of them burns 1 mB per second at full throttle (a modular engine, 1 mB per second per segment).
Redstone is the throttle. No method starts or stops an engine: like a player, the program gives it redstone, with rs.set when it touches the computer, or a Redstone Link next to it driven with link.set (see link). With the default settings, the strongest signal around the engine (around any segment of a modular one) sets its throttle: no signal is full speed, 15 stops it, and in between it runs slower, at (15 - signal) / 15. If the server turned off the setting "Engines controlled by analog lever", any signal stops the engine instead (and nothing does when "Engines disabled with redstone" is off too).
rs.set("left", 15) -- the engine on the left stops
rs.set("left", 5) -- runs at two thirds of its speed
rs.set("left", 0) -- full speedThe engine follows once the computer's output changes, at the end of the program's tick.
engine.active()
true while the engine runs: it has fuel, redstone does not stop it, and its network is not overstressed. A Huge Diesel Engine also needs its Powered Engine Shaft. All three engines have it.
- boolean
- true while the engine burns fuel and drives its network
local engine = peripheral.find("diesel_engine")
if not engine.active() then
print("engine stopped: no fuel, redstone or overstress")
endSee also diesel_engine.throttle() diesel_engine.generated_speed()
engine.fuel()
The engine's tank, like an entry of tank.tanks(): fluid is the fluid id ("createdieselgenerators:diesel"), nil when empty; amount and capacity are in mB. A Diesel Engine and a whole Modular Diesel Engine hold 1000 mB, a Huge Diesel Engine 100 mB. It works whatever face touches the computer or the cable, where tanks() exists only on the fuel port.
- table
- the fuel in the engine,
{fluid =, amount =, capacity =}
local f = engine.fuel()
local rate = engine.fuel_consumption()
if rate > 0 then
print(math.floor(f.amount / rate) .. " s of fuel left")
endengine.throttle()
How hard the engine runs, set by redstone: (15 - signal) / 15, rounded to 3 decimals. No signal gives 1, a signal of 5 gives 0.667, 15 gives 0. When the server turned analog control off, it is always 1 (a signal then stops the engine without changing it: read active()).
- number
- from 0 (stopped by redstone) to 1 (full speed)
The engine turns at its full speed times the throttle, and burns 0.25 + 0.75 × throttle of its full fuel rate: half the speed still costs 62.5 % of the fuel. A Diesel Engine and a Modular Diesel Engine keep the same stress capacity at any throttle above 0; a Huge Diesel Engine gives less with less throttle.
print(math.floor(engine.throttle() * 100) .. " % throttle")See also diesel_engine.generated_speed() diesel_engine.fuel_consumption()
engine.fuel_consumption()
With the default fuels, 1 mB per second at full throttle, 0.25 at the lowest (per segment for a modular engine): a full tank of 1000 mB lasts about 17 minutes. 0 while the engine is stopped: no fuel, a redstone signal of 15, an overstressed network, or a huge engine without its shaft.
- number
- the fuel the engine burns now, in mB per second; 0 while it burns nothing
When the server turned analog control off, a Modular Diesel Engine stopped by redstone keeps burning its fuel (the mod works that way), and this method shows it.
print(engine.fuel_consumption() .. " mB/s")engine.generated_speed()
The speed the engine drives its network at: the speed of its fuel (see the table above) times the throttle, doubled by a turbocharger. The sign is the way it turns, as Create counts it. For a Huge Diesel Engine, it is the speed of its Powered Engine Shaft (the fastest of the engines that drive it), and 0 while this engine does not run.
- number
- the speed the engine gives, in RPM, negative for the other way; 0 when it gives none
This is not speed() of Create kinetic blocks, the speed the block turns at, which reads 0 on an overstressed network.
print(engine.generated_speed() .. " RPM")See also diesel_engine.direction() kinetic.speed()
engine.stress_capacity()
The engine's own share of its network's capacity, what Engineer's Goggles show as the capacity it provides: with diesel at full throttle, 6144 SU for a Diesel Engine, 8192 per segment of a modular one, 16384 for a huge one. Not kinetic.capacity(), which is what all the sources of the network give together.
- number
- the stress capacity the engine gives its network now, in SU; 0 when it gives no rotation
local cap = engine.capacity()
if cap > 0 then
print(math.floor(engine.stress_capacity() / cap * 100) .. " % of the network's capacity")
endengine.direction()
The way set on the engine's value box (Rotation Direction), as a player sets it. All three engines have it.
- string
- "clockwise" or "counter_clockwise"
print(engine.direction())See also diesel_engine.set_direction()
engine.set_direction(way)
Sets the engine's value box, like a player. The change is made at the end of the tick, with the last value asked in that tick. Every segment of a Modular Diesel Engine takes it, and so does every Huge Diesel Engine that drives the same shaft. Any other text stops the program with bad argument #1 to 'set_direction' ("clockwise" or "counter_clockwise").
waystring- "clockwise" or "counter_clockwise"
All the sources of a network must turn the same way: change the others as well.
engine.set_direction("counter_clockwise")See also diesel_engine.direction()
engine.upgrade()
The upgrade a player fitted on the engine. An Engine Silencer makes it quiet; an Engine Turbocharger doubles its speed and its stress capacity (server setting "Turbocharged Diesel Engine Speed Multiplier") and does not fit on a huge engine. A program cannot fit or remove one.
- string|nil
- "silencer", "turbocharger", or nil without upgrade
if engine.upgrade() == "turbocharger" then
print("turbocharged")
endBurner
The Burner of Diesel Generators (not Create's Blaze Burner) burns a liquid fuel to heat what stands on it: a Basin, a bulk fermenter, a distillation tower. Its tank (100 mB) takes fuel through every face but the top. A shaft sets its valve: turning one way opens it, the other way closes it, and it stays where it was left. A redstone signal of any strength burns it hotter than a fully open valve, and its fuel much faster (up to 20 mB per second, against 2 with the valve fully open).
How hot it burns: (opening + 1) × the fuel's strength, where the opening is the valve (0 to 1), or 4 times the redstone signal when that is more. From 1.0 it is "smouldering", from 1.2 "fading", from 1.4 "kindled", from 1.8 "seething". The strength of the default fuels: gasoline 1.1, ethanol 0.9, diesel 0.6, biodiesel and plant oil 0.5. With diesel, a fully open valve gives 1.2, enough for a "heated" recipe (fading or hotter); a "superheated" one needs seething, as redstone gives.
A program sets the valve through its shaft: it turns the shaft with a Rotation Speed Controller (kinetic.set_speed()) or through a Clutch it drives with redstone, and stops it once valve() reads the opening wanted.
burner.heat()
The heat the burner gives the block on top of it, with the names of Create's heat levels.
- string
- "none", "smouldering", "fading", "kindled" or "seething"
local burner = peripheral.find("burner")
print(burner.heat(), burner.lit())See also burner.lit() burner.valve()
burner.lit()
true while its flame burns: it holds fuel, and its valve is open or it gets redstone. A weak flame can burn while heat() reads "none": it then heats nothing.
- boolean
- true while the burner burns
if not burner.lit() then
print("the burner is out")
endburner.valve()
How open the burner's valve is. A new burner starts at 0.2. A shaft at 64 RPM moves it from closed to fully open in about 4 seconds.
- number
- how open the valve is, from 0 (closed) to 1
print(math.floor(burner.valve() * 100) .. " % open")See also burner.signal()
burner.signal()
The strongest redstone signal around the burner. Any signal, even 1, burns it harder than its valve fully open.
- number
- the redstone power the burner receives, from 0 to 15
print(burner.signal())See also burner.valve()
Basin lid
The Basin Lid goes on top of a Create Basin and ferments what the basin holds: sugar and bone meal give ethanol, for example. It works while it is closed. A right click opens or closes it, and so does a redstone signal (open while the signal is on). Opening it stops the fermenting and loses the batch: closed again, it starts over.
lid.running()
true while a recipe runs under the closed lid.
- boolean
- true while the lid ferments
local lid = peripheral.find("basin_lid")
print(lid.running(), lid.progress())See also basin_lid.progress()
lid.progress()
- number
- how far the batch is, from 0 to 1; 0 while it does not ferment
print(math.floor(lid.progress() * 100) .. " %")lid.open()
lid.set_open(open)
Opens or closes the lid, like a right click. The change is made at the end of the tick. Opening it stops the fermenting (the batch starts over once it is closed). The lid stays as the program left it until the redstone signal around it changes. Anything else than true or false stops the program with bad argument #1 to 'set_open' (boolean expected, got number) (or the type given).
openboolean- true opens the lid, false closes it
lid.set_open(false) -- close it: fermenting starts againSee also basin_lid.open()
Bulk fermenter
The Bulk Fermenter is a big tank, up to 3 blocks wide and stacked high, that ferments items and fluids like a basin lid but in bulk. The bigger it is, the faster: a batch moves on by the square root of width × height each tick, and runs up to width × width times at once. It takes its heat from the blocks under it, the hottest one counting. Any of its blocks can be wrapped: the methods read the whole fermenter. It is also an inventory and a tank.
f.running()
- boolean
- true while the fermenter ferments
local f = peripheral.find("bulk_fermenter")
print(f.running(), f.progress(), f.heat())See also bulk_fermenter.progress()
f.progress()
- number
- how far the batch is, from 0 to 1; 0 while it does not ferment
print(math.floor(f.progress() * 100) .. " %")f.heat()
The hottest of the blocks under its bottom layer, with the names of Create's heat levels (see burner.heat()). A recipe that needs heat waits while this is too low.
- string
- the heat under the fermenter, from "none" to "seething"
if f.heat() == "none" then
print("no heat under the fermenter")
endDistillation tower
A Distillation Controller turns Create Fluid Tanks into a distillation tower: layers one block high, up to 3 blocks wide. Crude oil goes into the bottom layer; with heat under the tower, each batch of 100 mB gives 50 mB of diesel to the layer above it and 50 mB of gasoline to the next one, every 3 seconds (75 + 75 mB every 2 seconds when it is seething). Each heater at the highest heat under the bottom layer adds one batch per cycle. The bottom layer runs everything: any block of the tower can be wrapped, the methods read the bottom layer. Each layer is also a tank, so tanks() on a block of a layer gives that layer's fluid.
tower.running()
- boolean
- true while the tower distills
local tower = peripheral.find("distillation_tank")
print(tower.running(), tower.progress())See also distillation_tank.full()
tower.progress()
- number
- how far the batch is, from 0 to 1; 0 while it does not distill
print(math.floor(tower.progress() * 100) .. " %")tower.heat()
The hottest of the blocks under the bottom layer. Crude oil needs "fading" or hotter; "seething" gives more, faster.
- string
- the heat under the bottom layer, from "none" to "seething"
print(tower.heat())tower.full()
true while a layer above has no room for its share of the batch: the tower waits, its progress held, until that layer is emptied.
- boolean
- true when an output layer has no room for the next batch
if tower.full() then print("Empty the outputs") endSee also distillation_tank.running()
Pumpjack
A pumpjack, built over a Pumpjack Hole, pumps crude oil out of an oil chunk (an Oil Scanner finds them). A pipe must go straight down from the hole to the bedrock. Each stroke takes oil from the chunk into the hole's tank (8000 mB), and pipes carry it away from the sides of the hole. A chunk holds a set amount and runs dry; some chunks never do.
hole.oil()
The oil left in the chunk, as the hole read it at the pumpjack's last stroke: Engineer's Goggles show the same. math.huge for a chunk that never runs dry, nil while the pumpjack has never pumped.
- number|nil
- the oil left in the chunk, in mB; math.huge when it never runs out; nil before the first stroke
local hole = peripheral.find("pumpjack_hole")
local oil = hole.oil()
if oil == nil then
print("not pumped yet")
elseif oil == math.huge then
print("this chunk never runs dry")
else
print(math.floor(oil / 1000) .. " buckets left")
endSee also pumpjack_hole.connected()
hole.connected()
true when an unbroken column of fluid pipes goes from the hole down to the bedrock. The hole checks it once a second. Without it, the pumpjack pumps nothing.
- boolean
- true when the pipe under the hole reaches the bedrock
if not hole.connected() then
print("the pipe does not reach the bedrock")
endSee also pumpjack_hole.pipe_length()
hole.pipe_length()
- number
- how many blocks down the bedrock is; 0 while the pipe does not reach it
print(hole.pipe_length() .. " blocks deep")hole.stored()
The hole's own tank (8000 mB), like an entry of tank.tanks(). It works from any face, where tanks() exists only on the sides a pipe connects to.
- table
- the oil in the hole,
{fluid =, amount =, capacity =}
print(hole.stored().amount .. " mB")Chemical turret
The Chemical Turret sprays the fluid of its tank (1000 mB, filled from below): water, lava, a fuel, which a lighter fitted on the turret sets alight. A cogwheel must turn it: without rotation it does not spray, and a faster one throws further. While it gets a redstone signal, it sprays on and on. A player can take it over with a right click, and a mob sitting on a Seat next to it aims at living things and fires.
Its methods are those of the turret's own ComputerCraft peripheral, plus on_target and controlled, added by Computing Ages.
Angles. The horizontal angle goes from 0 to 359: 0 is north, 90 west, 180 south, 270 east (not the angles of the F3 screen). The vertical angle goes from -50 (barrel raised as far as it goes) to 11 (lowered). Both are whole numbers. Once asked, the turret turns there by itself, the short way, closing a fifth of the gap every tick: even a half turn is on target in about a second. The angle towards a target comes from the difference of coordinates (target minus turret):
local function yaw_to(dx, dz)
return math.floor(math.atan2(dx, dz) * 180 / math.pi + 180.5) % 360
end
print(yaw_to(0, -10)) -- north
print(yaw_to(10, 0)) -- east
print(yaw_to(-5, 5)) -- south-west0 270 135
turret.horizontal_rotation()
The angle the turret was asked to face, not where it points while it still turns. 0 to 359 when a program set it; a player or a mob controlling it may leave any angle, so take it % 360.
- number
- the horizontal angle the turret turns to, in degrees
local turret = peripheral.find("chemical_turret")
print(turret.horizontal_rotation(), turret.vertical_rotation())See also chemical_turret.set_horizontal_rotation() chemical_turret.on_target()
turret.vertical_rotation()
- number
- the barrel angle asked, from -50 (raised) to 11 (lowered)
print(turret.vertical_rotation())turret.set_horizontal_rotation(degrees)
Turns the turret to that angle: it starts turning at its next tick. Any whole number works and is taken modulo 360 (-90 is 270). A number with decimals stops the program with bad argument #1 to 'set_horizontal_rotation' (number has no integer representation). A player or a mob controlling the turret aims it over the program.
degreesnumber- the new horizontal angle, a whole number (0 north, 90 west, 180 south, 270 east)
turret.set_horizontal_rotation(270) -- face eastSee also chemical_turret.horizontal_rotation() chemical_turret.on_target()
turret.set_vertical_rotation(degrees)
degreesnumber- the new barrel angle, a whole number, kept between -50 (raised) and 11 (lowered)
turret.set_vertical_rotation(-20) -- raise the barrel 20 degreesSee also chemical_turret.vertical_rotation()
turret.spray()
One spray at the turret's next tick, where the barrel points then: wait for on_target() first. It returns false when the turret cannot spray, its cogwheel still or its tank empty. For a long spray, give it redstone instead.
- boolean
- true when the turret can spray (its cogwheel turns and its tank holds fluid)
while not turret.on_target() do sleep(0.1) end
if not turret.spray() then
print("no rotation, or the tank is empty")
endSee also chemical_turret.on_target()
turret.on_target()
The test the turret makes itself before a mob in its seat fires. A turret that sweeps an arc, one spray every 15 degrees:
- boolean
- true once the turret points within 2 degrees of the angles asked
local turret = peripheral.find("chemical_turret")
local arc = {150, 165, 180, 195, 210, 195, 180, 165}
turret.set_vertical_rotation(-5)
while true do
for _, yaw in ipairs(arc) do
turret.set_horizontal_rotation(yaw)
while not turret.on_target() do sleep(0.05) end
turret.spray()
sleep(0.3)
end
endturret.controlled()
true while a player controls it (until they crouch or move more than 3 blocks away), or while a mob sits on a Seat next to it. Their aim then replaces the program's angles (a mob's, while it has a target).
- boolean
- true while a player or a mob controls the turret
if turret.controlled() then
print("someone else is at the controls")
endA backup engine for the power station
A complete little program: a power station keeps a backup Diesel Engine stopped, and starts it when the network runs close to its limit. The engine touches the left face of the computer, which holds it stopped with a signal of 15; the computer turns on the same network, so the shaft at its back reads the load (see Create kinetic blocks). The engine stops again once the other sources could carry the load without it.
local backup = peripheral.wrap("left")
local network = peripheral.wrap("back")
local START, STOP = 0.9, 0.75 -- share of the capacity in use
rs.set("left", 15) -- stopped to begin with
local running = false
while true do
local used = network.stress()
local cap = network.capacity()
if running then
-- the load the other sources would carry without the backup
local others = cap - backup.stress_capacity()
if others > 0 and used / others < STOP then
rs.set("left", 15)
running = false
end
elseif cap == 0 or used / cap > START then
rs.set("left", 0)
running = true
end
local f = backup.fuel()
term.clear()
term.set_cursor(1, 1)
print("load " .. math.floor(used) .. " / " .. math.floor(cap) .. " SU")
print("backup " .. (backup.active() and "running" or "stopped"))
print("fuel " .. f.amount .. " / " .. f.capacity .. " mB")
if f.amount < 100 then
print("Refill the backup engine!")
end
sleep(2)
endThe backup must turn the same way as the station's other engines (diesel_engine.set_direction()).