Exemplo n.º 1
0
  public boolean strikeLightning(Entity entity) {
    // CraftBukkit start
    LightningStrikeEvent lightning =
        new LightningStrikeEvent(
            this.getWorld(), (org.bukkit.entity.LightningStrike) entity.getBukkitEntity());
    this.getServer().getPluginManager().callEvent(lightning);

    if (lightning.isCancelled()) {
      return false;
    }

    if (super.strikeLightning(entity)) {
      this.server
          .getPlayerList()
          .sendPacketNearby(
              entity.locX,
              entity.locY,
              entity.locZ,
              512.0D,
              this.dimension,
              new Packet71Weather(entity));
      // CraftBukkit end
      return true;
    } else {
      return false;
    }
  }
Exemplo n.º 2
0
  public void a(Packet7UseEntity packet7useentity) {
    // CraftBukkit start
    if (this.player.dead) {
      return;
    }
    // CraftBukkit end

    WorldServer worldserver = this.minecraftServer.a(this.player.dimension);
    Entity entity = worldserver.getEntity(packet7useentity.target);

    if (entity != null && this.player.e(entity) && this.player.g(entity) < 36.0D) {
      if (packet7useentity.c == 0) {
        // CraftBukkit start
        PlayerInteractEntityEvent piee =
            new PlayerInteractEntityEvent((Player) getPlayer(), entity.getBukkitEntity());
        server.getPluginManager().callEvent(piee);
        if (piee.isCancelled()) {
          return;
        }
        // CraftBukkit end
        this.player.c(entity);
      } else if (packet7useentity.c == 1) {
        this.player.d(entity);
      }
    }
  }
Exemplo n.º 3
0
  public List<org.bukkit.entity.Entity> getNearbyEntities(double x, double y, double z) {
    @SuppressWarnings("unchecked")
    List<Entity> notchEntityList =
        entity.world.getEntities(entity, entity.boundingBox.grow(x, y, z));
    List<org.bukkit.entity.Entity> bukkitEntityList =
        new java.util.ArrayList<org.bukkit.entity.Entity>(notchEntityList.size());

    for (Entity e : notchEntityList) {
      bukkitEntityList.add(e.getBukkitEntity());
    }
    return bukkitEntityList;
  }
Exemplo n.º 4
0
 /**
  * Checks if the player is on ground.
  *
  * @return true, if the player is on ground
  */
 public boolean isOnGround() {
   if (onGround == null) {
     final double d0 = 0.01D;
     onGround =
         BlockProperties.isOnGround(
             getBlockAccess(),
             minX - d0,
             minY - yOnGround,
             minZ - d0,
             maxX + d0,
             minY + 0.25,
             maxZ + d0);
     if (!onGround) {
       // TODO: Probably check other ids too before doing this ?
       final double d1 = 0.25D;
       final AxisAlignedBB box =
           useBox.b(
               minX - d1,
               minY - getyOnGround() - d1,
               minZ - d1,
               maxX + d1,
               minY + 0.25 + d1,
               maxZ + d1);
       @SuppressWarnings("rawtypes")
       final List list = worldServer.getEntities(entityPlayer, box);
       @SuppressWarnings("rawtypes")
       Iterator iterator = list.iterator();
       while (iterator.hasNext()) {
         final Entity entity = (Entity) iterator.next();
         final EntityType type = entity.getBukkitEntity().getType();
         if (type != EntityType.BOAT && type != EntityType.MINECART) continue;
         final AxisAlignedBB otherBox = entity.boundingBox;
         if (box.a > otherBox.d
             || box.d < otherBox.a
             || box.b > otherBox.e
             || box.e < otherBox.b
             || box.c > otherBox.f
             || box.f < otherBox.c) continue;
         else {
           onGround = true;
           break;
         }
       }
     }
   }
   return onGround;
 }
  @Override
  public void c(Entity entity) {
    if (lastBounceId != entity.id || System.currentTimeMillis() - lastBounceTick > 1000) {
      EntityTargetEvent event =
          new NpcEntityTargetEvent(
              getBukkitEntity(),
              entity.getBukkitEntity(),
              NpcEntityTargetEvent.NpcTargetReason.NPC_BOUNCED);
      CraftServer server = ((WorldServer) this.world).getServer();
      server.getPluginManager().callEvent(event);

      lastBounceTick = System.currentTimeMillis();
    }

    lastBounceId = entity.id;

    super.c(entity);
  }
Exemplo n.º 6
0
  private void c(Entity entity) {
    org.bukkit.entity.Entity bukkitTarget = entity == null ? null : entity.getBukkitEntity();

    EntityTargetEvent event =
        new EntityTargetEvent(
            getBukkitEntity(), bukkitTarget, EntityTargetEvent.TargetReason.PIG_ZOMBIE_TARGET);
    this.world.getServer().getPluginManager().callEvent(event);

    if (event.isCancelled()) {
      return;
    }

    if (event.getTarget() == null) {
      this.target = null;
      return;
    }
    entity = ((CraftEntity) event.getTarget()).getHandle();

    this.target = entity;
    this.angerLevel = (400 + this.random.nextInt(400));
    this.soundDelay = this.random.nextInt(40);
  }
Exemplo n.º 7
0
  public void j_() {
    super.j_();
    if (this.lastPitch == 0.0F && this.lastYaw == 0.0F) {
      float f = MathHelper.sqrt(this.motX * this.motX + this.motZ * this.motZ);

      this.lastYaw =
          this.yaw = (float) (Math.atan2(this.motX, this.motZ) * 180.0D / 3.1415927410125732D);
      this.lastPitch =
          this.pitch = (float) (Math.atan2(this.motY, (double) f) * 180.0D / 3.1415927410125732D);
    }

    int i = this.world.getTypeId(this.d, this.e, this.f);

    if (i > 0) {
      Block.byId[i].updateShape(this.world, this.d, this.e, this.f);
      AxisAlignedBB axisalignedbb = Block.byId[i].e(this.world, this.d, this.e, this.f);

      if (axisalignedbb != null
          && axisalignedbb.a(this.world.getVec3DPool().create(this.locX, this.locY, this.locZ))) {
        this.inGround = true;
      }
    }

    if (this.shake > 0) {
      --this.shake;
    }

    if (this.inGround) {
      int j = this.world.getTypeId(this.d, this.e, this.f);
      int k = this.world.getData(this.d, this.e, this.f);

      if (j == this.g && k == this.h) {
        ++this.j;
        if (this.j == 1200) {
          this.die();
        }
      } else {
        this.inGround = false;
        this.motX *= (double) (this.random.nextFloat() * 0.2F);
        this.motY *= (double) (this.random.nextFloat() * 0.2F);
        this.motZ *= (double) (this.random.nextFloat() * 0.2F);
        this.j = 0;
        this.at = 0;
      }
    } else {
      ++this.at;
      Vec3D vec3d = this.world.getVec3DPool().create(this.locX, this.locY, this.locZ);
      Vec3D vec3d1 =
          this.world
              .getVec3DPool()
              .create(this.locX + this.motX, this.locY + this.motY, this.locZ + this.motZ);
      MovingObjectPosition movingobjectposition = this.world.rayTrace(vec3d, vec3d1, false, true);

      vec3d = this.world.getVec3DPool().create(this.locX, this.locY, this.locZ);
      vec3d1 =
          this.world
              .getVec3DPool()
              .create(this.locX + this.motX, this.locY + this.motY, this.locZ + this.motZ);
      if (movingobjectposition != null) {
        vec3d1 =
            this.world
                .getVec3DPool()
                .create(
                    movingobjectposition.pos.c,
                    movingobjectposition.pos.d,
                    movingobjectposition.pos.e);
      }

      Entity entity = null;
      List list =
          this.world.getEntities(
              this, this.boundingBox.a(this.motX, this.motY, this.motZ).grow(1.0D, 1.0D, 1.0D));
      double d0 = 0.0D;

      int l;
      float f1;

      for (l = 0; l < list.size(); ++l) {
        Entity entity1 = (Entity) list.get(l);

        if (entity1.L() && (entity1 != this.shooter || this.at >= 5)) {
          f1 = 0.3F;
          AxisAlignedBB axisalignedbb1 =
              entity1.boundingBox.grow((double) f1, (double) f1, (double) f1);
          MovingObjectPosition movingobjectposition1 = axisalignedbb1.a(vec3d, vec3d1);

          if (movingobjectposition1 != null) {
            double d1 =
                vec3d.distanceSquared(
                    movingobjectposition1.pos); // CraftBukkit - distance efficiency

            if (d1 < d0 || d0 == 0.0D) {
              entity = entity1;
              d0 = d1;
            }
          }
        }
      }

      if (entity != null) {
        movingobjectposition = new MovingObjectPosition(entity);
      }

      float f2;
      float f3;

      if (movingobjectposition != null) {
        // CraftBukkit start
        Projectile projectile = (Projectile) this.getBukkitEntity();
        ProjectileHitEvent phe = new ProjectileHitEvent(projectile);
        this.world.getServer().getPluginManager().callEvent(phe);
        // CraftBukkit end
        if (movingobjectposition.entity != null) {
          f2 =
              MathHelper.sqrt(
                  this.motX * this.motX + this.motY * this.motY + this.motZ * this.motZ);
          int i1 = MathHelper.f((double) f2 * this.damage);

          if (this.d()) {
            i1 += this.random.nextInt(i1 / 2 + 2);
          }

          DamageSource damagesource = null;

          if (this.shooter == null) {
            damagesource = DamageSource.arrow(this, this);
          } else {
            damagesource = DamageSource.arrow(this, this.shooter);
          }

          // CraftBukkit start - moved damage call
          if (movingobjectposition.entity.damageEntity(damagesource, i1)) {
            if (this.isBurning()
                && !(movingobjectposition.entity instanceof EntityEnderman)
                && (!(movingobjectposition.entity instanceof EntityPlayer)
                    || !(this.shooter instanceof EntityPlayer)
                    || this.world
                        .pvpMode)) { // CraftBukkit - abide by pvp setting if destination is a
                                     // player.
              EntityCombustByEntityEvent combustEvent =
                  new EntityCombustByEntityEvent(
                      this.getBukkitEntity(), entity.getBukkitEntity(), 5);
              org.bukkit.Bukkit.getPluginManager().callEvent(combustEvent);

              if (!combustEvent.isCancelled()) {
                movingobjectposition.entity.setOnFire(combustEvent.getDuration());
              }
              // CraftBukkit end
            }

            // if (movingobjectposition.entity.damageEntity(damagesource, i1)) { // CraftBukkit -
            // moved up
            if (movingobjectposition.entity instanceof EntityLiving) {
              EntityLiving entityliving = (EntityLiving) movingobjectposition.entity;

              if (!this.world.isStatic) {
                entityliving.r(entityliving.bJ() + 1);
              }

              if (this.av > 0) {
                f3 = MathHelper.sqrt(this.motX * this.motX + this.motZ * this.motZ);

                if (f3 > 0.0F) {
                  movingobjectposition.entity.g(
                      this.motX * (double) this.av * 0.6000000238418579D / (double) f3,
                      0.1D,
                      this.motZ * (double) this.av * 0.6000000238418579D / (double) f3);
                }
              }

              if (this.shooter != null) {
                EnchantmentThorns.a(this.shooter, entityliving, this.random);
              }

              if (this.shooter != null
                  && movingobjectposition.entity != this.shooter
                  && movingobjectposition.entity instanceof EntityHuman
                  && this.shooter instanceof EntityPlayer) {
                ((EntityPlayer) this.shooter).playerConnection.sendPacket(new Packet70Bed(6, 0));
              }
            }

            this.makeSound("random.bowhit", 1.0F, 1.2F / (this.random.nextFloat() * 0.2F + 0.9F));
            if (!(movingobjectposition.entity instanceof EntityEnderman)) {
              this.die();
            }
          } else {
            this.motX *= -0.10000000149011612D;
            this.motY *= -0.10000000149011612D;
            this.motZ *= -0.10000000149011612D;
            this.yaw += 180.0F;
            this.lastYaw += 180.0F;
            this.at = 0;
          }
        } else {
          this.d = movingobjectposition.b;
          this.e = movingobjectposition.c;
          this.f = movingobjectposition.d;
          this.g = this.world.getTypeId(this.d, this.e, this.f);
          this.h = this.world.getData(this.d, this.e, this.f);
          this.motX = (double) ((float) (movingobjectposition.pos.c - this.locX));
          this.motY = (double) ((float) (movingobjectposition.pos.d - this.locY));
          this.motZ = (double) ((float) (movingobjectposition.pos.e - this.locZ));
          f2 =
              MathHelper.sqrt(
                  this.motX * this.motX + this.motY * this.motY + this.motZ * this.motZ);
          this.locX -= this.motX / (double) f2 * 0.05000000074505806D;
          this.locY -= this.motY / (double) f2 * 0.05000000074505806D;
          this.locZ -= this.motZ / (double) f2 * 0.05000000074505806D;
          this.makeSound("random.bowhit", 1.0F, 1.2F / (this.random.nextFloat() * 0.2F + 0.9F));
          this.inGround = true;
          this.shake = 7;
          this.e(false);
          if (this.g != 0) {
            Block.byId[this.g].a(this.world, this.d, this.e, this.f, this);
          }
        }
      }

      if (this.d()) {
        for (l = 0; l < 4; ++l) {
          this.world.addParticle(
              "crit",
              this.locX + this.motX * (double) l / 4.0D,
              this.locY + this.motY * (double) l / 4.0D,
              this.locZ + this.motZ * (double) l / 4.0D,
              -this.motX,
              -this.motY + 0.2D,
              -this.motZ);
        }
      }

      this.locX += this.motX;
      this.locY += this.motY;
      this.locZ += this.motZ;
      f2 = MathHelper.sqrt(this.motX * this.motX + this.motZ * this.motZ);
      this.yaw = (float) (Math.atan2(this.motX, this.motZ) * 180.0D / 3.1415927410125732D);

      for (this.pitch = (float) (Math.atan2(this.motY, (double) f2) * 180.0D / 3.1415927410125732D);
          this.pitch - this.lastPitch < -180.0F;
          this.lastPitch -= 360.0F) {;
      }

      while (this.pitch - this.lastPitch >= 180.0F) {
        this.lastPitch += 360.0F;
      }

      while (this.yaw - this.lastYaw < -180.0F) {
        this.lastYaw -= 360.0F;
      }

      while (this.yaw - this.lastYaw >= 180.0F) {
        this.lastYaw += 360.0F;
      }

      this.pitch = this.lastPitch + (this.pitch - this.lastPitch) * 0.2F;
      this.yaw = this.lastYaw + (this.yaw - this.lastYaw) * 0.2F;
      float f4 = 0.99F;

      f1 = 0.05F;
      if (this.H()) {
        for (int j1 = 0; j1 < 4; ++j1) {
          f3 = 0.25F;
          this.world.addParticle(
              "bubble",
              this.locX - this.motX * (double) f3,
              this.locY - this.motY * (double) f3,
              this.locZ - this.motZ * (double) f3,
              this.motX,
              this.motY,
              this.motZ);
        }

        f4 = 0.8F;
      }

      this.motX *= (double) f4;
      this.motY *= (double) f4;
      this.motZ *= (double) f4;
      this.motY -= (double) f1;
      this.setPosition(this.locX, this.locY, this.locZ);
      this.D();
    }
  }
Exemplo n.º 8
0
  public void h() {
    super.h();
    if (this.lastPitch == 0.0F && this.lastYaw == 0.0F) {
      float f = MathHelper.sqrt(this.motX * this.motX + this.motZ * this.motZ);

      this.lastYaw =
          this.yaw = (float) (Math.atan2(this.motX, this.motZ) * 180.0D / 3.1415927410125732D);
      this.lastPitch =
          this.pitch = (float) (Math.atan2(this.motY, (double) f) * 180.0D / 3.1415927410125732D);
    }

    Block block = this.world.getType(this.d, this.e, this.f);

    if (block.getMaterial() != Material.AIR) {
      block.updateShape(this.world, this.d, this.e, this.f);
      AxisAlignedBB axisalignedbb = block.a(this.world, this.d, this.e, this.f);

      if (axisalignedbb != null && axisalignedbb.a(Vec3D.a(this.locX, this.locY, this.locZ))) {
        this.inGround = true;
      }
    }

    if (this.shake > 0) {
      --this.shake;
    }

    if (this.inGround) {
      int i = this.world.getData(this.d, this.e, this.f);

      if (block == this.g && i == this.h) {
        ++this.at;
        if (this.at == 1200) {
          this.die();
        }
      } else {
        this.inGround = false;
        this.motX *= (double) (this.random.nextFloat() * 0.2F);
        this.motY *= (double) (this.random.nextFloat() * 0.2F);
        this.motZ *= (double) (this.random.nextFloat() * 0.2F);
        this.at = 0;
        this.au = 0;
      }
    } else {
      ++this.au;
      Vec3D vec3d = Vec3D.a(this.locX, this.locY, this.locZ);
      Vec3D vec3d1 = Vec3D.a(this.locX + this.motX, this.locY + this.motY, this.locZ + this.motZ);
      MovingObjectPosition movingobjectposition =
          this.world.rayTrace(vec3d, vec3d1, false, true, false);

      vec3d = Vec3D.a(this.locX, this.locY, this.locZ);
      vec3d1 = Vec3D.a(this.locX + this.motX, this.locY + this.motY, this.locZ + this.motZ);
      if (movingobjectposition != null) {
        vec3d1 =
            Vec3D.a(
                movingobjectposition.pos.a, movingobjectposition.pos.b, movingobjectposition.pos.c);
      }

      Entity entity = null;
      List list =
          this.world.getEntities(
              this, this.boundingBox.a(this.motX, this.motY, this.motZ).grow(1.0D, 1.0D, 1.0D));
      double d0 = 0.0D;

      int j;
      float f1;

      for (j = 0; j < list.size(); ++j) {
        Entity entity1 = (Entity) list.get(j);

        if (entity1.Q() && (entity1 != this.shooter || this.au >= 5)) {
          f1 = 0.3F;
          AxisAlignedBB axisalignedbb1 =
              entity1.boundingBox.grow((double) f1, (double) f1, (double) f1);
          MovingObjectPosition movingobjectposition1 = axisalignedbb1.a(vec3d, vec3d1);

          if (movingobjectposition1 != null) {
            double d1 =
                vec3d.distanceSquared(
                    movingobjectposition1.pos); // CraftBukkit - distance efficiency

            if (d1 < d0 || d0 == 0.0D) {
              entity = entity1;
              d0 = d1;
            }
          }
        }
      }

      if (entity != null) {
        movingobjectposition = new MovingObjectPosition(entity);
      }

      if (movingobjectposition != null
          && movingobjectposition.entity != null
          && movingobjectposition.entity instanceof EntityHuman) {
        EntityHuman entityhuman = (EntityHuman) movingobjectposition.entity;

        if (entityhuman.abilities.isInvulnerable
            || this.shooter instanceof EntityHuman
                && !((EntityHuman) this.shooter).a(entityhuman)) {
          movingobjectposition = null;
        }
      }

      float f2;
      float f3;

      if (movingobjectposition != null) {
        org.bukkit.craftbukkit.event.CraftEventFactory.callProjectileHitEvent(
            this); // CraftBukkit - Call event

        if (movingobjectposition.entity != null) {
          f2 =
              MathHelper.sqrt(
                  this.motX * this.motX + this.motY * this.motY + this.motZ * this.motZ);
          int k = MathHelper.f((double) f2 * this.damage);

          if (this.isCritical()) {
            k += this.random.nextInt(k / 2 + 2);
          }

          DamageSource damagesource = null;

          if (this.shooter == null) {
            damagesource = DamageSource.arrow(this, this);
          } else {
            damagesource = DamageSource.arrow(this, this.shooter);
          }

          // CraftBukkit start - Moved damage call
          if (movingobjectposition.entity.damageEntity(damagesource, k)) {
            if (this.isBurning()
                && !(movingobjectposition.entity instanceof EntityEnderman)
                && (!(movingobjectposition.entity instanceof EntityPlayer)
                    || !(this.shooter instanceof EntityPlayer)
                    || this.world
                        .pvpMode)) { // CraftBukkit - abide by pvp setting if destination is a
                                     // player
              EntityCombustByEntityEvent combustEvent =
                  new EntityCombustByEntityEvent(
                      this.getBukkitEntity(), entity.getBukkitEntity(), 5);
              org.bukkit.Bukkit.getPluginManager().callEvent(combustEvent);

              if (!combustEvent.isCancelled()) {
                movingobjectposition.entity.setOnFire(combustEvent.getDuration());
              }
              // CraftBukkit end
            }

            // if (movingobjectposition.entity.damageEntity(damagesource, (float) k)) { //
            // CraftBukkit - moved up
            if (movingobjectposition.entity instanceof EntityLiving) {
              EntityLiving entityliving = (EntityLiving) movingobjectposition.entity;

              if (!this.world.isStatic) {
                entityliving.p(entityliving.aY() + 1);
              }

              if (this.knockbackStrength > 0) {
                f3 = MathHelper.sqrt(this.motX * this.motX + this.motZ * this.motZ);
                if (f3 > 0.0F) {
                  movingobjectposition.entity.g(
                      this.motX
                          * (double) this.knockbackStrength
                          * 0.6000000238418579D
                          / (double) f3,
                      0.1D,
                      this.motZ
                          * (double) this.knockbackStrength
                          * 0.6000000238418579D
                          / (double) f3);
                }
              }

              if (this.shooter != null && this.shooter instanceof EntityLiving) {
                EnchantmentManager.a(entityliving, this.shooter);
                EnchantmentManager.b((EntityLiving) this.shooter, entityliving);
              }

              if (this.shooter != null
                  && movingobjectposition.entity != this.shooter
                  && movingobjectposition.entity instanceof EntityHuman
                  && this.shooter instanceof EntityPlayer) {
                ((EntityPlayer) this.shooter)
                    .playerConnection.sendPacket(new PacketPlayOutGameStateChange(6, 0.0F));
              }
            }

            this.makeSound("random.bowhit", 1.0F, 1.2F / (this.random.nextFloat() * 0.2F + 0.9F));
            if (!(movingobjectposition.entity instanceof EntityEnderman)) {
              this.die();
            }
          } else {
            this.motX *= -0.10000000149011612D;
            this.motY *= -0.10000000149011612D;
            this.motZ *= -0.10000000149011612D;
            this.yaw += 180.0F;
            this.lastYaw += 180.0F;
            this.au = 0;
          }
        } else {
          this.d = movingobjectposition.b;
          this.e = movingobjectposition.c;
          this.f = movingobjectposition.d;
          this.g = this.world.getType(d, e, f); // CraftBukkit - Get correct block for storage
          this.h = this.world.getData(this.d, this.e, this.f);
          this.motX = (double) ((float) (movingobjectposition.pos.a - this.locX));
          this.motY = (double) ((float) (movingobjectposition.pos.b - this.locY));
          this.motZ = (double) ((float) (movingobjectposition.pos.c - this.locZ));
          f2 =
              MathHelper.sqrt(
                  this.motX * this.motX + this.motY * this.motY + this.motZ * this.motZ);
          this.locX -= this.motX / (double) f2 * 0.05000000074505806D;
          this.locY -= this.motY / (double) f2 * 0.05000000074505806D;
          this.locZ -= this.motZ / (double) f2 * 0.05000000074505806D;
          this.makeSound("random.bowhit", 1.0F, 1.2F / (this.random.nextFloat() * 0.2F + 0.9F));
          this.inGround = true;
          this.shake = 7;
          this.setCritical(false);
          if (this.g.getMaterial() != Material.AIR) {
            this.g.a(this.world, this.d, this.e, this.f, (Entity) this);
          }
        }
      }

      if (this.isCritical()) {
        for (j = 0; j < 4; ++j) {
          this.world.addParticle(
              "crit",
              this.locX + this.motX * (double) j / 4.0D,
              this.locY + this.motY * (double) j / 4.0D,
              this.locZ + this.motZ * (double) j / 4.0D,
              -this.motX,
              -this.motY + 0.2D,
              -this.motZ);
        }
      }

      this.locX += this.motX;
      this.locY += this.motY;
      this.locZ += this.motZ;
      f2 = MathHelper.sqrt(this.motX * this.motX + this.motZ * this.motZ);
      this.yaw = (float) (Math.atan2(this.motX, this.motZ) * 180.0D / 3.1415927410125732D);

      for (this.pitch = (float) (Math.atan2(this.motY, (double) f2) * 180.0D / 3.1415927410125732D);
          this.pitch - this.lastPitch < -180.0F;
          this.lastPitch -= 360.0F) {;
      }

      while (this.pitch - this.lastPitch >= 180.0F) {
        this.lastPitch += 360.0F;
      }

      while (this.yaw - this.lastYaw < -180.0F) {
        this.lastYaw -= 360.0F;
      }

      while (this.yaw - this.lastYaw >= 180.0F) {
        this.lastYaw += 360.0F;
      }

      this.pitch = this.lastPitch + (this.pitch - this.lastPitch) * 0.2F;
      this.yaw = this.lastYaw + (this.yaw - this.lastYaw) * 0.2F;
      float f4 = 0.99F;

      f1 = 0.05F;
      if (this.L()) {
        for (int l = 0; l < 4; ++l) {
          f3 = 0.25F;
          this.world.addParticle(
              "bubble",
              this.locX - this.motX * (double) f3,
              this.locY - this.motY * (double) f3,
              this.locZ - this.motZ * (double) f3,
              this.motX,
              this.motY,
              this.motZ);
        }

        f4 = 0.8F;
      }

      if (this.K()) {
        this.extinguish();
      }

      this.motX *= (double) f4;
      this.motY *= (double) f4;
      this.motZ *= (double) f4;
      this.motY -= (double) f1;
      this.setPosition(this.locX, this.locY, this.locZ);
      this.H();
    }
  }
Exemplo n.º 9
0
  public void setPassengerOf(Entity entity) {
    // b(null) doesn't really fly for overloaded methods,
    // so this method is needed

    // CraftBukkit end
    this.d = 0.0D;
    this.e = 0.0D;
    if (entity == null) {
      if (this.vehicle != null) {
        // CraftBukkit start
        if ((this.getBukkitEntity() instanceof LivingEntity)
            && (vehicle.getBukkitEntity() instanceof CraftVehicle)) {
          CraftVehicle cvehicle = (CraftVehicle) vehicle.getBukkitEntity();
          LivingEntity living = (LivingEntity) getBukkitEntity();

          VehicleExitEvent event = new VehicleExitEvent(cvehicle, living);
          ((WorldServer) world).getServer().getPluginManager().callEvent(event);
        }
        // CraftBukkit end

        this.setPositionRotation(
            this.vehicle.locX,
            this.vehicle.boundingBox.b + (double) this.vehicle.width,
            this.vehicle.locZ,
            this.yaw,
            this.pitch);
        this.vehicle.passenger = null;
      }

      this.vehicle = null;
    } else if (this.vehicle == entity) {
      // CraftBukkit start
      if ((this.getBukkitEntity() instanceof LivingEntity)
          && (vehicle.getBukkitEntity() instanceof CraftVehicle)) {
        CraftVehicle cvehicle = (CraftVehicle) vehicle.getBukkitEntity();
        LivingEntity living = (LivingEntity) getBukkitEntity();

        VehicleExitEvent event = new VehicleExitEvent(cvehicle, living);
        ((WorldServer) world).getServer().getPluginManager().callEvent(event);
      }
      // CraftBukkit end

      this.vehicle.passenger = null;
      this.vehicle = null;
      this.setPositionRotation(
          entity.locX,
          entity.boundingBox.b + (double) entity.width,
          entity.locZ,
          this.yaw,
          this.pitch);
    } else {
      if (this.vehicle != null) {
        this.vehicle.passenger = null;
      }

      if (entity.passenger != null) {
        entity.passenger.vehicle = null;
      }

      this.vehicle = entity;
      entity.passenger = this;
    }
  }
Exemplo n.º 10
0
  public void execute(final ICommandListener icommandlistener, String[] astring)
      throws CommandException {
    if (astring.length < 5) {
      throw new ExceptionUsage("commands.execute.usage", new Object[0]);
    } else {
      final Entity entity = a(icommandlistener, astring[0], Entity.class);
      final double d0 = b(entity.locX, astring[1], false);
      final double d1 = b(entity.locY, astring[2], false);
      final double d2 = b(entity.locZ, astring[3], false);
      final BlockPosition blockposition = new BlockPosition(d0, d1, d2);
      byte b0 = 4;

      if ("detect".equals(astring[4]) && astring.length > 10) {
        World world = entity.getWorld();
        double d3 = b(d0, astring[5], false);
        double d4 = b(d1, astring[6], false);
        double d5 = b(d2, astring[7], false);
        Block block = g(icommandlistener, astring[8]);
        int i = a(astring[9], -1, 15);
        BlockPosition blockposition1 = new BlockPosition(d3, d4, d5);
        IBlockData iblockdata = world.getType(blockposition1);

        if (iblockdata.getBlock() != block
            || i >= 0 && iblockdata.getBlock().toLegacyData(iblockdata) != i) {
          throw new CommandException(
              "commands.execute.failed", new Object[] {"detect", entity.getName()});
        }

        b0 = 10;
      }

      String s = a(astring, b0);
      ICommandListener icommandlistener1 =
          new ICommandListener() {
            public String getName() {
              return entity.getName();
            }

            public IChatBaseComponent getScoreboardDisplayName() {
              return entity.getScoreboardDisplayName();
            }

            public void sendMessage(IChatBaseComponent ichatbasecomponent) {
              icommandlistener.sendMessage(ichatbasecomponent);
            }

            public boolean a(int i, String s) {
              return icommandlistener.a(i, s);
            }

            public BlockPosition getChunkCoordinates() {
              return blockposition;
            }

            public Vec3D d() {
              return new Vec3D(d0, d1, d2);
            }

            public World getWorld() {
              return entity.world;
            }

            public Entity f() {
              return entity;
            }

            public boolean getSendCommandFeedback() {
              MinecraftServer minecraftserver = MinecraftServer.getServer();

              return minecraftserver == null
                  || minecraftserver.worldServer[0].getGameRules().getBoolean("commandBlockOutput");
            }

            public void a(
                CommandObjectiveExecutor.EnumCommandResult
                    commandobjectiveexecutor_enumcommandresult,
                int i) {
              entity.a(commandobjectiveexecutor_enumcommandresult, i);
            }
          };
      ICommandHandler icommandhandler = MinecraftServer.getServer().getCommandHandler();

      try {
        // CraftBukkit start
        org.bukkit.command.CommandSender sender = null;
        if (icommandlistener instanceof DedicatedServer) {
          sender = MinecraftServer.getServer().server.getConsoleSender();
        } else if (icommandlistener instanceof CommandBlockListenerAbstract) {
          sender = ((CommandBlockListenerAbstract) icommandlistener).sender;
        } else if (VanillaCommandWrapper.lastSender != null) {
          sender = VanillaCommandWrapper.lastSender;
        } else if (icommandlistener.f() != null) {
          sender = icommandlistener.f().getBukkitEntity();
        } else {
          throw new CommandException(
              "Unhandled executor " + icommandlistener.getClass().getSimpleName(), new Object[0]);
        }
        int j =
            CommandBlockListenerAbstract.executeCommand(
                icommandlistener1,
                new ProxiedNativeCommandSender(icommandlistener1, sender, entity.getBukkitEntity()),
                s);
        // CraftBukkit end

        if (j < 1) {
          throw new CommandException("commands.execute.allInvocationsFailed", new Object[] {s});
        }
      } catch (Throwable throwable) {
        // CraftBukkit start
        if (throwable instanceof CommandException) {
          throw (CommandException) throwable;
        }
        // CraftBukkit end
        throw new CommandException("commands.execute.failed", new Object[] {s, entity.getName()});
      }
    }
  }
Exemplo n.º 11
0
  public void a() {
    float f = this.size;
    byte b0 = 16;

    int i;
    int j;
    int k;
    double d0;
    double d1;
    double d2;

    for (i = 0; i < b0; ++i) {
      for (j = 0; j < b0; ++j) {
        for (k = 0; k < b0; ++k) {
          if (i == 0 || i == b0 - 1 || j == 0 || j == b0 - 1 || k == 0 || k == b0 - 1) {
            double d3 = (double) ((float) i / ((float) b0 - 1.0F) * 2.0F - 1.0F);
            double d4 = (double) ((float) j / ((float) b0 - 1.0F) * 2.0F - 1.0F);
            double d5 = (double) ((float) k / ((float) b0 - 1.0F) * 2.0F - 1.0F);
            double d6 = Math.sqrt(d3 * d3 + d4 * d4 + d5 * d5);

            d3 /= d6;
            d4 /= d6;
            d5 /= d6;
            float f1 = this.size * (0.7F + this.world.random.nextFloat() * 0.6F);

            d0 = this.posX;
            d1 = this.posY;
            d2 = this.posZ;

            for (float f2 = 0.3F; f1 > 0.0F; f1 -= f2 * 0.75F) {
              int l = MathHelper.floor(d0);
              int i1 = MathHelper.floor(d1);
              int j1 = MathHelper.floor(d2);
              int k1 = this.world.getTypeId(l, i1, j1);

              if (k1 > 0) {
                f1 -= (Block.byId[k1].a(this.source) + 0.3F) * f2;
              }

              if (f1 > 0.0F) {
                this.g.add(new ChunkPosition(l, i1, j1));
              }

              d0 += d3 * (double) f2;
              d1 += d4 * (double) f2;
              d2 += d5 * (double) f2;
            }
          }
        }
      }
    }

    this.size *= 2.0F;
    i = MathHelper.floor(this.posX - (double) this.size - 1.0D);
    j = MathHelper.floor(this.posX + (double) this.size + 1.0D);
    k = MathHelper.floor(this.posY - (double) this.size - 1.0D);
    int l1 = MathHelper.floor(this.posY + (double) this.size + 1.0D);
    int i2 = MathHelper.floor(this.posZ - (double) this.size - 1.0D);
    int j2 = MathHelper.floor(this.posZ + (double) this.size + 1.0D);
    List list =
        this.world.b(
            this.source,
            AxisAlignedBB.b(
                (double) i, (double) k, (double) i2, (double) j, (double) l1, (double) j2));
    Vec3D vec3d = Vec3D.create(this.posX, this.posY, this.posZ);

    for (int k2 = 0; k2 < list.size(); ++k2) {
      Entity entity = (Entity) list.get(k2);
      double d7 = entity.e(this.posX, this.posY, this.posZ) / (double) this.size;

      if (d7 <= 1.0D) {
        d0 = entity.locX - this.posX;
        d1 = entity.locY - this.posY;
        d2 = entity.locZ - this.posZ;
        double d8 = (double) MathHelper.a(d0 * d0 + d1 * d1 + d2 * d2);

        d0 /= d8;
        d1 /= d8;
        d2 /= d8;
        double d9 = (double) this.world.a(vec3d, entity.boundingBox);
        double d10 = (1.0D - d7) * d9;

        // CraftBukkit start - explosion damage hook
        CraftServer server = ((WorldServer) this.world).getServer();
        org.bukkit.entity.Entity damagee = (entity == null) ? null : entity.getBukkitEntity();
        DamageCause damageType;
        int damageDone = (int) ((d10 * d10 + d10) / 2.0D * 8.0D * (double) this.size + 1.0D);

        if (damagee == null) {
          // nothing was hurt
        } else if (this.source == null) { // Block explosion
          // TODO: get the x/y/z of the tnt block?
          // does this even get called ever? @see EntityTNTPrimed - not BlockTNT or whatever
          damageType = EntityDamageEvent.DamageCause.BLOCK_EXPLOSION;

          EntityDamageByBlockEvent event =
              new EntityDamageByBlockEvent(null, damagee, damageType, damageDone);
          server.getPluginManager().callEvent(event);

          if (!event.isCancelled()) {
            entity.damageEntity(this.source, event.getDamage());
            entity.motX += d0 * d10;
            entity.motY += d1 * d10;
            entity.motZ += d2 * d10;
          }
        } else {
          org.bukkit.entity.Entity damager = this.source.getBukkitEntity();
          damageType = EntityDamageEvent.DamageCause.ENTITY_EXPLOSION;

          EntityDamageByEntityEvent event =
              new EntityDamageByEntityEvent(damager, damagee, damageType, damageDone);
          server.getPluginManager().callEvent(event);

          if (!event.isCancelled()) {
            entity.damageEntity(this.source, event.getDamage());

            entity.motX += d0 * d10;
            entity.motY += d1 * d10;
            entity.motZ += d2 * d10;
          }
        }
        // CraftBukkit end
      }
    }

    this.size = f;
    ArrayList arraylist = new ArrayList();

    arraylist.addAll(this.g);
    if (this.a) {
      for (int l2 = arraylist.size() - 1; l2 >= 0; --l2) {
        ChunkPosition chunkposition = (ChunkPosition) arraylist.get(l2);
        int i3 = chunkposition.x;
        int j3 = chunkposition.y;
        int k3 = chunkposition.z;
        int l3 = this.world.getTypeId(i3, j3, k3);
        int i4 = this.world.getTypeId(i3, j3 - 1, k3);

        if (l3 == 0 && Block.o[i4] && this.h.nextInt(3) == 0) {
          this.world.setTypeId(i3, j3, k3, Block.FIRE.id);
        }
      }
    }
  }
Exemplo n.º 12
0
 public org.bukkit.entity.Entity getBukkitEntity() {
   return entity.getBukkitEntity();
 }
Exemplo n.º 13
0
  public void a() {
    // CraftBukkit start
    if (this.size < 0.1F) {
      return;
    }
    // CraftBukkit end

    float f = this.size;
    HashSet hashset = new HashSet();

    int i;
    int j;
    int k;
    double d0;
    double d1;
    double d2;

    for (i = 0; i < this.i; ++i) {
      for (j = 0; j < this.i; ++j) {
        for (k = 0; k < this.i; ++k) {
          if (i == 0 || i == this.i - 1 || j == 0 || j == this.i - 1 || k == 0 || k == this.i - 1) {
            double d3 = (double) ((float) i / ((float) this.i - 1.0F) * 2.0F - 1.0F);
            double d4 = (double) ((float) j / ((float) this.i - 1.0F) * 2.0F - 1.0F);
            double d5 = (double) ((float) k / ((float) this.i - 1.0F) * 2.0F - 1.0F);
            double d6 = Math.sqrt(d3 * d3 + d4 * d4 + d5 * d5);

            d3 /= d6;
            d4 /= d6;
            d5 /= d6;
            float f1 = this.size * (0.7F + this.world.random.nextFloat() * 0.6F);

            d0 = this.posX;
            d1 = this.posY;
            d2 = this.posZ;

            for (float f2 = 0.3F; f1 > 0.0F; f1 -= f2 * 0.75F) {
              int l = MathHelper.floor(d0);
              int i1 = MathHelper.floor(d1);
              int j1 = MathHelper.floor(d2);
              int k1 = this.world.getTypeId(l, i1, j1);

              if (k1 > 0) {
                Block block = Block.byId[k1];
                float f3 =
                    this.source != null
                        ? this.source.a(this, this.world, l, i1, j1, block)
                        : block.a(this.source);

                f1 -= (f3 + 0.3F) * f2;
              }

              if (f1 > 0.0F
                  && (this.source == null || this.source.a(this, this.world, l, i1, j1, k1, f1))
                  && i1 < 256
                  && i1 >= 0) { // CraftBukkit - don't wrap explosions
                hashset.add(new ChunkPosition(l, i1, j1));
              }

              d0 += d3 * (double) f2;
              d1 += d4 * (double) f2;
              d2 += d5 * (double) f2;
            }
          }
        }
      }
    }

    this.blocks.addAll(hashset);
    this.size *= 2.0F;
    i = MathHelper.floor(this.posX - (double) this.size - 1.0D);
    j = MathHelper.floor(this.posX + (double) this.size + 1.0D);
    k = MathHelper.floor(this.posY - (double) this.size - 1.0D);
    int l1 = MathHelper.floor(this.posY + (double) this.size + 1.0D);
    int i2 = MathHelper.floor(this.posZ - (double) this.size - 1.0D);
    int j2 = MathHelper.floor(this.posZ + (double) this.size + 1.0D);
    List list =
        this.world.getEntities(
            this.source,
            AxisAlignedBB.a()
                .a((double) i, (double) k, (double) i2, (double) j, (double) l1, (double) j2));
    Vec3D vec3d = this.world.getVec3DPool().create(this.posX, this.posY, this.posZ);

    for (int k2 = 0; k2 < list.size(); ++k2) {
      Entity entity = (Entity) list.get(k2);
      double d7 = entity.f(this.posX, this.posY, this.posZ) / (double) this.size;

      if (d7 <= 1.0D) {
        d0 = entity.locX - this.posX;
        d1 = entity.locY + (double) entity.getHeadHeight() - this.posY;
        d2 = entity.locZ - this.posZ;
        double d8 = (double) MathHelper.sqrt(d0 * d0 + d1 * d1 + d2 * d2);

        if (d8 != 0.0D) {
          d0 /= d8;
          d1 /= d8;
          d2 /= d8;
          double d9 = (double) this.world.a(vec3d, entity.boundingBox);
          double d10 = (1.0D - d7) * d9;

          // CraftBukkit start - Explosion damage hook
          org.bukkit.entity.Entity damagee = (entity == null) ? null : entity.getBukkitEntity();
          float damageDone =
              (float) ((int) ((d10 * d10 + d10) / 2.0D * 8.0D * (double) this.size + 1.0D));

          if (damagee == null) {
            // nothing was hurt
          } else if (this.source == null) { // Block explosion (without an entity source; bed etc.)
            EntityDamageByBlockEvent event =
                new EntityDamageByBlockEvent(
                    null, damagee, EntityDamageEvent.DamageCause.BLOCK_EXPLOSION, damageDone);
            Bukkit.getPluginManager().callEvent(event);

            if (!event.isCancelled()) {
              damagee.setLastDamageCause(event);
              entity.damageEntity(DamageSource.explosion(this), (float) event.getDamage());
              double d11 = EnchantmentProtection.a(entity, d10);

              entity.motX += d0 * d11;
              entity.motY += d1 * d11;
              entity.motZ += d2 * d11;
              if (entity instanceof EntityHuman) {
                this.l.put(
                    (EntityHuman) entity,
                    this.world.getVec3DPool().create(d0 * d10, d1 * d10, d2 * d10));
              }
            }
          } else {
            final org.bukkit.entity.Entity damager = this.source.getBukkitEntity();
            final EntityDamageEvent.DamageCause damageCause;

            if (damager instanceof org.bukkit.entity.TNTPrimed) {
              damageCause = EntityDamageEvent.DamageCause.BLOCK_EXPLOSION;
            } else {
              damageCause = EntityDamageEvent.DamageCause.ENTITY_EXPLOSION;
            }

            EntityDamageByEntityEvent event =
                new EntityDamageByEntityEvent(damager, damagee, damageCause, damageDone);
            Bukkit.getPluginManager().callEvent(event);

            if (!event.isCancelled()) {
              entity.getBukkitEntity().setLastDamageCause(event);
              entity.damageEntity(DamageSource.explosion(this), (float) event.getDamage());

              entity.motX += d0 * d10;
              entity.motY += d1 * d10;
              entity.motZ += d2 * d10;
              if (entity instanceof EntityHuman) {
                this.l.put(
                    (EntityHuman) entity,
                    this.world.getVec3DPool().create(d0 * d10, d1 * d10, d2 * d10));
              }
            }
          }
          // CraftBukkit end
        }
      }
    }

    this.size = f;
  }