Interface RedstoneWorld

All Superinterfaces:
BlockGetter, SignalGetter

public interface RedstoneWorld extends SignalGetter
A world as the redstone engine drives it: the signals of SignalGetter, plus changing blocks, telling their neighbours, and scheduling ticks.

Neighbour updates run in the order vanilla runs them, one chain at a time: an update caused while another one is running is queued and runs right after it, rather than nested inside it. Updates reaching a block of another region are handed over to the thread of that region. A world may be configured to drive its redstone dust another way, such as with Alternate Current, which updates the blocks around a whole network of dust in the order power flows through it.

Since:
0.1.0
See Also:
  • Method Details

    • setBlock

      boolean setBlock(BlockPosition position, BlockData data, RedstoneWorld.Update update)
      Replaces a block, and lets the redstone around it react as update says. Players see the change and the light follows in every case.

      Like any block write, it must be called on the thread of the region owning position.

      Parameters:
      position - where the block is
      data - the new state
      update - how far the change spreads
      Returns:
      false if the block already held that state, or its chunk is not loaded
      Throws:
      IllegalStateException - if the calling thread does not own position
      Since:
      0.1.0
    • destroyBlock

      boolean destroyBlock(BlockPosition position)
      Removes a block that can no longer stand, such as redstone dust whose support was removed, telling its neighbours. A waterlogged block leaves its water behind.
      Parameters:
      position - where the block is
      Returns:
      false if there was nothing to remove, or its chunk is not loaded
      Throws:
      IllegalStateException - if the calling thread does not own position
      Since:
      0.1.0
    • updateNeighbors

      void updateNeighbors(BlockPosition position, TypedKey<BlockType> source)
      Tells the six neighbours of a block that something changed there, in vanilla order: west, east, down, up, north, south.
      Parameters:
      position - the block that changed
      source - the block type that caused the update
      Since:
      0.1.0
    • updateNeighborsExcept

      void updateNeighborsExcept(BlockPosition position, TypedKey<BlockType> source, BlockFace skipped)
      Tells the neighbours of a block that something changed there, except the one on one side.
      Parameters:
      position - the block that changed
      source - the block type that caused the update
      skipped - the side not to tell, usually where the change comes from
      Since:
      0.1.0
    • neighborChanged

      void neighborChanged(BlockPosition position, TypedKey<BlockType> source)
      Tells one block that one of its neighbours changed.
      Parameters:
      position - the block to tell
      source - the block type that caused the update
      Since:
      0.1.0
      See Also:
    • neighborShapeChanged

      void neighborShapeChanged(BlockPosition position, BlockFace direction)
      Tells one block that the block next to it on one side changed shape, so that it can follow: redstone dust reconnecting, an observer firing.
      Parameters:
      position - the block to tell
      direction - the side of position the changed block is on
      Since:
      0.1.0
      See Also:
    • analogOutputChanged

      void analogOutputChanged(BlockPosition position)
      Tells the comparators reading a block, next to it or behind a conductor, that its analog output changed. Call it when what a comparator reads changes without the block state changing, such as the contents of a container.
      Parameters:
      position - the block whose analog output changed
      Since:
      0.1.0
    • scheduleTick

      void scheduleTick(BlockPosition position, TypedKey<BlockType> block, int delay, TickPriority priority)
      Schedules a call to RedstoneBehaviour.tick(RedstoneWorld, BlockPosition, BlockData), once delay game ticks have elapsed. The tick only runs if the block is still of type block by then.

      A block holds at most one pending tick per block type: scheduling another one before the first ran does nothing.

      Parameters:
      position - the block to tick
      block - the block type the tick is for
      delay - the number of game ticks to wait, 1 for the next tick
      priority - the order among the ticks due on the same game tick
      Since:
      0.1.0
    • scheduleTick

      default void scheduleTick(BlockPosition position, TypedKey<BlockType> block, int delay)
      Schedules a tick at TickPriority.NORMAL priority.
      Parameters:
      position - the block to tick
      block - the block type the tick is for
      delay - the number of game ticks to wait, 1 for the next tick
      Since:
      0.1.0
      See Also:
    • hasScheduledTick

      boolean hasScheduledTick(BlockPosition position, TypedKey<BlockType> block)
      Returns true if a tick is pending for a block, not counting the ticks running this game tick.

      Only reliable on the thread of the region owning position.

      Parameters:
      position - the block
      block - the block type the tick is for
      Returns:
      true if a tick is pending for a block, not counting the ticks running this game tick
      Since:
      0.1.0
    • willTickThisTick

      boolean willTickThisTick(BlockPosition position, TypedKey<BlockType> block)
      Returns true if a tick of a block is due on the current game tick and has not run yet.

      Only reliable on the thread of the region owning position.

      Parameters:
      position - the block
      block - the block type the tick is for
      Returns:
      true if a tick of a block is due on the current game tick and has not run yet
      Since:
      0.1.0
    • blockEvent

      void blockEvent(BlockPosition position, TypedKey<BlockType> block, int type, int data)
      Queues a block event: a call to RedstoneBehaviour.triggerEvent(RedstoneWorld, BlockPosition, BlockData, int, int), later in the same game tick. What a piston moves on, rather than on the update that powered it.

      Block events run once the scheduled ticks due on that game tick have run, in the order they were queued. One queued while block events run still runs on that game tick, after those already queued. The event only runs if the block is still of type block by then, and queuing an event equal to one that is waiting does nothing.

      The players seeing the block are told of every event its behaviour accepts, before they are told of the blocks that event changed: their client plays the event out from the world as it was, the way a piston is drawn moving.

      Parameters:
      position - the block the event is for
      block - the block type the event is for
      type - what the event is, from 0 to 255, as the block type defines it
      data - a value going with it, from 0 to 255
      Throws:
      IllegalArgumentException - if type or data is out of range
      Since:
      0.1.0
    • blockChanged

      void blockChanged(BlockPosition position, BlockData previous, BlockData current)
      Tells the engine a block was replaced by something else than setBlock(BlockPosition, BlockData, RedstoneWorld.Update), so that the redstone around it reacts as if setBlock had been called with RedstoneWorld.Update.NEIGHBORS.

      The server calls it for every block placed, broken or blown up; a plugin only needs it when it writes blocks by other means.

      Parameters:
      position - where the block is
      previous - the state that was replaced
      current - the state now in place
      Since:
      0.1.0