Class BlockHarvestUtils

java.lang.Object
com.hypixel.hytale.server.core.modules.interaction.BlockHarvestUtils

public class BlockHarvestUtils extends Object
Static helpers for the server-side block gathering pipeline: damaging blocks (which break once their health is depleted), breaking blocks outright, and harvesting (picking up) blocks via interaction.

The performBlockDamage, performBlockBreak and performPickupByInteraction methods are the entry points; the rest support them with drops, durability, sounds, filler-block resolution and low-level block removal.

  • Constructor Details

    • BlockHarvestUtils

      public BlockHarvestUtils()
  • Method Details

    • performBlockDamage

      public static boolean performBlockDamage(@Nonnull org.joml.Vector3i targetBlock, @Nullable ItemStack itemStack, @Nullable ItemTool tool, float damageScale, int setBlockSettings, boolean isExplosion, @Nonnull Ref<ChunkStore> sectionReference, @Nonnull ComponentAccessor<EntityStore> componentAccessor, @Nonnull ComponentAccessor<ChunkStore> chunkStore)
      Convenience overload of performBlockDamage(Ref, Ref, Vector3i, ItemStack, ItemTool, String, boolean, float, int, boolean, Ref, ComponentAccessor, ComponentAccessor) for damage with no instigating entity (for example explosion damage): no ref, no tool id and no tool match.
      Parameters:
      targetBlock - The position of the block to damage.
      itemStack - The item stack responsible for the damage, or null.
      tool - The item tool to reference, or null.
      damageScale - A multiplier applied to the calculated damage.
      setBlockSettings - The SetBlockSettings to apply.
      isExplosion - Whether the damage originates from an explosion.
      sectionReference - The reference of the target block's chunk section entity.
      componentAccessor - The ComponentAccessor<EntityStore> for component access.
      chunkStore - The ComponentAccessor<ChunkStore> for component access.
      Returns:
      true if the block was broken, false otherwise.
    • performBlockDamage

      public static boolean performBlockDamage(@Nullable Ref<EntityStore> ref, @Nullable Ref<EntityStore> impactRef, @Nonnull org.joml.Vector3i targetBlockPos, @Nullable ItemStack itemStack, @Nullable ItemTool tool, @Nullable String toolId, boolean matchTool, float damageScale, int setBlockSettings, boolean isExplosion, @Nonnull Ref<ChunkStore> sectionReference, @Nonnull ComponentAccessor<EntityStore> entityStore, @Nonnull ComponentAccessor<ChunkStore> chunkStore)
      Damages the single block at the given position, breaking it once its health reaches zero.

      Tool durability is always consumed for the hit (subject to the usual gating in applyItemDurabilityLoss(Ref, ItemStack, Item, BlockType, ActiveSlotInventoryComponent, ComponentAccessor)).

      To damage several blocks from one action, prefer the List-based overload.

      Parameters:
      ref - The instigating entity, or null.
      impactRef - The entity that physically reached the block, which is the projectile when one acts for its shooter. Pass ref when they are the same entity.
      targetBlockPos - The position of the block to damage.
      itemStack - The item stack of the held item, or null.
      tool - The item tool to reference, or null to derive it from the item.
      toolId - The tool id to break as, or null.
      matchTool - Whether the block must match the configured tool to be damaged.
      damageScale - A multiplier applied to the calculated damage.
      setBlockSettings - The SetBlockSettings to apply.
      isExplosion - Whether the damage originates from an explosion.
      sectionReference - The reference of the target block's chunk section entity.
      entityStore - The ComponentAccessor<EntityStore> for component access.
      chunkStore - The ComponentAccessor<ChunkStore> for component access.
      Returns:
      true if the block was broken, false otherwise.
    • performBlockDamage

      public static int performBlockDamage(@Nullable Ref<EntityStore> ref, @Nullable Ref<EntityStore> impactRef, @Nonnull List<org.joml.Vector3i> targetBlocks, @Nonnull org.joml.Vector3i anchorBlock, @Nullable ItemStack itemStack, @Nullable ItemTool tool, @Nullable String toolId, boolean matchTool, float damageScale, int setBlockSettings, boolean isExplosion, boolean durabilityPerBlock, @Nonnull ComponentAccessor<EntityStore> entityStore, @Nonnull ComponentAccessor<ChunkStore> chunkStore)
      Applies block damage to a collection of blocks (which may span multiple chunks) using a single item, for example a shaped break.

      When durabilityPerBlock is false the whole set is treated as a single swing: tool durability is charged once, against anchorBlock (the aimed-at block), no matter how many blocks the set contains or how many break. When it is true, every damaged block consumes durability independently.

      Parameters:
      ref - The instigating entity, or null.
      impactRef - The entity that physically reached the block, which is the projectile when one acts for its shooter. Pass ref when they are the same entity.
      targetBlocks - The blocks to damage.
      anchorBlock - The aimed-at block; the per-swing durability cost is charged against it.
      itemStack - The item stack used, or null.
      tool - The item tool to reference, or null to derive from the item.
      toolId - The tool id to break as, or null.
      matchTool - Whether the block must match the configured tool to be damaged.
      damageScale - A multiplier applied to the calculated damage.
      setBlockSettings - The SetBlockSettings to apply.
      isExplosion - Whether the damage originates from an explosion.
      durabilityPerBlock - Whether every broken block consumes durability, or only the primary.
      entityStore - The ComponentAccessor<EntityStore> for component access.
      chunkStore - The ComponentAccessor<ChunkStore> for component access.
      Returns:
      The number of blocks that were broken.
    • performBlockBreak

      public static void performBlockBreak(@Nullable Ref<EntityStore> ref, @Nullable ItemStack heldItemStack, @Nonnull org.joml.Vector3i targetBlock, @Nonnull Ref<ChunkStore> sectionReference, @Nonnull ComponentAccessor<EntityStore> entityStore, @Nonnull ComponentAccessor<ChunkStore> chunkStore)
      Parameters:
      ref - The instigating entity, or null.
      heldItemStack - The item stack of the held item, or null.
      targetBlock - The position of the block to break.
      sectionReference - The reference of the target block's chunk section entity.
      entityStore - The ComponentAccessor<EntityStore> for component access.
      chunkStore - The ComponentAccessor<ChunkStore> for component access.
    • performBlockBreak

      public static int performBlockBreak(@Nullable Ref<EntityStore> ref, @Nullable ItemStack heldItemStack, @Nonnull List<org.joml.Vector3i> targetBlocks, int setBlockSettings, @Nonnull ComponentAccessor<EntityStore> entityStore, @Nonnull ComponentAccessor<ChunkStore> chunkStore)
      Breaks a collection of blocks (which may span multiple chunks) using a single item, for example a creative-mode shaped break.
      Parameters:
      ref - The entity reference of the instigating entity, or null.
      heldItemStack - The item stack of the held item, if any.
      targetBlocks - The positions of the blocks to break.
      setBlockSettings - Determines the block breaking behavior.
      entityStore - The ComponentAccessor<EntityStore> for component access.
      chunkStore - The ComponentAccessor<ChunkStore> for component access.
      Returns:
      The number of blocks that were processed for breaking.
    • performBlockBreak

      public static void performBlockBreak(@Nullable Ref<EntityStore> ref, @Nullable ItemStack heldItemStack, @Nonnull org.joml.Vector3i targetBlock, int setBlockSettings, @Nonnull Ref<ChunkStore> sectionReference, @Nonnull ComponentAccessor<EntityStore> entityStore, @Nonnull ComponentAccessor<ChunkStore> chunkStore)
      Breaks the block at the given position, resolving filler blocks so that breaking any cell of a multi-block structure breaks the whole structure.
      Parameters:
      ref - The instigating entity, or null.
      heldItemStack - The item stack of the held item, or null.
      targetBlock - The position of the block to break.
      setBlockSettings - The SetBlockSettings that determine the break behavior.
      sectionReference - The reference of the target block's chunk section entity.
      entityStore - The ComponentAccessor<EntityStore> for component access.
      chunkStore - The ComponentAccessor<ChunkStore> for component access.
    • performBlockBreak

      public static void performBlockBreak(@Nullable Ref<EntityStore> ref, @Nullable Ref<EntityStore> impactRef, @Nullable ItemStack heldItemStack, @Nonnull org.joml.Vector3i targetBlock, int setBlockSettings, @Nonnull Ref<ChunkStore> sectionReference, @Nonnull ComponentAccessor<EntityStore> entityStore, @Nonnull ComponentAccessor<ChunkStore> chunkStore)
      Breaks the block at the given position and attributes the break separately from the entity that physically reached it. Resolves filler cells to the base cell of a multi-block structure.
      Parameters:
      ref - The instigating entity, or null.
      impactRef - The entity that physically reached the block, or null.
      heldItemStack - The item stack of the held item, or null.
      targetBlock - The position of the block to break.
      setBlockSettings - The SetBlockSettings that determine the break behavior.
      sectionReference - The reference of the target block's chunk section entity.
      entityStore - The ComponentAccessor<EntityStore> for component access.
      chunkStore - The ComponentAccessor<ChunkStore> for component access.
    • performBlockBreak

      public static void performBlockBreak(@Nonnull org.joml.Vector3i blockPosition, @Nonnull BlockType targetBlockTypeKey, @Nullable ItemStack heldItemStack, int dropQuantity, @Nullable String dropItemId, @Nullable String dropListId, int setBlockSettings, @Nullable Ref<EntityStore> ref, @Nonnull Ref<ChunkStore> sectionReference, @Nonnull ComponentAccessor<EntityStore> entityStore, @Nonnull ComponentAccessor<ChunkStore> chunkStore)
      Convenience overload of performBlockBreak(Vector3i, BlockType, ItemStack, int, String, String, int, Ref, Ref, Ref, ComponentAccessor, ComponentAccessor) for a break where the instigating entity reached the block itself.
      Parameters:
      blockPosition - The position of the block to break.
      targetBlockTypeKey - The block type being broken.
      heldItemStack - The item stack of the held item, or null.
      dropQuantity - The quantity of items to drop on breaking.
      dropItemId - The id of the item to drop, or null.
      dropListId - The id of the drop list to roll, or null.
      setBlockSettings - The SetBlockSettings that determine the break behavior.
      ref - The instigating entity, or null.
      sectionReference - The reference of the target block's chunk section entity.
      entityStore - The ComponentAccessor<EntityStore> for component access.
      chunkStore - The ComponentAccessor<ChunkStore> for component access.
    • performBlockBreak

      public static void performBlockBreak(@Nonnull org.joml.Vector3i blockPosition, @Nonnull BlockType targetBlockTypeKey, @Nullable ItemStack heldItemStack, int dropQuantity, @Nullable String dropItemId, @Nullable String dropListId, int setBlockSettings, @Nullable Ref<EntityStore> ref, @Nullable Ref<EntityStore> impactRef, @Nonnull Ref<ChunkStore> sectionReference, @Nonnull ComponentAccessor<EntityStore> entityStore, @Nonnull ComponentAccessor<ChunkStore> chunkStore)
      The core block-break implementation: removes the block and spawns its drops, firing a cancellable BreakBlockEvent when an instigating entity is present.
      Parameters:
      blockPosition - The position of the block to break.
      targetBlockTypeKey - The block type being broken.
      heldItemStack - The item stack of the held item, or null.
      dropQuantity - The quantity of items to drop on breaking.
      dropItemId - The id of the item to drop, or null.
      dropListId - The id of the drop list to roll, or null.
      setBlockSettings - The SetBlockSettings that determine the break behavior.
      ref - The instigating entity, or null.
      impactRef - The entity that physically reached the block, which is the projectile when one acts for its shooter. Pass ref when they are the same entity.
      sectionReference - The reference of the target block's chunk section entity.
      entityStore - The ComponentAccessor<EntityStore> for component access.
      chunkStore - The ComponentAccessor<ChunkStore> for component access.
    • naturallyRemoveBlockByPhysics

      @Deprecated public static void naturallyRemoveBlockByPhysics(@Nonnull org.joml.Vector3i blockPosition, @Nonnull BlockType blockType, int filler, int setBlockSettings, @Nonnull Ref<ChunkStore> sectionReference, @Nonnull ComponentAccessor<EntityStore> entityStore, @Nonnull ComponentAccessor<ChunkStore> chunkStore)
      Removes the block at the given position as a physics-driven break, deriving its drops from the block's own gathering data.
      Parameters:
      blockPosition - The position of the block to remove.
      blockType - The block type being removed.
      filler - The packed filler offset of the block.
      setBlockSettings - The SetBlockSettings that determine the removal behavior.
      sectionReference - The reference of the target block's chunk section entity.
      entityStore - The ComponentAccessor<EntityStore> for component access.
      chunkStore - The ComponentAccessor<ChunkStore> for component access.
    • naturallyRemoveBlock

      public static void naturallyRemoveBlock(@Nonnull org.joml.Vector3i blockPosition, @Nullable BlockType blockType, int filler, int quantity, String itemId, String dropListId, int setBlockSettings, @Nonnull Ref<ChunkStore> sectionReference, @Nonnull ComponentAccessor<EntityStore> entityStore, @Nonnull ComponentAccessor<ChunkStore> chunkStore)
      Removes the block at the given position and spawns its drops, resolving filler blocks back to their origin.
      Parameters:
      blockPosition - The position of the block to remove.
      blockType - The block type being removed, or null for a no-op.
      filler - The packed filler offset of the block.
      quantity - The quantity of items to drop.
      itemId - The id of the item to drop, or null.
      dropListId - The id of the drop list to roll, or null.
      setBlockSettings - The SetBlockSettings that determine the removal behavior.
      sectionReference - The reference of the target block's chunk section entity.
      entityStore - The ComponentAccessor<EntityStore> for component access.
      chunkStore - The ComponentAccessor<ChunkStore> for component access.
    • shouldPickupByInteraction

      public static boolean shouldPickupByInteraction(@Nullable BlockType blockType)
      Determines whether the given block type can be picked up via interaction.
      Parameters:
      blockType - The block type to check.
      Returns:
      true if it can be picked up via interaction, false otherwise.
    • performPickupByInteraction

      public static void performPickupByInteraction(@Nonnull Ref<EntityStore> ref, @Nonnull org.joml.Vector3i targetBlock, @Nonnull BlockType blockType, int filler, @Nonnull Ref<ChunkStore> sectionReference, @Nonnull BlockSection blockSection, @Nonnull ComponentAccessor<EntityStore> entityStore, @Nonnull ComponentAccessor<ChunkStore> chunkStore)
      Harvests (picks up) the block at the given position straight into the entity's inventory, as used by harvest interactions.
      Parameters:
      ref - The instigating entity.
      targetBlock - The position of the block to harvest.
      blockType - The block type of the target block.
      filler - The packed filler offset of the block.
      sectionReference - The reference of the target block's chunk section entity.
      blockSection - The BlockSection of the target block's chunk section.
      entityStore - The ComponentAccessor<EntityStore> for component access.
      chunkStore - The ComponentAccessor<ChunkStore> for component access.
    • getDrops

      @Nonnull public static List<ItemStack> getDrops(@Nonnull BlockType blockType, int quantity, @Nullable String itemId, @Nullable String dropListId)
      Builds the list of item stacks to drop for a broken block.
      Parameters:
      blockType - The block type that was broken.
      quantity - The quantity to drop.
      itemId - The id of an explicit item to drop, or null.
      dropListId - The id of the drop list to roll, or null.
      Returns:
      A new list of ItemStacks to drop, possibly empty.
    • fireOnBreakInteraction

      public static void fireOnBreakInteraction(@Nullable Ref<EntityStore> breakerRef, @Nullable Ref<EntityStore> impactRef, @Nonnull BlockType blockType, @Nonnull org.joml.Vector3i blockPosition, int rotationIndex, int setBlockSettings, @Nonnull ComponentAccessor<EntityStore> entityStore)
      Fires the InteractionType.OnBreak interaction chain defined on the broken block type, if any. Does nothing when the break has no instigator, when the break set SetBlockSettings.NO_FIRE_ON_BREAK, or when the break happens outside a tick, where no CommandBuffer is available to queue the chain with.
      Parameters:
      breakerRef - The entity the break is attributed to, or null if the break has no instigator. This is the shooter when a projectile broke the block.
      impactRef - The entity that physically reached the block, which is the projectile when one acts for its shooter. The chain runs for this entity, so distance checks measure from it. Pass breakerRef when they are the same entity.
      blockType - The block type that was broken.
      blockPosition - The position where the block was broken.
      rotationIndex - The rotation index the block had before being removed.
      setBlockSettings - The SetBlockSettings flags the block was removed with.
      entityStore - The entity store for component access.
    • queueOnBreakImpactInteraction

      public static void queueOnBreakImpactInteraction(@Nonnull Ref<EntityStore> attributedRef, @Nonnull BlockType blockType, @Nonnull org.joml.Vector3i blockPosition, int rotationIndex, @Nonnull CommandBuffer<EntityStore> commandBuffer)
      Queues the InteractionType.OnBreakImpact interaction chain defined on the block type, if any. Fired for blocks broken by impact (e.g. a falling block landing) rather than by direct damage or gathering.
      Parameters:
      attributedRef - The reference the break is attributed to. A falling block holds no interaction manager and is removed on impact, so those breaks run on a host instead.
      blockType - The block type that was broken.
      blockPosition - The position where the block was broken.
      rotationIndex - The rotation index the block had before being removed.
      commandBuffer - The command buffer for the current tick.