Class BlockBreakHandler

java.lang.Object
org.geysermc.geyser.session.cache.BlockBreakHandler

public class BlockBreakHandler extends Object
Class responsible for block breaking handling. This is designed to be extensible by extensions (not officially supported!).
  • Field Details

    • session

      protected final GeyserSession session
    • currentBlockPos

      protected @Nullable org.cloudburstmc.math.vector.Vector3i currentBlockPos
      The position of the current block being broken. Null indicates no block breaking in progress.
    • currentBlockState

      protected @Nullable BlockState currentBlockState
      The current block state that is being broken. Null indicates no block breaking in progress.
    • updatedServerBlockStateId

      protected @Nullable Integer updatedServerBlockStateId
      Indicates that we should re-check the current block state for changes
    • serverSideBlockBreaking

      protected boolean serverSideBlockBreaking
      Whether we must break the block ourselves. Only set when keeping track of custom blocks / custom items breaking blocks.
    • currentProgress

      protected float currentProgress
      The current block breaking progress
    • currentBlockFace

      protected Direction currentBlockFace
      The last known face of the block the client was breaking. Only set when keeping track of custom blocks / custom items breaking blocks.
    • currentItemStack

      protected GeyserItemStack currentItemStack
      The last item used to break blocks. Used to track whether block breaking should be re-started as the item changed
    • lastMinedPosition

      protected org.cloudburstmc.math.vector.Vector3i lastMinedPosition
      The last block position that was broken. Used to ignore subsequent block actions from the Bedrock client.
    • restoredBlocks

      protected Set<org.cloudburstmc.math.vector.Vector3i> restoredBlocks
      Caches all blocks we had to restore e.g. due to out-of-range or being unable to mine in order to avoid duplicate corrections.
    • itemFramePos

      protected @Nullable org.cloudburstmc.math.vector.Vector3i itemFramePos
      Used to ignore subsequent block interactions after an item frame interaction
  • Constructor Details

    • BlockBreakHandler

      public BlockBreakHandler(GeyserSession session)
  • Method Details

    • handlePlayerAuthInputPacket

      public void handlePlayerAuthInputPacket(org.cloudburstmc.protocol.bedrock.packet.PlayerAuthInputPacket packet)
      Main entrypoint that handles block breaking actions, if present. Ticks the handler if no breaking actions were performed.
      Parameters:
      packet - the player auth input packet
    • tick

      protected void tick(long tick)
    • handleBlockBreakActions

      protected void handleBlockBreakActions(org.cloudburstmc.protocol.bedrock.packet.PlayerAuthInputPacket packet)
    • handleStartBreak

      protected void handleStartBreak(@NonNull org.cloudburstmc.math.vector.Vector3i position, @NonNull BlockState state, Direction blockFace, long tick)
    • handleContinueDestroy

      protected void handleContinueDestroy(@NonNull org.cloudburstmc.math.vector.Vector3i position, @NonNull BlockState state, @NonNull Direction blockFace, boolean bedrockDestroyed, boolean sendParticles, long tick)
    • handlePredictDestroy

      protected void handlePredictDestroy(org.cloudburstmc.math.vector.Vector3i position, BlockState state, Direction blockFace, long tick)
    • testForItemFrameEntity

      protected boolean testForItemFrameEntity(org.cloudburstmc.math.vector.Vector3i position)
      Tests for a previous item frame block interaction, or the presence of an item frame at the position.
      Returns:
      whether block breaking must stop due to an item frame interaction
    • canBreak

      protected boolean canBreak(org.cloudburstmc.math.vector.Vector3i vector, BlockState state, org.cloudburstmc.protocol.bedrock.data.PlayerActionType action)
      Checks whether a block interaction may proceed, or whether it must be interrupted. This includes world border, "hands busy" (boat steering), and GameMode checks.
    • canDestroyBlock

      protected boolean canDestroyBlock(BlockState state)
    • mayBreak

      protected boolean mayBreak(float progress, boolean bedrockDestroyed)
    • destroyBlock

      protected void destroyBlock(BlockState state, org.cloudburstmc.math.vector.Vector3i vector, Direction direction, boolean instamine)
    • calculateBreakProgress

      protected float calculateBreakProgress(BlockState state, org.cloudburstmc.math.vector.Vector3i vector, GeyserItemStack stack)
    • testForLastBreakPosOrReset

      protected boolean testForLastBreakPosOrReset(org.cloudburstmc.math.vector.Vector3i position)
      Helper method to ignore all insta-break actions that were already sent to the Java server. This ensures that Geyser does not send a FINISH_DIGGING player action for instantly mined blocks, or those mined while in creative mode.
    • clearCurrentVariables

      protected void clearCurrentVariables()
      Resets variables after a block was broken.
    • reset

      public void reset()
      Resets the handler, including variables that persist across single packets
    • getCurrentBlockPos

      public @Nullable org.cloudburstmc.math.vector.Vector3i getCurrentBlockPos()
      The position of the current block being broken. Null indicates no block breaking in progress.
    • setUpdatedServerBlockStateId

      public void setUpdatedServerBlockStateId(@Nullable Integer updatedServerBlockStateId)
      Indicates that we should re-check the current block state for changes
    • getDestructionStageCache

      public com.google.common.cache.Cache<org.cloudburstmc.math.vector.Vector3i,it.unimi.dsi.fastutil.Pair<Long,org.geysermc.mcprotocollib.protocol.data.game.entity.player.BlockBreakStage>> getDestructionStageCache()
      See JavaBlockDestructionTranslator for usage and explanation