Java Code Examples for net.minecraft.entity.item.EntityItem#getItem()

The following examples show how to use net.minecraft.entity.item.EntityItem#getItem() . These examples are extracted from open source projects. 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
default void colorableOnEntityItemUpdate(EntityItem entityItem) {
	if (entityItem.world.isRemote) return;
	ItemStack stack = entityItem.getItem();

	if (!NBTHelper.hasNBTEntry(stack, NBT.RAND))
		NBTHelper.setFloat(stack, NBT.RAND, entityItem.world.rand.nextFloat());

	IBlockState state = entityItem.world.getBlockState(entityItem.getPosition());

	if (state.getBlock() == ModFluids.NACRE.getActualBlock() && !NBTHelper.getBoolean(stack, NBT.COMPLETE, false)) {
		int purity = NBTHelper.getInt(stack, NBT.PURITY, 0);
		purity = Math.min(purity + 1, NBT.NACRE_PURITY_CONVERSION * 2);
		NBTHelper.setInt(stack, NBT.PURITY, purity);
	} else if (NBTHelper.getInt(stack, NBT.PURITY, 0) > 0)
		NBTHelper.setBoolean(stack, NBT.COMPLETE, true);
}
 
Example 2
@SubscribeEvent
public void redstoneHandler(EntityJoinWorldEvent event) {
	if (event.getWorld().isRemote) {
		return;
	}

	if (event.getEntity() instanceof EntityItem && !(event.getEntity() instanceof EntityBurnableItem)) {
		EntityItem item = (EntityItem) event.getEntity();
		if (EntityBurnableItem.isBurnable(item.getItem())) {
			EntityBurnableItem newItem = new EntityBurnableItem(event.getWorld(), item.posX, item.posY, item.posZ, item.getItem());
			newItem.motionX = item.motionX;
			newItem.motionY = item.motionY;
			newItem.motionZ = item.motionZ;
			newItem.setPickupDelay(40);
			item.setDead();
			event.getWorld().spawnEntity(newItem);
		}
	}
}
 
Example 3
@SubscribeEvent
public void worldTick(WorldTickEvent event) {
    if (event.phase == Phase.START) {
        for (Entity entity : event.world.loadedEntityList) {
            if (entity instanceof EntityItem) {
                EntityItem itemEntity = (EntityItem) entity;
                ItemStack itemStack = itemEntity.getItem();
                ICapabilityAntiGravity capability = itemStack.getCapability(ValkyrienSkiesWorld.ANTI_GRAVITY_CAPABILITY, null);
                if (capability != null) {
                    if (capability.getMultiplier() != 0) {
                        double multiplier = 0.12 / capability.getMultiplier(); // trust me it multiplies Y increase
                        itemEntity.addVelocity(0, .1 - (itemEntity.motionY * multiplier), 0);
                    }
                }
            }
        }
    }
}
 
Example 4
Source Project: TofuCraftReload   File: EntityTofunian.java    License: MIT License 5 votes vote down vote up
protected void updateEquipmentIfNeeded(EntityItem itemEntity) {
    ItemStack itemstack = itemEntity.getItem();

    if (this.canTofunianPickupItem(itemstack)) {
        ItemStack itemstack1 = this.getVillagerInventory().addItem(itemstack);

        if (itemstack1.isEmpty()) {
            itemEntity.setDead();
        } else {
            itemstack.setCount(itemstack1.getCount());
        }
    }
}
 
Example 5
protected void moveItemsInEffectRange() {
    List<EntityItem> itemsInRange = getWorld().getEntitiesWithinAABB(EntityItem.class, areaBoundingBox);
    for (EntityItem entityItem : itemsInRange) {
        double distanceX = (areaCenterPos.getX() + 0.5) - entityItem.posX;
        double distanceZ = (areaCenterPos.getZ() + 0.5) - entityItem.posZ;
        double distance = MathHelper.sqrt(distanceX * distanceX + distanceZ * distanceZ);
        if(!itemFilter.testItemStack(entityItem.getItem())) {
            continue;
        }
        if (distance >= 0.7) {
            if(!entityItem.cannotPickup()) {
                double directionX = distanceX / distance;
                double directionZ = distanceZ / distance;
                entityItem.motionX = directionX * MOTION_MULTIPLIER * getTier();
                entityItem.motionZ = directionZ * MOTION_MULTIPLIER * getTier();
                entityItem.velocityChanged = true;
                entityItem.setPickupDelay(1);
            }
        } else {
            ItemStack itemStack = entityItem.getItem();
            ItemStack remainder = ItemHandlerHelper.insertItemStacked(exportItems, itemStack, false);
            if (remainder.isEmpty()) {
                entityItem.setDead();
            } else if (itemStack.getCount() > remainder.getCount()) {
                entityItem.setItem(remainder);
            }
        }
    }
    if (getTimer() % 5 == 0) {
        pushItemsIntoNearbyHandlers(getFrontFacing());
    }
}
 
Example 6
public ItemStack finish(EntityItem entity) {
	int count = output.getCount();
	ItemStack input = entity.getItem();
	if (input.isEmpty()) {
		entity.setDead();
		return ItemStack.EMPTY;
	}
	count *= input.getCount();
	ItemStack out = output.copy();
	out.setCount(count);
	return out;
}
 
Example 7
Source Project: ForgeWurst   File: WItem.java    License: GNU General Public License v3.0 4 votes vote down vote up
public static ItemStack getItemStack(EntityItem entityItem)
{
	return entityItem.getItem();
}
 
Example 8
/**
 * 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 9
/**
 * 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 10
/**
 * 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;
}