/** Drops the entity's currently held item into the world */
 public static void dropHeldItem(EntityLivingBase entity) {
   if (!entity.worldObj.isRemote && entity.getHeldItem() != null) {
     EntityItem drop =
         new EntityItem(
             entity.worldObj,
             entity.posX,
             entity.posY - 0.30000001192092896D + (double) entity.getEyeHeight(),
             entity.posZ,
             entity.getHeldItem().copy());
     float f = 0.3F;
     float f1 = entity.worldObj.rand.nextFloat() * (float) Math.PI * 2.0F;
     drop.motionX =
         (double)
             (-MathHelper.sin(entity.rotationYaw / 180.0F * (float) Math.PI)
                 * MathHelper.cos(entity.rotationPitch / 180.0F * (float) Math.PI)
                 * f);
     drop.motionZ =
         (double)
             (MathHelper.cos(entity.rotationYaw / 180.0F * (float) Math.PI)
                 * MathHelper.cos(entity.rotationPitch / 180.0F * (float) Math.PI)
                 * f);
     drop.motionY =
         (double) (-MathHelper.sin(entity.rotationPitch / 180.0F * (float) Math.PI) * f + 0.1F);
     f = 0.02F * entity.worldObj.rand.nextFloat();
     drop.motionX += Math.cos((double) f1) * (double) f;
     drop.motionY +=
         (double) ((entity.worldObj.rand.nextFloat() - entity.worldObj.rand.nextFloat()) * 0.1F);
     drop.motionZ += Math.sin((double) f1) * (double) f;
     drop.delayBeforeCanPickup = 40;
     entity.worldObj.spawnEntityInWorld(drop);
     entity.setCurrentItemOrArmor(0, (ItemStack) null);
   }
 }
 @Override
 public boolean onBlockDestroyed(
     ItemStack is, World world, int blockID, int x, int y, int z, EntityLivingBase e) {
   if (is.getItemDamage() > 0 && e instanceof EntityPlayer) {
     EntityPlayer ep = (EntityPlayer) e;
     Block b = Block.blocksList[blockID];
     if (b.blockMaterial == Material.leaves) {
       is.setItemDamage(is.getItemDamage() - 1);
       int r = 3;
       for (int i = -r; i <= r; i++) {
         for (int j = -r; j <= r; j++) {
           for (int k = -r; k <= r; k++) {
             int dx = x + i;
             int dy = y + j;
             int dz = z + k;
             Block b2 = Block.blocksList[world.getBlockId(dx, dy, dz)];
             if (b2 != null && b2.blockMaterial == Material.leaves) {
               b2.dropBlockAsItem(world, dx, dy, dz, world.getBlockMetadata(dx, dy, dz), 0);
               b2.removeBlockByPlayer(world, ep, dx, dy, dz);
               is.setItemDamage(is.getItemDamage() - 1);
             }
           }
         }
       }
       e.setCurrentItemOrArmor(0, is);
       return true;
     }
   }
   return false;
 }
  private void giveEntityWeapon(EntityLivingBase mob, int tier, int weaponType) {
    if (tier < 0) return;

    Item[] weapon = ToolListMF.swords;
    if (weaponType == 1) {
      weapon = ToolListMF.waraxes;
    }
    if (weaponType == 2) {
      weapon = ToolListMF.maces;
    }
    if (weaponType == 3) {
      weapon = ToolListMF.tantos;
    }
    mob.setCurrentItemOrArmor(0, new ItemStack(weapon[tier]));
  }
  private void giveEntityArmour(EntityLivingBase mob, int tier, int suit) {
    mob.getEntityData().setBoolean(zombieArmourNBT, true);

    ItemArmourMF[] pool = ArmourListMF.scalemail;
    if (suit == 1) {
      pool = ArmourListMF.chainmail;
    }
    if (suit == 2) {
      pool = ArmourListMF.splintmail;
    }
    if (suit == 3) {
      pool = ArmourListMF.fieldplate;
    }
    ArmourMaterialMF material = (ArmourMaterialMF) ArmourListMF.mats[tier][0];

    for (int a = 0; a < 4; a++) {
      mob.setCurrentItemOrArmor(4 - a, ArmourListMF.armour(pool, tier, a));
    }
  }
Example #5
0
        protected ItemStack dispenseStack(IBlockSource source, ItemStack stack) {
          BlockPos blockpos =
              source.getBlockPos().offset(BlockDispenser.getFacing(source.getBlockMetadata()));
          int i = blockpos.getX();
          int j = blockpos.getY();
          int k = blockpos.getZ();
          AxisAlignedBB axisalignedbb =
              new AxisAlignedBB(
                  (double) i,
                  (double) j,
                  (double) k,
                  (double) (i + 1),
                  (double) (j + 1),
                  (double) (k + 1));
          List<EntityLivingBase> list =
              source
                  .getWorld()
                  .<EntityLivingBase>getEntitiesWithinAABB(
                      EntityLivingBase.class,
                      axisalignedbb,
                      Predicates.<EntityLivingBase>and(
                          EntitySelectors.NOT_SPECTATING, new EntitySelectors.ArmoredMob(stack)));

          if (list.size() > 0) {
            EntityLivingBase entitylivingbase = (EntityLivingBase) list.get(0);
            int l = entitylivingbase instanceof EntityPlayer ? 1 : 0;
            int i1 = EntityLiving.getArmorPosition(stack);
            ItemStack itemstack = stack.copy();
            itemstack.stackSize = 1;
            entitylivingbase.setCurrentItemOrArmor(i1 - l, itemstack);

            if (entitylivingbase instanceof EntityLiving) {
              ((EntityLiving) entitylivingbase).setEquipmentDropChance(i1, 2.0F);
            }

            --stack.stackSize;
            return stack;
          } else {
            return super.dispenseStack(source, stack);
          }
        }