Search in sources :

Example 81 with EntityItem

use of net.minecraft.entity.item.EntityItem in project ConvenientAdditions by Necr0.

the class EventHandlerLuck method luck.

@SubscribeEvent
public void luck(HarvestDropsEvent e) {
    //e.getState().getBlock().getDrops(e.getWorld(), e.getPos(), e.getState(), 3);
    if (e.getHarvester() != null && !e.getHarvester().isSneaking() && !e.getHarvester().getHeldItemMainhand().isEmpty() && e.getHarvester().getHeldItemMainhand().getItem() == ModItems.itemAdventurersPickaxe) {
        int luck = (int) ModItems.itemAdventurersPickaxe.getToolProperty(e.getHarvester().getHeldItemMainhand(), "mining_luck");
        if (Helper.doesOreDictMatch(e.getState(), "ore", true) && luck > 0) {
            e.setDropChance(0f);
            for (ItemStack s : e.getState().getBlock().getDrops(e.getWorld(), e.getPos(), e.getState(), luck)) {
                double x = e.getPos().getX() + .5, y = e.getPos().getY() + .5, z = e.getPos().getZ() + .5;
                e.getWorld().spawnEntity(new EntityItem(e.getWorld(), x, y, z, s));
            }
        }
    }
}
Also used : ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 82 with EntityItem

use of net.minecraft.entity.item.EntityItem in project Minechem by iopleke.

the class ItemHelper method throwItemStack.

public static void throwItemStack(World world, ItemStack itemStack, double x, double y, double z) {
    if (itemStack != null) {
        Random random = new Random();
        float xFloat = random.nextFloat() * 0.8F + 0.1F;
        float yFloat = random.nextFloat() * 0.8F + 0.1F;
        float zFloat = random.nextFloat() * 0.8F + 0.1F;
        float motionMultiplier = 0.05F;
        EntityItem entityitem = new EntityItem(world, (float) x + xFloat, (float) y + yFloat, (float) z + zFloat, itemStack);
        entityitem.motionX = (float) random.nextGaussian() * motionMultiplier;
        entityitem.motionY = (float) random.nextGaussian() * motionMultiplier + 0.2F;
        entityitem.motionZ = (float) random.nextGaussian() * motionMultiplier;
        world.spawnEntityInWorld(entityitem);
    }
}
Also used : Random(java.util.Random) EntityItem(net.minecraft.entity.item.EntityItem)

Example 83 with EntityItem

use of net.minecraft.entity.item.EntityItem in project compactsolars by cpw.

the class BlockCompactSolar method dropContent.

public void dropContent(int newSize, TileEntityCompactSolar tileSolar, World world) {
    for (int l = newSize; l < tileSolar.getSizeInventory(); l++) {
        ItemStack itemstack = tileSolar.getStackInSlot(l);
        if (itemstack == null) {
            continue;
        }
        float f = random.nextFloat() * 0.8F + 0.1F;
        float f1 = random.nextFloat() * 0.8F + 0.1F;
        float f2 = random.nextFloat() * 0.8F + 0.1F;
        while (itemstack.stackSize > 0) {
            int i1 = random.nextInt(21) + 10;
            if (i1 > itemstack.stackSize) {
                i1 = itemstack.stackSize;
            }
            itemstack.stackSize -= i1;
            EntityItem entityitem = new EntityItem(world, (float) tileSolar.xCoord + f, (float) tileSolar.yCoord + (newSize > 0 ? 1 : 0) + f1, (float) tileSolar.zCoord + f2, new ItemStack(itemstack.itemID, i1, itemstack.getItemDamage()));
            float f3 = 0.05F;
            entityitem.motionX = (float) random.nextGaussian() * f3;
            entityitem.motionY = (float) random.nextGaussian() * f3 + 0.2F;
            entityitem.motionZ = (float) random.nextGaussian() * f3;
            if (itemstack.hasTagCompound()) {
                entityitem.getEntityItem().setTagCompound((NBTTagCompound) itemstack.getTagCompound().copy());
            }
            world.spawnEntityInWorld(entityitem);
        }
    }
}
Also used : ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Example 84 with EntityItem

use of net.minecraft.entity.item.EntityItem in project BetterStorage by copygirl.

the class WorldUtils method spawnItem.

// Item spawning related functions
/** Spawns an ItemStack in the world. */
public static EntityItem spawnItem(World world, double x, double y, double z, ItemStack stack) {
    if ((stack == null) || (stack.stackSize <= 0))
        return null;
    EntityItem item = new EntityItem(world, x, y, z, stack);
    world.spawnEntityInWorld(item);
    return item;
}
Also used : EntityItem(net.minecraft.entity.item.EntityItem)

Example 85 with EntityItem

use of net.minecraft.entity.item.EntityItem in project BetterStorage by copygirl.

the class WorldUtils method dropStackFromEntity.

/** Spawns an ItemStack as if it was dropped from an entity on death. */
public static EntityItem dropStackFromEntity(Entity entity, ItemStack stack, float speed) {
    EntityPlayer player = ((entity instanceof EntityPlayer) ? (EntityPlayer) entity : null);
    EntityItem item;
    if (player == null) {
        double y = entity.posY + entity.getEyeHeight() - 0.3;
        item = spawnItem(entity.worldObj, entity.posX, y, entity.posZ, stack);
        if (item == null)
            return null;
        item.delayBeforeCanPickup = 40;
        float f1 = RandomUtils.getFloat(0.5F);
        float f2 = RandomUtils.getFloat((float) Math.PI * 2.0F);
        item.motionX = -MathHelper.sin(f2) * f1;
        item.motionY = 0.2;
        item.motionZ = MathHelper.cos(f2) * f1;
        return item;
    } else
        item = player.dropPlayerItemWithRandomChoice(stack, true);
    if (item != null) {
        item.motionX *= speed / 4;
        item.motionZ *= speed / 4;
    }
    return item;
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityItem(net.minecraft.entity.item.EntityItem)

Aggregations

EntityItem (net.minecraft.entity.item.EntityItem)284 ItemStack (net.minecraft.item.ItemStack)178 TileEntity (net.minecraft.tileentity.TileEntity)45 EntityPlayer (net.minecraft.entity.player.EntityPlayer)36 Entity (net.minecraft.entity.Entity)26 ArrayList (java.util.ArrayList)19 BlockPos (net.minecraft.util.math.BlockPos)19 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)18 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)16 World (net.minecraft.world.World)16 Random (java.util.Random)15 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)14 Item (net.minecraft.item.Item)13 IInventory (net.minecraft.inventory.IInventory)12 AxisAlignedBB (net.minecraft.util.AxisAlignedBB)12 List (java.util.List)11 Block (net.minecraft.block.Block)11 EntityLivingBase (net.minecraft.entity.EntityLivingBase)11 IBlockState (net.minecraft.block.state.IBlockState)10 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)6