@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;
  }
 @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;
         }
       }
     }
   }
 }
Esempio n. 3
0
 private void fire(ItemStack is, World world, EntityPlayer ep, Entity ent) {
   Vec3 look = ep.getLookVec();
   double[] looks = ReikaVectorHelper.getPlayerLookCoords(ep, 2);
   if (!(ent instanceof EntityPlayer) && ReikaWorldHelper.lineOfSight(world, ep, ent)) {
     ItemStack fl = new ItemStack(Item.flint.itemID, 0, 0);
     EntityItem ei =
         new EntityItem(
             world,
             looks[0] / look.lengthVector(),
             looks[1] / look.lengthVector(),
             looks[2] / look.lengthVector(),
             fl);
     ei.delayBeforeCanPickup = 100;
     ei.motionX = look.xCoord / look.lengthVector();
     ei.motionY = look.yCoord / look.lengthVector();
     ei.motionZ = look.zCoord / look.lengthVector();
     if (!world.isRemote) ei.velocityChanged = true;
     if (!world.isRemote) world.playSoundAtEntity(ep, "dig.gravel", 1.5F, 2F);
     world.spawnEntityInWorld(ei);
     if (is.getItemDamage() > 4096) { // approx the 1-hit kill of a 10-heart mob
       ReikaParticleHelper.EXPLODE.spawnAt(world, ent.posX, ent.posY, ent.posZ);
       world.playSoundAtEntity(ent, "random.explode", 1, 1);
     }
     ent.attackEntityFrom(DamageSource.causePlayerDamage(ep), this.getAttackDamage(is));
     ReikaEntityHelper.knockbackEntity(ep, ent, 0.4);
     // ent.setRevengeTarget(ep);
   }
 }
 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;
 }
  @SubscribeEvent
  public void onPlayerAttackMount(LivingAttackEvent event) {
    if (event.entity instanceof EntityChocobo) {
      EntityChocobo chocobo = (EntityChocobo) event.entity;

      if (null != chocobo.riddenByEntity && chocobo.riddenByEntity instanceof EntityPlayer) {
        EntityPlayer player = (EntityPlayer) chocobo.riddenByEntity;

        if (event.source.equals(DamageSource.causePlayerDamage(player))) {
          event.setCanceled(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;
  }
 protected void superSmash(ItemStack itemstack, World world, EntityPlayer entityplayer) {
   entityplayer.swingItem();
   float f = getEntityDamage() / 2F;
   WarhammerExplosion expl =
       new WarhammerExplosion(
           world,
           entityplayer,
           entityplayer.posX,
           entityplayer.posY - entityplayer.getEyeHeight(),
           entityplayer.posZ,
           f);
   expl.doEntityExplosion(DamageSource.causePlayerDamage(entityplayer));
   expl.doParticleExplosion(true, false);
   itemstack.damageItem(16, entityplayer);
   entityplayer.addExhaustion(6F);
   setSmashed(entityplayer);
 }
Esempio n. 8
0
    public void enterState() {
      SwingSilencer silencer = getItem().getAction("SwingSilencer");
      if (silencer != null) {
        silencer.active = false;
      }
      EntityPlayer player = getPlayer();
      player.swingItem();

      if (!isRemote()) {
        Vec3 vec1 =
            Vec3.createVectorHelper(player.posX, player.posY + player.eyeHeight, player.posZ);
        Vec3 vec2 = VecUtils.add(vec1, VecUtils.multiply(player.getLookVec(), 1.5));
        MovingObjectPosition ret =
            Raytrace.perform(player.worldObj, vec1, vec2, EntitySelectors.excludeOf(player));
        if (ret != null && ret.typeOfHit == MovingObjectType.ENTITY) {
          ret.entityHit.attackEntityFrom(DamageSource.causePlayerDamage(player), stockDamage);
          player.worldObj.playSoundAtEntity(player, "dawn47:weapons.stock_attack", 0.5f, 1.0f);
        } else player.worldObj.playSoundAtEntity(player, "dawn47:weapons.stock_swing", 0.5f, 1.0f);
      }
    }
Esempio n. 9
0
  @Override
  public boolean onLeftClickEntity(ItemStack stack, EntityPlayer player, Entity entity) {

    if (entity instanceof EntityLivingBase) {
      MovingObjectPosition movingobjectposition = new MovingObjectPosition(entity);

      // SAVE ENTITY NBT //
      NBTTagCompound nbt = new NBTTagCompound();
      if (movingobjectposition.entityHit instanceof EntityLivingBase) {
        ((EntityLivingBase) movingobjectposition.entityHit).writeEntityToNBT(nbt);
      }

      // CAUSE DAMAGE //

      if (player.capabilities.isCreativeMode) {
        movingobjectposition.entityHit.attackEntityFrom(
            DamageSource.causePlayerDamage(player), (float) 99999F);
      } else {
        movingobjectposition.entityHit.attackEntityFrom(
            DamageSource.causePlayerDamage(player), (float) 2F);
        stack.stackSize--;
        if (stack.stackSize <= 0)
          player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
      }

      // PETRIFICATION //
      EntityLivingBase target = (EntityLivingBase) entity;

      if (target.getHealth() <= 0) {
        World world = target.worldObj;
        int x = (int) target.posX;
        int y = (int) target.posY;
        int z = (int) target.posZ;

        WorldUtil.setBlock(world, x, y, z, BlockData.statue.block);

        TileStatue tile = (TileStatue) WorldUtil.getPTile(world, x, y, z);

        EntityLivingBase statueEntity = null;
        Class oclass = target.getClass();

        if (oclass != null) {
          try {
            statueEntity =
                (EntityLivingBase)
                    oclass
                        .getConstructor(new Class[] {World.class})
                        .newInstance(new Object[] {player.worldObj});
          } catch (Exception exception) {
            exception.printStackTrace();
          }
        }

        if (statueEntity != null) {
          statueEntity.readEntityFromNBT(nbt);
          tile.setEntity((EntityLivingBase) statueEntity);

          tile.setAngle((int) (-target.rotationYaw));
          if (!world.isRemote && ConfigData.statueSmoke)
            PacketHandler.sendToAllInDimension(
                new SmokePacket(x, y, z, player.dimension), player.dimension);
        } else System.out.println("Entity was null!");
      }

      return true;
    }

    return false;
  }
Esempio n. 10
0
 /** Called when a player attacks an entity. If this returns true the attack will not happen. */
 public boolean hitByEntity(Entity entityIn) {
   return entityIn instanceof EntityPlayer
       ? this.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) entityIn), 0.0F)
       : false;
 }
Esempio n. 11
0
  /** Does the first part of the explosion (destroy blocks) */
  @Override
  public void doExplosionA() {
    float var1 = explosionSize;
    int var3;
    int var4;
    int var5;
    double var15;
    double var17;
    double var19;

    for (var3 = 0; var3 < field_77289_h; ++var3) {
      for (var4 = 0; var4 < field_77289_h; ++var4) {
        for (var5 = 0; var5 < field_77289_h; ++var5) {
          if (var3 == 0
              || var3 == field_77289_h - 1
              || var4 == 0
              || var4 == field_77289_h - 1
              || var5 == 0
              || var5 == field_77289_h - 1) {
            double var6 = var3 / (field_77289_h - 1.0F) * 2.0F - 1.0F;
            double var8 = var4 / (field_77289_h - 1.0F) * 2.0F - 1.0F;
            double var10 = var5 / (field_77289_h - 1.0F) * 2.0F - 1.0F;
            double var12 = Math.sqrt(var6 * var6 + var8 * var8 + var10 * var10);
            var6 /= var12;
            var8 /= var12;
            var10 /= var12;
            var15 = explosionX;
            var17 = explosionY;
            var19 = explosionZ;
          }
        }
      }
    }

    explosionSize *= 2.0F;
    var3 = MathHelper.floor_double(explosionX - explosionSize - 1.0D);
    var4 = MathHelper.floor_double(explosionX + explosionSize + 1.0D);
    var5 = MathHelper.floor_double(explosionY - explosionSize - 1.0D);
    int var28 = MathHelper.floor_double(explosionY + explosionSize + 1.0D);
    int var7 = MathHelper.floor_double(explosionZ - explosionSize - 1.0D);
    int var29 = MathHelper.floor_double(explosionZ + explosionSize + 1.0D);
    List var9 =
        worldObj.getEntitiesWithinAABBExcludingEntity(
            exploder, AxisAlignedBB.getBoundingBox(var3, var5, var7, var4, var28, var29));

    Vec3 var30 = Vec3.createVectorHelper(explosionX, explosionY, explosionZ);

    for (int var11 = 0; var11 < var9.size(); ++var11) {
      Entity var31 = (Entity) var9.get(var11);
      if (!(var31 instanceof EntityLiving)) {
        continue;
      }
      if (var31 == shootingEntity && !hurtsPlayer) {
        continue;
      }
      double var13 = var31.getDistance(explosionX, explosionY, explosionZ) / explosionSize;
      if (var13 <= 1.0D) {
        var15 = var31.posX - explosionX;
        var17 = var31.posY + var31.getEyeHeight() - explosionY;
        var19 = var31.posZ - explosionZ;
        double var33 = MathHelper.sqrt_double(var15 * var15 + var17 * var17 + var19 * var19);

        if (var33 != 0.0D) {
          var15 /= var33;
          var17 /= var33;
          var19 /= var33;
          double var32 = worldObj.getBlockDensity(var30, var31.boundingBox);
          double var34 = (1.0D - var13) * var32;
          var31.attackEntityFrom(
              DamageSource.causePlayerDamage(shootingEntity),
              (int) ((var34 * var34 + var34) * 6.0D * (explosionSize * 2) + 3.0D));
          var31.motionX += var15 * var34;
          var31.motionY += var17 * var34;
          var31.motionZ += var19 * var34;

          if (var31 instanceof EntityPlayer) {
            field_77288_k.put(
                var31, Vec3.createVectorHelper(var15 * var34, var17 * var34, var19 * var34));
          }
        }
      }
    }

    explosionSize = var1;
  }
  /**
   * @author gabizou - April 8th, 2016
   * @reason Rewrites the attackTargetEntityWithCurrentItem to throw an {@link AttackEntityEvent}
   *     prior to the ensuing {@link DamageEntityEvent}. This should cover all cases where players
   *     are attacking entities and those entities override {@link
   *     EntityLivingBase#attackEntityFrom(DamageSource, float)} and effectively bypass our damage
   *     event hooks.
   * @param targetEntity The target entity
   */
  @Overwrite
  public void attackTargetEntityWithCurrentItem(net.minecraft.entity.Entity targetEntity) {
    // Sponge Start - Add SpongeImpl hook to override in forge as necessary
    if (!SpongeImplHooks.checkAttackEntity((EntityPlayer) (Object) this, targetEntity)) {
      return;
    }
    // Sponge End
    if (targetEntity.canAttackWithItem()) {
      if (!targetEntity.hitByEntity((EntityPlayer) (Object) this)) {
        // Sponge Start - Prepare our event values
        // float baseDamage =
        // this.getEntityAttribute(SharedMonsterAttributes.attackDamage).getAttributeValue();
        final double originalBaseDamage =
            this.getEntityAttribute(SharedMonsterAttributes.attackDamage).getAttributeValue();
        float baseDamage = (float) originalBaseDamage;
        // Sponge End
        int knockbackModifier = 0;
        float enchantmentModifierAmount = 0.0F;

        // Sponge Start - gather the attack modifiers
        final List<Tuple<DamageModifier, Function<? super Double, Double>>> originalFunctions =
            new ArrayList<>();

        final EnumCreatureAttribute creatureAttribute =
            targetEntity instanceof EntityLivingBase
                ? ((EntityLivingBase) targetEntity).getCreatureAttribute()
                : EnumCreatureAttribute.UNDEFINED;
        final List<Tuple<DamageModifier, Function<? super Double, Double>>>
            enchantmentModifierFunctions =
                DamageEventHandler.createAttackEnchamntmentFunction(
                    this.getHeldItem(), creatureAttribute);
        // if (targetEntity instanceof EntityLivingBase) {
        //     enchantmentModifierAmount =
        // EnchantmentHelper.getModifierForCreature(this.getHeldItem(), creatureAttribute);
        // } else {
        //     enchantmentModifierAmount =
        // EnchantmentHelper.getModifierForCreature(this.getHeldItem(),
        // EnumCreatureAttribute.UNDEFINED);
        // }
        enchantmentModifierAmount =
            (float)
                enchantmentModifierFunctions
                    .stream()
                    .map(Tuple::getSecond)
                    .mapToDouble(function -> function.apply(originalBaseDamage))
                    .sum();
        originalFunctions.addAll(enchantmentModifierFunctions);
        // Sponge End

        knockbackModifier =
            knockbackModifier
                + EnchantmentHelper.getKnockbackModifier((EntityPlayer) (Object) this);

        if (this.isSprinting()) {
          ++knockbackModifier;
        }

        if (baseDamage > 0.0F || enchantmentModifierAmount > 0.0F) {
          boolean fallingCriticalHit =
              this.fallDistance > 0.0F
                  && !this.onGround
                  && !this.isOnLadder()
                  && !this.isInWater()
                  && !this.isPotionActive(Potion.blindness)
                  && this.ridingEntity == null
                  && targetEntity instanceof EntityLivingBase;

          if (fallingCriticalHit && baseDamage > 0.0F) {
            // Sponge - Add the function for critical attacking
            originalFunctions.add(
                DamageEventHandler.provideCriticalAttackTuple((EntityPlayer) (Object) this));
            // baseDamage *= 1.5F; Sponge - remove since it's handled in the event
          }

          // baseDamage = baseDamage + enchantmentModifierAmount; // Sponge - remove since it is
          // delegated through the event.
          boolean targetLitOnFire = false;
          int fireAspectLevel =
              EnchantmentHelper.getFireAspectModifier((EntityPlayer) (Object) this);

          if (targetEntity instanceof EntityLivingBase
              && fireAspectLevel > 0
              && !targetEntity.isBurning()) {
            targetLitOnFire = true;
            targetEntity.setFire(1);
          }

          double targetMotionX = targetEntity.motionX;
          double targetMotionY = targetEntity.motionY;
          double targetMotionZ = targetEntity.motionZ;

          // Sponge Start - Create the event and throw it
          final DamageSource damageSource =
              DamageSource.causePlayerDamage((EntityPlayer) (Object) this);
          final AttackEntityEvent event =
              SpongeEventFactory.createAttackEntityEvent(
                  Cause.source(damageSource).build(),
                  originalFunctions,
                  EntityUtil.fromNative(targetEntity),
                  knockbackModifier,
                  originalBaseDamage);
          SpongeImpl.postEvent(event);
          if (event.isCancelled()) {
            if (targetLitOnFire) {
              targetEntity.extinguish();
            }
            return;
          }
          baseDamage = (float) event.getFinalOutputDamage();
          knockbackModifier = event.getKnockbackModifier();
          boolean attackSucceded =
              targetEntity.attackEntityFrom(damageSource, (float) event.getFinalOutputDamage());
          // Sponge End
          if (attackSucceded) {
            if (knockbackModifier > 0) {
              targetEntity.addVelocity(
                  (double)
                      (-MathHelper.sin(this.rotationYaw * (float) Math.PI / 180.0F)
                          * (float) knockbackModifier
                          * 0.5F),
                  0.1D,
                  (double)
                      (MathHelper.cos(this.rotationYaw * (float) Math.PI / 180.0F)
                          * (float) knockbackModifier
                          * 0.5F));
              this.motionX *= 0.6D;
              this.motionZ *= 0.6D;
              this.setSprinting(false);
            }

            if (targetEntity instanceof EntityPlayerMP && targetEntity.velocityChanged) {
              ((EntityPlayerMP) targetEntity)
                  .playerNetServerHandler.sendPacket(new S12PacketEntityVelocity(targetEntity));
              targetEntity.velocityChanged = false;
              targetEntity.motionX = targetMotionX;
              targetEntity.motionY = targetMotionY;
              targetEntity.motionZ = targetMotionZ;
            }

            if (fallingCriticalHit) {
              this.onCriticalHit(targetEntity);
            }

            if (enchantmentModifierAmount > 0.0F) {
              this.onEnchantmentCritical(targetEntity);
            }

            if (baseDamage >= 18.0F) {
              this.triggerAchievement(AchievementList.overkill);
            }

            this.setLastAttacker(targetEntity);

            if (targetEntity instanceof EntityLivingBase) {
              EnchantmentHelper.applyThornEnchantments(
                  (EntityLivingBase) targetEntity, (EntityPlayer) (Object) this);
            }

            EnchantmentHelper.applyArthropodEnchantments(
                (EntityPlayer) (Object) this, targetEntity);
            ItemStack itemstack = this.getCurrentEquippedItem();
            net.minecraft.entity.Entity entity = targetEntity;

            if (targetEntity instanceof EntityDragonPart) {
              IEntityMultiPart ientitymultipart = ((EntityDragonPart) targetEntity).entityDragonObj;

              if (ientitymultipart instanceof EntityLivingBase) {
                entity = (EntityLivingBase) ientitymultipart;
              }
            }

            if (itemstack != null && entity instanceof EntityLivingBase) {
              itemstack.hitEntity((EntityLivingBase) entity, (EntityPlayer) (Object) this);

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

            if (targetEntity instanceof EntityLivingBase) {
              this.addStat(StatList.damageDealtStat, Math.round(baseDamage * 10.0F));

              if (fireAspectLevel > 0) {
                targetEntity.setFire(fireAspectLevel * 4);
              }
            }

            this.addExhaustion(0.3F);
          } else if (targetLitOnFire) {
            targetEntity.extinguish();
          }
        }
      }
    }
  }
  @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);
  }
Esempio n. 14
0
  @Override
  public ItemStack onItemRightClick(ItemStack is, World world, EntityPlayer ep) {
    if (is.getItemDamage() <= 0) {
      this.noCharge();
      return is;
    }
    this.warnCharge(is);
    if (!ReikaPlayerAPI.playerHasOrIsCreative(ep, Block.gravel.blockID, -1)) {
      if (!world.isRemote) world.playAuxSFX(1001, (int) ep.posX, (int) ep.posY, (int) ep.posZ, 1);
      return is;
    }
    for (float i = 1; i <= 128; i += 0.5) {
      Vec3 look = ep.getLookVec();
      double[] looks = ReikaVectorHelper.getPlayerLookCoords(ep, i);
      AxisAlignedBB fov =
          AxisAlignedBB.getBoundingBox(
              looks[0] - 0.5,
              looks[1] - 0.5,
              looks[2] - 0.5,
              looks[0] + 0.5,
              looks[1] + 0.5,
              looks[2] + 0.5);
      List infov = world.getEntitiesWithinAABB(EntityLivingBase.class, fov);
      for (int k = 0; k < infov.size(); k++) {
        EntityLivingBase ent = (EntityLivingBase) infov.get(k);
        if (!ep.equals(ent)
            && this.isEntityAttackable(ent)
            && ReikaWorldHelper.lineOfSight(world, ep, ent)) {
          double dist =
              ReikaMathLibrary.py3d(ep.posX - ent.posX, ep.posY - ent.posY, ep.posZ - ent.posZ);
          double x = ep.posX + look.xCoord;
          double y = ep.posY + ep.getEyeHeight() + look.yCoord;
          double z = ep.posZ + look.zCoord;
          double dx = ent.posX - ep.posX;
          double dy = ent.posY - ep.posY;
          double dz = ent.posZ - ep.posZ;
          if (!world.isRemote) {
            ItemStack fl = new ItemStack(Item.flint);
            EntityItem ei =
                new EntityItem(
                    world,
                    look.xCoord / look.lengthVector() + ep.posX,
                    look.yCoord / look.lengthVector() + ep.posY,
                    look.zCoord / look.lengthVector() + ep.posZ,
                    fl);
            ei.delayBeforeCanPickup = 100;
            ei.motionX = dx;
            ei.motionY = dy + 1;
            ei.motionZ = dz;
            // ReikaChatHelper.writeCoords(world, ei.posX, ei.posY, ei.posZ);
            ei.velocityChanged = true;
            world.playSoundAtEntity(ep, "dig.gravel", 1.5F, 2F);
            ei.lifespan = 5;
            world.spawnEntityInWorld(ei);

            if (is.getItemDamage() > 4096) { // approx the 1-hit kill of a 10-heart mob
              // ReikaPacketHelper.sendUpdatePacket(RotaryCraft.packetChannel,
              // PacketRegistry.GRAVELGUN.getMinValue(), world, (int)ent.posX, (int)ent.posY,
              // (int)ent.posZ);
              // world.playSoundAtEntity(ep, "random.explode", 0.25F, 1F);
            }
            if (ent instanceof EntityDragon) {
              EntityDragon ed = (EntityDragon) ent;
              ed.attackEntityFromPart(
                  ed.dragonPartBody, DamageSource.causePlayerDamage(ep), this.getAttackDamage(is));
            } else {
              int dmg = this.getAttackDamage(is);
              if (ent instanceof EntityPlayer) {
                for (int n = 1; n < 5; n++) {
                  ItemRegistry ir = ItemRegistry.getEntry(ent.getCurrentItemOrArmor(n));
                  if (ir != null) {
                    if (ir.isBedrockArmor()) dmg *= 0.75;
                  }
                }
              }
              ent.attackEntityFrom(DamageSource.causePlayerDamage(ep), dmg);
              if (dmg >= 500) RotaryAchievements.MASSIVEHIT.triggerAchievement(ep);
            }
            if (ent instanceof EntityMob
                && (ent.isDead || ent.getHealth() <= 0)
                && ReikaMathLibrary.py3d(ep.posX - ent.posX, ep.posY - ent.posY, ep.posZ - ent.posZ)
                    >= 80) RotaryAchievements.GRAVELGUN.triggerAchievement(ep);
          }
          // ReikaWorldHelper.spawnParticleLine(world, x, y, z, ent.posX, ent.posY+ent.height/2,
          // ent.posZ, "crit", 0, 0, 0, 60);
          for (float t = 0; t < 2; t += 0.05F)
            world.spawnParticle("crit", x, y, z, dx / dist * t, dy / dist * t, dz / dist * t);
        }
      }
      if (infov.size() > 0 && !(infov.size() == 1 && infov.get(0) instanceof EntityPlayer)) {
        if (!ep.capabilities.isCreativeMode)
          ReikaInventoryHelper.findAndDecrStack(
              Block.gravel.blockID, -1, ep.inventory.mainInventory);
        return new ItemStack(is.itemID, is.stackSize, is.getItemDamage() - 1);
      }
    }
    return is;
  }
Esempio n. 15
0
  @Override
  public boolean onLeftClickEntity(ItemStack stack, EntityPlayer player, Entity entity) {
    if (entity.canAttackWithItem()) {
      if (!entity.hitByEntity(player)) {
        float damage = (float) getAttackDamage(stack);
        int i = 0;
        float extraDamage = 0.0F;
        if (entity instanceof EntityLivingBase) {
          extraDamage =
              EnchantmentHelper.getEnchantmentModifierLiving(player, (EntityLivingBase) entity);
          i += EnchantmentHelper.getKnockbackModifier(player, (EntityLivingBase) entity);
        }
        if (player.isSprinting()) {
          i++;
        }
        if (damage > 0.0F || extraDamage > 0.0F) {
          boolean criricalHit =
              player.fallDistance > 0.0F
                  && !player.onGround
                  && !player.isOnLadder()
                  && !player.isInWater()
                  && !player.isPotionActive(Potion.blindness)
                  && player.ridingEntity == null
                  && entity instanceof EntityLivingBase;
          if (criricalHit && damage > 0.0F) {
            damage *= 1.5F;
          }
          damage += extraDamage;
          boolean fire = false;
          int j = EnchantmentHelper.getFireAspectModifier(player);
          if (entity instanceof EntityLivingBase && j > 0 && !entity.isBurning()) {
            fire = true;
            entity.setFire(1);
          }
          boolean attack = entity.attackEntityFrom(DamageSource.causePlayerDamage(player), damage);
          if (attack) {
            if (i > 0) {
              entity.addVelocity(
                  (double)
                      (-MathHelper.sin(player.rotationYaw * (float) Math.PI / 180.0F)
                          * (float) i
                          * 0.5F),
                  0.1D,
                  (double)
                      (MathHelper.cos(player.rotationYaw * (float) Math.PI / 180.0F)
                          * (float) i
                          * 0.5F));
              player.motionX *= 0.6D;
              player.motionZ *= 0.6D;
              player.setSprinting(false);
            }
            if (criricalHit) {
              player.onCriticalHit(entity);
            }
            if (extraDamage > 0.0F) {
              player.onEnchantmentCritical(entity);
            }
            if (damage >= 18.0F) {
              player.triggerAchievement(AchievementList.overkill);
            }
            player.setLastAttacker(entity);
            if (entity instanceof EntityLivingBase) {
              EnchantmentHelper.func_151384_a((EntityLivingBase) entity, player);
            }
          }

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

          if (entity instanceof EntityDragonPart) {
            IEntityMultiPart entityMultipart = ((EntityDragonPart) entity).entityDragonObj;
            if (entityMultipart != null && entityMultipart instanceof EntityLivingBase) {
              object = (EntityLivingBase) entityMultipart;
            }
          }
          if (itemstack != null && object instanceof EntityLivingBase) {
            itemstack.hitEntity((EntityLivingBase) object, player);
            if (itemstack.stackSize <= 0) {
              player.destroyCurrentEquippedItem();
            }
          }
          if (entity instanceof EntityLivingBase) {
            player.addStat(StatList.damageDealtStat, Math.round(damage * 10.0F));
            if (j > 0 && attack) {
              entity.setFire(j * 4);
            } else if (fire) {
              entity.extinguish();
            }
          }
          player.addExhaustion(0.3F);
        }
      }
    }
    return true;
  }