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 Summary

    Fields
    Modifier and Type
    Field
    Description
    protected long
    The Bedrock client tick in which block breaking of the current block began.
    protected @Nullable org.cloudburstmc.math.vector.Vector3i
    The position of the current block being broken.
    protected @Nullable BlockState
    The current block state that is being broken.
    protected @Nullable org.cloudburstmc.math.vector.Vector3i
    Used to ignore subsequent block interactions after an item frame interaction
    protected org.geysermc.mcprotocollib.protocol.data.game.entity.object.Direction
    The last known face of the block the client was breaking.
    protected org.cloudburstmc.math.vector.Vector3i
    The last block position that was instantly broken.
    protected Set<org.cloudburstmc.math.vector.Vector3i>
    Caches all blocks we had to restore e.g.
    protected final GeyserSession
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected float
    calculateBreakProgress(BlockState state, org.cloudburstmc.math.vector.Vector3i vector, GeyserItemStack stack)
     
    protected boolean
    canBreak(org.cloudburstmc.math.vector.Vector3i vector, BlockState state)
    Checks whether a block interaction may proceed, or whether it must be interrupted.
    protected boolean
     
    protected void
    Resets variables after a block was broken.
    protected void
    destroyBlock(BlockState state, org.cloudburstmc.math.vector.Vector3i vector, org.geysermc.mcprotocollib.protocol.data.game.entity.object.Direction direction, boolean instamine)
     
    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>>
    See JavaBlockDestructionTranslator for usage and explanation
    protected void
    handleAbortBreaking(org.cloudburstmc.math.vector.Vector3i position)
     
    protected void
    handleBlockBreakActions(org.cloudburstmc.protocol.bedrock.packet.PlayerAuthInputPacket packet)
     
    protected void
    handleContinueDestroy(org.cloudburstmc.math.vector.Vector3i position, BlockState state, org.geysermc.mcprotocollib.protocol.data.game.entity.object.Direction blockFace, long tick)
     
    void
    handlePlayerAuthInputPacket(org.cloudburstmc.protocol.bedrock.packet.PlayerAuthInputPacket packet)
    Main entrypoint that handles block breaking actions, if present.
    protected void
    handlePredictDestroy(org.cloudburstmc.math.vector.Vector3i position, BlockState state, org.geysermc.mcprotocollib.protocol.data.game.entity.object.Direction blockFace, long tick)
     
    protected void
    handleStartBreak(@NonNull org.cloudburstmc.math.vector.Vector3i position, @NonNull BlockState state, org.geysermc.mcprotocollib.protocol.data.game.entity.object.Direction blockFace, long tick)
     
    void
    Resets the handler, including variables that persist across single packets
    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.
    protected boolean
    testForLastInstaBreakPosOrReset(org.cloudburstmc.math.vector.Vector3i position)
    Helper method to ignore all insta-break actions that were already sent to the Java server.
    protected void
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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.
    • blockStartBreakTime

      protected long blockStartBreakTime
      The Bedrock client tick in which block breaking of the current block began. Only set when keeping track of custom blocks / custom items breaking blocks.
    • lastBlockBreakFace

      protected org.geysermc.mcprotocollib.protocol.data.game.entity.object.Direction lastBlockBreakFace
      The last known face of the block the client was breaking. Only set when keeping track of custom blocks / custom items breaking blocks.
    • lastInstaMinedPosition

      protected org.cloudburstmc.math.vector.Vector3i lastInstaMinedPosition
      The last block position that was instantly 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()
    • 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, org.geysermc.mcprotocollib.protocol.data.game.entity.object.Direction blockFace, long tick)
    • handleContinueDestroy

      protected void handleContinueDestroy(org.cloudburstmc.math.vector.Vector3i position, BlockState state, org.geysermc.mcprotocollib.protocol.data.game.entity.object.Direction blockFace, long tick)
    • handlePredictDestroy

      protected void handlePredictDestroy(org.cloudburstmc.math.vector.Vector3i position, BlockState state, org.geysermc.mcprotocollib.protocol.data.game.entity.object.Direction blockFace, long tick)
    • handleAbortBreaking

      protected void handleAbortBreaking(org.cloudburstmc.math.vector.Vector3i position)
    • 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)
      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)
    • destroyBlock

      protected void destroyBlock(BlockState state, org.cloudburstmc.math.vector.Vector3i vector, org.geysermc.mcprotocollib.protocol.data.game.entity.object.Direction direction, boolean instamine)
    • calculateBreakProgress

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

      protected boolean testForLastInstaBreakPosOrReset(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
    • 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