Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hey everyone,

 

So, I am trying to make a block look like it gets broken when you right click it, without destroying the actual block. I am using playSound() and spawnParticle() to achieve this. But, for some reason, these are not working. I have never used these methods before, so I can't really figure out the reason why they're not working. I know for a fact that they are running because the line, infused_log.carveAmount++ , is working. Here is the method:

 

@Override
    public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
        if(worldIn.getTileEntity(pos) != null) {
            if (worldIn.getTileEntity(pos) instanceof TileEntityInfusedLog) {
                TileEntityInfusedLog infused_log = (TileEntityInfusedLog) worldIn.getTileEntity(pos);
              
                worldIn.playSound(pos.getX(), pos.getY(), pos.getZ(), SoundEvents.BLOCK_WOOD_BREAK, SoundCategory.BLOCKS, 1000.0f, 1.0f, false);
                worldIn.spawnParticle(EnumParticleTypes.CLOUD, pos.getX(), pos.getY() + 1.0D, pos.getX(), 0.0, 0.0, 0.0, new int[0]);
                infused_log.carveAmount++;
            }
        }
        return super.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ);
    }

 

Thanks!

Edited by MSpace-Dev
Changed font

  • Author

(Debug mode wasn't on)

Re-added if(worldIn.isRemote) {}

 

Edited by MSpace-Dev
Added solution

  • Author

Oh, wow. I am such an idiot. I was under the impression that I was running my game on debug mode! All changes  I made weren't actually going through. It's working now =p

 

Anyways, new problem. What params do I use in the spawnParticle to change the blockcrack ID? I know in commands, you type a specific number, but I'm not sure where to put that number in the spawnParticle() method.

  • Author

You work it out like this:

blockId + (metaData * 4096)

 

For example:

 

412 + (0 * 4096) = 412

therefore, the blockcrack ID will be 412.

 

So, my question is how do I get the number ID of my block? There is no like ".getBlockID" type thing

Edited by MSpace-Dev

  • Author

Finally figured it out, after trawling through the MC code

 

worldIn.spawnParticle(EnumParticleTypes.BLOCK_CRACK, pos.getX() + 0.5D, pos.getY() + 0.5D, pos.getZ() + 0.5D, 1.0, 1.0, 1.0, Block.getIdFromBlock(worldIn.getBlockState(pos).getBlock()));

 

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.