Class ConnectedBlockRuleSet

java.lang.Object
com.hypixel.hytale.server.core.universe.world.connectedblocks.ConnectedBlockRuleSet
Direct Known Subclasses:
CustomTemplateConnectedBlockRuleSet, PatternedConnectedBlockRuleSet, RoofConnectedBlockRuleSet, StairConnectedBlockRuleSet

public abstract class ConnectedBlockRuleSet extends Object
Defines how a "smart block" (a block whose shape depends on its neighbors) chooses which concrete variant to display based on the surrounding world.

Attached to a BlockType: when that block is placed or its neighbors change, getConnectedBlockType(ChunkStore, Vector3ic, BlockType, int, Vector3ic, boolean) is invoked to produce the replacement block (e.g. stair corner vs. straight, fence post vs. cross-piece). Subclasses pick the matching logic (stair-like, roof-like, or a pattern-based template) and resolve to a ConnectedBlocksUtil.ConnectedBlockResult.

  • Field Details

  • Constructor Details

    • ConnectedBlockRuleSet

      public ConnectedBlockRuleSet()
  • Method Details

    • onlyUpdateOnPlacement

      public abstract boolean onlyUpdateOnPlacement()
      Returns:
      true if the block should only update its connected block type on placement, false otherwise.
    • getConnectedBlockType

      public abstract Optional<ConnectedBlocksUtil.ConnectedBlockResult> getConnectedBlockType(@Nonnull ChunkStore chunkStore, @Nonnull org.joml.Vector3ic testedCoordinate, @Nonnull BlockType blockType, int rotation, @Nonnull org.joml.Vector3ic placementNormal, boolean isPlacement)
      Called to fetch the connected block type for a block at the given coordinate, with the given block type and rotation, when being placed or updated.
      Parameters:
      chunkStore - The ChunkStore for chunk component and data access.
      testedCoordinate - The coordinate of the block being tested for connected block type updates.
      blockType - The BlockType of the block being tested for connected block type updates.
      rotation - The rotation of the block being tested for connected block type updates.
      placementNormal - The face normal of the block being placed against, if the block is being placed. Otherwise, this will be a zero vector.
      isPlacement - Indicates whether the block is being placed (as opposed to updated).
      Returns:
      an Optional containing the ConnectedBlocksUtil.ConnectedBlockResult if a connected block type was found, or an empty Optional if no connected block type applies.
    • updateCachedBlockTypes

      public void updateCachedBlockTypes(@Nonnull BlockType blockType, @Nonnull BlockTypeAssetMap<String, BlockType> assetMap)
      Called once after asset resolution so the rule set can cache lookups against the resolved variants. Implementations that maintain block-id to shape lookup maps should rebuild them here. The default implementation is a no-op; not all rule sets need cached state.
      Parameters:
      blockType - The base BlockType that owns this rule set; variants resolve relative to it.
      assetMap - The BlockTypeAssetMap for resolving variant block types to their asset index.
    • toPacket

      @Nullable public ConnectedBlockRuleSet toPacket(@Nonnull BlockTypeAssetMap<String, BlockType> assetMap)
      Called to create a new packet instance for this connected block rule set, using the given asset map to fetch connected block types by their asset ID.
      Parameters:
      assetMap - The BlockTypeAssetMap for fetching connected block types by their asset ID.
      Returns:
      a new ConnectedBlockRuleSet instance representing this connected block rule set, or null if this connected block rule set should not be sent to clients.
    • getUpdateMode

      @Nonnull public ConnectedBlockUpdateMode getUpdateMode()