jonaskohl Posted April 7, 2021 Posted April 7, 2021 I am using the following snippet inside of an onBlockClicked event listener to strip a custom log. Reveal hidden contents @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? Quote
Beethoven92 Posted April 7, 2021 Posted April 7, 2021 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 Quote Check out the port of the BetterEnd fabric mod (WIP): https://www.curseforge.com/minecraft/mc-mods/betterend-forge-port
Recommended Posts
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.