List of usage examples for net.minecraftforge.event.entity.player EntityItemPickupEvent EntityItemPickupEvent
public EntityItemPickupEvent(PlayerEntity player, ItemEntity item)
From source file:md.zazpro.mod.common.baubles.Ring_NotLMagnet.java
License:Open Source License
@Override public void onWornTick(ItemStack item, EntityLivingBase e) { if (!(e instanceof EntityPlayer)) { return;/*from w ww . ja va 2 s. c o m*/ } EntityPlayer player = (EntityPlayer) e; World world = player.worldObj; if (world.isRemote) { return; } int cooldown = getCooldown(item); if (cooldown <= 0) { Iterator iterator = getEntitiesInRange(EntityItem.class, world, player).iterator(); while (iterator.hasNext()) { EntityItem itemToGet = (EntityItem) iterator.next(); if (isItemInRangeOfNegator(world, itemToGet)) { EntityItemPickupEvent pickupEvent = new EntityItemPickupEvent(player, itemToGet); ItemStack itemStackToGet = itemToGet.getEntityItem(); int stackSize = itemStackToGet.stackSize; if ((pickupEvent.getResult() == Event.Result.ALLOW) || (stackSize <= 0) || (player.inventory.addItemStackToInventory(itemStackToGet))) { player.onItemPickup(itemToGet, stackSize); } } } iterator = getEntitiesInRange(EntityXPOrb.class, world, player).iterator(); while (iterator.hasNext()) { EntityXPOrb xpToGet = (EntityXPOrb) iterator.next(); if ((!xpToGet.isDead) && (!xpToGet.isInvisible())) { int xpAmount = xpToGet.xpValue; xpToGet.xpValue = 0; player.xpCooldown = 0; player.addExperience(xpAmount); xpToGet.setDead(); xpToGet.setInvisible(true); } } } else setCooldown(item, cooldown - 1); }