Class BlockHealthSection

java.lang.Object
com.hypixel.hytale.server.core.modules.blockhealth.BlockHealthSection
All Implemented Interfaces:
Component<ChunkStore>, Cloneable

public class BlockHealthSection extends Object implements Component<ChunkStore>
Block damage and placement fragility for one chunk section, keyed by the section block index.

Every section carries this component. The maps are allocated on first use and released when they empty, so an undamaged section costs no more than the component object itself. Mutations never mark the section for saving. The caller that owns the change does that.

Each change records the accumulated health delta for its block index. The replication system drains those deltas once per tick and sends one packet per section. A block whose entry was destroyed or cleared sends nothing, because the block change that follows resets the client state.

Not thread safe.

  • Field Details

  • Constructor Details

    • BlockHealthSection

      public BlockHealthSection()
  • Method Details

    • getComponentType

      @Nonnull public static ComponentType<ChunkStore, BlockHealthSection> getComponentType()
    • isEmpty

      public boolean isEmpty()
    • getHealth

      public float getHealth(int x, int y, int z)
    • getHealth

      public float getHealth(int index)
    • isDamaged

      public boolean isDamaged(int index)
    • isFragile

      public boolean isFragile(int x, int y, int z)
    • isFragile

      public boolean isFragile(int index)
    • getFragilitySeconds

      public float getFragilitySeconds(int index)
    • damage

      public float damage(int x, int y, int z, float amount, @Nonnull Instant now)
    • damage

      public float damage(int index, float amount, @Nonnull Instant now)
      Removes amount from the health of the block at index and returns what is left.

      A block that reaches zero, or that ends at full health, drops its entry. Only a block that stays damaged records a delta for replication.

    • clearHealth

      public boolean clearHealth(int index)
      Drops the health entry of the block at index, if any. Nothing is replicated: the caller replaces the block, and that change resets the client state on its own.
    • makeFragile

      public void makeFragile(int x, int y, int z, float seconds)
    • makeFragile

      public void makeFragile(int index, float seconds)
    • clearFragility

      public void clearFragility(int index)
    • tickFragility

      public boolean tickFragility(float deltaSeconds)
      Counts down every fragile block.
      Returns:
      true if a block stopped being fragile and dropped its entry.
    • tickRegeneration

      public boolean tickRegeneration(@Nonnull Instant now, float deltaSeconds, long secondsUntilRegeneration, float healingPerSecond)
      Regenerates every block whose last hit is at least secondsUntilRegeneration old.
      Returns:
      true if a block reached full health and dropped its entry.
    • clone

      @Nonnull public Component<ChunkStore> clone()
      Specified by:
      clone in interface Component<ChunkStore>
      Returns:
      a clone instance of the original component instance.