Ghten Posted January 3, 2018 Posted January 3, 2018 @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:
American2050 Posted January 3, 2018 Posted January 3, 2018 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.
Ghten Posted January 3, 2018 Author Posted January 3, 2018 (edited) 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 January 3, 2018 by Ghten
American2050 Posted January 3, 2018 Posted January 3, 2018 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 If player is sneaking, "do nothing"
Ghten Posted January 3, 2018 Author Posted January 3, 2018 Just now, American2050 said: Apply it only when player is not sneaking, as you did on the code you showing us 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
American2050 Posted January 3, 2018 Posted January 3, 2018 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
Recommended Posts