@Override
 public boolean onItemUse(
     ItemStack par1ItemStack,
     EntityPlayer par2EntityPlayer,
     World par3World,
     int par4,
     int par5,
     int par6,
     int par7,
     float par8,
     float par9,
     float par10) {
   EntityPlayer player = par2EntityPlayer;
   ExtendedPlayer props = ExtendedPlayer.get(player);
   if (!player.capabilities.isCreativeMode) {
     float maxHealth = player.getMaxHealth();
     IAttributeInstance attrMaxHealth =
         player.getEntityAttribute(SharedMonsterAttributes.maxHealth);
     if (attrMaxHealth.getAttributeValue() < dblMaxHealthLimit
         && props.getMaxHealth() < dblMaxHealthLimit) {
       maxHealth += healthIncreaseAmount;
       player.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(maxHealth);
       player.setHealth(maxHealth);
       props.setMaxHealth(maxHealth);
       par1ItemStack.damageItem(2, par2EntityPlayer);
       if (!player.worldObj.isRemote) {
         ZollernHelper.addChatMessage(
             player,
             EnumChatFormatting.GOLD
                 + "+"
                 + this.healthIncreaseAmount
                 + " Max Health! Total: "
                 + props.getMaxHealth());
       }
     } else {
       ZollernHelper.addChatMessage(player, "Max health cannot exceed " + dblMaxHealthLimit + ".");
     }
   }
   return true;
 }
Пример #2
0
  public void renderHealth(int width, int height) {
    bind(icons);
    if (pre(HEALTH)) return;
    mc.mcProfiler.startSection("health");
    GlStateManager.enableBlend();

    EntityPlayer player = (EntityPlayer) this.mc.getRenderViewEntity();
    int health = MathHelper.ceiling_float_int(player.getHealth());
    boolean highlight =
        healthUpdateCounter > (long) updateCounter
            && (healthUpdateCounter - (long) updateCounter) / 3L % 2L == 1L;

    if (health < this.playerHealth && player.hurtResistantTime > 0) {
      this.lastSystemTime = Minecraft.getSystemTime();
      this.healthUpdateCounter = (long) (this.updateCounter + 20);
    } else if (health > this.playerHealth && player.hurtResistantTime > 0) {
      this.lastSystemTime = Minecraft.getSystemTime();
      this.healthUpdateCounter = (long) (this.updateCounter + 10);
    }

    if (Minecraft.getSystemTime() - this.lastSystemTime > 1000L) {
      this.playerHealth = health;
      this.lastPlayerHealth = health;
      this.lastSystemTime = Minecraft.getSystemTime();
    }

    this.playerHealth = health;
    int healthLast = this.lastPlayerHealth;

    IAttributeInstance attrMaxHealth = player.getEntityAttribute(SharedMonsterAttributes.maxHealth);
    float healthMax = (float) attrMaxHealth.getAttributeValue();
    float absorb = player.getAbsorptionAmount();

    int healthRows = MathHelper.ceiling_float_int((healthMax + absorb) / 2.0F / 10.0F);
    int rowHeight = Math.max(10 - (healthRows - 2), 3);

    this.rand.setSeed((long) (updateCounter * 312871));

    int left = width / 2 - 91;
    int top = height - left_height;
    left_height += (healthRows * rowHeight);
    if (rowHeight != 10) left_height += 10 - rowHeight;

    int regen = -1;
    if (player.isPotionActive(Potion.regeneration)) {
      regen = updateCounter % 25;
    }

    final int TOP = 9 * (mc.theWorld.getWorldInfo().isHardcoreModeEnabled() ? 5 : 0);
    final int BACKGROUND = (highlight ? 25 : 16);
    int MARGIN = 16;
    if (player.isPotionActive(Potion.poison)) MARGIN += 36;
    else if (player.isPotionActive(Potion.wither)) MARGIN += 72;
    float absorbRemaining = absorb;

    for (int i = MathHelper.ceiling_float_int((healthMax + absorb) / 2.0F) - 1; i >= 0; --i) {
      // int b0 = (highlight ? 1 : 0);
      int row = MathHelper.ceiling_float_int((float) (i + 1) / 10.0F) - 1;
      int x = left + i % 10 * 8;
      int y = top - row * rowHeight;

      if (health <= 4) y += rand.nextInt(2);
      if (i == regen) y -= 2;

      drawTexturedModalRect(x, y, BACKGROUND, TOP, 9, 9);

      if (highlight) {
        if (i * 2 + 1 < healthLast) drawTexturedModalRect(x, y, MARGIN + 54, TOP, 9, 9); // 6
        else if (i * 2 + 1 == healthLast) drawTexturedModalRect(x, y, MARGIN + 63, TOP, 9, 9); // 7
      }

      if (absorbRemaining > 0.0F) {
        if (absorbRemaining == absorb && absorb % 2.0F == 1.0F)
          drawTexturedModalRect(x, y, MARGIN + 153, TOP, 9, 9); // 17
        else drawTexturedModalRect(x, y, MARGIN + 144, TOP, 9, 9); // 16
        absorbRemaining -= 2.0F;
      } else {
        if (i * 2 + 1 < health) drawTexturedModalRect(x, y, MARGIN + 36, TOP, 9, 9); // 4
        else if (i * 2 + 1 == health) drawTexturedModalRect(x, y, MARGIN + 45, TOP, 9, 9); // 5
      }
    }

    GlStateManager.disableBlend();
    mc.mcProfiler.endSection();
    post(HEALTH);
  }
  /* HUD */
  @SubscribeEvent
  public void renderHealthbar(RenderGameOverlayEvent.Pre event) {
    if (!Loader.isModLoaded("tukmc_Vz")) // Loader check to avoid conflicting
    // with a GUI mod (thanks Vazkii!)
    {
      if (event.type == ElementType.HEALTH) {
        updateCounter++;

        ScaledResolution scaledresolution =
            new ScaledResolution(this.mc.gameSettings, this.mc.displayWidth, this.mc.displayHeight);
        int scaledWidth = scaledresolution.getScaledWidth();
        int scaledHeight = scaledresolution.getScaledHeight();
        int xBasePos = scaledWidth / 2 - 91;
        int yBasePos = scaledHeight - 39;

        boolean highlight = mc.thePlayer.hurtResistantTime / 3 % 2 == 1;

        if (mc.thePlayer.hurtResistantTime < 10) {
          highlight = false;
        }

        IAttributeInstance attrMaxHealth =
            this.mc.thePlayer.getEntityAttribute(SharedMonsterAttributes.maxHealth);
        int health = MathHelper.ceiling_float_int(mc.thePlayer.getHealth());
        int healthLast = MathHelper.ceiling_float_int(mc.thePlayer.prevHealth);
        float healthMax = (float) attrMaxHealth.getAttributeValue();
        if (healthMax > 20) healthMax = 20;
        float absorb = this.mc.thePlayer.getAbsorptionAmount();

        int healthRows = MathHelper.ceiling_float_int((healthMax + absorb) / 2.0F / 10.0F);
        int rowHeight = Math.max(10 - (healthRows - 2), 3);

        this.rand.setSeed((long) (updateCounter * 312871));

        int left = scaledWidth / 2 - 91;
        int top = scaledHeight - GuiIngameForge.left_height;

        int regen = -1;
        if (mc.thePlayer.isPotionActive(Potion.regeneration)) {
          regen = updateCounter % 25;
        }

        final int TOP = 9 * (mc.theWorld.getWorldInfo().isHardcoreModeEnabled() ? 5 : 0);
        final int BACKGROUND = (highlight ? 25 : 16);
        int MARGIN = 16;
        if (mc.thePlayer.isPotionActive(Potion.poison)) MARGIN += 36;
        else if (mc.thePlayer.isPotionActive(Potion.wither)) MARGIN += 72;
        float absorbRemaining = absorb;

        for (int i = MathHelper.ceiling_float_int((healthMax + absorb) / 2.0F) - 1; i >= 0; --i) {
          int b0 = (highlight ? 1 : 0);
          int row = MathHelper.ceiling_float_int((float) (i + 1) / 10.0F) - 1;
          int x = left + i % 10 * 8;
          int y = top - row * rowHeight;

          if (health <= 4) y += rand.nextInt(2);
          if (i == regen) y -= 2;

          drawTexturedModalRect(x, y, BACKGROUND, TOP, 9, 9);

          if (highlight) {
            if (i * 2 + 1 < healthLast) drawTexturedModalRect(x, y, MARGIN + 54, TOP, 9, 9); // 6
            else if (i * 2 + 1 == healthLast)
              drawTexturedModalRect(x, y, MARGIN + 63, TOP, 9, 9); // 7
          }

          if (absorbRemaining > 0.0F) {
            if (absorbRemaining == absorb && absorb % 2.0F == 1.0F)
              drawTexturedModalRect(x, y, MARGIN + 153, TOP, 9, 9); // 17
            else drawTexturedModalRect(x, y, MARGIN + 144, TOP, 9, 9); // 16
            absorbRemaining -= 2.0F;
          } else {
            if (i * 2 + 1 < health) drawTexturedModalRect(x, y, MARGIN + 36, TOP, 9, 9); // 4
            else if (i * 2 + 1 == health) drawTexturedModalRect(x, y, MARGIN + 45, TOP, 9, 9); // 5
          }
        }

        PotionEffect potion = mc.thePlayer.getActivePotionEffect(Potion.wither);
        if (potion != null) return;
        potion = mc.thePlayer.getActivePotionEffect(Potion.poison);
        if (potion != null) return;

        // Extra hearts
        this.mc.getTextureManager().bindTexture(hearts);

        int hp = MathHelper.ceiling_float_int(this.mc.thePlayer.getHealth());
        for (int iter = 0; iter < hp / 20; iter++) {
          int renderHearts = (hp - 20 * (iter + 1)) / 2;
          if (renderHearts > 10) renderHearts = 10;
          for (int i = 0; i < renderHearts; i++) {
            this.drawTexturedModalRect(xBasePos + 8 * i, yBasePos, 0 + 18 * iter, 0, 8, 8);
          }
          if (hp % 2 == 1 && renderHearts < 10) {
            this.drawTexturedModalRect(
                xBasePos + 8 * renderHearts, yBasePos, 9 + 18 * iter, 0, 8, 8);
          }
        }

        this.mc.getTextureManager().bindTexture(icons);
        GuiIngameForge.left_height += 10;
        if (absorb > 0) GuiIngameForge.left_height += 10;

        event.setCanceled(true);
        if (event.type == ElementType.CROSSHAIRS && gs.thirdPersonView != 0) {
          event.setCanceled(true);
        }
      }
    }
  }
Пример #4
0
 public static float getMcBonusDmg(EntityLivingBase entity) {
   IAttributeInstance attackDamage =
       entity.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE);
   return (float) Math.max(attackDamage.getAttributeValue() - attackDamage.getBaseValue(), 0);
 }
Пример #5
0
 public static float getAttackCooldown(EntityLivingBase entity) {
   IAttributeInstance attr = entity.getEntityAttribute(SharedMonsterAttributes.ATTACK_SPEED);
   double val = null != attr ? attr.getAttributeValue() : 4;
   return (float) (1 / val * 20);
 }
Пример #6
0
  private void func_180477_d(ScaledResolution p_180477_1_) {
    if (this.mc.func_175606_aa() instanceof EntityPlayer) {
      EntityPlayer var2 = (EntityPlayer) this.mc.func_175606_aa();
      int var3 = MathHelper.ceiling_float_int(var2.getHealth());
      boolean var4 =
          this.field_175191_F > (long) this.updateCounter
              && (this.field_175191_F - (long) this.updateCounter) / 3L % 2L == 1L;

      if (var3 < this.field_175194_C && var2.hurtResistantTime > 0) {
        this.field_175190_E = Minecraft.getSystemTime();
        this.field_175191_F = (long) (this.updateCounter + 20);
      } else if (var3 > this.field_175194_C && var2.hurtResistantTime > 0) {
        this.field_175190_E = Minecraft.getSystemTime();
        this.field_175191_F = (long) (this.updateCounter + 10);
      }

      if (Minecraft.getSystemTime() - this.field_175190_E > 1000L) {
        this.field_175194_C = var3;
        this.field_175189_D = var3;
        this.field_175190_E = Minecraft.getSystemTime();
      }

      this.field_175194_C = var3;
      int var5 = this.field_175189_D;
      this.rand.setSeed((long) (this.updateCounter * 312871));
      boolean var6 = false;
      FoodStats var7 = var2.getFoodStats();
      int var8 = var7.getFoodLevel();
      int var9 = var7.getPrevFoodLevel();
      IAttributeInstance var10 = var2.getEntityAttribute(SharedMonsterAttributes.maxHealth);
      int var11 = p_180477_1_.getScaledWidth() / 2 - 91;
      int var12 = p_180477_1_.getScaledWidth() / 2 + 91;
      int var13 = p_180477_1_.getScaledHeight() - 39;
      float var14 = (float) var10.getAttributeValue();
      float var15 = var2.getAbsorptionAmount();
      int var16 = MathHelper.ceiling_float_int((var14 + var15) / 2.0F / 10.0F);
      int var17 = Math.max(10 - (var16 - 2), 3);
      int var18 = var13 - (var16 - 1) * var17 - 10;
      float var19 = var15;
      int var20 = var2.getTotalArmorValue();
      int var21 = -1;

      if (var2.isPotionActive(Potion.regeneration)) {
        var21 = this.updateCounter % MathHelper.ceiling_float_int(var14 + 5.0F);
      }

      this.mc.mcProfiler.startSection("armor");
      int var22;
      int var23;

      for (var22 = 0; var22 < 10; ++var22) {
        if (var20 > 0) {
          var23 = var11 + var22 * 8;

          if (var22 * 2 + 1 < var20) {
            this.drawTexturedModalRect(var23, var18, 34, 9, 9, 9);
          }

          if (var22 * 2 + 1 == var20) {
            this.drawTexturedModalRect(var23, var18, 25, 9, 9, 9);
          }

          if (var22 * 2 + 1 > var20) {
            this.drawTexturedModalRect(var23, var18, 16, 9, 9, 9);
          }
        }
      }

      this.mc.mcProfiler.endStartSection("health");
      int var25;
      int var26;
      int var27;

      for (var22 = MathHelper.ceiling_float_int((var14 + var15) / 2.0F) - 1; var22 >= 0; --var22) {
        var23 = 16;

        if (var2.isPotionActive(Potion.poison)) {
          var23 += 36;
        } else if (var2.isPotionActive(Potion.wither)) {
          var23 += 72;
        }

        byte var24 = 0;

        if (var4) {
          var24 = 1;
        }

        var25 = MathHelper.ceiling_float_int((float) (var22 + 1) / 10.0F) - 1;
        var26 = var11 + var22 % 10 * 8;
        var27 = var13 - var25 * var17;

        if (var3 <= 4) {
          var27 += this.rand.nextInt(2);
        }

        if (var22 == var21) {
          var27 -= 2;
        }

        byte var28 = 0;

        if (var2.worldObj.getWorldInfo().isHardcoreModeEnabled()) {
          var28 = 5;
        }

        this.drawTexturedModalRect(var26, var27, 16 + var24 * 9, 9 * var28, 9, 9);

        if (var4) {
          if (var22 * 2 + 1 < var5) {
            this.drawTexturedModalRect(var26, var27, var23 + 54, 9 * var28, 9, 9);
          }

          if (var22 * 2 + 1 == var5) {
            this.drawTexturedModalRect(var26, var27, var23 + 63, 9 * var28, 9, 9);
          }
        }

        if (var19 > 0.0F) {
          if (var19 == var15 && var15 % 2.0F == 1.0F) {
            this.drawTexturedModalRect(var26, var27, var23 + 153, 9 * var28, 9, 9);
          } else {
            this.drawTexturedModalRect(var26, var27, var23 + 144, 9 * var28, 9, 9);
          }

          var19 -= 2.0F;
        } else {
          if (var22 * 2 + 1 < var3) {
            this.drawTexturedModalRect(var26, var27, var23 + 36, 9 * var28, 9, 9);
          }

          if (var22 * 2 + 1 == var3) {
            this.drawTexturedModalRect(var26, var27, var23 + 45, 9 * var28, 9, 9);
          }
        }
      }

      Entity var34 = var2.ridingEntity;
      int var36;

      if (var34 == null) {
        this.mc.mcProfiler.endStartSection("food");

        for (var23 = 0; var23 < 10; ++var23) {
          var36 = var13;
          var25 = 16;
          byte var38 = 0;

          if (var2.isPotionActive(Potion.hunger)) {
            var25 += 36;
            var38 = 13;
          }

          if (var2.getFoodStats().getSaturationLevel() <= 0.0F
              && this.updateCounter % (var8 * 3 + 1) == 0) {
            var36 = var13 + (this.rand.nextInt(3) - 1);
          }

          if (var6) {
            var38 = 1;
          }

          var27 = var12 - var23 * 8 - 9;
          this.drawTexturedModalRect(var27, var36, 16 + var38 * 9, 27, 9, 9);

          if (var6) {
            if (var23 * 2 + 1 < var9) {
              this.drawTexturedModalRect(var27, var36, var25 + 54, 27, 9, 9);
            }

            if (var23 * 2 + 1 == var9) {
              this.drawTexturedModalRect(var27, var36, var25 + 63, 27, 9, 9);
            }
          }

          if (var23 * 2 + 1 < var8) {
            this.drawTexturedModalRect(var27, var36, var25 + 36, 27, 9, 9);
          }

          if (var23 * 2 + 1 == var8) {
            this.drawTexturedModalRect(var27, var36, var25 + 45, 27, 9, 9);
          }
        }
      } else if (var34 instanceof EntityLivingBase) {
        this.mc.mcProfiler.endStartSection("mountHealth");
        EntityLivingBase var35 = (EntityLivingBase) var34;
        var36 = (int) Math.ceil((double) var35.getHealth());
        float var37 = var35.getMaxHealth();
        var26 = (int) (var37 + 0.5F) / 2;

        if (var26 > 30) {
          var26 = 30;
        }

        var27 = var13;

        for (int var39 = 0; var26 > 0; var39 += 20) {
          int var29 = Math.min(var26, 10);
          var26 -= var29;

          for (int var30 = 0; var30 < var29; ++var30) {
            byte var31 = 52;
            byte var32 = 0;

            if (var6) {
              var32 = 1;
            }

            int var33 = var12 - var30 * 8 - 9;
            this.drawTexturedModalRect(var33, var27, var31 + var32 * 9, 9, 9, 9);

            if (var30 * 2 + 1 + var39 < var36) {
              this.drawTexturedModalRect(var33, var27, var31 + 36, 9, 9, 9);
            }

            if (var30 * 2 + 1 + var39 == var36) {
              this.drawTexturedModalRect(var33, var27, var31 + 45, 9, 9, 9);
            }
          }

          var27 -= 10;
        }
      }

      this.mc.mcProfiler.endStartSection("air");

      if (var2.isInsideOfMaterial(Material.water)) {
        var23 = this.mc.thePlayer.getAir();
        var36 = MathHelper.ceiling_double_int((double) (var23 - 2) * 10.0D / 300.0D);
        var25 = MathHelper.ceiling_double_int((double) var23 * 10.0D / 300.0D) - var36;

        for (var26 = 0; var26 < var36 + var25; ++var26) {
          if (var26 < var36) {
            this.drawTexturedModalRect(var12 - var26 * 8 - 9, var18, 16, 18, 9, 9);
          } else {
            this.drawTexturedModalRect(var12 - var26 * 8 - 9, var18, 25, 18, 9, 9);
          }
        }
      }

      this.mc.mcProfiler.endSection();
    }
  }