public void onPickupFromSlot(EntityPlayer playerIn, ItemStack stack) {
    net.minecraftforge.fml.common.FMLCommonHandler.instance()
        .firePlayerCraftingEvent(playerIn, stack, craftMatrix);
    this.onCrafting(stack);
    net.minecraftforge.common.ForgeHooks.setCraftingPlayer(playerIn);
    ItemStack[] aitemstack =
        AltarCraftingManager.getInstance().func_180303_b(this.craftMatrix, playerIn.worldObj);
    net.minecraftforge.common.ForgeHooks.setCraftingPlayer(null);

    for (int i = 0; i < aitemstack.length; ++i) {
      ItemStack itemstack1 = this.craftMatrix.getStackInSlot(i);
      ItemStack itemstack2 = aitemstack[i];

      if (itemstack1 != null) {
        this.craftMatrix.decrStackSize(i, 1);
      }

      if (itemstack2 != null) {
        if (this.craftMatrix.getStackInSlot(i) == null) {
          this.craftMatrix.setInventorySlotContents(i, itemstack2);
        } else if (!this.thePlayer.inventory.addItemStackToInventory(itemstack2)) {
          this.thePlayer.dropPlayerItemWithRandomChoice(itemstack2, false);
        }
      }
    }
  }
 @Override
 public boolean canHarvestBlock(ItemStack stack, Block block, int meta, EntityPlayer player) {
   if (!PickaxeModule.ironPickaxe.canHarvestBlock(block)
       && !ForgeHooks.canToolHarvestBlock(block, meta, PickaxeModule.ironPickaxe)) {
     if (diamondPick.canHarvestBlock(block)
         || ForgeHooks.canToolHarvestBlock(block, meta, diamondPick)) {
       if (ElectricItemUtils.getPlayerEnergy(player)
           > ModuleManager.computeModularProperty(
               stack, PickaxeModule.PICKAXE_ENERGY_CONSUMPTION)) {
         return true;
       }
     }
   }
   return false;
 }
Exemple #3
0
 /** FORGE: Overridden to allow custom tool effectiveness */
 @Override
 public float getStrVsBlock(ItemStack stack, Block block, int meta) {
   if (ForgeHooks.isToolEffective(stack, block, meta)) {
     return efficiencyOnProperMaterial;
   }
   return getStrVsBlock(stack, block);
 }
  protected void renderArmor(int width, int height) {
    if (pre(ARMOR)) return;
    mc.mcProfiler.startSection("armor");

    GlStateManager.enableBlend();
    int left = width / 2 - 91;
    int top = height - left_height;

    int level = ForgeHooks.getTotalArmorValue(mc.thePlayer);
    for (int i = 1; level > 0 && i < 20; i += 2) {
      if (i < level) {
        drawTexturedModalRect(left, top, 34, 9, 9, 9);
      } else if (i == level) {
        drawTexturedModalRect(left, top, 25, 9, 9, 9);
      } else if (i > level) {
        drawTexturedModalRect(left, top, 16, 9, 9, 9);
      }
      left += 8;
    }
    left_height += 10;

    GlStateManager.disableBlend();
    mc.mcProfiler.endSection();
    post(ARMOR);
  }
Exemple #5
0
  /* Tests a block to see if it can be mined with the current equipment
   * Returns 0 if it can't, -1 if it is cobble
   * Will return 2 if mined with pick, 3 if shovel, 1 if none
   * return 4 if just need to fill using the filler upgrade  */
  public int canMineBlock(int x, int y, int z) {
    BlockPos minePos = new BlockPos(x, y, z);
    IBlockState tryState = worldObj.getBlockState(minePos);
    Block tryBlock = tryState.getBlock();

    if (tryBlock != null) {
      int meta = tryBlock.getMetaFromState(tryState);
      if ((tryBlock.getBlockHardness(tryState, worldObj, minePos) >= 0)
          && (!tryBlock.isAir(tryState, worldObj, minePos))) {
        boolean mine = false;
        // ProgressiveAutomation.logger.info("Tool: "+tryBlock.getHarvestTool(meta)+", Level:
        // "+tryBlock.getHarvestLevel(meta)+", Can use Pick: "+tryBlock.isToolEffective("pickaxe",
        // meta));
        // ProgressiveAutomation.logger.info("Harvestable:
        // "+ForgeHooks.canToolHarvestBlock(tryBlock, meta, getStackInSlot(2)));
        if (tryBlock == Blocks.COBBLESTONE) {
          return -1;
        }
        if (tryBlock.getHarvestTool(tryState) == "chisel") { // this is compatibility for chisel 1
          return 2;
        } else if (tryBlock.getHarvestTool(tryState) == "pickaxe") {
          if (ForgeHooks.canToolHarvestBlock(worldObj, minePos, getStackInSlot(2))) {
            // ProgressiveAutomation.logger.info("Tool can harvest");
            return 2;
          }
        } else if (tryBlock.getHarvestTool(tryState) == "shovel") {
          if (ForgeHooks.canToolHarvestBlock(worldObj, minePos, getStackInSlot(3))) {
            return 3;
          }
        } else {
          if (!tryBlock.getMaterial(tryState).isLiquid()) {
            return 1;
          }
        }
      }

      // see if the filler upgrade is active, if it is then the block will need to be filled.
      if (hasUpgrade(UpgradeType.FILLER)) {
        if ((tryBlock.isAir(tryState, worldObj, minePos))
            || (tryBlock.getMaterial(tryState).isLiquid())) {
          return 4;
        }
      }
    }
    return 0;
  }
  @Override
  public ItemStack[] getRemainingItems(InventoryCrafting inventoryCrafting) {
    ItemStack[] aitemstack = new ItemStack[inventoryCrafting.getSizeInventory()];

    for (int i = 0; i < aitemstack.length; ++i) {
      ItemStack itemstack = inventoryCrafting.getStackInSlot(i);
      aitemstack[i] = net.minecraftforge.common.ForgeHooks.getContainerItem(itemstack);
    }

    return aitemstack;
  }
 @Override
 public ItemStack[] getRemainingItems(InventoryCrafting inv) {
   return ForgeHooks.defaultRecipeGetRemainingItems(inv);
   //		for(int i=0;i<inv.getSizeInventory();i++)
   //		{
   //			ItemStack stackInSlot = inv.getStackInSlot(i);
   //			if(stackInSlot!=null)
   //				if(jerrycan==null && IEContent.itemJerrycan.equals(stackInSlot.getItem()) &&
   // ItemNBTHelper.hasKey(stackInSlot, "fluid"))
   //
   //		return new ItemStack[]
 }
  /** Called when the mob's health reaches 0. */
  public void onDeath(DamageSource p_70645_1_) {
    if (ForgeHooks.onLivingDeath(this, p_70645_1_)) return;
    this.mcServer.getConfigurationManager().sendChatMsg(this.getCombatTracker().func_151521_b());

    if (!this.worldObj.getGameRules().getGameRuleBooleanValue("keepInventory")) {
      captureDrops = true;
      capturedDrops.clear();

      this.inventory.dropAllItems();

      captureDrops = false;
      PlayerDropsEvent event =
          new PlayerDropsEvent(this, p_70645_1_, capturedDrops, recentlyHit > 0);
      if (!MinecraftForge.EVENT_BUS.post(event)) {
        for (EntityItem item : capturedDrops) {
          joinEntityItemWithWorld(item);
        }
      }
    }

    Collection collection =
        this.worldObj.getScoreboard().func_96520_a(IScoreObjectiveCriteria.deathCount);
    Iterator iterator = collection.iterator();

    while (iterator.hasNext()) {
      ScoreObjective scoreobjective = (ScoreObjective) iterator.next();
      Score score =
          this.getWorldScoreboard()
              .getValueFromObjective(this.getCommandSenderName(), scoreobjective);
      score.func_96648_a();
    }

    EntityLivingBase entitylivingbase = this.func_94060_bK();

    if (entitylivingbase != null) {
      int i = EntityList.getEntityID(entitylivingbase);
      EntityList.EntityEggInfo entityegginfo =
          (EntityList.EntityEggInfo) EntityList.entityEggs.get(Integer.valueOf(i));

      if (entityegginfo != null) {
        this.addStat(entityegginfo.field_151513_e, 1);
      }

      entitylivingbase.addToPlayerScore(this, this.scoreValue);
    }

    this.addStat(StatList.deathsStat, 1);
    this.getCombatTracker().func_94549_h();
  }
  /** Attempts to harvest a block at the given coordinate */
  @Override
  public boolean tryHarvestBlock(int x, int y, int z) {
    BlockEvent.BreakEvent event =
        ForgeHooks.onBlockBreakEvent(theWorld, getGameType(), thisPlayerMP, x, y, z);
    if (event.isCanceled()) {
      return false;
    } else {
      ItemStack stack = thisPlayerMP.getCurrentEquippedItem();
      if (stack != null && stack.getItem().onBlockStartBreak(stack, x, y, z, thisPlayerMP)) {
        return false;
      }
      Block block = theWorld.getBlock(x, y, z);
      int l = theWorld.getBlockMetadata(x, y, z);
      theWorld.playAuxSFXAtEntity(
          thisPlayerMP,
          2001,
          x,
          y,
          z,
          Block.getIdFromBlock(block) + (theWorld.getBlockMetadata(x, y, z) << 12));
      boolean flag = false;

      ItemStack itemstack = thisPlayerMP.getCurrentEquippedItem();

      if (itemstack != null) {
        itemstack.func_150999_a(theWorld, block, x, y, z, thisPlayerMP);

        if (itemstack.stackSize == 0) {
          thisPlayerMP.destroyCurrentEquippedItem();
        }
      }

      if (removeBlock(x, y, z)) {
        block.harvestBlock(theWorld, thisPlayerMP, x, y, z, l);
        flag = true;
      }

      // Drop experience
      if (!isCreative() && flag && event != null) {
        block.dropXpOnBlockBreak(theWorld, x, y, z, event.getExpToDrop());
      }
      drone.addAir(null, -PneumaticValues.DRONE_USAGE_DIG);
      return true;
    }
  }
  @Override
  protected void jump() {
    this.motionY = 0.52D / WorldUtil.getGravityFactor(this);
    if (this.motionY < 0.26D) this.motionY = 0.26D;

    if (this.isPotionActive(Potion.jump)) {
      this.motionY += (this.getActivePotionEffect(Potion.jump).getAmplifier() + 1) * 0.1F;
    }

    if (this.isSprinting()) {
      float f = this.rotationYaw * 0.017453292F;
      this.motionX -= MathHelper.sin(f) * 0.2F;
      this.motionZ += MathHelper.cos(f) * 0.2F;
    }

    this.isAirBorne = true;
    ForgeHooks.onLivingJump(this);
  }
  private void breakBlock() {
    if (worldObj.isRemote) return;

    ForgeDirection direction = getRotation();
    int x = xCoord + direction.offsetX,
        y = yCoord + direction.offsetY,
        z = zCoord + direction.offsetZ;

    if (worldObj.blockExists(x, y, z)) {
      int blockId = worldObj.getBlockId(x, y, z);
      Block block = Block.blocksList[blockId];
      if (block != null) {
        int metadata = worldObj.getBlockMetadata(x, y, z);
        if (block != Block.bedrock && block.getBlockHardness(worldObj, z, y, z) > -1.0F) {
          EntityPlayer fakePlayer = OpenModsFakePlayer.getPlayerForWorld(worldObj);
          fakePlayer.inventory.currentItem = 0;
          fakePlayer.inventory.setInventorySlotContents(0, new ItemStack(Item.pickaxeDiamond));
          if (ForgeHooks.canHarvestBlock(block, fakePlayer, metadata)) {
            ArrayList<ItemStack> items = block.getBlockDropped(worldObj, x, y, z, metadata, 0);
            if (items != null) {
              ForgeDirection back = direction.getOpposite();
              ejectAt(
                  worldObj,
                  xCoord + back.offsetX,
                  yCoord + back.offsetY,
                  zCoord + back.offsetZ,
                  back,
                  items);
            }
          }
          fakePlayer.setDead();
          worldObj.playAuxSFX(2001, x, y, z, blockId + (metadata << 12));
          worldObj.setBlockToAir(x, y, z);
        }
      }
      worldObj.playSoundEffect(
          xCoord + 0.5D,
          yCoord + 0.5D,
          zCoord + 0.5D,
          "tile.piston.in",
          0.5F,
          worldObj.rand.nextFloat() * 0.15F + 0.6F);
    }
  }
  /** Moves the entity based on the specified heading. Args: strafe, forward */
  public void moveEntityWithHeading(float p_70612_1_, float p_70612_2_) {
    if (this.riddenByEntity != null
        && this.riddenByEntity instanceof EntityLivingBase
        && this.isHorseSaddled()) {
      this.prevRotationYaw = this.rotationYaw = this.riddenByEntity.rotationYaw;
      this.rotationPitch = this.riddenByEntity.rotationPitch * 0.5F;
      this.setRotation(this.rotationYaw, this.rotationPitch);
      this.rotationYawHead = this.renderYawOffset = this.rotationYaw;
      p_70612_1_ = ((EntityLivingBase) this.riddenByEntity).moveStrafing * 0.5F;
      p_70612_2_ = ((EntityLivingBase) this.riddenByEntity).moveForward;

      if (p_70612_2_ <= 0.0F) {
        p_70612_2_ *= 0.25F;
        this.gallopTime = 0;
      }

      if (this.onGround && this.jumpPower == 0.0F && this.isRearing() && !this.field_110294_bI) {
        p_70612_1_ = 0.0F;
        p_70612_2_ = 0.0F;
      }

      if (this.jumpPower > 0.0F && !this.isHorseJumping() && this.onGround) {
        this.motionY = this.getHorseJumpStrength() * (double) this.jumpPower;

        if (this.isPotionActive(Potion.jump)) {
          this.motionY +=
              (double)
                  ((float) (this.getActivePotionEffect(Potion.jump).getAmplifier() + 1) * 0.1F);
        }

        this.setHorseJumping(true);
        this.isAirBorne = true;

        if (p_70612_2_ > 0.0F) {
          float f2 = MathHelper.sin(this.rotationYaw * (float) Math.PI / 180.0F);
          float f3 = MathHelper.cos(this.rotationYaw * (float) Math.PI / 180.0F);
          this.motionX += (double) (-0.4F * f2 * this.jumpPower);
          this.motionZ += (double) (0.4F * f3 * this.jumpPower);
          this.playSound("mob.horse.jump", 0.4F, 1.0F);
        }

        this.jumpPower = 0.0F;
        net.minecraftforge.common.ForgeHooks.onLivingJump(this);
      }

      this.stepHeight = 1.0F;
      this.jumpMovementFactor = this.getAIMoveSpeed() * 0.1F;

      if (!this.worldObj.isRemote) {
        this.setAIMoveSpeed(
            (float)
                this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).getAttributeValue());
        super.moveEntityWithHeading(p_70612_1_, p_70612_2_);
      }

      if (this.onGround) {
        this.jumpPower = 0.0F;
        this.setHorseJumping(false);
      }

      this.prevLimbSwingAmount = this.limbSwingAmount;
      double d1 = this.posX - this.prevPosX;
      double d0 = this.posZ - this.prevPosZ;
      float f4 = MathHelper.sqrt_double(d1 * d1 + d0 * d0) * 4.0F;

      if (f4 > 1.0F) {
        f4 = 1.0F;
      }

      this.limbSwingAmount += (f4 - this.limbSwingAmount) * 0.4F;
      this.limbSwing += this.limbSwingAmount;
    } else {
      this.stepHeight = 0.5F;
      this.jumpMovementFactor = 0.02F;
      super.moveEntityWithHeading(p_70612_1_, p_70612_2_);
    }
  }
 @Override
 public ItemStack[] getRemainingItems(InventoryCrafting inv) // getRecipeLeftovers
     {
   return ForgeHooks.defaultRecipeGetRemainingItems(inv);
 }
  /** Called to update the entity's position/logic. */
  public void onUpdate() {
    this.theItemInWorldManager.updateBlockRemoving();
    --this.field_147101_bU;

    if (this.hurtResistantTime > 0) {
      --this.hurtResistantTime;
    }

    this.openContainer.detectAndSendChanges();

    if (!this.worldObj.isRemote && !ForgeHooks.canInteractWith(this, this.openContainer)) {
      this.closeScreen();
      this.openContainer = this.inventoryContainer;
    }

    while (!this.destroyedItemsNetCache.isEmpty()) {
      int i = Math.min(this.destroyedItemsNetCache.size(), 127);
      int[] aint = new int[i];
      Iterator iterator = this.destroyedItemsNetCache.iterator();
      int j = 0;

      while (iterator.hasNext() && j < i) {
        aint[j++] = ((Integer) iterator.next()).intValue();
        iterator.remove();
      }

      this.playerNetServerHandler.sendPacket(new S13PacketDestroyEntities(aint));
    }

    if (!this.loadedChunks.isEmpty()) {
      ArrayList arraylist = new ArrayList();
      Iterator iterator1 = this.loadedChunks.iterator();
      ArrayList arraylist1 = new ArrayList();
      Chunk chunk;

      while (iterator1.hasNext() && arraylist.size() < S26PacketMapChunkBulk.func_149258_c()) {
        ChunkCoordIntPair chunkcoordintpair = (ChunkCoordIntPair) iterator1.next();

        if (chunkcoordintpair != null) {
          if (this.worldObj.blockExists(
              chunkcoordintpair.chunkXPos << 4, 0, chunkcoordintpair.chunkZPos << 4)) {
            chunk =
                this.worldObj.getChunkFromChunkCoords(
                    chunkcoordintpair.chunkXPos, chunkcoordintpair.chunkZPos);

            if (chunk.func_150802_k()) {
              arraylist.add(chunk);
              arraylist1.addAll(
                  ((WorldServer) this.worldObj)
                      .func_147486_a(
                          chunkcoordintpair.chunkXPos * 16,
                          0,
                          chunkcoordintpair.chunkZPos * 16,
                          chunkcoordintpair.chunkXPos * 16 + 15,
                          256,
                          chunkcoordintpair.chunkZPos * 16 + 15));
              // BugFix: 16 makes it load an extra chunk, which isn't associated with a player,
              // which makes it not unload unless a player walks near it.
              iterator1.remove();
            }
          }
        } else {
          iterator1.remove();
        }
      }

      if (!arraylist.isEmpty()) {
        this.playerNetServerHandler.sendPacket(new S26PacketMapChunkBulk(arraylist));
        Iterator iterator2 = arraylist1.iterator();

        while (iterator2.hasNext()) {
          TileEntity tileentity = (TileEntity) iterator2.next();
          this.func_147097_b(tileentity);
        }

        iterator2 = arraylist.iterator();

        while (iterator2.hasNext()) {
          chunk = (Chunk) iterator2.next();
          this.getServerForPlayer().getEntityTracker().func_85172_a(this, chunk);
          MinecraftForge.EVENT_BUS.post(
              new ChunkWatchEvent.Watch(chunk.getChunkCoordIntPair(), this));
        }
      }
    }
  }
  @Override
  public void tickEnd(EnumSet<TickType> type, Object... tickData) {
    EntityClientPlayerMP player = Minecraft.getMinecraft().thePlayer;
    if (player != null) {
      double currEnergy = ElectricItemUtils.getPlayerEnergy(player);
      double maxEnergy = ElectricItemUtils.getMaxEnergy(player);
      if (maxEnergy > 0) {
        String currStr = MuseStringUtils.formatNumberShort(currEnergy);
        String maxStr = MuseStringUtils.formatNumberShort(maxEnergy);
        MuseRenderer.drawString(currStr + '/' + maxStr + " J", 1, 1);
      }
    }
    if (Minecraft.getMinecraft().currentScreen == null) {
      Minecraft mc = Minecraft.getMinecraft();
      ScaledResolution screen =
          new ScaledResolution(mc.gameSettings, mc.displayWidth, mc.displayHeight);
      int i = player.inventory.currentItem;
      ItemStack stack = player.inventory.mainInventory[i];
      if (stack != null && stack.getItem() instanceof IModularItem) {
        MuseRenderer.blendingOn();
        NBTTagCompound itemTag = MuseItemUtils.getMuseItemTag(stack);
        int swapTime = (int) Math.min(System.currentTimeMillis() - lastSwapTime, SWAPTIME);
        Icon currentMode = null;
        Icon nextMode = null;
        Icon prevMode = null;
        List<String> modes = MuseItemUtils.getModes(stack, player);
        String mode = itemTag.getString("Mode");
        int modeIndex = modes.indexOf(mode);
        if (modeIndex > -1) {
          String prevModeName = modes.get((modeIndex + modes.size() - 1) % modes.size());
          String nextModeName = modes.get((modeIndex + 1) % modes.size());
          IPowerModule module = ModuleManager.getModule(mode);
          IPowerModule nextModule = ModuleManager.getModule(nextModeName);
          IPowerModule prevModule = ModuleManager.getModule(prevModeName);

          if (module != null) {
            currentMode = module.getIcon(stack);
            if (!nextModeName.equals(mode)) {
              nextMode = nextModule.getIcon(stack);
              prevMode = prevModule.getIcon(stack);
            }
          }
        }
        double prevX, prevY, currX, currY, nextX, nextY;
        double sw = screen.getScaledWidth_double();
        double baroffset = screen.getScaledHeight_double() - 40;
        if (!player.capabilities.isCreativeMode) {
          baroffset -= 16;
          if (ForgeHooks.getTotalArmorValue(player) > 0) {
            baroffset -= 8;
          }
        }
        // Root locations of the mode list
        prevX = sw / 2.0 - 105.0 + 20.0 * i;
        prevY = baroffset + 10;
        currX = sw / 2.0 - 89.0 + 20.0 * i;
        currY = baroffset;
        nextX = sw / 2.0 - 73.0 + 20.0 * i;
        nextY = baroffset + 10;
        if (swapTime == SWAPTIME || lastSwapDirection == 0) {
          drawIcon(prevX, prevY, prevMode, 0.4, 0, 0, 16, baroffset - prevY + 16);
          drawIcon(currX, currY, currentMode, 0.8, 0, 0, 16, baroffset - currY + 16);
          drawIcon(nextX, nextY, nextMode, 0.4, 0, 0, 16, baroffset - nextY + 16);
        } else {
          double r1 = 1 - swapTime / (double) SWAPTIME;
          double r2 = swapTime / (double) SWAPTIME;
          if (lastSwapDirection == -1) {
            nextX = (currX * r1 + nextX * r2);
            nextY = (currY * r1 + nextY * r2);
            currX = (prevX * r1 + currX * r2);
            currY = (prevY * r1 + currY * r2);
            drawIcon(currX, currY, currentMode, 0.8, 0, 0, 16, baroffset - currY + 16);
            drawIcon(nextX, nextY, nextMode, 0.8, 0, 0, 16, baroffset - nextY + 16);

          } else {
            prevX = (currX * r1 + prevX * r2);
            prevY = (currY * r1 + prevY * r2);
            currX = (nextX * r1 + currX * r2);
            currY = (nextY * r1 + currY * r2);
            // MuseRenderer
            drawIcon(prevX, prevY, prevMode, 0.8, 0, 0, 16, baroffset - prevY + 16);
            drawIcon(currX, currY, currentMode, 0.8, 0, 0, 16, baroffset - currY + 16);
          }
        }
        // MuseRenderer.blendingOff();
        GL11.glDisable(GL11.GL_LIGHTING);
        Colour.WHITE.doGL();
      }
    }
  }
Exemple #16
0
  @Override
  public boolean attackEntityFrom(DamageSource par1DamageSource, float par2) {
    if (ForgeHooks.onLivingAttack(this, par1DamageSource, par2)) return false;
    if (this.isEntityInvulnerable()) {
      return false;
    } else if (this.worldObj.isRemote) {
      return false;
    } else {
      this.entityAge = 0;

      if (this.getHealth() <= 0.0F) {
        return false;
      } else if (par1DamageSource.isFireDamage() && this.isPotionActive(Potion.fireResistance)) {
        return false;
      } else {
        if ((par1DamageSource == DamageSource.anvil
                || par1DamageSource == DamageSource.fallingBlock)
            && this.getCurrentItemOrArmor(4) != null) {
          this.getCurrentItemOrArmor(4)
              .damageItem((int) (par2 * 4.0F + this.rand.nextFloat() * par2 * 2.0F), this);
          par2 *= 0.75F;
        }

        this.limbSwingAmount = 1.5F;
        boolean flag = true;

        if ((float) this.hurtResistantTime > (float) this.maxHurtResistantTime / 2.0F) {
          if (par2 <= this.lastDamage) {
            return false;
          }

          this.damageEntity(par1DamageSource, par2 - this.lastDamage);
          this.lastDamage = par2;
          flag = false;
        } else {
          this.lastDamage = par2;
          this.prevHealth = this.getHealth();
          this.hurtResistantTime = this.maxHurtResistantTime;
          this.damageEntity(par1DamageSource, par2);
          this.hurtTime = this.maxHurtTime = 10;
        }

        this.attackedAtYaw = 0.0F;
        Entity entity = par1DamageSource.getEntity();

        if (entity != null) {
          if (entity instanceof EntityLivingBase) {
            this.setRevengeTarget((EntityLivingBase) entity);
          }

          if (entity instanceof EntityPlayer) {
            this.recentlyHit = 100;
            this.attackingPlayer = (EntityPlayer) entity;
          } else if (entity instanceof EntityWolf) {
            EntityWolf entitywolf = (EntityWolf) entity;

            if (entitywolf.isTamed()) {
              this.recentlyHit = 100;
              this.attackingPlayer = null;
            }
          }
        }

        if (flag) {
          this.worldObj.setEntityState(this, (byte) 2);

          if (par1DamageSource != DamageSource.drown) {
            this.setBeenAttacked();
          }

          if (entity != null) {
            double d0 = entity.posX - this.posX;
            double d1;

            for (d1 = entity.posZ - this.posZ;
                d0 * d0 + d1 * d1 < 1.0E-4D;
                d1 = (Math.random() - Math.random()) * 0.01D) {
              d0 = (Math.random() - Math.random()) * 0.01D;
            }

            this.attackedAtYaw = (float) (Math.atan2(d1, d0) * 180.0D / Math.PI) - this.rotationYaw;
            this.knockBack(entity, par2, d0, d1);
          } else {
            this.attackedAtYaw = (float) ((int) (Math.random() * 2.0D) * 180);
          }
        }

        if (this.getHealth() <= 0.0F) {
          if (flag) {
            this.playSound(this.getDeathSound(), this.getSoundVolume(), this.getSoundPitch());
          }

          this.onDeath(par1DamageSource);
        } else if (flag) {
          this.playSound(this.getHurtSound(), this.getSoundVolume(), this.getSoundPitch());
        }

        return true;
      }
    }
  }