示例#1
0
 private DamageSource getFlamethrowerDamage() {
   if (owner == null) {
     return DamageSource.causeThrownDamage(this, this);
   } else {
     return DamageSource.causeThrownDamage(this, owner);
   }
 }
  public boolean func_70097_a(DamageSource p_70097_1_, float p_70097_2_) {
    if (!this.field_70170_p.field_72995_K && !this.field_70128_L) {
      if (this.func_85032_ar()) {
        return false;
      } else {
        this.func_70494_i(-this.func_70493_k());
        this.func_70497_h(10);
        this.func_70018_K();
        this.func_70492_c(this.func_70491_i() + p_70097_2_ * 10.0F);
        boolean var3 =
            p_70097_1_.func_76346_g() instanceof EntityPlayer
                && ((EntityPlayer) p_70097_1_.func_76346_g()).field_71075_bZ.field_75098_d;
        if (var3 || this.func_70491_i() > 40.0F) {
          if (this.field_70153_n != null) {
            this.field_70153_n.func_70078_a(this);
          }

          if (var3 && !this.func_94042_c()) {
            this.func_70106_y();
          } else {
            this.func_94095_a(p_70097_1_);
          }
        }

        return true;
      }
    } else {
      return true;
    }
  }
  @Override
  public boolean attackEntityFrom(DamageSource par1DamageSource, float par2) {
    if (!this.worldObj.isRemote && !this.isDead && !this.indestructable) {
      if (this.isEntityInvulnerable()) {
        return false;
      } else {
        this.setBeenAttacked();
        this.setDamage(this.getDamage() + par2 * 10);

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

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

          this.setDead();
          this.dropItemStack();
        }

        return true;
      }
    } else {
      return true;
    }
  }
示例#4
0
 @Override
 public boolean attackEntityFrom(DamageSource damagesource, float i) {
   if (worldObj.isRemote) {
     return true;
   }
   if (canBeDestroyedByPlayer(damagesource)) return true;
   super.attackEntityFrom(damagesource, i);
   setRollingDirection(-getRollingDirection());
   setRollingAmplitude(10);
   setBeenAttacked();
   setDamage(getDamage() + i * 10);
   if (getDamage() > 40) {
     if (riddenByEntity != null) {
       riddenByEntity.mountEntity(this);
     }
     this.setDead();
     boolean flag =
         damagesource.getEntity() instanceof EntityPlayer
             && ((EntityPlayer) damagesource.getEntity()).capabilities.isCreativeMode;
     if (!flag) {
       dropCartAsItem();
     }
   }
   return true;
 }
 protected void onImpact(MovingObjectPosition var1) {
   @SuppressWarnings("rawtypes")
   List list =
       this.worldObj.getEntitiesWithinAABBExcludingEntity(
           this, this.boundingBox.expand(4.5D, 3.0D, 4.5D));
   list.remove(getThrower());
   for (int i = 0; i < list.size(); i++) {
     Entity entity = (Entity) list.get(i);
     if (!worldObj.isRemote) {
       if (var1.entityHit != null) {
         this.worldObj.newExplosion(
             (Entity) null,
             this.posX,
             this.posY,
             this.posZ,
             (float) this.radius,
             true,
             this.worldObj.getGameRules().getGameRuleBooleanValue("mobGriefing"));
         if (entity instanceof EntityPlayer) {
           entity.attackEntityFrom(
               DamageSource.causeMobDamage(getThrower()), 4 + this.rand.nextInt(14));
         } else {
           entity.attackEntityFrom(
               DamageSource.causeMobDamage(getThrower()), 29 + this.rand.nextInt(121));
         }
       }
     }
   }
 }
示例#6
0
  /** Called when the entity is attacked. */
  public boolean attackEntityFrom(DamageSource source, float amount) {
    if (!this.worldObj.isRemote && !this.isDead) {
      if (this.isEntityInvulnerable(source)) {
        return false;
      } else {
        this.setRollingDirection(-this.getRollingDirection());
        this.setRollingAmplitude(10);
        this.setBeenAttacked();
        this.setDamage(this.getDamage() + amount * 10.0F);
        boolean flag =
            source.getEntity() instanceof EntityPlayer
                && ((EntityPlayer) source.getEntity()).capabilities.isCreativeMode;

        if (flag || this.getDamage() > 40.0F) {
          if (this.riddenByEntity != null) {
            this.riddenByEntity.mountEntity((Entity) null);
          }

          if (flag && !this.hasCustomName()) {
            this.setDead();
          } else {
            this.killMinecart(source);
          }
        }

        return true;
      }
    } else {
      return true;
    }
  }
示例#7
0
  @Override
  public boolean attackEntityFrom(DamageSource source, float damage) {
    if (!worldObj.isRemote && !isDead) {
      setTimeSinceHit(10);
      setDamageTaken(this.getDamageTaken() + damage * 10.0F);

      boolean isPlayer = source.getEntity() instanceof EntityPlayer;

      if (this.getDamageTaken() > 20.0F) {
        setDead();
        if (isPlayer) {
          if (!((EntityPlayer) source.getEntity()).capabilities.isCreativeMode)
            dropItem(Extruder.Items.extruder, 1);
          if (source.getEntity().isSprinting()) setMotion(0, 0, 0);
        }

        if (inventory.contents().size() != 0)
          for (ItemStack stack : inventory.contents()) if (stack != null) entityDropItem(stack, 0);
      }

      if (!getRunning())
        setMotion(
            (double) getFacing().offsetX / 10,
            (double) getFacing().offsetY / 10,
            (double) getFacing().offsetZ / 10);
      setRunning(!getRunning());
    }

    if (worldObj.isRemote) worldObj.playAuxSFX(1001, (int) posX, (int) posY, (int) posZ, 0);

    return false;
  }
 @Override
 public void onUsingTick(ItemStack stack, EntityPlayer player, int count) {
   if (toolMaterial == ToolMaterial.EMERALD) {
     if (player.getHeldItem() != null && ZSSPlayerInfo.get(player).canBlock()) {
       Vec3 vec3 = player.getLookVec();
       double dx = player.posX + vec3.xCoord * 2.0D;
       double dy = player.posY + player.getEyeHeight() + vec3.yCoord * 2.0D;
       double dz = player.posZ + vec3.zCoord * 2.0D;
       List<EntityFireball> list =
           player.worldObj.getEntitiesWithinAABB(
               EntityFireball.class,
               AxisAlignedBB.getBoundingBox(dx - 1, dy - 1, dz - 1, dx + 1, dy + 1, dz + 1));
       for (EntityFireball fireball : list) {
         DamageSource source = DamageSource.causeFireballDamage(fireball, fireball.shootingEntity);
         if (canBlockDamage(stack, source)
             && fireball.attackEntityFrom(DamageSource.causePlayerDamage(player), 1.0F)) {
           fireball.getEntityData().setBoolean("isReflected", true);
           ZSSPlayerInfo.get(player).onAttackBlocked(stack, 1.0F);
           WorldUtils.playSoundAtEntity(player, Sounds.HAMMER, 0.4F, 0.5F);
           break;
         }
       }
     }
   }
 }
    @Override
    /**
     * Called when the entity is attacked.
     */
    public boolean attackEntityFrom(DamageSource source, float amount)
    {
        if (this.isEntityInvulnerable(source))
        {
            return false;
        }
        else
        {
            if (source.getEntity() == null || !(source.getEntity() instanceof EntityEndermite))
            {
                if (!this.worldObj.isRemote)
                {
                    this.setScreaming(true);
                }

                if (source instanceof EntityDamageSource && source.getEntity() instanceof EntityPlayer)
                {
                    if (source.getEntity() instanceof EntityPlayerMP && ((EntityPlayerMP)source.getEntity()).theItemInWorldManager.isCreative())
                    {
                        this.setScreaming(false);
                    }
                    else
                    {
                        this.isAggressive = true;
                    }
                }

                if (source instanceof EntityDamageSourceIndirect)
                {
                    this.isAggressive = false;

                    for (int i = 0; i < 64; ++i)
                    {
                        if (this.teleportRandomly())
                        {
                            return true;
                        }
                    }

                    return false;
                }
            }

            boolean flag = super.attackEntityFrom(source, amount);

            if (source.isUnblockable() && this.rand.nextInt(10) != 0)
            {
                this.teleportRandomly();
            }

            return flag;
        }
    }
  @Override
  protected void onImpact(@Nonnull RayTraceResult pos) {
    if (isReturning()) return;

    switch (pos.typeOfHit) {
      case BLOCK:
        {
          Block block = worldObj.getBlockState(pos.getBlockPos()).getBlock();
          if (block instanceof BlockBush || block instanceof BlockLeaves) return;

          int bounces = getTimesBounced();
          if (bounces < MAX_BOUNCES) {
            Vector3 currentMovementVec = new Vector3(motionX, motionY, motionZ);
            EnumFacing dir = pos.sideHit;
            Vector3 normalVector =
                new Vector3(dir.getFrontOffsetX(), dir.getFrontOffsetY(), dir.getFrontOffsetZ())
                    .normalize();
            Vector3 movementVec =
                normalVector
                    .multiply(-2 * currentMovementVec.dotProduct(normalVector))
                    .add(currentMovementVec);

            motionX = movementVec.x;
            motionY = movementVec.y;
            motionZ = movementVec.z;
            bounced = true;

            if (!worldObj.isRemote) setTimesBounced(getTimesBounced() + 1);
          }

          break;
        }
      case ENTITY:
        {
          if (!worldObj.isRemote
              && pos.entityHit != null
              && pos.entityHit instanceof EntityLivingBase
              && pos.entityHit != getThrower()) {
            EntityLivingBase thrower = getThrower();
            pos.entityHit.attackEntityFrom(
                thrower != null
                    ? thrower instanceof EntityPlayer
                        ? DamageSource.causeThrownDamage(this, thrower)
                        : DamageSource.causeMobDamage(thrower)
                    : DamageSource.generic,
                12);
            if (isFire()) pos.entityHit.setFire(5);
            else if (worldObj.rand.nextInt(3) == 0)
              ((EntityLivingBase) pos.entityHit)
                  .addPotionEffect(new PotionEffect(MobEffects.POISON, 60, 0));
          }

          break;
        }
    }
  }
 /** Returns true if the shield can block this kind of damage */
 public boolean canBlockDamage(ItemStack shield, DamageSource source) {
   boolean flag = source.isUnblockable() && !(source instanceof DamageSourceArmorBreak);
   if (toolMaterial == ToolMaterial.WOOD) {
     return !flag;
   }
   return !flag
       || source.isMagicDamage()
       || source.isFireDamage()
       || (source.isProjectile() && toolMaterial == ToolMaterial.EMERALD);
 }
示例#12
0
 public void a(DamageSource damagesource) {
   super.a(damagesource);
   if (damagesource.j() instanceof EntityCreeper
       && !(this instanceof EntityPigZombie)
       && ((EntityCreeper) damagesource.j()).n()
       && ((EntityCreeper) damagesource.j()).cn()) {
     ((EntityCreeper) damagesource.j()).co();
     this.a(new ItemStack(Items.bX, 1, 2), 0.0F);
   }
 }
 public static Cause generateCauseFor(DamageSource damageSource) {
   if (damageSource instanceof EntityDamageSourceIndirect) {
     net.minecraft.entity.Entity source = damageSource.getEntity();
     Optional<User> owner =
         ((IMixinEntity) source).getTrackedPlayer(NbtDataUtil.SPONGE_ENTITY_CREATOR);
     if (owner.isPresent()) {
       return Cause.of(
           NamedCause.of(DamageEntityEvent.SOURCE, damageSource),
           NamedCause.of(DamageEntityEvent.CREATOR, owner.get()));
     } else {
       return Cause.of(NamedCause.of(DamageEntityEvent.SOURCE, damageSource));
     }
   } else if (damageSource instanceof EntityDamageSource) {
     net.minecraft.entity.Entity source = damageSource.getEntity();
     Optional<User> owner =
         ((IMixinEntity) source).getTrackedPlayer(NbtDataUtil.SPONGE_ENTITY_CREATOR);
     Optional<User> notifier =
         ((IMixinEntity) source).getTrackedPlayer(NbtDataUtil.SPONGE_ENTITY_NOTIFIER);
     List<Object> causeObjects = new ArrayList<>();
     causeObjects.add(NamedCause.of(DamageEntityEvent.SOURCE, damageSource));
     if (notifier.isPresent()) {
       causeObjects.add(NamedCause.of(DamageEntityEvent.NOTIFIER, notifier.get()));
     }
     if (owner.isPresent()) {
       causeObjects.add(NamedCause.of(DamageEntityEvent.CREATOR, owner.get()));
     }
     return Cause.of(causeObjects.toArray());
   } else if (damageSource instanceof BlockDamageSource) {
     List<Object> causeObjects = new ArrayList<>();
     Location<org.spongepowered.api.world.World> location =
         ((BlockDamageSource) damageSource).getLocation();
     BlockPos blockPos = VecHelper.toBlockPos(location);
     Optional<User> owner =
         ((IMixinChunk)
                 ((net.minecraft.world.World) location.getExtent())
                     .getChunkFromBlockCoords(blockPos))
             .getBlockOwner(blockPos);
     Optional<User> notifier =
         ((IMixinChunk)
                 ((net.minecraft.world.World) location.getExtent())
                     .getChunkFromBlockCoords(blockPos))
             .getBlockNotifier(blockPos);
     causeObjects.add(NamedCause.of(DamageEntityEvent.SOURCE, damageSource));
     if (notifier.isPresent()) {
       causeObjects.add(NamedCause.of(DamageEntityEvent.NOTIFIER, notifier.get()));
     }
     if (owner.isPresent()) {
       causeObjects.add(NamedCause.of(DamageEntityEvent.CREATOR, owner.get()));
     }
     return Cause.of(causeObjects.toArray());
   } else {
     return Cause.of(NamedCause.of(DamageEntityEvent.SOURCE, damageSource));
   }
 }
示例#14
0
 public boolean a(DamageSource damagesource, float f0) {
   if (this.b(damagesource)) {
     return false;
   } else if ("fireball".equals(damagesource.p()) && damagesource.j() instanceof EntityPlayer) {
     super.a(damagesource, 1000.0F);
     ((EntityPlayer) damagesource.j()).b((StatBase) AchievementList.z);
     return true;
   } else {
     return super.a(damagesource, f0);
   }
 }
示例#15
0
 /** Called when the entity is attacked. */
 public boolean attackEntityFrom(DamageSource p_70097_1_, float p_70097_2_) {
   if (this.isEntityInvulnerable()) {
     return false;
   } else if ("fireball".equals(p_70097_1_.getDamageType())
       && p_70097_1_.getEntity() instanceof EntityPlayer) {
     super.attackEntityFrom(p_70097_1_, 1000.0F);
     ((EntityPlayer) p_70097_1_.getEntity()).triggerAchievement(AchievementList.ghast);
     return true;
   } else {
     return super.attackEntityFrom(p_70097_1_, p_70097_2_);
   }
 }
  @Override
  public ArmorProperties getProperties(
      EntityLivingBase player, ItemStack stack, DamageSource source, double damage, int slot) {
    int h = getArmorMaterial().getDamageReductionAmount(EntityEquipmentSlot.HEAD);
    int c = getArmorMaterial().getDamageReductionAmount(EntityEquipmentSlot.CHEST);
    int p = getArmorMaterial().getDamageReductionAmount(EntityEquipmentSlot.LEGS);
    int b = getArmorMaterial().getDamageReductionAmount(EntityEquipmentSlot.FEET);

    if (!stack.hasTagCompound()) stack.setTagCompound(new NBTTagCompound());

    if (stack.getTagCompound().getBoolean("destroyed"))
      return new ArmorProperties(0, 1 / damage, 1);

    if (stack.getTagCompound().getByte("all") > 0) {
      h += 1;
      c += 2;
      p += 1;
      b += 1;
    } else if (stack.getTagCompound().getByte("blast") > 0 && source.isExplosion()) {
      h += 2;
      c += 3;
      p += 2;
      b += 2;
    } else if (stack.getTagCompound().getByte("fire") > 0 && source.isFireDamage()) {
      h += 2;
      c += 3;
      p += 2;
      b += 2;
    } else if (stack.getTagCompound().getByte("magic") > 0 && source.isMagicDamage()) {
      h += 2;
      c += 3;
      p += 2;
      b += 2;
    } else if (stack.getTagCompound().getByte("projectile") > 0 && source.isProjectile()) {
      h += 2;
      c += 3;
      p += 2;
      b += 2;
    }

    switch (slot) {
      case 3:
        return new ArmorProperties(0, h / 25D, Integer.MAX_VALUE);
      case 2:
        return new ArmorProperties(1, c / 25D, Integer.MAX_VALUE);
      case 1:
        return new ArmorProperties(1, p / 25D, Integer.MAX_VALUE);
      case 0:
        return new ArmorProperties(0, b / 25D, Integer.MAX_VALUE);
      default:
        return null;
    }
  }
示例#17
0
 /** Called when the entity is attacked. */
 public boolean attackEntityFrom(DamageSource par1DamageSource, int par2) {
   if (this.isEntityInvulnerable()) {
     return false;
   } else if ("fireball".equals(par1DamageSource.getDamageType())
       && par1DamageSource.getEntity() instanceof EntityPlayer) {
     super.attackEntityFrom(par1DamageSource, 1000);
     ((EntityPlayer) par1DamageSource.getEntity()).triggerAchievement(AchievementList.ghast);
     return true;
   } else {
     return super.attackEntityFrom(par1DamageSource, par2);
   }
 }
示例#18
0
  protected float applyPotionDamageCalculations(DamageSource par1DamageSource, float par2) {
    par2 = super.applyPotionDamageCalculations(par1DamageSource, par2);
    if (par1DamageSource.getEntity() == this) {
      par2 = 0.0F;
    }

    if (par1DamageSource.isMagicDamage()) {
      par2 = (float) ((double) par2 * 0.15D);
    }

    return par2;
  }
示例#19
0
  public boolean a(DamageSource damagesource, float f0) {
    if (super.a(damagesource, f0)) {
      EntityLivingBase entitylivingbase = this.u();

      if (entitylivingbase == null && damagesource.j() instanceof EntityLivingBase) {
        entitylivingbase = (EntityLivingBase) damagesource.j();
      }

      if (entitylivingbase != null
          && this.o.aa() == EnumDifficulty.HARD
          && (double) this.V.nextFloat() < this.a(b).e()) {
        int i0 = MathHelper.c(this.s);
        int i1 = MathHelper.c(this.t);
        int i2 = MathHelper.c(this.u);
        EntityZombie entityzombie = new EntityZombie(this.o);

        for (int i3 = 0; i3 < 50; ++i3) {
          int i4 = i0 + MathHelper.a(this.V, 7, 40) * MathHelper.a(this.V, -1, 1);
          int i5 = i1 + MathHelper.a(this.V, 7, 40) * MathHelper.a(this.V, -1, 1);
          int i6 = i2 + MathHelper.a(this.V, 7, 40) * MathHelper.a(this.V, -1, 1);

          if (World.a((IBlockAccess) this.o, new BlockPos(i4, i5 - 1, i6))
              && this.o.l(new BlockPos(i4, i5, i6)) < 10) {
            entityzombie.b((double) i4, (double) i5, (double) i6);
            if (!this.o.b((double) i4, (double) i5, (double) i6, 7.0D)
                && this.o.a(entityzombie.aQ(), (Entity) entityzombie)
                && this.o.a((Entity) entityzombie, entityzombie.aQ()).isEmpty()
                && !this.o.d(entityzombie.aQ())) {
              this.o.d((Entity) entityzombie);
              entityzombie.d(entitylivingbase);
              entityzombie.a(this.o.E(new BlockPos(entityzombie)), (IEntityLivingData) null);
              this.a(b)
                  .b(
                      new AttributeModifier(
                          "Zombie reinforcement caller charge", -0.05000000074505806D, 0));
              entityzombie
                  .a(b)
                  .b(
                      new AttributeModifier(
                          "Zombie reinforcement callee charge", -0.05000000074505806D, 0));
              break;
            }
          }
        }
      }

      return true;
    } else {
      return false;
    }
  }
  /** Called when the mob's health reaches 0. */
  public void onDeath(DamageSource p_70645_1_) {
    super.onDeath(p_70645_1_);

    if (p_70645_1_.getSourceOfDamage() instanceof EntityThrownApple
        && p_70645_1_.getEntity() instanceof EntityPlayer) {
      EntityPlayer entityplayer = (EntityPlayer) p_70645_1_.getEntity();
      double d0 = entityplayer.posX - this.posX;
      double d1 = entityplayer.posZ - this.posZ;

      if (d0 * d0 + d1 * d1 >= 2500.0D) {
        entityplayer.triggerAchievement(AchievementList.snipeSkeleton);
      }
    }
  }
 /**
  * Can a damage source harm the entity in question.
  *
  * @param entity - entity being attacked
  * @param source - damage source/type
  * @param damage - amount of damage
  * @return true if the damage can be applied
  */
 public static boolean canHarm(Entity entity, DamageSource source, float damage) {
   if (canDamage(entity)) {
     if (isMachine(entity)) {
       if (source.isFireDamage()) {
         return false;
       }
       if (source.isMagicDamage()) {
         return false;
       }
     }
     return source != null && damage > 0;
   }
   return false;
 }
  /** Called when the mob's health reaches 0. */
  @Override
  public void onDeath(DamageSource par1DamageSource) {
    super.onDeath(par1DamageSource);

    if (par1DamageSource.getSourceOfDamage() instanceof EntityArrow
        && par1DamageSource.getEntity() instanceof EntityPlayer) {
      final EntityPlayer var2 = (EntityPlayer) par1DamageSource.getEntity();
      final double var3 = var2.posX - this.posX;
      final double var5 = var2.posZ - this.posZ;

      if (var3 * var3 + var5 * var5 >= 2500.0D) {
        var2.triggerAchievement(AchievementList.snipeSkeleton);
      }
    }
  }
 @Override
 public void onDeath(DamageSource par1DamageSource) {
   super.onDeath(par1DamageSource);
   if (par1DamageSource.getEntity() instanceof EntityPlayerMP)
     ((EntityPlayerMP) par1DamageSource.getEntity())
         .triggerAchievement(TragicAchievements.overlord2);
   List<EntityPlayerMP> list =
       this.worldObj.getEntitiesWithinAABB(
           EntityPlayerMP.class, this.getEntityBoundingBox().expand(24.0, 24.0, 24.0));
   if (!list.isEmpty()) {
     for (EntityPlayerMP mp : list) {
       mp.triggerAchievement(TragicAchievements.overlord2);
     }
   }
 }
示例#24
0
  @Override
  public void doSpellCasterEffect(EntityPlayer caster) {
    final int radius = 10;

    caster.worldObj.playSoundAtEntity(caster, "mob.enderdragon.wings", 1.0F, 1.0F);

    for (final Object obj :
        caster.worldObj.getEntitiesWithinAABBExcludingEntity(
            caster,
            AxisAlignedBB.getBoundingBox(
                caster.posX - radius,
                caster.posY - 3,
                caster.posZ - radius,
                caster.posX + radius,
                caster.posY + 3,
                caster.posZ + radius))) {
      if (obj instanceof EntityLivingBase) {
        final EntityLivingBase entity = (EntityLivingBase) obj;
        entity.attackEntityFrom(DamageSource.causeIndirectMagicDamage(caster, entity), 0.0F);

        double deltaX = entity.posX - caster.posX;
        double deltaZ;

        for (deltaZ = entity.posZ - caster.posZ;
            deltaX * deltaX + deltaZ * deltaZ < 1.0E-4D;
            deltaZ = (Math.random() - Math.random()) * 0.01D) {
          deltaX = (Math.random() - Math.random()) * 0.01D;
        }

        for (int i = 0; i < 10; i++) {
          entity.knockBack(caster, 10.0F, deltaX * -1, deltaZ * -1);
        }
      }
    }
  }
  @Override
  public IMessage onMessage(PacketKurosawaAttack message, MessageContext ctx) {
    EntityPlayer player = ctx.getServerHandler().playerEntity;
    Kurosawa item = (Kurosawa) player.getHeldItem().getItem();

    if (!item.getCooldown()) {
      World world = player.worldObj;
      EntityLivingBase target = (EntityLivingBase) world.getEntityByID(message.targetID);
      Vec3 targetPos = target.getPositionVector();
      Vec3 attackerPos = player.getPositionVector();

      Vec3 distance = targetPos.subtractReverse(attackerPos).normalize();
      distance = new Vec3(distance.xCoord * 3, distance.yCoord * 3, distance.zCoord * 3);

      player.setPositionAndRotation(
          target.posX - distance.xCoord,
          target.posY - distance.yCoord,
          target.posZ - distance.zCoord,
          player.rotationYaw + 180,
          player.rotationPitch);
      player.setRotationYawHead(player.rotationYawHead + 180);
      player.cameraPitch += 180;
      player.setPositionAndUpdate(
          target.posX - distance.xCoord,
          target.posY - distance.yCoord,
          target.posZ - distance.zCoord);
      target.attackEntityFrom(DamageSource.causePlayerDamage(player), 44);
      item.setCooldown();
    }
    return null;
  }
  public void killMinecart(DamageSource par1DamageSource) {
    super.killMinecart(par1DamageSource);

    if (!par1DamageSource.isExplosion()) {
      this.entityDropItem(new ItemStack(Block.furnaceIdle, 1), 0.0F);
    }
  }
  /**
   * Basic mob attack. Default to touch of death in EntityCreature. Overridden by each mob to define
   * their attack.
   */
  protected void attackEntity(Entity entity, float f) {
    if (onGround) {
      double d = entity.posX - posX;
      double d1 = entity.posZ - posZ;
      float f1 = MathHelper.sqrt_double(d * d + d1 * d1);
      motionX =
          (d / (double) f1)
              * 0.20000000000000001D
              * (0.850000011920929D + motionX * 0.20000000298023224D);
      motionZ =
          (d1 / (double) f1)
              * 0.20000000000000001D
              * (0.80000001192092896D + motionZ * 0.20000000298023224D);
      motionY = 0.10000000596246449D;
      fallDistance = -25F;
    }

    if ((double) f < 2D
        && entity.getBoundingBox().maxY > this.getBoundingBox().minY
        && entity.getBoundingBox().minY < this.getBoundingBox().maxY
        && !(entity instanceof CREEPSEntityCamel)) {
      // attackTime = 20;
      entity.attackEntityFrom(DamageSource.causeMobDamage(this), attack);
    }
  }
示例#28
0
 public boolean tryFireMinigun(EntityLivingBase target) {
   boolean lastShotOfAmmo = false;
   if (ammo != null && (pressurizable == null || pressurizable.getPressure(stack) > 0)) {
     setMinigunTriggerTimeOut(Math.max(10, getMinigunSoundCounter()));
     if (getMinigunSpeed() == MAX_GUN_SPEED && (!requiresTarget || gunAimedAtTarget)) {
       if (!requiresTarget) target = raytraceTarget();
       lastShotOfAmmo = ammo.attemptDamageItem(1, rand);
       if (pressurizable != null) pressurizable.addAir(stack, -airUsage);
       if (target != null) {
         ItemStack potion = ItemGunAmmo.getPotion(ammo);
         if (potion != null) {
           if (rand.nextInt(20) == 0) {
             List<PotionEffect> effects = Items.potionitem.getEffects(potion);
             if (effects != null) {
               for (PotionEffect effect : effects) {
                 target.addPotionEffect(new PotionEffect(effect));
               }
             }
           }
         } else {
           target.attackEntityFrom(DamageSource.causePlayerDamage(player), 4);
         }
       }
     }
   }
   return lastShotOfAmmo;
 }
  @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;
  }
示例#30
0
  public static boolean attackEntityFrom(
      EntityItem item, DamageSource par1DamageSource, float par2) {
    if (item.isEntityInvulnerable()) {
      return false;
    } else if (item.getEntityItem() != null
        && item.getEntityItem().getItem() == Items.nether_star
        && par1DamageSource.isExplosion()
        && canItemBurn(item.getEntityItem())) {
      return false;
    } else {
      if ((par1DamageSource == DamageSource.lava
              | par1DamageSource == DamageSource.onFire
              | par1DamageSource == DamageSource.inFire)
          && !canItemBurn(item.getEntityItem())) return false;
      if (par1DamageSource == DamageSource.cactus) return false;

      setHealth(item, (int) (getHealth(item) - 1));

      if (getHealth(item) <= 0) {
        item.setDead();
      }

      return false;
    }
  }