Ejemplo n.º 1
0
  /** Called when the entity is attacked. */
  public boolean attackEntityFrom(DamageSource par1DamageSource, int par2) {
    if (worldObj.isRemote || isDead) {
      return true;
    }

    func_41016_d(-func_41021_q());
    func_41014_b(10);
    setBeenAttacked();
    func_41018_e_(func_41020_o() + par2 * 10);

    if (func_41020_o() > 40) {
      if (riddenByEntity != null) {
        riddenByEntity.mountEntity(this);
      }

      setEntityDead();
      dropItemWithOffset(Item.minecartEmpty.shiftedIndex, 1, 0.0F);

      if (minecartType == 1) {
        EntityMinecart entityminecart = this;
        label0:
        for (int i = 0; i < entityminecart.getSizeInventory(); i++) {
          ItemStack itemstack = entityminecart.getStackInSlot(i);

          if (itemstack == null) {
            continue;
          }

          float f = rand.nextFloat() * 0.8F + 0.1F;
          float f1 = rand.nextFloat() * 0.8F + 0.1F;
          float f2 = rand.nextFloat() * 0.8F + 0.1F;

          do {
            if (itemstack.stackSize <= 0) {
              continue label0;
            }

            int j = rand.nextInt(21) + 10;

            if (j > itemstack.stackSize) {
              j = itemstack.stackSize;
            }

            itemstack.stackSize -= j;
            EntityItem entityitem =
                new EntityItem(
                    worldObj,
                    posX + (double) f,
                    posY + (double) f1,
                    posZ + (double) f2,
                    new ItemStack(itemstack.itemID, j, itemstack.getItemDamage()));
            float f3 = 0.05F;
            entityitem.motionX = (float) rand.nextGaussian() * f3;
            entityitem.motionY = (float) rand.nextGaussian() * f3 + 0.2F;
            entityitem.motionZ = (float) rand.nextGaussian() * f3;
            worldObj.spawnEntityInWorld(entityitem);
          } while (true);
        }

        dropItemWithOffset(Block.chest.blockID, 1, 0.0F);
      } else if (minecartType == 2) {
        dropItemWithOffset(Block.stoneOvenIdle.blockID, 1, 0.0F);
      }
    }

    return true;
  }
Ejemplo n.º 2
0
  /** Called when the entity is attacked. */
  public boolean attackEntityFrom(DamageSource par1DamageSource, int par2) {
    if (!this.worldObj.isRemote && !this.isDead) {
      if (this.func_85032_ar()) {
        return false;
      } else {
        this.func_70494_i(-this.func_70493_k());
        this.func_70497_h(10);
        this.setBeenAttacked();
        this.setDamage(this.getDamage() + par2 * 10);

        if (par1DamageSource.getEntity() instanceof EntityPlayer
            && ((EntityPlayer) par1DamageSource.getEntity()).capabilities.isCreativeMode) {
          this.setDamage(100);
        }

        if (this.getDamage() > 40) {
          if (this.riddenByEntity != null) {
            this.riddenByEntity.mountEntity(this);
          }

          this.setDead();
          this.dropItemWithOffset(Item.minecartEmpty.shiftedIndex, 1, 0.0F);

          if (this.minecartType == 1) {
            EntityMinecart var3 = this;

            for (int var4 = 0; var4 < var3.getSizeInventory(); ++var4) {
              ItemStack var5 = var3.getStackInSlot(var4);

              if (var5 != null) {
                float var6 = this.rand.nextFloat() * 0.8F + 0.1F;
                float var7 = this.rand.nextFloat() * 0.8F + 0.1F;
                float var8 = this.rand.nextFloat() * 0.8F + 0.1F;

                while (var5.stackSize > 0) {
                  int var9 = this.rand.nextInt(21) + 10;

                  if (var9 > var5.stackSize) {
                    var9 = var5.stackSize;
                  }

                  var5.stackSize -= var9;
                  EntityItem var10 =
                      new EntityItem(
                          this.worldObj,
                          this.posX + (double) var6,
                          this.posY + (double) var7,
                          this.posZ + (double) var8,
                          new ItemStack(var5.itemID, var9, var5.getItemDamage()));
                  float var11 = 0.05F;
                  var10.motionX = (double) ((float) this.rand.nextGaussian() * var11);
                  var10.motionY = (double) ((float) this.rand.nextGaussian() * var11 + 0.2F);
                  var10.motionZ = (double) ((float) this.rand.nextGaussian() * var11);
                  this.worldObj.spawnEntityInWorld(var10);
                }
              }
            }

            this.dropItemWithOffset(Block.chest.blockID, 1, 0.0F);
          } else if (this.minecartType == 2) {
            this.dropItemWithOffset(Block.stoneOvenIdle.blockID, 1, 0.0F);
          }
        }

        return true;
      }
    } else {
      return true;
    }
  }