Пример #1
0
 public override void attackEntity(Entity entity, float f)
 {
     if (f < 10F)
     {
         double d  = entity.posX - posX;
         double d1 = entity.posZ - posZ;
         if (attackTime == 0)
         {
             var entityarrow = new EntityArrow(worldObj, this);
             entityarrow.posY += 1.3999999761581421D;
             double d2 = entity.posY - 0.20000000298023224D - entityarrow.posY;
             float  f1 = MathHelper.sqrt_double(d * d + d1 * d1) * 0.2F;
             worldObj.playSoundAtEntity(this, "random.bow", 1.0F, 1.0F / (rand.nextFloat() * 0.4F + 0.8F));
             worldObj.entityJoinedWorld(entityarrow);
             entityarrow.setArrowHeading(d, d2 + f1, d1, 0.6F, 12F);
             attackTime = 30;
         }
         rotationYaw = (float)((Math.atan2(d1, d) * 180D) / 3.1415927410125732D) - 90F;
         hasAttacked = true;
     }
 }
Пример #2
0
        private void dispenseItem(World world, int i, int j, int k, Random random)
        {
            int   l  = world.getBlockMetadata(i, j, k);
            float f  = 0.0F;
            float f1 = 0.0F;

            if (l == 3)
            {
                f1 = 1.0F;
            }
            else if (l == 2)
            {
                f1 = -1F;
            }
            else if (l == 5)
            {
                f = 1.0F;
            }
            else
            {
                f = -1F;
            }
            var       tileentitydispenser = (TileEntityDispenser)world.getBlockTileEntity(i, j, k);
            ItemStack itemstack           = tileentitydispenser.getRandomStackFromInventory();
            double    d  = i + f * 0.5D + 0.5D;
            double    d1 = j + 0.5D;
            double    d2 = k + f1 * 0.5D + 0.5D;

            if (itemstack == null)
            {
                world.playSoundEffect(i, j, k, "random.click", 1.0F, 1.2F);
            }
            else
            {
                if (itemstack.itemID == Item.arrow.shiftedIndex)
                {
                    var entityarrow = new EntityArrow(world, d, d1, d2);
                    entityarrow.setArrowHeading(f, 0.10000000149011612D, f1, 1.1F, 6F);
                    world.entityJoinedWorld(entityarrow);
                    world.playSoundEffect(i, j, k, "random.bow", 1.0F, 1.2F);
                }
                else if (itemstack.itemID == Item.egg.shiftedIndex)
                {
                    var entityegg = new EntityEgg(world, d, d1, d2);
                    entityegg.func_20078_a(f, 0.10000000149011612D, f1, 1.1F, 6F);
                    world.entityJoinedWorld(entityegg);
                    world.playSoundEffect(i, j, k, "random.bow", 1.0F, 1.2F);
                }
                else if (itemstack.itemID == Item.snowball.shiftedIndex)
                {
                    var entitysnowball = new EntitySnowball(world, d, d1, d2);
                    entitysnowball.func_6141_a(f, 0.10000000149011612D, f1, 1.1F, 6F);
                    world.entityJoinedWorld(entitysnowball);
                    world.playSoundEffect(i, j, k, "random.bow", 1.0F, 1.2F);
                }
                else
                {
                    var    entityitem = new EntityItem(world, d, d1 - 0.29999999999999999D, d2, itemstack);
                    double d3         = random.nextDouble() * 0.10000000000000001D + 0.20000000000000001D;
                    entityitem.motionX  = f * d3;
                    entityitem.motionY  = 0.20000000298023224D;
                    entityitem.motionZ  = f1 * d3;
                    entityitem.motionX += random.nextGaussian() * 0.0074999998323619366D * 6D;
                    entityitem.motionY += random.nextGaussian() * 0.0074999998323619366D * 6D;
                    entityitem.motionZ += random.nextGaussian() * 0.0074999998323619366D * 6D;
                    world.entityJoinedWorld(entityitem);
                    world.playSoundEffect(i, j, k, "random.click", 1.0F, 1.0F);
                }
                for (int i1 = 0; i1 < 10; i1++)
                {
                    double d4  = random.nextDouble() * 0.20000000000000001D + 0.01D;
                    double d5  = d + f * 0.01D + (random.nextDouble() - 0.5D) * f1 * 0.5D;
                    double d6  = d1 + (random.nextDouble() - 0.5D) * 0.5D;
                    double d7  = d2 + f1 * 0.01D + (random.nextDouble() - 0.5D) * f * 0.5D;
                    double d8  = f * d4 + random.nextGaussian() * 0.01D;
                    double d9  = -0.029999999999999999D + random.nextGaussian() * 0.01D;
                    double d10 = f1 * d4 + random.nextGaussian() * 0.01D;
                    world.spawnParticle("smoke", d5, d6, d7, d8, d9, d10);
                }
            }
        }