Jump to content

Recommended Posts

Posted

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

Spoiler

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

    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()
                        .with(RotatedPillarBlock.AXIS,
                              blockstate.get(RotatedPillarBlock.AXIS)),
                         FLAG_BLOCK_UPDATE | FLAG_SEND_TO_CLIENTS | FLAG_FORCE_RERENDER_MAIN_THREAD);
                if (playerentity != null) {
                    playerentity.swingArm(event.getHand());
                    event.getItemStack().damageItem(1, playerentity, (entityIn) -> {
                        entityIn.sendBreakAnimation(event.getHand());
                    });
                }
            }
        }
    }
}

 

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

playerentity.swingArm(event.getHand());

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

Posted

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

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.

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

Announcements



×
×
  • Create New...

Important Information

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