net.minecraftforge.event.entity.player.EntityItemPickupEvent Java Examples

The following examples show how to use net.minecraftforge.event.entity.player.EntityItemPickupEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ItemPickupEventHandler.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
@SubscribeEvent
public void onEntityItemPickupEvent(EntityItemPickupEvent event)
{
    if (ItemPickupManager.onEntityItemPickupEvent(event))
    {
        return;
    }

    if (ItemHandyBag.onEntityItemPickupEvent(event))
    {
        return;
    }

    if (ItemNullifier.onEntityItemPickupEvent(event))
    {
        return;
    }
}
 
Example #2
Source File: DroneEntityAIPickupItems.java    From PneumaticCraft with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns whether an in-progress EntityAIBase should continue executing
 */
@Override
public boolean continueExecuting(){
    if(curPickingUpEntity.isDead) return false;
    if(Vec3.createVectorHelper(curPickingUpEntity.posX, curPickingUpEntity.posY, curPickingUpEntity.posZ).distanceTo(drone.getPosition()) < 1.5) {
        ItemStack stack = curPickingUpEntity.getEntityItem();
        if(itemPickupWidget.isItemValidForFilters(stack)) {
            new EventHandlerPneumaticCraft().onPlayerPickup(new EntityItemPickupEvent(drone.getFakePlayer(), curPickingUpEntity));//not posting the event globally, as I don't have a way of handling a canceled event.
            int stackSize = stack.stackSize;
            ItemStack remainder = PneumaticCraftUtils.exportStackToInventory(drone.getInventory(), stack, ForgeDirection.UP);//side doesn't matter, drones aren't ISided.
            if(remainder == null) {
                drone.onItemPickupEvent(curPickingUpEntity, stackSize);
                curPickingUpEntity.setDead();
            }
        }
        return false;
    }
    return !drone.getPathNavigator().hasNoPath();
}
 
Example #3
Source File: AgentQuitFromCollectingItemImplementation.java    From malmo with MIT License 5 votes vote down vote up
@SubscribeEvent
public void onPickupItem(EntityItemPickupEvent event)
{
    if (event.getItem() != null && event.getItem().getEntityItem() != null)
    {
        ItemStack stack = event.getItem().getEntityItem();
        checkForMatch(stack);
    }
}
 
Example #4
Source File: RewardForCollectingItemImplementation.java    From malmo with MIT License 5 votes vote down vote up
@SubscribeEvent
public void onPickupItem(EntityItemPickupEvent event)
{
    if (event.getItem() != null && event.getEntityPlayer() instanceof EntityPlayerMP )
    {
        // This event is received on the server side, so we need to pass it to the client.
        sendItemStackToClient((EntityPlayerMP)event.getEntityPlayer(), MalmoMessageType.SERVER_COLLECTITEM, event.getItem().getEntityItem());
    }
}
 
Example #5
Source File: UpgradeCollector.java    From BetterChests with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
public void pickupItem(EntityItemPickupEvent event) {
	for (int i = 0; i < event.getEntityPlayer().inventory.getSizeInventory() && !event.getItem().getItem().isEmpty(); i++) {
		IUpgradableBlock chest = UpgradeHelper.INSTANCE.getInventory(event.getEntityPlayer().inventory.getStackInSlot(i), event.getEntity());
		if (chest != null) {
			if (!hasUpgradeOperationCost(chest)) {
				continue;
			}

			for (ItemStack upgrade : chest.getActiveUpgrades()) {
				if (upgrade.getItem() == BlocksItemsBetterChests.upgrade && BlocksItemsBetterChests.upgrade.getType(upgrade) == UpgradeType.COLLECTOR) {
					IBetterChest inv = (IBetterChest) chest;
					IFilter filter = ((IBetterChest) chest).getFilterFor(upgrade);
					if (filter.matchesStack(event.getItem().getItem())) {
						ItemStack prev = event.getItem().getItem();
						event.getItem().setItem(InvUtil.putStackInInventoryInternal(event.getItem().getItem(), inv, false));

						if (prev.getCount() != event.getItem().getItem().getCount()) {
							event.setCanceled(true);
							drawUpgradeOperationCode(chest);
							((IBetterChest) chest).markDirty();
						}
					}
					break;
				}
			}
		}
	}
}
 
Example #6
Source File: PlayerItemPickupSensor.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int emitRedstoneOnEvent(PlayerEvent event, TileEntity sensor, int range){
    if(event instanceof EntityItemPickupEvent) {
        return 15;
    }
    return 0;
}
 
Example #7
Source File: RewardForPossessingItemImplementation.java    From malmo with MIT License 4 votes vote down vote up
@SubscribeEvent
public void onPickupItem(EntityItemPickupEvent event) {
    if (event.getItem() != null && event.getEntityPlayer() instanceof EntityPlayerMP)
        checkForMatch(event.getItem().getEntityItem());
}
 
Example #8
Source File: AgentQuitFromCollectingItemQuantityImplementation.java    From malmo with MIT License 4 votes vote down vote up
@SubscribeEvent
public void onPickupItem(EntityItemPickupEvent event) {
    if (event.getItem() != null && event.getEntityPlayer() instanceof EntityPlayerMP)
        checkForMatch(event.getItem().getEntityItem());
}
 
Example #9
Source File: AgentQuitFromPossessingItemImplementation.java    From malmo with MIT License 4 votes vote down vote up
@SubscribeEvent
public void onPickupItem(EntityItemPickupEvent event) {
    if (event.getItem() != null && event.getEntityPlayer() instanceof EntityPlayerMP)
        checkForMatch(event.getItem().getEntityItem());
}
 
Example #10
Source File: RewardForCollectingItemQuantityImplementation.java    From malmo with MIT License 4 votes vote down vote up
@SubscribeEvent
public void onPickupItem(EntityItemPickupEvent event) {
    if (event.getItem() != null && event.getEntityPlayer() instanceof EntityPlayerMP)
        checkForMatch(event.getItem().getEntityItem());
}
 
Example #11
Source File: ItemPickupManager.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Try to handle the items being picked up.
 * @param event
 * @return true to prevent further processing of the event
 */
public static boolean onEntityItemPickupEvent(EntityItemPickupEvent event)
{
    EntityItem entityItem = event.getItem();
    ItemStack stack = entityItem.getItem();
    EntityPlayer player = event.getEntityPlayer();

    if (player.getEntityWorld().isRemote || entityItem.isDead || stack.isEmpty())
    {
        return true;
    }

    ItemStack origStack = ItemStack.EMPTY;
    final int origStackSize = stack.getCount();
    List<ItemStack> managers = getEnabledItems(player);
    // If there are enabled managers in the player's inventory, then initialize to "deny"
    boolean deny = managers.size() > 0;

    //int i = 0;
    for (ItemStack manager : managers)
    {
        // Delayed the stack copying until we know if there is a valid bag,
        // so check if the stack was copied already or not.
        if (origStack == ItemStack.EMPTY)
        {
            origStack = stack.copy();
        }

        Result result = ((ItemPickupManager) manager.getItem()).handleItems(player, manager, stack);

        //System.out.println("i: " + i++ + " result: " + result);
        // Blacklisted or successfully transported, cancel further processing
        if (result == Result.BLACKLISTED || result == Result.TRANSPORTED)
        {
            if (result == Result.TRANSPORTED)
            {
                entityItem.setDead();
            }

            deny = true;
            break;
        }

        // Whitelisted, no need to check any further managers, just allow picking it up
        if (result == Result.WHITELISTED)
        {
            deny = false;
            break;
        }

        // Filters disabled or filtering mode was black list, and the item was not on the black list => allow through
        if (result == Result.NOT_HANDLED || result == Result.NOT_BLACKLISTED)
        {
            deny = false;
        }
    }

    // At least some items were picked up
    if (stack.getCount() != origStackSize || entityItem.isDead)
    {
        if (entityItem.isSilent() == false)
        {
            player.getEntityWorld().playSound(null, player.getPosition(), SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.MASTER, 0.2F,
                    ((player.getEntityWorld().rand.nextFloat() - player.getEntityWorld().rand.nextFloat()) * 0.7F + 1.0F) * 2.0F);
        }

        if (stack.isEmpty() || entityItem.isDead)
        {
            FMLCommonHandler.instance().firePlayerItemPickupEvent(player, entityItem, origStack);
            player.onItemPickup(entityItem, origStackSize);
        }
    }

    if (deny)
    {
        event.setCanceled(true);
    }

    return deny;
}
 
Example #12
Source File: ItemHandyBag.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Tries to first fill the matching stacks in the player's inventory,
 * and then depending on the bag's mode, tries to add the remaining items
 * to the bag's inventory.
 * @param event
 * @return true if all items were handled and further processing of the event should not occur
 */
public static boolean onEntityItemPickupEvent(EntityItemPickupEvent event)
{
    EntityItem entityItem = event.getItem();
    ItemStack stack = entityItem.getItem();
    EntityPlayer player = event.getEntityPlayer();

    if (player.getEntityWorld().isRemote || entityItem.isDead || stack.isEmpty())
    {
        return true;
    }

    ItemStack origStack = ItemStack.EMPTY;
    final int origStackSize = stack.getCount();
    int stackSizeLast = origStackSize;
    boolean ret = false;

    IItemHandler playerInv = player.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
    // Not all the items could fit into existing stacks in the player's inventory, move them directly to the bag
    List<Integer> slots = InventoryUtils.getSlotNumbersOfMatchingItems(playerInv, EnderUtilitiesItems.HANDY_BAG);

    for (int slot : slots)
    {
        ItemStack bagStack = playerInv.getStackInSlot(slot);

        // Bag is not locked
        if (bagStack.isEmpty() == false && bagStack.getItem() == EnderUtilitiesItems.HANDY_BAG && ItemHandyBag.bagIsOpenable(bagStack))
        {
            // Delayed the stack copying until we know if there is a valid bag,
            // so check if the stack was copied already or not.
            if (origStack == ItemStack.EMPTY)
            {
                origStack = stack.copy();
            }

            stack = handleItems(stack, bagStack, player);

            if (stack.isEmpty() || stack.getCount() != stackSizeLast)
            {
                if (stack.isEmpty())
                {
                    entityItem.setDead();
                    event.setCanceled(true);
                    ret = true;
                    break;
                }

                ItemStack pickedUpStack = origStack.copy();
                pickedUpStack.setCount(stackSizeLast - stack.getCount());

                FMLCommonHandler.instance().firePlayerItemPickupEvent(player, entityItem, pickedUpStack);
                player.onItemPickup(entityItem, origStackSize);
            }

            stackSizeLast = stack.getCount();
        }
    }

    // Not everything was handled, update the stack
    if (entityItem.isDead == false && stack.getCount() != origStackSize)
    {
        entityItem.setItem(stack);
    }

    // At least some items were picked up
    if (entityItem.isSilent() == false && (entityItem.isDead || stack.getCount() != origStackSize))
    {
        player.getEntityWorld().playSound(null, player.getPosition(), SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.MASTER,
                0.2F, ((itemRand.nextFloat() - itemRand.nextFloat()) * 0.7F + 1.0F) * 2.0F);
    }

    return ret;
}
 
Example #13
Source File: ItemNullifier.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Tries to first fill the matching stacks in the player's inventory,
 * and then depending on the bag's mode, tries to add the remaining items
 * to the bag's inventory.
 * @param event
 * @return true if all items were handled and further processing of the event should not occur
 */
public static boolean onEntityItemPickupEvent(EntityItemPickupEvent event)
{
    EntityItem entityItem = event.getItem();
    ItemStack stack = entityItem.getItem();
    EntityPlayer player = event.getEntityPlayer();

    if (player.getEntityWorld().isRemote || entityItem.isDead || stack.isEmpty())
    {
        return true;
    }

    ItemStack origStack = ItemStack.EMPTY;
    final int origStackSize = stack.getCount();
    int stackSizeLast = origStackSize;
    boolean ret = false;

    IItemHandler playerInv = player.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
    // Not all the items could fit into existing stacks in the player's inventory, move them directly to the nullifier
    List<Integer> slots = InventoryUtils.getSlotNumbersOfMatchingItems(playerInv, EnderUtilitiesItems.NULLIFIER);

    for (int slot : slots)
    {
        ItemStack nullifierStack = playerInv.getStackInSlot(slot);

        // Nullifier is not disabled
        if (nullifierStack.isEmpty() == false && isNullifierEnabled(nullifierStack))
        {
            // Delayed the stack copying until we know if there is a valid bag,
            // so check if the stack was copied already or not.
            if (origStack == ItemStack.EMPTY)
            {
                origStack = stack.copy();
            }

            stack = handleItems(stack, nullifierStack, player);

            if (stack.isEmpty() || stack.getCount() != stackSizeLast)
            {
                if (stack.isEmpty())
                {
                    entityItem.setDead();
                    event.setCanceled(true);
                    ret = true;
                    break;
                }

                ItemStack pickedUpStack = origStack.copy();
                pickedUpStack.setCount(stackSizeLast - stack.getCount());

                FMLCommonHandler.instance().firePlayerItemPickupEvent(player, entityItem, pickedUpStack);
                player.onItemPickup(entityItem, origStackSize);
            }

            stackSizeLast = stack.getCount();
        }
    }

    // Not everything was handled, update the stack
    if (entityItem.isDead == false && stack.getCount() != origStackSize)
    {
        entityItem.setItem(stack);
    }

    // At least some items were picked up
    if (entityItem.isSilent() == false && (entityItem.isDead || stack.getCount() != origStackSize))
    {
        player.getEntityWorld().playSound(null, player.getPosition(), SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.MASTER,
                0.2F, ((itemRand.nextFloat() - itemRand.nextFloat()) * 0.7F + 1.0F) * 2.0F);
    }

    return ret;
}
 
Example #14
Source File: EventHandlerPneumaticCraft.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
@SubscribeEvent
public void onPlayerPickup(EntityItemPickupEvent event){
    if(event.item != null && event.entityPlayer != null) AchievementHandler.giveAchievement(event.entityPlayer, event.item.getEntityItem());
}
 
Example #15
Source File: EventHandlerUniversalSensor.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
@SubscribeEvent
public void onItemPickUp(EntityItemPickupEvent event){
    sendEventToSensors(event.entity.worldObj, event);
}