Interface IHackableBlock

All Known Implementing Classes:
HackableButton, HackableDispenser, HackableDoor, HackableJukebox, HackableLever, HackableMobSpawner, HackableNoteblock, HackableSecurityStation, HackableSilverfish, HackableTNT, HackableTrapDoor, HackableTripwire

public interface IHackableBlock
Use this interface to specify any hackable block. When it's your block, you can simply implement this interface in your block's class. If you don't have access to the class (vanilla blocks or blocks from other mods), you can implement this interface in a separate class and register it using ICommonArmorRegistry.addHackable(Block, Supplier) . With the former way there will be one instance only per type. In the latter, there will be an IHackableBlock instance for every block.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addInfo(net.minecraft.world.level.BlockGetter world, net.minecraft.core.BlockPos pos, List<net.minecraft.network.chat.Component> curInfo, net.minecraft.world.entity.player.Player player)
    Add info that is displayed on the block tracker panel, describing what the hack would do to the block.
    void
    addPostHackInfo(net.minecraft.world.level.BlockGetter world, net.minecraft.core.BlockPos pos, List<net.minecraft.network.chat.Component> curInfo, net.minecraft.world.entity.player.Player player)
    Add info that is displayed on the block tracker panel, describing what the hack has done to the block.
    default boolean
    afterHackTick(net.minecraft.world.level.BlockGetter world, net.minecraft.core.BlockPos pos)
    Called every tick after the hack completed.
    default boolean
    canHack(net.minecraft.world.level.BlockGetter level, net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState state, net.minecraft.world.entity.player.Player player)
    Can this block actually be hacked? This will normally return true, since the object is registered with the block, but this can be overridden to filter hackability by the actual blockstate (e.g Jukeboxes can only be hacked when they contain a music disc), or by some property of the player.
    default Optional<net.minecraft.world.phys.BlockHitResult>
    fakeRayTrace(net.minecraft.world.entity.player.Player player, net.minecraft.core.BlockPos targetPos)
    Convenience method to fake up a ray trace result for a targeted block.
    net.minecraft.resources.ResourceLocation
    Get a unique id to represent this hackable.
    int
    getHackTime(net.minecraft.world.level.BlockGetter world, net.minecraft.core.BlockPos pos, net.minecraft.world.entity.player.Player player)
    Get the time it takes to hack this block in ticks.
    void
    onHackComplete(net.minecraft.world.level.Level world, net.minecraft.core.BlockPos pos, net.minecraft.world.entity.player.Player player)
    When the player has been hacking the block for getHackTime(BlockGetter, BlockPos, Player) ticks, this will be called on both server and client side.
  • Method Details

    • getHackableId

      @Nonnull net.minecraft.resources.ResourceLocation getHackableId()
      Get a unique id to represent this hackable. Used in NBT saving to be able to trigger the afterHackTime after a server restart.

      The returned ResourceLocation should be in the namespace of the mod which adds the hack (which is not necessarily the mod that adds the hackable block).

      Returns:
      a unique ID for this hack type
    • canHack

      default boolean canHack(net.minecraft.world.level.BlockGetter level, net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState state, net.minecraft.world.entity.player.Player player)
      Can this block actually be hacked? This will normally return true, since the object is registered with the block, but this can be overridden to filter hackability by the actual blockstate (e.g Jukeboxes can only be hacked when they contain a music disc), or by some property of the player.

      Note that this can be called on both server and client.

      Parameters:
      level - the world
      pos - the block pos
      state - the blockstate at the given blockpos
      player - the player potentially hacking the block
    • addInfo

      void addInfo(net.minecraft.world.level.BlockGetter world, net.minecraft.core.BlockPos pos, List<net.minecraft.network.chat.Component> curInfo, net.minecraft.world.entity.player.Player player)
      Add info that is displayed on the block tracker panel, describing what the hack would do to the block. This is only called when canHack(BlockGetter, BlockPos, BlockState, Player) has returned true. Keep this message short; one short phrase is enough.
      Parameters:
      world - the world
      pos - the block pos of the to-be-hacked block
      curInfo - text component list to add info to
      player - the player observing the hackable block
    • addPostHackInfo

      void addPostHackInfo(net.minecraft.world.level.BlockGetter world, net.minecraft.core.BlockPos pos, List<net.minecraft.network.chat.Component> curInfo, net.minecraft.world.entity.player.Player player)
      Add info that is displayed on the block tracker panel, describing what the hack has done to the block. This is displayed for a second or so after the hack completes. Keep this message short; one short phrase is enough.
      Parameters:
      world - the world
      pos - the block pos of the hacked block
      curInfo - text component list to add info to
      player - the player observing the hacked block
    • getHackTime

      int getHackTime(net.minecraft.world.level.BlockGetter world, net.minecraft.core.BlockPos pos, net.minecraft.world.entity.player.Player player)
      Get the time it takes to hack this block in ticks. For more powerful hacks, a longer hacking time is recommended.
      Parameters:
      world - the world
      pos - the block pos
      player - the player observing the hackable block
    • onHackComplete

      void onHackComplete(net.minecraft.world.level.Level world, net.minecraft.core.BlockPos pos, net.minecraft.world.entity.player.Player player)
      When the player has been hacking the block for getHackTime(BlockGetter, BlockPos, Player) ticks, this will be called on both server and client side.
      Parameters:
      world - the world
      pos - the block pos
      player - the player observing the hacked block
    • afterHackTick

      default boolean afterHackTick(net.minecraft.world.level.BlockGetter world, net.minecraft.core.BlockPos pos)
      Called every tick after the hack completed. Return false for one-shot hacks, or true to keep this hack ticking. Most hacks are fine as one-shot hacks.
      Parameters:
      world - the world
      pos - the block pos
      Returns:
      true to keep the hack running (e.g. mob spawners), or false for one-shot hacks (e.g. levers/doors)
    • fakeRayTrace

      default Optional<net.minecraft.world.phys.BlockHitResult> fakeRayTrace(net.minecraft.world.entity.player.Player player, net.minecraft.core.BlockPos targetPos)
      Convenience method to fake up a ray trace result for a targeted block. This is intended to be passed into BlockBehaviour.BlockStateBase.use(Level, Player, InteractionHand, BlockHitResult) (often called by onHackComplete(Level, BlockPos, Player)), which needs a non-null ray trace result to know exactly where the player is looking.
      Parameters:
      player - player doing the hacking
      targetPos - position of the to-be-hacked block
      Returns:
      an optional ray trace result