@Override
  public boolean attackEntityAsMob(Entity victim) {
    float attackDamage =
        (float) getEntityAttribute(SharedMonsterAttributes.attackDamage).getAttributeValue();
    int knockback = 0;

    if (victim instanceof EntityLivingBase) {
      attackDamage +=
          EnchantmentHelper.getEnchantmentModifierLiving(this, (EntityLivingBase) victim);
      knockback += EnchantmentHelper.getKnockbackModifier(this, (EntityLivingBase) victim);
    }

    boolean attacked = victim.attackEntityFrom(DamageSource.causeMobDamage(this), attackDamage);

    if (attacked) {
      if (knockback > 0) {
        double vx = -Math.sin(Math.toRadians(rotationYaw)) * knockback * 0.5;
        double vy = 0.1;
        double vz = Math.cos(Math.toRadians(rotationYaw)) * knockback * 0.5;
        victim.addVelocity(vx, vy, vz);
        motionX *= 0.6;
        motionZ *= 0.6;
      }

      if (victim instanceof EntityLivingBase) {
        // EnchantmentThorns.func_92096_a(this, (EntityLivingBase) victim, rand);
      }

      setLastAttacker(victim);
    }

    return attacked;
  }
  /** This gets called when a dinosaur grows naturally or through Chicken Essence. */
  @Override
  public void updateSize() {
    double healthStep;
    double attackStep;
    double speedStep;
    healthStep = (this.maxHealth - this.baseHealth) / (this.adultAge + 1);
    attackStep = (this.maxDamage - this.baseDamage) / (this.adultAge + 1);
    speedStep = (this.maxSpeed - this.baseSpeed) / (this.adultAge + 1);

    if (this.getDinoAge() <= this.adultAge) {
      this.getEntityAttribute(SharedMonsterAttributes.maxHealth)
          .setBaseValue(Math.round(this.baseHealth + (healthStep * this.getDinoAge())));
      this.getEntityAttribute(SharedMonsterAttributes.attackDamage)
          .setBaseValue(Math.round(this.baseDamage + (attackStep * this.getDinoAge())));
      this.getEntityAttribute(SharedMonsterAttributes.movementSpeed)
          .setBaseValue(this.baseSpeed + (speedStep * this.getDinoAge()));

      if (this.isTeen()) {
        this.getEntityAttribute(SharedMonsterAttributes.knockbackResistance).setBaseValue(0.5D);
      } else if (this.isAdult()) {
        this.getEntityAttribute(SharedMonsterAttributes.knockbackResistance).setBaseValue(2.0D);
      } else {
        this.getEntityAttribute(SharedMonsterAttributes.knockbackResistance).setBaseValue(0.0D);
      }
    }
  }
Esempio n. 3
0
 protected void a(int i0) {
   this.bm = i0;
   this.H().b(14, Byte.valueOf((byte) 1));
   this.m(Potion.t.H);
   this.c(new PotionEffect(Potion.g.H, i0, Math.min(this.o.aa().a() - 1, 0)));
   this.o.a((Entity) this, (byte) 16);
 }
Esempio n. 4
0
  public void m() {
    if (this.o.w() && !this.o.D && !this.i_()) {
      float f0 = this.c(1.0F);
      BlockPos blockpos = new BlockPos(this.s, (double) Math.round(this.t), this.u);

      if (f0 > 0.5F && this.V.nextFloat() * 30.0F < (f0 - 0.4F) * 2.0F && this.o.i(blockpos)) {
        boolean flag0 = true;
        ItemStack itemstack = this.p(4);

        if (itemstack != null) {
          if (itemstack.e()) {
            itemstack.b(itemstack.h() + this.V.nextInt(2));
            if (itemstack.h() >= itemstack.j()) {
              this.b(itemstack);
              this.c(4, (ItemStack) null);
            }
          }

          flag0 = false;
        }

        if (flag0) {
          this.e(8);
        }
      }
    }

    if (this.av() && this.u() != null && this.m instanceof EntityChicken) {
      ((EntityLiving) this.m).s().a(this.s().j(), 1.5D);
    }

    super.m();
  }
 private float processDamageSource(
     DamageSource source, float damage, float pierceMult, float slashMult, float crushMult) {
   EnumDamageType damageType = getDamageType(source);
   // 4.2 Reduce the damage based upon the incoming Damage Type
   if (damageType == EnumDamageType.PIERCING) {
     damage *= pierceMult;
   } else if (damageType == EnumDamageType.SLASHING) {
     damage *= slashMult;
   } else if (damageType == EnumDamageType.CRUSHING) {
     damage *= crushMult;
   } else if (damageType == EnumDamageType.GENERIC) {
     damage *= (crushMult + slashMult + pierceMult) / 3 - 0.25;
   }
   return Math.max(0, damage);
 }
Esempio n. 6
0
  @Override
  public void attackEntityWithRangedAttack(EntityLivingBase var1, float var2) {
    EntityArrow entityarrow =
        new EntityArrow(
            this.worldObj, this, var1, Math.max(1F, getDistanceToEntity(var1) / 10F), 1);
    entityarrow.posX = this.posX;
    entityarrow.posY = this.posY + this.getEyeHeight();
    entityarrow.posZ = this.posZ;

    int power =
        EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, this.getHeldItem());
    int punch =
        EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, this.getHeldItem());
    double damage = (double) (var2 * 3.0F) + this.rand.nextGaussian() * 0.25D;
    entityarrow.setDamage(damage);

    if (power > 0) entityarrow.setDamage(entityarrow.getDamage() + (double) power * 0.5D + 0.5D);
    if (punch > 0) entityarrow.setKnockbackStrength(punch);
    if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, this.getHeldItem()) > 0)
      entityarrow.setFire(100);

    this.playSound("random.bow", 1.0F, 1.0F / (this.getRNG().nextFloat() * 0.4F + 0.8F));
    this.worldObj.spawnEntityInWorld(entityarrow);
  }
 public void playNoteSound(Vector3f loc, String type, int pitch) {
   float realPitch = (float) Math.pow(2.0D, (double) (pitch - 12) / 12.0D);
   _world.playSoundEffect(loc.getX(), loc.getY(), loc.getZ(), "note." + type, 3.0f, realPitch);
 }
  @Override
  public void onChunkPopulate(World worldObj, Random rand, int i, int j) {
    if (!worldObj.isRemote) {
      int chunkX = i / 16;
      int chunkZ = j / 16;
      int ch =
          (chunkX * chunkX
                  + chunkZ * chunkZ
                  + worldObj.provider.dimensionId
                  + (int) Math.pow(chunkX * chunkZ, 3))
              % (57 + chunkZ % 5);
      BiomeGenBase b = worldObj.getBiomeGenForCoords(i, j);
      // int bid = b.biomeID;
      if (ch == 0) {
        int x = rand.nextInt(16) + i;
        int z = rand.nextInt(16) + j;
        // System.out.println("Adding healing crystal formation (" + x + "," + z + ")");
        worldGen.generate(worldObj, rand, x, 0, z);
      }

      // if(b.biomeID > 22) {
      ch =
          (chunkX * chunkX
                  + chunkZ * chunkZ
                  + worldObj.provider.dimensionId
                  + (int) Math.pow(chunkX * chunkZ, 3))
              % (37 + chunkZ % 5);
      // System.out.println("Positive Energy Populate");
      if (b.rainfall < 0.35 || b.temperature >= 0.8) {
        ch++;
      }
      if (ch == 0) {
        int x = rand.nextInt(16) + i;
        int z = rand.nextInt(16) + j;
        int y = getFirstUncoveredBlock(worldObj, x, z);
        if (i > 0) {
          // System.out.println("Placed treant at (" + x + "," + y + "," + z + ")");
          EntityTreant entitychicken = new EntityTreant(worldObj);
          entitychicken.setLocationAndAngles((double) x, (double) y, (double) z, 0.0F, 0.0F);
          worldObj.spawnEntityInWorld(entitychicken);
        }
      }
      EntityPlayer p = worldObj.getClosestPlayer(i, 64, j, 64);
      if (p != null) {
        ch =
            (chunkX * chunkX
                    + chunkZ * chunkZ
                    + worldObj.provider.dimensionId
                    + (int) Math.pow(chunkX * chunkZ, 3))
                % (17 + chunkX % 5);
        if (ch == 0) {
          int n = 1 + rand.nextInt(3);
          for (; n >= 0; n--) {
            int x = rand.nextInt(16) + i;
            int z = rand.nextInt(16) + j;
            int y = getFirstUncoveredBlock(worldObj, x, z);
            if (y > 0) {
              // System.out.println("Placed blink dog at (" + x + "," + y + "," + z + ")");
              EntityBlinkDog entitychicken = new EntityBlinkDog(worldObj);
              entitychicken.setLocationAndAngles((double) x, (double) y, (double) z, 0.0F, 0.0F);
              worldObj.spawnEntityInWorld(entitychicken);
            }
          }
        }
        ch =
            (chunkX * (chunkX + chunkZ)
                    + chunkZ * (chunkZ + chunkX)
                    + worldObj.provider.dimensionId
                    + (int) Math.pow(chunkX * chunkZ, 3))
                % (17 + chunkX % 5);
        if (b.getFloatTemperature() < 0.5) {
          ch++;
        } else if (b.getFloatTemperature() > 1.5) {
          ch--;
        }
        if (ch == 0) {
          int x = rand.nextInt(16) + i;
          int z = rand.nextInt(16) + j;
          int y = getFirstAirBlock(worldObj, x, z);
          if (y > 0) {
            // System.out.println("Placed blink dog at (" + x + "," + y + "," + z + ")");
            EntityEmpyreal entitychicken = new EntityEmpyreal(worldObj);
            entitychicken.setLocationAndAngles((double) x, (double) y, (double) z, 0.0F, 0.0F);
            worldObj.spawnEntityInWorld(entitychicken);
          }
        }
      }
      // }

      for (int vary = 130; vary > 0; vary--) {
        int bID = worldObj.getBlockId(chunkX * 16 + 8, vary, chunkZ * 16 + 4);
        int tex = chunkX * 16 + 8;
        int tez = chunkZ * 16 + 4;
        if (MystObjects.book_lectern != null && bID == MystObjects.book_lectern.blockID) {
          // System.out.println("Spawning foo dogs at (" + tex + "," + vary + "," + tez + ")");
          EntityFooDog entitychicken;
          int l = worldObj.getBlockId(tex + 1, vary, tez);
          int r = worldObj.getBlockId(tex - 1, vary, tez);
          if (l == r) {
            l = worldObj.getBlockId(tex, vary, tez + 1);
            r = worldObj.getBlockId(tex, vary, tez - 1);
            if (r == Block.cobblestone.blockID) {
              // te.xCoord+2, vary, tez+6
              entitychicken = new EntityFooDog(worldObj);
              entitychicken.setLocationAndAngles(tex + 2, vary, tez + 6, 0.0F, 0.0F);
              worldObj.spawnEntityInWorld(entitychicken);
              entitychicken = new EntityFooDog(worldObj);
              entitychicken.setLocationAndAngles(tex - 2, vary, tez + 6, 0.0F, 0.0F);
              worldObj.spawnEntityInWorld(entitychicken);
            } else {
              // te.xCoord+2, vary, tez-6
              entitychicken = new EntityFooDog(worldObj);
              entitychicken.setLocationAndAngles(tex + 2, vary, tez - 6, 180.0F, 0.0F);
              worldObj.spawnEntityInWorld(entitychicken);
              entitychicken = new EntityFooDog(worldObj);
              entitychicken.setLocationAndAngles(tex - 2, vary, tez - 6, 180.0F, 0.0F);
              worldObj.spawnEntityInWorld(entitychicken);
            }
          } else {
            if (r == Block.cobblestone.blockID) {
              // te.xCoord-6, vary, tez+2
              entitychicken = new EntityFooDog(worldObj);
              entitychicken.setLocationAndAngles(tex + 6, vary, tez - 2, 90.0F, 0.0F);
              worldObj.spawnEntityInWorld(entitychicken);
              entitychicken = new EntityFooDog(worldObj);
              entitychicken.setLocationAndAngles(tex + 6, vary, tez + 2, 90.0F, 0.0F);
              worldObj.spawnEntityInWorld(entitychicken);
            } else {
              // te.xCoord+6, vary, tez+2
              entitychicken = new EntityFooDog(worldObj);
              entitychicken.setLocationAndAngles(tex - 6, vary, tez - 2, 270.0F, 0.0F);
              worldObj.spawnEntityInWorld(entitychicken);
              entitychicken = new EntityFooDog(worldObj);
              entitychicken.setLocationAndAngles(tex - 6, vary, tez + 2, 270.0F, 0.0F);
              worldObj.spawnEntityInWorld(entitychicken);
            }
          }
        }
      }
    }
  }
  @Override
  public void tick(World worldObj, Chunk chunk) {
    // int s = worldObj.calculateSkylightSubtracted(0);
    if (!worldObj.isRemote && chunk.hasEntities) {
      int foundblinkdog = 0;
      boolean foundempyreal = false;
      // if (worldObj.rand.nextInt(10) < level)
      // {
      for (int var3 = chunk.entityLists.length - 1; var3 >= 0; var3--) {
        // int var3 = worldObj.rand.nextInt(chunk.entityLists.length);
        List var4 = chunk.entityLists[var3];

        if (var4.size() > 0) {
          for (int entind = var4.size() - 1; entind >= 0; entind--) {
            Entity e = (Entity) var4.get(entind);

            if (e instanceof EntityLiving) {
              EntityLiving var5 = (EntityLiving) e;
              NBTTagCompound nbt = var5.getEntityData();
              float hpo = nbt.getFloat("HealthOverflow");
              int timer = nbt.getInteger("HealthOverflowTimer");
              if (timer < 0) {
                timer = 0;
              }
              timer += level;
              if (DecayingWorld.goodmobs(var5)) {
                timer += (5 - level);
              }
              if (var5 instanceof EntityBlinkDog) {
                foundblinkdog += 1;
              }
              if (var5 instanceof EntityEmpyreal) {
                foundempyreal = true;
              }
              // System.out.println("Timer:  " +timer);
              // System.out.println("HPO:    " +hpo);
              float hp = var5.getHealth();
              if (timer > 180) {
                if (DecayingWorld.evilmobs(var5)) {
                  if (hpo > 0) hpo--;
                  else hp--;
                } else {
                  hpo++;
                  int r = worldObj.rand.nextInt(60);
                  nbt.setInteger("HealthOverflowTimer", r);
                  timer = r;
                }
              }

              float mhp = var5.getMaxHealth();
              float newhp = hp;
              float newhpo = hpo;

              if (hp < mhp && !DecayingWorld.evilmobs(var5)) {
                newhp = Math.min(hp + hpo, mhp);
                newhpo = Math.max(hp + hpo - mhp, 0);
                var5.heal(newhp - hp);
              }
              // System.out.println("newHPO: " +newhpo);

              if (newhpo > mhp * 2) {
                newhpo = mhp * 2;
                if (!(DecayingWorld.goodmobs(var5) || var5 instanceof EntityCreeper))
                // if (!(var5 instanceof EntitySkeleton || var5 instanceof EntityZombie || var5
                // instanceof EntityCreeper || e instanceof EntityGhast || e instanceof
                // EntityPigZombie))
                {
                  worldObj.newExplosion(var5, var5.posX, var5.posY, var5.posZ, 0F, false, true);
                  var5.attackEntityFrom(PositiveDamage.type, mhp * 3);
                }
              }

              nbt.setFloat("HealthOverflow", newhpo);
              nbt.setInteger("HealthOverflowTimer", timer);
              nbt.setBoolean("TempDecay", true);

              if (e instanceof EntityPlayer) {
                ByteArrayOutputStream bt = new ByteArrayOutputStream();
                DataOutputStream out = new DataOutputStream(bt);
                try {
                  out.writeInt(1);
                  out.writeFloat(newhpo);
                  Packet250CustomPayload packet =
                      new Packet250CustomPayload("MoreDecay", bt.toByteArray());
                  Player player = (Player) e;
                  PacketDispatcher.sendPacketToPlayer(packet, player);
                } catch (IOException ex) {
                  System.out.println("couldnt send packet!");
                }
              }
            }
          }
        }
      }
      int chunkX = chunk.xPosition;
      int chunkZ = chunk.zPosition;
      BiomeGenBase b = worldObj.getBiomeGenForCoords(chunkX * 16, chunkZ * 16);
      // if(b.biomeID > 22) {
      int x, y, z, n, ch;
      EntityPlayer p = worldObj.getClosestPlayer(chunkX * 16, 96, chunkZ * 16, 96);
      EntityPlayer p2 = worldObj.getClosestPlayer(chunkX * 16, 24, chunkZ * 16, 24);
      if (p != null && p2 == null) {
        if (foundblinkdog < 2) {
          ch =
              (chunkX * chunkX
                      + chunkZ * chunkZ
                      + worldObj.provider.dimensionId
                      + (int) Math.pow(chunkX * chunkZ, 3))
                  % (17 + chunkX % 5);
          if (ch == 0 && worldObj.rand.nextInt(120) == 0) {
            AxisAlignedBB par2AxisAlignedBB =
                AxisAlignedBB.getBoundingBox(
                    (double) (chunkX * 16) - 32,
                    (double) 0,
                    (double) (chunkZ * 16) - 32,
                    (double) (chunkX * 16) + 32,
                    (double) 96,
                    (double) (chunkZ * 16) + 32);
            // par2AxisAlignedBB.expand(16, 16, 16);
            List<Entity> ents =
                worldObj.getEntitiesWithinAABB(EntityBlinkDog.class, par2AxisAlignedBB);
            if (ents.size() < 4) {
              n = 1 + worldObj.rand.nextInt(2);
              for (; n >= 0; n--) {
                x = worldObj.rand.nextInt(16) + chunkX * 16;
                z = worldObj.rand.nextInt(16) + chunkZ * 16;
                y = getFirstUncoveredBlock(worldObj, x, z);
                if (y > 0) {
                  // System.out.println("Placed blink dog at (" + x + "," + y + "," + z + ")");
                  EntityBlinkDog entitychicken = new EntityBlinkDog(worldObj);
                  entitychicken.setLocationAndAngles(
                      (double) x, (double) y, (double) z, 0.0F, 0.0F);
                  worldObj.spawnEntityInWorld(entitychicken);
                }
              }
            }
          }
        }
        if (!foundempyreal) {
          ch =
              (chunkX * (chunkX + chunkZ)
                      + chunkZ * (chunkZ + chunkX)
                      + worldObj.provider.dimensionId
                      + (int) Math.pow(chunkX * chunkZ, 3))
                  % (17 + chunkX % 5);
          if (ch == 0 && worldObj.rand.nextInt(80) == 0) {
            x = worldObj.rand.nextInt(16) + chunkX * 16;
            z = worldObj.rand.nextInt(16) + chunkZ * 16;
            y = getFirstAirBlock(worldObj, x, z);
            if (y > 0) {
              // System.out.println("Placed blink dog at (" + x + "," + y + "," + z + ")");
              EntityEmpyreal entitychicken = new EntityEmpyreal(worldObj);
              entitychicken.setLocationAndAngles((double) x, (double) y, (double) z, 0.0F, 0.0F);
              worldObj.spawnEntityInWorld(entitychicken);
            }
          }
        }
      }
      // }
    }
  }
  @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);
  }