Jump to content

Swing arm/tool on use


Recommended Posts

I am using the following snippet inside of an onBlockClicked event listener to strip a custom log.


public static void onBlockClicked(PlayerInteractEvent.RightClickBlock event) {
    final int FLAG_BLOCK_UPDATE = 1;
    final int FLAG_SEND_TO_CLIENTS = 2;

    if (event.getItemStack().getItem() instanceof AxeItem) {
        World world = event.getWorld();
        BlockPos blockpos = event.getPos();
        BlockState blockstate = world.getBlockState(blockpos);
        Block block = BLOCK_STRIPPING_MAP.get(blockstate.getBlock());
        if (block != null) {
            PlayerEntity playerentity = event.getPlayer();
            world.playSound(playerentity, blockpos, SoundEvents.ITEM_AXE_STRIP, SoundCategory.BLOCKS, 1.0F, 1.0F);
            if (!world.isRemote) {
                world.setBlockState(blockpos, block.getDefaultState()
                if (playerentity != null) {
                    event.getItemStack().damageItem(1, playerentity, (entityIn) -> {


Everything works as expected, except the axe doesn't "swing" as it does with vanilla blocks. It just does nothing. I tried using


but that does absolutely nothing. How can I achieve a swinging tool?

Link to comment
Share on other sites

Why don't you use the onBlockActivated method of your custom log class to handle this? You can take a look at this template class that represents a stripable log: https://github.com/Beethoven92/BetterEndForge/blob/master/src/main/java/mod/beethoven92/betterendforge/common/block/template/StripableLogBlockTemplate.java

Check out the port of the BetterEnd fabric mod (WIP): https://www.curseforge.com/minecraft/mc-mods/betterend-forge-port

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

By using this site, you agree to our Terms of Use.