I'm having trouble with a code. I'm trying to make it where if you r-click a snowball entity in the air, you get a snowball item in your inventory. For some reason this will work with all entities except arrows and snowballs. Does PlayerInteractEntityEvent not work with projectiles?
Create an account or sign in to comment.
7
1
Can anybody tell me why this code isn't working with arrows and snowballs? It works perfectly fine with other entities. I have tested it on cows, pigs, chickens, squids, and fireballs and it works. Why is it not on snowballs?
1
If you want them to have an item in their hand you can use:
player.setItemInHand(new ItemStack(Material.SNOW_BALL));
but their hand would have to be empty i think to have the item you could try it and see if it works
player.setItemInHand(new ItemStack(Material.SNOW_BALL));
but their hand would have to be empty i think to have the item you could try it and see if it works
1
Make sure that your method has a @EventHandler annotation, and that the event i s registered. Try to see if the entity is an instance of a projectile, and then check if the projectile is an instance of a snowball. You might haver to use PlayerInteractEvent, then get the player's line of sight and check for a snowball.
1
I already had it deprecated, I'm sorry I forgot to put that in there. I tried it with Entity entity = e.getRightClicked();, but it still isn't working(though it does with other entities.)
1
i have no idea what Entity entity = ((PlayerInteractEntityEvent) e).getRightClicked(); is supposed to do
-> Entity entity = e.getRightClicked();
no idea why it wouldn't work then
http://prntscr.com/2qqj66
p.updateInventory() is deprecated
-> Entity entity = e.getRightClicked();
no idea why it wouldn't work then
http://prntscr.com/2qqj66
p.updateInventory() is deprecated
1
public void onSnowballCatch(PlayerInteractEntityEvent e){
Player p = e.getPlayer();
Entity entity = ((PlayerInteractEntityEvent) e).getRightClicked();
if(entity instanceof Snowball){
p.getInventory().addItem(new ItemStack(Material.SNOW_BALL));
p.updateInventory();
}
}
1
could you paste your current code?. Yes PlayerInterractEntityEvent does work with snowball