Skip to main content

Machine class

Namespace: DoriosCore · Package: DoriosCore/index.js

Machine is the primary runtime class for processing machinery. It adds upgrade boosts, operation costs, item transfer helpers, status labels, and the standard placement and destruction lifecycle to BasicMachine.

import { Machine } from "DoriosCore/index.js";

Definition

class Machine extends BasicMachine

Inheritance:

BasicMachine
└─ Machine
└─ MultiblockMachine

Constructor

new Machine(block, settings)

new Machine(block: Block, settings: MachineSettings)

Creates a scheduled runtime for a placed machine.

ParameterTypeDescription
blockBlockMachine block in the world.
settingsMachineSettingsEntity, rotation, storage, rate, and upgrade configuration.

settings.machine.rate_speed_base defaults to 0. After the base runtime becomes valid, the constructor resolves installed upgrade perks and calculates:

consumption = max(0.01, energy_cost / energy_efficiency)
adjusted base rate = configured base rate × speed × consumption
effective rate = adjusted base rate × scheduler interval

Overclock contributes 35% speed and 25% energy cost per level unless settings.machine.overclock is false.

const machine = new Machine(block, settings);
if (!machine.valid) return;

MachineSettings

interface MachineSettings {
entity: MachineEntityConfig;
machine: MachineRuntimeConfig;
spawn_offset?: Vector3;
rotation?: boolean;
ignoreTick?: boolean;
requirements?: Record<string, Requirement>;
required_case?: string;
}

MachineEntityConfig

PropertyTypeRequiredDescription
inventory_sizenumberYesInventory-size event suffix used by the helper entity.
identifierstringNoHelper entity identifier. Uses DoriosCore's default when omitted.
namestringNoLocalization/name suffix for the helper entity.
input_range[number, number]NoInclusive item input range for compatible container setup.
output_range[number, number]NoInclusive item output range.
input_slotnumberNoSingle input-slot shortcut.
output_slotnumberNoSingle output-slot shortcut.
fixed_fluid_typesbooleanNoKeeps indexed liquid types when their amount reaches zero.
fixed_gas_typesbooleanNoKeeps indexed gas types when their amount reaches zero.
typestringNoOptional helper-entity event suffix triggered after spawn.

MachineRuntimeConfig

PropertyTypeRequiredDescription
rate_speed_basenumberNoBase work/energy rate before scheduler and upgrade scaling. Defaults to 0.
energy_capnumberNoMaximum energy stored by the helper entity.
fluid_capnumberNoCapacity assigned to every indexed liquid tank.
fluid_typesnumberNoNumber of liquid tanks. Defaults to 1 when fluid_cap is set.
gas_capnumberNoCapacity assigned to every indexed gas tank.
gas_typesnumberNoNumber of gas tanks. Defaults to 1 when gas_cap is set.
upgradesnumber[]NoOrdered inventory slots scanned by MachineUpgradeRegistry.
overclockbooleanNoSet to false to ignore the helper entity's overclock property.

Additional addon-owned fields can be placed in a subclass-specific settings contract.

Properties

PropertyTypeDescription
settingsMachineSettingsOriginal settings supplied to the constructor.
boostsMachineBoostsStandard and addon-defined numeric perks resolved from upgrade slots.

Machine also inherits every property from BasicMachine.

boosts

PropertyBaseDescription
speed1Processing-speed multiplier.
energy_cost1Energy-cost multiplier before efficiency.
energy_efficiency1Efficiency divisor.
process_batch1Operations per completed process.
overclockEntity propertyCurrent overclock level.
consumptionCalculatedenergy_cost / energy_efficiency, clamped to at least 0.01.

See MachineUpgradeRegistry for registration and duplicate-category rules.

Static methods

Machine.spawnEntity(event, config, callback)

Machine.spawnEntity(event: PlacementEventLike, config: MachineSettings, callback?: (entity: Entity) => void): void

Queues creation and initialization of the helper entity.

ParameterTypeRequiredDescription
event.blockBlockYesBlock receiving the helper entity.
event.playerPlayerYesPlayer placing the machine. Used for held-item restoration and optional rotation.
event.permutationToPlaceBlockPermutationYesOriginal placement permutation.
event.cancelbooleanNoSet to true internally when manual rotation placement is enabled.
configMachineSettingsYesEntity and machine configuration.
callback(entity: Entity) => voidNoRuns after storage and IO initialization, before interface buttons are finalized.

The method:

  1. Reads preserved energy, liquid, and gas data from the placed item lore.
  2. Applies manual facing when rotation is enabled.
  3. Spawns the configured helper entity.
  4. Sets energy capacity.
  5. Creates all configured liquid and gas tanks and applies their capacities.
  6. Restores every preserved resource index.
  7. Prepares item, liquid, and gas IO documents.
  8. Runs callback and installs registered interface buttons.
  9. Notifies adjacent UtilityCore-managed networks that the block changed.
beforeOnPlayerPlace(event, { params: settings }) {
Machine.spawnEntity(event, settings, () => {
const machine = new Machine(event.block, { ...settings, ignoreTick: true });
if (!machine.valid) return;
machine.setEnergyCost(settings.machine.energy_cost);
machine.displayProgress();
});
}

Machine.onDestroy(event)

Machine.onDestroy(event: DestroyEventLike): boolean

Queues cleanup for the machine at the broken block location.

ParameterTypeDescription
event.blockBlockBlock being destroyed.
event.brokenBlockPermutationBlockPermutationOriginal permutation; its type ID becomes the preserved block item.
event.player`Playerundefined`
event.dimensionDimensionDimension containing the block and helper entity.

Returns false when no helper entity is found. Otherwise returns true immediately after cleanup is queued. Cleanup serializes energy and all indexed liquid/gas values, releases the scheduler group, drops non-interface inventory, removes the helper entity, and spawns the preserved block item.

Instance methods

transferItems()

transferItems(): boolean

Transfers registered output slots into the cached item output target. The target's opposite face policy is respected. Stale cached targets are cleared. Returns true when at least one item moves.

For new machines with configurable six-face IO, prefer inherited processIO() to process inputs and outputs together.

hasOutputItems()

hasOutputItems(): boolean

Returns whether at least one no-face output slot currently contains an item.

pullItemsFromAbove(targetSlot)

pullItemsFromAbove(targetSlot: number): boolean

Attempts to move items from the compatible container directly above the machine into one machine slot. The source's down-face output policy is respected.

ParameterTypeDescription
targetSlotnumberMachine inventory slot that should receive the item.

Returns true after the first successful transfer; otherwise false.

setProgress(value, options)

setProgress(value: number, options?: ProgressOptions): void

Stores progress using options.maxValue or the selected energy cost as the full value.

ParameterTypeDescription
valuenumberNew nonnegative progress value.
optionsProgressOptionsProgress slot, type, display, index, scale, legacy mode, and optional maxValue.

displayProgress(options)

displayProgress(options?: ProgressOptions): void
displayProgress(maxValue: number, options?: ProgressOptions): void

Draws progress using the selected energy cost by default. Supply maxValue explicitly for a different process scale. All ProgressOptions fields and defaults are documented by BasicMachine.displayProgress().

setEnergyCost(value, index)

setEnergyCost(value: number, index?: number): void

Stores the full operation cost in the dynamic property dorios:energy_cost_{index}.

ParameterTypeDefaultDescription
valuenumberOperation cost. Values below 1 are stored as 1.
indexnumber0Cost/progress channel.

getEnergyCost(index)

getEnergyCost(index?: number): number

Returns the stored cost for index, or 800 when unset.

displayEnergy(slot)

displayEnergy(slot?: number): void

Calls energy.display(slot).

ParameterTypeDefaultDescription
slotnumber0Inventory slot containing the energy display item.

showWarning(message, options)

showWarning(message: string, options?: WarningOptions): void

Shows a yellow status label, redraws energy, turns the block off, and resets progress unless disabled.

ParameterTypeDefaultDescription
messagestringWarning text. The standard label appends an exclamation mark.
options.resetProgressbooleantrueWhether to set progress to zero.
options.displayProgressbooleantrueWhether resetting progress redraws the bar.
Remaining optionsProgressOptionsSee progress APISelects slot, type, index, scale, and legacy rendering.

Use { resetProgress: false } for temporary conditions such as missing energy when partial work should remain.

showStatus(message)

showStatus(message: string): void

Shows a green running label containing the supplied message, speed, effective efficiency, energy cost, and base rate. It also redraws energy and does not change progress.

Processing example

import { Machine } from "DoriosCore/index.js";

function tick(block, settings) {
const machine = new Machine(block, settings);
if (!machine.valid) return;

machine.processIO();
machine.setEnergyCost(800);

const energyStep = machine.rate * machine.boosts.consumption;
if (!machine.energy.has(energyStep)) {
machine.showWarning("No Energy", { resetProgress: false });
return;
}

machine.energy.consume(energyStep);
machine.addProgress(machine.rate);

if (machine.getProgress() >= machine.getEnergyCost()) {
const crafts = Math.max(1, Math.floor(machine.boosts.process_batch));
// Validate and mutate recipe inputs/outputs for `crafts` operations.
machine.setProgress(0);
}

machine.on();
machine.displayProgress();
machine.showStatus("Running");
}

For a complete capacity-safe scripted recipe, see the Thermal Crusher.