Ejemplo n.º 1
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);
   }
 }
Ejemplo n.º 2
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;
  }