當前位置: 首頁>>代碼示例>>Java>>正文


Java EntityItemPickupEvent.getItem方法代碼示例

本文整理匯總了Java中net.minecraftforge.event.entity.player.EntityItemPickupEvent.getItem方法的典型用法代碼示例。如果您正苦於以下問題:Java EntityItemPickupEvent.getItem方法的具體用法?Java EntityItemPickupEvent.getItem怎麽用?Java EntityItemPickupEvent.getItem使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在net.minecraftforge.event.entity.player.EntityItemPickupEvent的用法示例。


在下文中一共展示了EntityItemPickupEvent.getItem方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: itemPickup

import net.minecraftforge.event.entity.player.EntityItemPickupEvent; //導入方法依賴的package包/類
@SubscribeEvent
public void itemPickup(EntityItemPickupEvent event){
	EntityItem ent = event.getItem();
   	if(ent == null)return;
   	if(!ItemStackTools.isValid(ent.getEntityItem()))return;
   	EntityPlayer player = event.getEntityPlayer();
   	if(player !=null && player.isEntityAlive()){
   		ItemStack backpack = BackpackUtil.getBackpackOnBack(player);
   		if(ItemStackTools.isValid(backpack)){
   			IBackpack backpackType = BackpackUtil.getType(backpack);
   			if(backpackType !=null && backpackType.handleItemPickup(event, player, backpack)){
   				event.setCanceled(true);
   			}
   		}
   	}
}
 
開發者ID:Alec-WAM,項目名稱:CrystalMod,代碼行數:17,代碼來源:EventHandler.java

示例2: onPickupItem

import net.minecraftforge.event.entity.player.EntityItemPickupEvent; //導入方法依賴的package包/類
@SubscribeEvent
public void onPickupItem(EntityItemPickupEvent event)
{
    if (event.getItem() != null && event.getItem().getEntityItem() != null)
    {
        ItemStack stack = event.getItem().getEntityItem();
        checkForMatch(stack);
    }
}
 
開發者ID:Microsoft,項目名稱:malmo,代碼行數:10,代碼來源:AgentQuitFromCollectingItemImplementation.java

示例3: onPickupItem

import net.minecraftforge.event.entity.player.EntityItemPickupEvent; //導入方法依賴的package包/類
@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());
    }
}
 
開發者ID:Microsoft,項目名稱:malmo,代碼行數:10,代碼來源:RewardForCollectingItemImplementation.java

示例4: pickupSeeds

import net.minecraftforge.event.entity.player.EntityItemPickupEvent; //導入方法依賴的package包/類
@SubscribeEvent
public static void pickupSeeds(EntityItemPickupEvent event) {
    boolean handled = false;
    EntityItem entityItem = event.getItem();
    if (entityItem != null) {
        ItemStack leftover = entityItem.getItem();
        InventoryPlayer playerInv = event.getEntityPlayer().inventory;
        for (int i = 0; i < playerInv.getSizeInventory(); i++) {
            ItemStack playerSlotStack = playerInv.getStackInSlot(i);
            if (playerSlotStack.getItem() instanceof ItemSeedBag) {
                SeedBagInventory seedBagInventory = new SeedBagInventory(playerSlotStack);
                ItemStack original = leftover.copy();
                leftover = InventoryHandlerHelper.insertStackIntoInventory(seedBagInventory, leftover, EnumFacing.DOWN, true);
                if (!leftover.isEmpty()) {
                    if (leftover.getCount() <= 0) {
                        finishSeeds(event, entityItem, event.getEntityPlayer(), leftover);
                    }
                } else {
                    finishSeeds(event, entityItem, event.getEntityPlayer(), leftover);
                    return;
                }

                if (!handled) {
                    handled = original.getCount() != leftover.getCount();
                }
            }
        }
        if (handled) {
            finishSeeds(event, entityItem, event.getEntityPlayer(), leftover);
        }
    }
}
 
開發者ID:GirafiStudios,項目名稱:Culinary-Cultivation,代碼行數:33,代碼來源:ItemSeedBag.java

示例5: onTryPickupItem

import net.minecraftforge.event.entity.player.EntityItemPickupEvent; //導入方法依賴的package包/類
@SubscribeEvent(priority = EventPriority.LOWEST)
public void onTryPickupItem(EntityItemPickupEvent event)
{
       if (!SettingsFlags.instance.enableCustomInventory)
       {
           return;
       }

	if (event.getItem() != null && !event.getItem().getItem().isEmpty() && !event.getItem().isDead && !event.getEntityPlayer().world.isRemote)
	{
		int i = PlayerInventoryHelper.findFirstAvailableSlotFor(event.getItem().getItem(), Optional.empty(), event.getEntityPlayer());
		if (i == -1)
		{
			event.setCanceled(true);
		}
		else
		{
			if (i < Short.MAX_VALUE)
			{
				event.getEntityPlayer().inventory.setInventorySlotContents(i, event.getItem().getItem().copy());
				net.minecraftforge.fml.common.FMLCommonHandler.instance().firePlayerItemPickupEvent(event.getEntityPlayer(), event.getItem());
				event.getEntityPlayer().onItemPickup(event.getItem(), event.getItem().getItem().getCount());
				event.getEntityPlayer().addStat(StatList.getObjectsPickedUpStats(event.getItem().getItem().getItem()), event.getItem().getItem().getCount());
				event.getItem().setDead();
				event.setCanceled(true);
			}
			else
			{
				int slotID = i - Short.MAX_VALUE;
				ItemStack toIncrement = event.getEntityPlayer().inventory.getStackInSlot(slotID);
				Optional<Slot> s = Optional.ofNullable(event.getEntityPlayer().openContainer != null ? event.getEntityPlayer().openContainer.getSlot(slotID) : null);
				int max = Math.min(toIncrement.getMaxStackSize(), s.map(slot -> slot.getItemStackLimit(toIncrement)).orElseGet(() -> event.getEntityPlayer().inventory.getInventoryStackLimit()));
				int current = toIncrement.getCount();
				final int added = Math.min(event.getItem().getItem().getCount(), max - current);
				net.minecraftforge.fml.common.FMLCommonHandler.instance().firePlayerItemPickupEvent(event.getEntityPlayer(), event.getItem());
				event.getEntityPlayer().addStat(StatList.getObjectsPickedUpStats(event.getItem().getItem().getItem()), added);
				event.getItem().getItem().shrink(added);
				toIncrement.grow(added);
				event.getEntityPlayer().world.playSound(null, event.getEntityPlayer().getPosition(), SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.PLAYERS, 0.2F, (event.getEntityPlayer().world.rand.nextFloat() - event.getEntityPlayer().world.rand.nextFloat()) * 1.4F + 2.0F);
				if (toIncrement.isEmpty())
				{
					event.getItem().setDead();
				}
				
				event.setCanceled(true);
			}
		}
	}
}
 
開發者ID:V0idWa1k3r,項目名稱:ExPetrum,代碼行數:50,代碼來源:ExPHandlerServer.java

示例6: onEntityItemPickupEvent

import net.minecraftforge.event.entity.player.EntityItemPickupEvent; //導入方法依賴的package包/類
/**
 * 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;
}
 
開發者ID:maruohon,項目名稱:enderutilities,代碼行數:80,代碼來源:ItemHandyBag.java

示例7: onEntityItemPickupEvent

import net.minecraftforge.event.entity.player.EntityItemPickupEvent; //導入方法依賴的package包/類
/**
 * 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;
}
 
開發者ID:maruohon,項目名稱:enderutilities,代碼行數:80,代碼來源:ItemNullifier.java


注:本文中的net.minecraftforge.event.entity.player.EntityItemPickupEvent.getItem方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。