Skip to main content

GasStorage class

Namespace: DoriosCore · Package: DoriosCore/index.js

GasStorage manages one indexed gas tank on a helper entity. Its scores, type tags, registered items, IO documents, and displays are fully separate from FluidStorage.

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

The current display formatter uses the same bucket-derived units as liquids: mB, B, KB, MB, GB, TB, PB, and EB.

Constructor

new GasStorage(entity, index)

new GasStorage(entity: Entity, index?: number)

ParameterTypeDefaultDescription
entityEntityEntity owning the gas tanks.
indexnumber0Independent gas tank index represented by this wrapper.

The constructor binds the gas objectives for index, reads type and capacity, and changes an empty nonfixed tank to type empty.

Properties

PropertyTypeDescription
entityEntityOwner of this gas tank.
indexnumberGas index managed by the wrapper.
scoreId`ScoreboardIdentityundefined`
scores{ gas, gasExp, gasCap, gasCapExp }Four scoreboard objectives bound to this index.
shouldUpdateUIbooleanWhether the entity UI was open when the wrapper was created.
typestringCached gas type or empty.
capnumberCached gas capacity.

Static properties

GasStorage.itemGasStorages

Record<string, GasContainerData> defines exact item IDs that insert gas:

interface GasContainerData {
amount: number;
type: string;
output?: string;
infinite?: boolean;
}

GasStorage.itemGasHolders

Record<string, GasHolderData> defines empty items that extract gas:

interface GasHolderData {
types: Record<string, string>;
required: number;
}

Register addon gases and containers through DoriosLib so definitions are shared across enabled extensions.

Initialization methods

GasStorage.initializeSingle(entity)

GasStorage.initializeSingle(entity: Entity): GasStorage returns tank index 0.

GasStorage.initializeMultiple(entity, count)

GasStorage.initializeMultiple(entity: Entity, count: number): GasStorage[]

Stores the supported count, initializes indices 0 through count - 1, and returns their wrappers.

ParameterTypeDescription
entityEntityEntity receiving gas storage.
countnumberPositive number of indexed tanks.
const [hydrogen, exhaust] = GasStorage.initializeMultiple(entity, 2);
hydrogen.setCap(8_000);
exhaust.setCap(8_000);
hydrogen.setType("example_hydrogen");
exhaust.setType("example_exhaust");

GasStorage.initializeObjectives(index)

GasStorage.initializeObjectives(index?: number): void creates or loads maxGases and the four gas objectives for index. The default index is 0.

GasStorage.initialize(entity)

GasStorage.initialize(entity: Entity): void bootstraps the base gas score for a newly spawned standalone gas entity.

GasStorage.hasOpenUI(entity)

GasStorage.hasOpenUI(entity: Entity): boolean reads the shared open-player property and safely returns false for an invalid entity.

GasStorage.getMaxGases(entity)

GasStorage.getMaxGases(entity: Entity): number reads the maxGases score, falls back to indexed gas{index}Type: tags, and returns at least 1.

Formatting and item helpers

GasStorage.normalizeValue(amount)

normalizeValue(amount: number): NormalizedValue produces a scoreboard-safe mantissa and exponent.

GasStorage.combineValue(value, exp)

combineValue(value: number, exp: number): number reconstructs value × 10^exp.

GasStorage.formatGas(value)

formatGas(value: number): string formats a nonnegative gas amount with the current storage unit suffixes.

GasStorage.getGasFromText(input)

GasStorage.getGasFromText(input: string): { type: string; amount: number }

Parses legacy gas display/lore text, including type names wrapped as Gas (type). Failed parsing returns { type: "empty", amount: 0 }.

GasStorage.getContainerData(id)

getContainerData(id: string): GasContainerData | null returns registered insertion data for an exact item ID.

GasStorage.getSelectedInventoryItem(player)

getSelectedInventoryItem(player: Player): SelectedInventoryItem | null returns the selected slot, inventory, and current item, or null.

GasStorage.replaceHeldGasItem(player, expectedTypeId, nextTypeId)

GasStorage.replaceHeldGasItem(player: Player, expectedTypeId: string, nextTypeId?: string): boolean

ParameterTypeRequiredDescription
playerPlayerYesPlayer whose selected item changes. Creative players succeed without mutation.
expectedTypeIdstringYesExact input ID still expected in the selected slot.
nextTypeIdstringNoResult item ID; omit to consume the input.

Stacks are decremented and the output is inserted separately. Overflow is dropped at the player. A single item is replaced in place.

GasStorage.handleGasItemInteraction(player, entity, mainHand)

GasStorage.handleGasItemInteraction(player: Player, entity: Entity, mainHand?: ItemStack): void

Finds a compatible indexed tank, applies a registered gas item, shows the new amount on the action bar, and replaces the held item outside Creative mode.

ParameterTypeRequiredDescription
playerPlayerYesInteracting player.
entityEntityYesEntity containing gas tanks.
mainHandItemStackNoExplicit interaction stack; otherwise the main hand is resolved.

Storage methods

hasFixedGasType()

hasFixedGasType(): boolean returns whether the entity has dorios:constant_gas_type. Fixed gas tanks retain their type at zero.

setCap(amount) / getCap()

setCap(amount: number): void writes maximum capacity and reduces an amount above the new cap. getCap(): number reads and caches capacity.

set(amount) / get()

set(amount: number): void writes a raw normalized amount. get(): number returns the combined amount. Prefer capacity-aware methods for gameplay insertion and consumption.

add(amount)

add(amount: number): number

Adds a signed amount and limits positive additions to free capacity. Returns the signed amount applied. Standalone UtilityCraft gas tank entities update their health representation and remove their empty resource entity when appropriate.

consume(amount)

consume(amount: number): number consumes the full amount when available. Infinite and legacy creative storage tags report success without reducing storage. Returns the amount or 0.

getFreeSpace() / has(amount) / isFull()

MethodReturnsDescription
getFreeSpace()numberRemaining gas capacity.
has(amount: number)booleanWhether at least amount is available.
isFull()booleanWhether storage reached capacity.

getType() / setType(type)

getType(): string
setType(type: string): void

Gas types use indexed tags such as gas0Type:example_hydrogen. setType replaces the previous tag and updates the cached property.

tryInsert(type, amount)

tryInsert(type: string, amount: number): boolean inserts only when the positive amount fits completely and the tank is empty or already has the same type. An empty tank adopts type.

gasItem(typeId)

gasItem(typeId: string): string | false

Processes a registered gas insertion or extraction item.

  • Finite insertion adds the complete registered amount.
  • Infinite insertion fills all available capacity.
  • Holder extraction requires a type-specific output and its full registered amount.
  • The return value is the resulting item ID, or false when the operation fails or has no result item.

Transfer methods

GasStorage.transferBetween(dim, sourceLoc, targetLoc, amount)

GasStorage.transferBetween(dim: Dimension, sourceLoc: Vector3, targetLoc: Vector3, amount?: number): boolean

Transfers gas index 0 between blocks tagged dorios:gas and creates an empty gas-tank entity when required.

ParameterTypeDefaultDescription
dimDimensionDimension containing both endpoints.
sourceLocVector3Source block position.
targetLocVector3Target block position.
amountnumber100Maximum amount transferred.

Returns true when gas moves.

GasStorage.findType(entity, type)

findType(entity: Entity, type: string): GasStorage | null returns an existing matching index, then the first empty index with space, or null.

transferTo(other, amount) / receiveFrom(other, amount)

transferTo(other: GasStorage, amount: number): number moves up to amount when the receiver is empty or holds the same type. receiveFrom(other, amount) delegates in the opposite direction. Both return the moved amount.

transferGases(block, amount)

transferGases(block: Block, amount?: number): boolean

Transfers to the cached single gas output target.

ParameterTypeDefaultDescription
blockBlockSource block paired with this gas entity.
amountnumber100Maximum amount sent.

Stale output targets are cleared. New six-face machines normally use machine.processIO().

transferToNetwork(speed, mode, nodes)

transferToNetwork(speed: number, mode?: TransferMode, nodes?: Vector3[]): number

ParameterTypeDefaultDescription
speednumberTotal maximum amount sent.
mode"nearest" | "farthest" | "round"nearestTarget processing mode.
nodesVector3[]Precomputed UtilityCore network nodes. Empty or missing arrays return 0.

Returns total gas transferred. DoriosCore does not discover or own the network.

Display and tank blocks

display(slot)

display(slot?: number): void

While the UI is open, writes utilitycraft:{type}_00 through utilitycraft:{type}_48 to the selected inventory slot. Empty gas tanks use the neutral empty resource bar.

ParameterTypeDefaultDescription
slotnumber4Inventory slot used by the gas display.
Required resource files

Every custom gas needs 49 display-frame items and textures. Standalone tanks also require utilitycraft:gas_tank_{type} behavior/resource entities using the shared geometry and an addon-owned texture. Missing frames cause Invalid item identifier errors when display() runs.

GasStorage.addGasToTank(block, type, amount)

GasStorage.addGasToTank(block: Block, type: string, amount: number): Entity | undefined | false

Finds or spawns utilitycraft:gas_tank_{type}, initializes it, assigns the block tier capacity, sets its gas type, and adds amount. Empty or missing type returns undefined; failed spawning returns false.

GasStorage.getTankCapacity(typeId)

getTankCapacity(typeId: string): number returns 8000, 32000, 128000, or 512000 for the basic through ultimate gas tanks. Unknown IDs use the basic capacity.

Example: two-gas process

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

const [hydrogen, exhaust] = GasStorage.initializeMultiple(entity, 2);
hydrogen.setCap(8_000);
exhaust.setCap(8_000);

if (hydrogen.type === "empty") hydrogen.setType("example_hydrogen");
if (exhaust.type === "empty") exhaust.setType("example_exhaust");

if (hydrogen.has(250) && exhaust.getFreeSpace() >= 100) {
hydrogen.consume(250);
exhaust.add(100);
}

hydrogen.display(5);
exhaust.display(6);

See the complete Gas Reactor.