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 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 tracker tooltip here.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 to be displayed on the HUD after hacking is complete, as long asafterHackTick(BlockGetter, BlockPos)continues to returning true, e.g.default booleanafterHackTick(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 booleancanHack(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.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
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 worldpos- the block posplayer- 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 whencanHack(BlockGetter, BlockPos, Player)has returned true. Keep this message short; one short sentence 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 to be displayed on the HUD after hacking is complete, as long asafterHackTick(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 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 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 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) Fake up a ray trace result for a targeted block. This is intended to be passed intoBlockBehaviour.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 hackingtargetPos- position of the to-be-hacked block- Returns:
- an optional ray trace result
-