RedstoneEngine 5.46.0
Per-world redstone power engine.
Power model: every block may emit weak and strong power out of each of its faces (see \pocketmine\block\Block::getWeakPower() and \pocketmine\block\Block::getStrongPower()). A redstone conductor (a full solid block) which receives strong power gives that power to all of its neighbours.
Components react to power changes from \pocketmine\block\Block::onNearbyBlockChange(); delays (repeaters, torches, comparators) use the world's scheduled block updates.
Redstone wire is solved per network: wires only mark themselves dirty when a neighbour changes, and the engine recomputes each dirty network once after the world's neighbour updates have been processed, so a change never recurses wire by wire. The number of wire blocks recomputed per tick is capped; extra work waits for the next tick.
Constants
MAX_FLUSH_ROUNDS_PER_TICK
public const MAX_FLUSH_ROUNDS_PER_TICK = 16Maximum number of wire flush rounds (wire solve + resulting neighbour updates) per world tick.
MAX_WIRE_NETWORK_SIZE
public const MAX_WIRE_NETWORK_SIZE = 65536Networks bigger than this are truncated to protect the server from absurd circuits.
RAIL_POWER_RANGE
public const RAIL_POWER_RANGE = 8Number of rails a powered or activator rail passes power on to.
REDSTONE_TICK
public const REDSTONE_TICK = 2Number of game ticks in one redstone tick.
TORCH_BURNOUT_COOLDOWN_TICKS
public const TORCH_BURNOUT_COOLDOWN_TICKS = 160TORCH_BURNOUT_TOGGLES
public const TORCH_BURNOUT_TOGGLES = 8TORCH_BURNOUT_WINDOW_TICKS
public const TORCH_BURNOUT_WINDOW_TICKS = 60Methods
__construct()
public function __construct(\pocketmine\world\World $world, int $maxWireUpdatesPerTick = 20000)clearTorchState()
public function clearTorchState(int $x, int $y, int $z) : voidconsumeObserverRetrigger()
public function consumeObserverRetrigger(int $x, int $y, int $z) : boolReturns whether the observer at x/y/z must pulse again, and forgets it.
getCurrentTick()
public function getCurrentTick() : intgetMaxWireUpdatesPerTick()
public function getMaxWireUpdatesPerTick() : intgetPower()
public function getPower(int $x, int $y, int $z) : intReturns the highest power received by the block at x/y/z from any side.
getPowerFrom()
public function getPowerFrom(int $x, int $y, int $z, int $face, bool $ignoreWires = false) : intReturns the power that reaches the block at x/y/z from its neighbour on the given face: the neighbour's weak power towards this block, or, if the neighbour is a conductor, the strong power the neighbour receives.
Only blocks which declare themselves as power sources (\pocketmine\block\Block::isRedstoneSource()) are asked for their power.
getRememberedPowered()
public function getRememberedPowered(int $x, int $y, int $z) : boolgetStatistics()
public function getStatistics() : arraygetStrongPowerInto()
public function getStrongPowerInto(int $x, int $y, int $z, bool $ignoreWires = false) : intReturns the highest strong power delivered into the block at x/y/z by any of its neighbours.
getTransientPower()
public function getTransientPower(int $x, int $y, int $z) : intgetWirePoweredFaces()
public function getWirePoweredFaces(int $x, int $y, int $z) : intReturns a bitmask of the horizontal faces (1 << face) that the wire at x/y/z powers. A wire with no connections (a dot) powers all four sides; a wire with a single connection powers both ends of its line.
getWorld()
public function getWorld() : \pocketmine\world\WorldhasDirtyWires()
public function hasDirtyWires() : boolisConductorAt()
public function isConductorAt(int $x, int $y, int $z) : boolReturns whether the block at the given position is a redstone conductor.
isPowered()
public function isPowered(int $x, int $y, int $z) : boolReturns whether the block at x/y/z receives any power from any side.
isTorchBurnedOut()
public function isTorchBurnedOut(int $x, int $y, int $z) : boolReturns whether the torch at x/y/z is burned out. Once the cooldown is over the burnout is forgotten, and the torch relights on its next update.
isWireAt()
public function isWireAt(int $x, int $y, int $z) : boolReturns whether the block at the given position is redstone wire.
markWireDirty()
public function markWireDirty(int $x, int $y, int $z) : voidMarks the wire at x/y/z as needing its network to be recalculated.
recordTorchTurnOff()
public function recordTorchTurnOff(int $x, int $y, int $z) : boolRecords that the torch at x/y/z was turned off by its input. Returns true if the torch toggled too often and must burn out.
resetStatistics()
public function resetStatistics() : voidsetMaxWireUpdatesPerTick()
public function setMaxWireUpdatesPerTick(int $max) : voidsetObserverRetrigger()
public function setObserverRetrigger(int $x, int $y, int $z) : voidRemembers that the observer at x/y/z saw a change while it was already pulsing, so that it pulses again.
setRememberedPowered()
public function setRememberedPowered(int $x, int $y, int $z, bool $powered) : voidsetTransientPower()
public function setTransientPower(int $x, int $y, int $z, int $power) : voidupdateAround()
public function updateAround(int $x, int $y, int $z) : voidQueues neighbour updates for the block at x/y/z and its six neighbours. Used by components whose output strongly powers a block, so that the components around that block notice the change.
updateAroundSide()
public function updateAroundSide(\pocketmine\math\Vector3 $pos, int $face) : voidSame as RedstoneEngine::updateAround(), for the block on the given side of the given position.
updateComparatorsReading()
public function updateComparatorsReading(int $x, int $y, int $z) : voidQueues neighbour updates for the comparators that read the block at x/y/z, directly or through a conductor.
wireConnects()
public function wireConnects(int $x, int $y, int $z, int $face, ?bool $aboveIsConductor = null) : boolReturns whether wire at x/y/z connects through the given horizontal face (to another wire, stepping up or down, or to a power source which accepts wire connections).
