@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;
 }
  @Override
  public boolean onUse(final EntityPlayer player) {
    if (player.worldObj.isRemote) {
      return false;
    }

    Entity targetCl = Minecraft.getMinecraft().pointedEntity;
    Entity targetSr = null;

    if (targetCl != null) {
      targetSr = player.worldObj.getEntityByID(targetCl.getEntityId());
    }

    float base =
        (float) player.getEntityAttribute(SharedMonsterAttributes.attackDamage).getAttributeValue();
    float extra = new Random().nextFloat() * 1024 / (2048 - this.getExperience(player));

    if (targetSr instanceof EntityLivingBase) {
      EntityLivingBase entity = (EntityLivingBase) targetSr;
      if (entity instanceof EntitySlime) {
        base = Math.min(base / 5, entity.getHealth() - 0.1F);
        extra = 0F;
      }
      entity.attackEntityFrom(DamageSource.causePlayerDamage(player), base);
      entity.attackEntityFrom(NullaDamageSource.CauseAuroraDamage(player), base * extra);
      double vx = 0.2D * (entity.posX - player.posX);
      double vy = 0.2D * (entity.posY - player.posY + 2D);
      double vz = 0.2D * (entity.posZ - player.posZ);
      Minecraft.getMinecraft().thePlayer.setVelocity(vx, vy, vz);

    } else {
      return false;
    }

    if (player.getHeldItem() != null) {
      player.getHeldItem().damageItem(16, player);
    }

    // 随机事件只在服务器发生
    if (!player.worldObj.isRemote) {
      Random rand = new Random();
      int exp = rand.nextInt(5) + 1;
      modifyExperience(player, exp);
    }

    return true;
  }
Exemplo n.º 3
0
  @Override
  public void onArmorTick(World world, EntityPlayer player, ItemStack itemStack) {
    if (player.inventory.armorItemInSlot(3) != null
        && player.inventory.armorItemInSlot(3).getItem() == InitItemsEA.vengeance_helmet
        && player.inventory.armorItemInSlot(2) != null
        && player.inventory.armorItemInSlot(2).getItem() == InitItemsEA.vengeance_chestplate
        && player.inventory.armorItemInSlot(1) != null
        && player.inventory.armorItemInSlot(1).getItem() == InitItemsEA.vengeance_leggings
        && player.inventory.armorItemInSlot(0) != null
        && player.inventory.armorItemInSlot(0).getItem() == InitItemsEA.vengeance_boots) {

      if (!player
          .getEntityAttribute(SharedMonsterAttributes.movementSpeed)
          .hasModifier(EAAttributeModifier.VENGEANCE_SPEED_BONUS)) {
        player
            .getEntityAttribute(SharedMonsterAttributes.movementSpeed)
            .applyModifier(EAAttributeModifier.VENGEANCE_SPEED_BONUS);
      }

      if (!player
          .getEntityAttribute(SharedMonsterAttributes.maxHealth)
          .hasModifier(EAAttributeModifier.VENGEANCE_HP_BONUS)) {
        player
            .getEntityAttribute(SharedMonsterAttributes.maxHealth)
            .applyModifier(EAAttributeModifier.VENGEANCE_HP_BONUS);
      }

      if (!player
          .getEntityAttribute(SharedMonsterAttributes.attackDamage)
          .hasModifier(EAAttributeModifier.VENGEANCE_ATTACK_BONUS)) {
        player
            .getEntityAttribute(SharedMonsterAttributes.attackDamage)
            .applyModifier(EAAttributeModifier.VENGEANCE_ATTACK_BONUS);
      }

      if (!EbonArtsConfiguration.armorParticle) {
        if (world.isRemote) {

          if (player.getHeldItem() != null) {

            int d = random.nextInt(100) + 1;

            if (d <= 2) {
              EbonArtsMod.proxy.generateUnholyParticles(player);
            }
          }

          // Blocking with shield
          // if (player.isHandActive())
          // {

          //	int d = random.nextInt(100) + 1;

          //	if (d <= 25)
          //	{

          //		playerPosX = player.getPositionVector().xCoord;
          //		playerPosY = player.getPositionVector().yCoord;
          //		playerPosZ = player.getPositionVector().zCoord;

          //		world.spawnParticle(EnumParticleTypes.SPELL_WITCH, playerPosX, playerPosY, playerPosZ,
          // (double)((random.nextFloat() - 0.5F) * 0.2F), (double)((random.nextFloat() - 0.5F) *
          // 0.2F), (double)((random.nextFloat() - 0.5F) * 0.2F), new int[0]);

          //	}

          // }

        }
      }
    }
  }
Exemplo n.º 4
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);
  }
Exemplo n.º 5
0
  @SubscribeEvent
  public void onAttackEntity(AttackEntityEvent event) {
    if (event.entityLiving.worldObj.isRemote) return;

    EntityLivingBase attacker = event.entityLiving;
    EntityPlayer player = event.entityPlayer;
    Entity target = event.target;
    ItemStack stack = attacker.getEquipmentInSlot(0);
    if (stack != null && stack.getItem().onLeftClickEntity(stack, player, target)) return;

    if (target.canAttackWithItem()) {
      if (!target.hitByEntity(target)) {
        float damageAmount = TFC_MobData.STEVE_DAMAGE;
        if (stack != null) {
          damageAmount =
              (float)
                  player
                      .getEntityAttribute(SharedMonsterAttributes.attackDamage)
                      .getAttributeValue();
          // player.addChatMessage("Damage: " + i);
          if (damageAmount == 1.0f) {
            damageAmount = TFC_MobData.STEVE_DAMAGE;
            // i = player.inventory.getCurrentItem().getItem().getDamageVsEntity(target,
            // player.inventory.getCurrentItem());
          }
        }

        if (player.isPotionActive(Potion.damageBoost))
          damageAmount += 3 << player.getActivePotionEffect(Potion.damageBoost).getAmplifier();

        if (player.isPotionActive(Potion.weakness))
          damageAmount -= 2 << player.getActivePotionEffect(Potion.weakness).getAmplifier();

        int knockback = 0;
        float enchantmentDamage = 0;

        if (target instanceof EntityLiving) {
          enchantmentDamage =
              EnchantmentHelper.getEnchantmentModifierLiving(player, (EntityLiving) target);
          knockback += EnchantmentHelper.getKnockbackModifier(player, (EntityLiving) target);
        }

        if (player.isSprinting()) ++knockback;

        if (damageAmount > 0 || enchantmentDamage > 0) {
          boolean criticalHit =
              player.fallDistance > 0.0F
                  && !player.onGround
                  && !player.isOnLadder()
                  && !player.isInWater()
                  && !player.isPotionActive(Potion.blindness)
                  && player.ridingEntity == null
                  && target instanceof EntityLiving;

          if (criticalHit && damageAmount > 0)
            damageAmount += event.entity.worldObj.rand.nextInt((int) (damageAmount / 2 + 2));

          damageAmount += enchantmentDamage;
          boolean onFire = false;
          int fireAspect = EnchantmentHelper.getFireAspectModifier(player);

          if (target instanceof EntityLiving && fireAspect > 0 && !target.isBurning()) {
            onFire = true;
            target.setFire(1);
          }

          boolean entityAttacked =
              target.attackEntityFrom(DamageSource.causePlayerDamage(player), damageAmount);

          if (entityAttacked) {
            if (knockback > 0) {
              target.addVelocity(
                  -MathHelper.sin(player.rotationYaw * (float) Math.PI / 180.0F) * knockback * 0.5F,
                  0.1D,
                  MathHelper.cos(player.rotationYaw * (float) Math.PI / 180.0F) * knockback * 0.5F);
              player.motionX *= 0.6D;
              player.motionZ *= 0.6D;
              player.setSprinting(false);
            }

            if (criticalHit) player.onCriticalHit(target);

            if (enchantmentDamage > 0) player.onEnchantmentCritical(target);

            if (damageAmount >= 18) player.triggerAchievement(AchievementList.overkill);

            player.setLastAttacker(target);

            if (target instanceof EntityLiving)
              target.attackEntityFrom(DamageSource.causeThornsDamage(attacker), damageAmount);
          }

          ItemStack itemstack = player.getCurrentEquippedItem();
          Object object = target;

          if (target instanceof EntityDragonPart) {
            IEntityMultiPart ientitymultipart = ((EntityDragonPart) target).entityDragonObj;
            if (ientitymultipart instanceof EntityLiving) object = ientitymultipart;
          }

          if (itemstack != null && object instanceof EntityLiving) {
            itemstack.hitEntity((EntityLiving) object, player);
            if (itemstack.stackSize <= 0) player.destroyCurrentEquippedItem();
          }

          if (target instanceof EntityLivingBase) {
            player.addStat(StatList.damageDealtStat, Math.round(damageAmount * 10.0f));
            if (fireAspect > 0 && entityAttacked) target.setFire(fireAspect * 4);
            else if (onFire) target.extinguish();
          }

          player.addExhaustion(0.3F);
        }
      }
    }
    event.setCanceled(true);
  }
Exemplo n.º 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();
    }
  }