Java Code Examples for net.minecraftforge.event.entity.player.EntityItemPickupEvent#getEntityPlayer()
The following examples show how to use
net.minecraftforge.event.entity.player.EntityItemPickupEvent#getEntityPlayer() .
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: RewardForCollectingItemImplementation.java From malmo with MIT License | 5 votes |
@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 2
Source File: RewardForPossessingItemImplementation.java From malmo with MIT License | 4 votes |
@SubscribeEvent public void onPickupItem(EntityItemPickupEvent event) { if (event.getItem() != null && event.getEntityPlayer() instanceof EntityPlayerMP) checkForMatch(event.getItem().getEntityItem()); }
Example 3
Source File: AgentQuitFromCollectingItemQuantityImplementation.java From malmo with MIT License | 4 votes |
@SubscribeEvent public void onPickupItem(EntityItemPickupEvent event) { if (event.getItem() != null && event.getEntityPlayer() instanceof EntityPlayerMP) checkForMatch(event.getItem().getEntityItem()); }
Example 4
Source File: AgentQuitFromPossessingItemImplementation.java From malmo with MIT License | 4 votes |
@SubscribeEvent public void onPickupItem(EntityItemPickupEvent event) { if (event.getItem() != null && event.getEntityPlayer() instanceof EntityPlayerMP) checkForMatch(event.getItem().getEntityItem()); }
Example 5
Source File: RewardForCollectingItemQuantityImplementation.java From malmo with MIT License | 4 votes |
@SubscribeEvent public void onPickupItem(EntityItemPickupEvent event) { if (event.getItem() != null && event.getEntityPlayer() instanceof EntityPlayerMP) checkForMatch(event.getItem().getEntityItem()); }
Example 6
Source File: ItemPickupManager.java From enderutilities with GNU Lesser General Public License v3.0 | 4 votes |
/** * 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 7
Source File: ItemHandyBag.java From enderutilities with GNU Lesser General Public License v3.0 | 4 votes |
/** * 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 8
Source File: ItemNullifier.java From enderutilities with GNU Lesser General Public License v3.0 | 4 votes |
/** * 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; }