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

@SubscribeEvent
public void PlayerInteractEvent(PlayerInteractEvent event)
{
    Block block = event.world.getBlock(event.x, event.y, event.z);
    
    if ((event.action == PlayerInteractEvent.Action.LEFT_CLICK_BLOCK) && (event.world.getBlock(event.x, event.y, event.z) == Blocks.tnt) &&
       (!event.entityPlayer.isSneaking()))
    {
        EntityTNTPrimed entitytntprimed = new EntityTNTPrimed(event.world, (double)((float)event.x + 0.5F), (double)event.y+0.5, (double)((float)event.z + 0.5F), null);
        event.world.spawnEntityInWorld(entitytntprimed);
    }
}

--------------------------------------------------------

I have this code to ignite tnt when you punch it. It works, but it still drops the tnt as an item. How can I fix that? C:

You need to cancel the drops. Not sure if you can from that event, if not try BlockEvent.BreakEvent
And look there for cancelling the event event.setCanceled(true); or a way to remove the drops. I think you can access the list of drops and clear it.

  • Author
2 minutes ago, American2050 said:

You need to cancel the drops. Not sure if you can from that event, if not try BlockEvent.BreakEvent
And look there for cancelling the event event.setCanceled(true); or a way to remove the drops. I think you can access the list of drops and clear it.

That one works kinda. But I want to ignite the tnt when you punch it normally (and not drop anything) and when you punch it and hold shift it shouldn't explode and instead drop the item :L So the drop should only be disabled when I'm not holding shift

Edited by Ghten

1 minute ago, Ghten said:

That one works kinda. But I want to ignite the tnt when you punch it normally (and not drop anything) and when you punch it and hold shift it shouldn't explode and instead drop the item :L So the drop should only be disabled when I'm not holding shift

Apply it only when player is not sneaking, as you did on the code you showing us :P If player is sneaking, "do nothing"

  • Author
Just now, American2050 said:

Apply it only when player is not sneaking, as you did on the code you showing us :P If player is sneaking, "do nothing"

But can I use the event.entityPlayer.isSneaking() inside the BlockEvent.BreakEvent or BlockEvent.HarvestDropsEvent? I couldn't find it :L

EntityPlayer player = event.getPlayer();

 

And don't forget to check if it was actually a player who actually broke the block, because the cause could be an explosion, or a quarry on modded MC

So you can probably can do everything within that Event ;)

  • Guest locked this topic
Guest
This topic is now closed to further replies.

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.