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 TypeMethodDescriptionvoidaddInfo(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.voidaddPostHackInfo(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 booleanafterHackTick(net.minecraft.world.level.BlockGetter world, net.minecraft.core.BlockPos pos) Called every tick after the hack completed.default booleancanHack(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.ResourceLocationGet a unique id to represent this hackable.intgetHackTime(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.voidonHackComplete(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 forgetHackTime(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 worldpos- the block posstate- the blockstate at the given blockposplayer- 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 whencanHack(BlockGetter, BlockPos, BlockState, Player)has returned true. Keep this message short; one short phrase is enough.- Parameters:
world- the worldpos- the block pos of the to-be-hacked blockcurInfo- text component list to add info toplayer- 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 worldpos- the block pos of the hacked blockcurInfo- text component list to add info toplayer- 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 worldpos- the block posplayer- 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 forgetHackTime(BlockGetter, BlockPos, Player)ticks, this will be called on both server and client side.- Parameters:
world- the worldpos- the block posplayer- 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 worldpos- 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 intoBlockBehaviour.BlockStateBase.use(Level, Player, InteractionHand, BlockHitResult)(often called byonHackComplete(Level, BlockPos, Player)), which needs a non-null ray trace result to know exactly where the player is looking.- Parameters:
player- player doing the hackingtargetPos- position of the to-be-hacked block- Returns:
- an optional ray trace result
-