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 IPneumaticHelmetRegistry.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 tracker tooltip here.
    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 to be displayed on the HUD after hacking is complete, as long as afterHackTick(BlockGetter, BlockPos) continues to returning true, e.g.
    default boolean
    afterHackTick(net.minecraft.world.level.BlockGetter world, net.minecraft.core.BlockPos pos)
    Called every tick after the hacking finished (on both server and client side).
    default boolean
    canHack(net.minecraft.world.level.BlockGetter world, net.minecraft.core.BlockPos pos, net.minecraft.world.entity.player.Player player)
    Returning true will allow the player to hack this block.
    default Optional<net.minecraft.world.phys.BlockHitResult>
    fakeRayTrace(net.minecraft.world.entity.player.Player player, net.minecraft.core.BlockPos targetPos)
    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

      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. Null is a valid return: afterHackTick will not be triggered at all in that case.

      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).

      CURRENTLY THIS ISN'T IMPLEMENTED.

      Returns:
      a unique ID for this hack type
    • canHack

      default boolean canHack(net.minecraft.world.level.BlockGetter world, net.minecraft.core.BlockPos pos, net.minecraft.world.entity.player.Player player)
      Returning true will allow the player to hack this block. This can be used to only allow hacking under certain conditions.
      Parameters:
      world - the world
      pos - the block pos
      player - the player observing 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 tracker tooltip here. Text like "Hack to explode" can be added. This method is only called when canHack(BlockGetter, BlockPos, Player) has returned true. Keep this message short; one short sentence 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 to be displayed on the HUD after hacking is complete, as long as afterHackTick(BlockGetter, BlockPos) continues to returning true, e.g. "Spawner Disabled". Keep this message short; one short sentence or even a couple of words 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 hacking finished (on both server and client side). Returning true will keep this going (for mob spawners, to keep them neutralized), or false to stop ticking for one-shot hacks (e.g. door/lever hacking).

      CURRENTLY THIS METHOD WILL STOP GETTING INVOKED AFTER A SERVER RESTART!

      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)
      Fake up a ray trace result for a targeted block. This is intended to be passed into BlockBehaviour.BlockStateBase.use(Level, Player, InteractionHand, BlockHitResult), which needs a non-null ray trace result to get the block's position.
      Parameters:
      player - player doing the hacking
      targetPos - position of the to-be-hacked block
      Returns:
      an optional ray trace result