Search in sources :

Example 86 with EntityItem

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

the class WorldUtils method spawnItemWithMotion.

/** Spawns an ItemStack in the world with random motion. */
public static EntityItem spawnItemWithMotion(World world, double x, double y, double z, ItemStack stack) {
    EntityItem item = spawnItem(world, x, y, z, stack);
    if (item != null) {
        item.motionX = RandomUtils.getGaussian() * 0.05F;
        item.motionY = RandomUtils.getGaussian() * 0.05F + 0.2F;
        item.motionZ = RandomUtils.getGaussian() * 0.05F;
    }
    return item;
}
Also used : EntityItem(net.minecraft.entity.item.EntityItem)

Example 87 with EntityItem

use of net.minecraft.entity.item.EntityItem in project Pearcel-Mod by MiningMark48.

the class ItemPearcelMagnet method doUpdate.

private void doUpdate(ItemStack stack, World world, Entity entity) {
    int range = ConfigurationHandler.pearcelMagnetRange;
    float pullSpeed = ConfigurationHandler.pearcelMagnetPullSpeed;
    if (!stack.hasTagCompound()) {
        stack.setTagCompound(new NBTTagCompound());
        stack.getTagCompound().setBoolean("enabled", false);
        stack.getTagCompound().setString("mode", "Attracts");
    }
    if (entity instanceof EntityPlayer) {
        EntityPlayer player = (EntityPlayer) entity;
        if (stack.getTagCompound().getBoolean("enabled") && hasEnoughEnergy(stack, ConfigurationHandler.rfPerTick_magnet, player)) {
            double x = player.posX;
            double y = player.posY;
            double z = player.posZ;
            List<EntityItem> items = entity.world.getEntitiesWithinAABB(EntityItem.class, new AxisAlignedBB(x - range, y - range, z - range, x + range, y + range, z + range));
            List<EntityXPOrb> xp = entity.world.getEntitiesWithinAABB(EntityXPOrb.class, new AxisAlignedBB(x - range, y - range, z - range, x + range, y + range, z + range));
            for (EntityItem e : items) {
                if (!player.isSneaking()) {
                    if (stack.getTagCompound().getString("mode").equalsIgnoreCase("attracts")) {
                        //Attracts
                        e.addVelocity((x - e.posX) * pullSpeed, (y - e.posY) * pullSpeed, (z - e.posZ) * pullSpeed);
                    } else {
                        //Repels
                        e.addVelocity((e.posX - x) * pullSpeed, (e.posY - y) * pullSpeed, (e.posZ - z) * pullSpeed);
                    }
                    if (ConfigurationHandler.pearcelMagnetParticles) {
                        world.spawnParticle(EnumParticleTypes.SPELL_INSTANT, e.posX, e.posY + 0.3, e.posZ, 0.0D, 0.0D, 0.0D);
                    }
                    useEnergy(stack, ConfigurationHandler.rfPerTick_magnet, false, player);
                }
            }
            for (EntityXPOrb e : xp) {
                if (!player.isSneaking()) {
                    if (stack.getTagCompound().getString("mode").equalsIgnoreCase("attracts")) {
                        //Attracts
                        e.addVelocity((x - e.posX) * pullSpeed, (y - e.posY) * pullSpeed, (z - e.posZ) * pullSpeed);
                    } else {
                        //Repels
                        e.addVelocity((e.posX - x) * pullSpeed, (e.posY - y) * pullSpeed, (e.posZ - z) * pullSpeed);
                    }
                    useEnergy(stack, ConfigurationHandler.rfPerTick_magnet, false, player);
                }
            }
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityItem(net.minecraft.entity.item.EntityItem) EntityXPOrb(net.minecraft.entity.item.EntityXPOrb)

Example 88 with EntityItem

use of net.minecraft.entity.item.EntityItem in project ArsMagica2 by Mithion.

the class BlockSpellSealedDoor method breakBlock.

@Override
public void breakBlock(World world, int i, int j, int k, Block par5, int metadata) {
    if (world.isRemote) {
        super.breakBlock(world, i, j, k, par5, metadata);
        return;
    }
    if (world.getBlock(i, j - 1, k) == BlocksCommonProxy.spellSealedDoor)
        j--;
    TileEntitySpellSealedDoor door = (TileEntitySpellSealedDoor) world.getTileEntity(i, j, k);
    if (door == null)
        return;
    ItemStack itemstack = door.getStackInSlot(3);
    if (itemstack == null) {
        return;
    }
    float f = world.rand.nextFloat() * 0.8F + 0.1F;
    float f1 = world.rand.nextFloat() * 0.8F + 0.1F;
    float f2 = world.rand.nextFloat() * 0.8F + 0.1F;
    do {
        if (itemstack.stackSize <= 0) {
            break;
        }
        int i1 = world.rand.nextInt(21) + 10;
        if (i1 > itemstack.stackSize) {
            i1 = itemstack.stackSize;
        }
        itemstack.stackSize -= i1;
        ItemStack newItem = new ItemStack(itemstack.getItem(), i1, itemstack.getItemDamage());
        newItem.setTagCompound(itemstack.getTagCompound());
        EntityItem entityitem = new EntityItem(world, i + f, j + f1, k + f2, newItem);
        float f3 = 0.05F;
        entityitem.motionX = (float) world.rand.nextGaussian() * f3;
        entityitem.motionY = (float) world.rand.nextGaussian() * f3 + 0.2F;
        entityitem.motionZ = (float) world.rand.nextGaussian() * f3;
        world.spawnEntityInWorld(entityitem);
    } while (true);
    world.setBlockToAir(i, j + 1, k);
    super.breakBlock(world, i, j, k, par5, metadata);
}
Also used : TileEntitySpellSealedDoor(am2.blocks.tileentities.TileEntitySpellSealedDoor) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Example 89 with EntityItem

use of net.minecraft.entity.item.EntityItem in project ArsMagica2 by Mithion.

the class BlockSummoner method breakBlock.

@Override
public void breakBlock(World world, int i, int j, int k, Block par5, int metadata) {
    if (world.isRemote) {
        super.breakBlock(world, i, j, k, par5, metadata);
        return;
    }
    TileEntitySummoner summoner = (TileEntitySummoner) world.getTileEntity(i, j, k);
    if (summoner == null)
        return;
    for (int l = 0; l < summoner.getSizeInventory() - 3; l++) {
        ItemStack itemstack = summoner.getStackInSlot(l);
        if (itemstack == null) {
            continue;
        }
        float f = world.rand.nextFloat() * 0.8F + 0.1F;
        float f1 = world.rand.nextFloat() * 0.8F + 0.1F;
        float f2 = world.rand.nextFloat() * 0.8F + 0.1F;
        do {
            if (itemstack.stackSize <= 0) {
                break;
            }
            int i1 = world.rand.nextInt(21) + 10;
            if (i1 > itemstack.stackSize) {
                i1 = itemstack.stackSize;
            }
            itemstack.stackSize -= i1;
            ItemStack newStack = new ItemStack(itemstack.getItem(), i1, itemstack.getItemDamage());
            if (itemstack.hasTagCompound()) {
                newStack.setTagCompound((NBTTagCompound) itemstack.getTagCompound().copy());
            }
            EntityItem entityitem = new EntityItem(world, i + f, j + f1, k + f2, newStack);
            float f3 = 0.05F;
            entityitem.motionX = (float) world.rand.nextGaussian() * f3;
            entityitem.motionY = (float) world.rand.nextGaussian() * f3 + 0.2F;
            entityitem.motionZ = (float) world.rand.nextGaussian() * f3;
            world.spawnEntityInWorld(entityitem);
        } while (true);
    }
    super.breakBlock(world, i, j, k, par5, metadata);
}
Also used : TileEntitySummoner(am2.blocks.tileentities.TileEntitySummoner) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Example 90 with EntityItem

use of net.minecraft.entity.item.EntityItem in project ArsMagica2 by Mithion.

the class BlockLectern method onBlockActivated.

@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9) {
    super.onBlockActivated(world, x, y, z, player, par6, par7, par8, par9);
    TileEntityLectern te = getTileEntity(world, x, y, z);
    if (te == null) {
        return true;
    }
    if (te.hasStack()) {
        if (player.isSneaking()) {
            if (!world.isRemote && ((player instanceof EntityPlayerMP) && ((EntityPlayerMP) player).theItemInWorldManager.getGameType() != GameType.ADVENTURE)) {
                float f = world.rand.nextFloat() * 0.8F + 0.1F;
                float f1 = world.rand.nextFloat() * 0.8F + 0.1F;
                float f2 = world.rand.nextFloat() * 0.8F + 0.1F;
                ItemStack newItem = new ItemStack(te.getStack().getItem(), 1, te.getStack().getItemDamage());
                if (te.getStack().stackTagCompound != null)
                    newItem.setTagCompound((NBTTagCompound) te.getStack().stackTagCompound.copy());
                EntityItem entityitem = new EntityItem(world, x + f, y + f1, z + f2, newItem);
                float f3 = 0.05F;
                entityitem.motionX = (float) world.rand.nextGaussian() * f3;
                entityitem.motionY = (float) world.rand.nextGaussian() * f3 + 0.2F;
                entityitem.motionZ = (float) world.rand.nextGaussian() * f3;
                world.spawnEntityInWorld(entityitem);
                te.setStack(null);
            }
        } else {
            te.getStack().getItem().onItemRightClick(te.getStack(), world, player);
        }
    } else {
        if (player.getCurrentEquippedItem() != null) {
            if (te.setStack(player.getCurrentEquippedItem())) {
                player.getCurrentEquippedItem().stackSize--;
                if (player.getCurrentEquippedItem().stackSize <= 0) {
                    player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
                }
            }
        }
    }
    return true;
}
Also used : TileEntityLectern(am2.blocks.tileentities.TileEntityLectern) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) ItemStack(net.minecraft.item.ItemStack) 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