Jump to content

Disable Item drop


Ghten

Recommended Posts

@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:

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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"

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Announcements



×
×
  • Create New...

Important Information

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