/**
  * Current implementations of this method in child classes do not use the entry argument beside
  * ev. They just raise the damage on the stack.
  */
 @Override
 public boolean hitEntity(
     ItemStack par1ItemStack,
     EntityLivingBase par2EntityLivingBase,
     EntityLivingBase par3EntityLivingBase) {
   // DON'T MOVE A SINGLE DANG BIT!
   par2EntityLivingBase.motionX = 0;
   par2EntityLivingBase.motionY = 0;
   par2EntityLivingBase.motionZ = 0;
   // Apply poison
   if (this.poisonous) {
     par2EntityLivingBase.addPotionEffect(new PotionEffect(Potion.poison.id, 75, 1));
   }
   // Damage item stack
   par1ItemStack.damageItem(1, par3EntityLivingBase);
   return true;
 }
Example #2
0
  private void updateAbility() {
    if (!worldObj.isRemote) {
      abilityCounter--;

      if (abilityCounter <= 0) {
        // Boom spider throws a boom ball.
        if (spiderType == EnumSpiderType.BOOM && target != null) {
          EntityBoomBall boomBall = new EntityBoomBall(this, target, 2.5F);
          worldObj.spawnEntityInWorld(boomBall);
        }

        // Slinger spider throws a web shot.
        else if (spiderType == EnumSpiderType.SLINGER && target != null) {
          EntityWebShot webShot = new EntityWebShot(this, target, 2.5F);
          worldObj.spawnEntityInWorld(webShot);

          worldObj.playSoundAtEntity(this, "random.bow", 0.75F, 1.0F);
        }

        // Nova spider heals nearby spiders.
        else if (spiderType == EnumSpiderType.NOVA && RadixLogic.getBooleanWithProbability(20)) {
          EntitySpiderEx spider =
              (EntitySpiderEx)
                  RadixLogic.getNearestEntityOfTypeWithinDistance(EntitySpiderEx.class, this, 8);

          if (spider != null && spider.getHealth() < spider.getMaxHealth()) {
            int healthIncrease = getLevel() * 5;
            spider.setHealth(healthIncrease);
            Utils.spawnParticlesAroundEntityS("heart", this, 6);
            Utils.spawnParticlesAroundEntityS("heart", spider, 6);
          }
        }

        // Ender spider throws targets into the air.
        else if (spiderType == EnumSpiderType.ENDER && target != null) {
          if (worldObj.canBlockSeeTheSky((int) posX, (int) posY, (int) posZ)) {
            Utils.spawnParticlesAroundEntityS(Particle.PORTAL, this, 6);
            target.motionY = 1.0F + (0.3F * getLevel());

            target.motionX =
                rand.nextBoolean()
                    ? rand.nextDouble()
                    : rand.nextBoolean() ? rand.nextDouble() * -1 : 0;
            target.motionZ =
                rand.nextBoolean()
                    ? rand.nextDouble()
                    : rand.nextBoolean() ? rand.nextDouble() * -1 : 0;

            if (getLevel() == 3) {
              target.motionX = target.motionX > 0 ? target.motionX + 2.0F : target.motionX - 2.0F;
              target.motionZ = target.motionZ > 0 ? target.motionZ + 2.0F : target.motionZ - 2.0F;
            }

            worldObj.playSoundAtEntity(target, "mob.endermen.portal", 1.0F, 1.0F);

            Utils.spawnParticlesAroundEntityS(Particle.PORTAL, target, 6);
          }
        }

        abilityCounter = abilityThreshold;
      }
    }
  }
 protected void swingThrower() {
   EntityLivingBase thrower = getThrower();
   if (thrower != null && !thrower.onGround && isInGround()) {
     if (thrower.worldObj.isRemote) {
       // Determine the swing variables on first swing tick:
       float x = dataWatcher.getWatchableObjectFloat(HIT_POS_X);
       float y = dataWatcher.getWatchableObjectFloat(HIT_POS_Y);
       float z = dataWatcher.getWatchableObjectFloat(HIT_POS_Z);
       if (swingTicks == 0 && swingVec == null && thrower.motionY < 0) {
         swingVec =
             Vec3.createVectorHelper(
                     (x - thrower.posX),
                     y - (thrower.posY + thrower.getEyeHeight()),
                     (z - thrower.posZ))
                 .normalize();
         dy = (thrower.getDistance(x, y, z) / 7.0D); // lower divisor gives bigger change in y
         // calculate horizontal distance to find initial swing tick position
         // as distance approaches zero, swing ticks should approach ticks required / 2
         // as distance approaches maxDistance, swing ticks should approach zero
         // this makes sure player's arc is even around pivot point
         double d = Math.min(thrower.getDistance(x, thrower.posY, z), getMaxDistance());
         swingTicks = MathHelper.floor_double(((getMaxDistance() - d) / getMaxDistance()) * 8);
       }
       if (swingVec != null) {
         double sin = Math.sin(10.0D * swingTicks * Math.PI / 180.0D);
         double f = 0.8D; // arbitrary horizontal motion factor
         thrower.motionX = (sin * swingVec.xCoord * f);
         thrower.motionZ = (sin * swingVec.zCoord * f);
         // y motion needs to oscillate twice as quickly, so it goes up on the other side of the
         // swing
         thrower.motionY = dy * -Math.sin(20.0D * swingTicks * Math.PI / 180.0D);
         // check for horizontal collisions that should stop swinging motion
         MovingObjectPosition mop =
             TargetUtils.checkForImpact(worldObj, thrower, this, -(thrower.width / 4.0F), false);
         if (mop != null && mop.typeOfHit != MovingObjectType.MISS) {
           thrower.motionX = -thrower.motionX * 0.15D;
           thrower.motionY = -thrower.motionY * 0.15D;
           thrower.motionZ = -thrower.motionZ * 0.15D;
           swingVec = null;
         }
         ++swingTicks; // increment at end
         if (thrower.fallDistance > 0 && thrower.motionY < 0) {
           // 0.466885F seems to be roughly the amount added each tick while swinging; round for a
           // little extra server-side padding
           PacketDispatcher.sendToServer(new FallDistancePacket(thrower, -0.467F));
           thrower.fallDistance -= 0.467F;
         }
       } else if (swingTicks > 0) {
         // still let player hang there after colliding, but move towards center
         if (thrower.getDistanceSq(x, thrower.posY, z) > 1.0D) {
           double dx = x - thrower.posX;
           double dz = z - thrower.posZ;
           thrower.motionX = 0.15D * dx;
           thrower.motionZ = 0.15D * dz;
         }
         if (thrower.posY < (y - (getMaxDistance() / 2.0D))) {
           thrower.motionY = 0;
         }
         ++swingTicks; // increment at end
         PacketDispatcher.sendToServer(new FallDistancePacket(thrower, 0.0F));
         thrower.fallDistance = 0.0F;
       }
     }
   }
 }
  @Override
  public void updateEntity() {
    if (worldObj.isRemote) {
      this.rotation += this.rotationIncrement;
    } else {
      surroundingCheckTicks++;
    }

    if (worldObj.isRemote || ticksSinceLastEntityScan++ > 25) {
      updateNearbyEntities();
      ticksSinceLastEntityScan = 0;
    }

    Iterator<EntityLivingBase> it = cachedEntities.iterator();
    while (it.hasNext()) {

      EntityLivingBase ent = it.next();

      if (ent.isDead) {
        it.remove();
        continue;
      }

      MovingObjectPosition mop =
          this.worldObj.rayTraceBlocks(
              Vec3.createVectorHelper(xCoord + 0.5, yCoord + 1.5, zCoord + 0.5),
              Vec3.createVectorHelper(ent.posX, ent.posY + ent.getEyeHeight(), ent.posZ),
              false);

      if (EntityUtilities.isSummon(ent) || mop != null) {
        continue;
      }

      ent.motionY = 0;
      ent.motionX = 0;
      ent.motionZ = 0;
      double deltaX = this.xCoord + 0.5f - ent.posX;
      double deltaZ = this.zCoord + 0.5f - ent.posZ;
      double deltaY = this.yCoord - ent.posY;
      double angle = Math.atan2(deltaZ, deltaX);

      double offsetX = Math.cos(angle) * 0.1;
      double offsetZ = Math.sin(angle) * 0.1;
      double offsetY = 0.05f;

      double distanceHorizontal = deltaX * deltaX + deltaZ * deltaZ;
      double distanceVertical = this.yCoord - ent.posY;
      boolean spawnedParticles = false;

      if (distanceHorizontal < 1.3) {
        if (distanceVertical < -1.5) {
          if (worldObj.isRemote && worldObj.rand.nextInt(10) < 3) {
            AMCore.proxy.particleManager.BoltFromPointToPoint(
                worldObj,
                xCoord + 0.5,
                yCoord + 1.3,
                zCoord + 0.5,
                ent.posX,
                ent.posY,
                ent.posZ,
                4,
                0x000000);
          }
        }
        if (distanceVertical < -2) {
          offsetY = 0;
          if (!worldObj.isRemote) {
            if (ent.attackEntityFrom(DamageSources.darkNexus, 4)) {
              if (ent.getHealth() <= 0) {
                ent.setDead();
                float power =
                    ((int) Math.ceil((ent.getMaxHealth() * (ent.ticksExisted / 20)) % 5000))
                        * this.powerMultiplier;
                PowerNodeRegistry.For(this.worldObj).insertPower(this, PowerTypes.DARK, power);
              }
            }
          }
        }
      }

      if (worldObj.isRemote) {
        if (!arcs.containsKey(ent)) {
          AMLineArc arc =
              (AMLineArc)
                  AMCore.proxy.particleManager.spawn(
                      worldObj,
                      "textures/blocks/oreblocksunstone.png",
                      xCoord + 0.5,
                      yCoord + 1.3,
                      zCoord + 0.5,
                      ent);
          if (arc != null) {
            arc.setExtendToTarget();
            arc.setRBGColorF(1, 1, 1);
          }
          arcs.put(ent, arc);
        }
        Iterator arcIterator = arcs.keySet().iterator();
        ArrayList<Entity> toRemove = new ArrayList<Entity>();
        while (arcIterator.hasNext()) {
          Entity arcEnt = (Entity) arcIterator.next();
          AMLineArc arc = (AMLineArc) arcs.get(arcEnt);
          if (arcEnt == null
              || arcEnt.isDead
              || arc == null
              || arc.isDead
              || new AMVector3(ent).distanceSqTo(new AMVector3(xCoord, yCoord, zCoord)) > 100)
            toRemove.add(arcEnt);
        }

        for (Entity e : toRemove) {
          arcs.remove(e);
        }
      }
      if (!worldObj.isRemote) ent.moveEntity(offsetX, offsetY, offsetZ);
    }
    if (surroundingCheckTicks % 100 == 0) {
      checkNearbyBlockState();
      surroundingCheckTicks = 1;
      if (!worldObj.isRemote
          && PowerNodeRegistry.For(this.worldObj).checkPower(this, this.capacity * 0.1f)) {
        List<EntityPlayer> nearbyPlayers =
            worldObj.getEntitiesWithinAABB(
                EntityPlayer.class,
                AxisAlignedBB.getBoundingBox(
                    this.xCoord - 2,
                    this.yCoord,
                    this.zCoord - 2,
                    this.xCoord + 2,
                    this.yCoord + 3,
                    this.zCoord + 2));
        for (EntityPlayer p : nearbyPlayers) {
          if (p.isPotionActive(BuffList.manaRegen.id)) continue;
          p.addPotionEffect(new BuffEffectManaRegen(600, 3));
        }
      }

      // TODO:
      /*if (rand.nextDouble() < (this.getCharge() / this.getCapacity()) * 0.01){
      	int maxSev = (int)Math.ceil((this.getCharge() / this.getCapacity()) * 2) + rand.nextInt(2);
      	IllEffectsManager.instance.ApplyRandomBadThing(this, IllEffectSeverity.values()[maxSev], BadThingTypes.DARKNEXUS);
      }*/
    }

    super.callSuperUpdate();
  }