Esempio n. 1
0
  public void move(double d0, double d1, double d2) {
    if (this.bt) {
      this.boundingBox.d(d0, d1, d2);
      this.locX = (this.boundingBox.a + this.boundingBox.d) / 2.0D;
      this.locY = this.boundingBox.b + (double) this.height - (double) this.br;
      this.locZ = (this.boundingBox.c + this.boundingBox.f) / 2.0D;
    } else {
      this.br *= 0.4F;
      double d3 = this.locX;
      double d4 = this.locZ;

      if (this.bf) {
        this.bf = false;
        d0 *= 0.25D;
        d1 *= 0.05000000074505806D;
        d2 *= 0.25D;
        this.motX = 0.0D;
        this.motY = 0.0D;
        this.motZ = 0.0D;
      }

      double d5 = d0;
      double d6 = d1;
      double d7 = d2;
      AxisAlignedBB axisalignedbb = this.boundingBox.clone();
      boolean flag = this.onGround && this.isSneaking();

      if (flag) {
        double d8;

        for (d8 = 0.05D;
            d0 != 0.0D
                && this.world.getEntities(this, this.boundingBox.c(d0, -1.0D, 0.0D)).size() == 0;
            d5 = d0) {
          if (d0 < d8 && d0 >= -d8) {
            d0 = 0.0D;
          } else if (d0 > 0.0D) {
            d0 -= d8;
          } else {
            d0 += d8;
          }
        }

        for (;
            d2 != 0.0D
                && this.world.getEntities(this, this.boundingBox.c(0.0D, -1.0D, d2)).size() == 0;
            d7 = d2) {
          if (d2 < d8 && d2 >= -d8) {
            d2 = 0.0D;
          } else if (d2 > 0.0D) {
            d2 -= d8;
          } else {
            d2 += d8;
          }
        }
      }

      List list = this.world.getEntities(this, this.boundingBox.a(d0, d1, d2));

      for (int i = 0; i < list.size(); ++i) {
        d1 = ((AxisAlignedBB) list.get(i)).b(this.boundingBox, d1);
      }

      this.boundingBox.d(0.0D, d1, 0.0D);
      if (!this.bg && d6 != d1) {
        d2 = 0.0D;
        d1 = 0.0D;
        d0 = 0.0D;
      }

      boolean flag1 = this.onGround || d6 != d1 && d6 < 0.0D;

      int j;

      for (j = 0; j < list.size(); ++j) {
        d0 = ((AxisAlignedBB) list.get(j)).a(this.boundingBox, d0);
      }

      this.boundingBox.d(d0, 0.0D, 0.0D);
      if (!this.bg && d5 != d0) {
        d2 = 0.0D;
        d1 = 0.0D;
        d0 = 0.0D;
      }

      for (j = 0; j < list.size(); ++j) {
        d2 = ((AxisAlignedBB) list.get(j)).c(this.boundingBox, d2);
      }

      this.boundingBox.d(0.0D, 0.0D, d2);
      if (!this.bg && d7 != d2) {
        d2 = 0.0D;
        d1 = 0.0D;
        d0 = 0.0D;
      }

      double d9;
      double d10;
      int k;

      if (this.bs > 0.0F && flag1 && (flag || this.br < 0.05F) && (d5 != d0 || d7 != d2)) {
        d9 = d0;
        d10 = d1;
        double d11 = d2;

        d0 = d5;
        d1 = (double) this.bs;
        d2 = d7;
        AxisAlignedBB axisalignedbb1 = this.boundingBox.clone();

        this.boundingBox.b(axisalignedbb);
        list = this.world.getEntities(this, this.boundingBox.a(d5, d1, d7));

        for (k = 0; k < list.size(); ++k) {
          d1 = ((AxisAlignedBB) list.get(k)).b(this.boundingBox, d1);
        }

        this.boundingBox.d(0.0D, d1, 0.0D);
        if (!this.bg && d6 != d1) {
          d2 = 0.0D;
          d1 = 0.0D;
          d0 = 0.0D;
        }

        for (k = 0; k < list.size(); ++k) {
          d0 = ((AxisAlignedBB) list.get(k)).a(this.boundingBox, d0);
        }

        this.boundingBox.d(d0, 0.0D, 0.0D);
        if (!this.bg && d5 != d0) {
          d2 = 0.0D;
          d1 = 0.0D;
          d0 = 0.0D;
        }

        for (k = 0; k < list.size(); ++k) {
          d2 = ((AxisAlignedBB) list.get(k)).c(this.boundingBox, d2);
        }

        this.boundingBox.d(0.0D, 0.0D, d2);
        if (!this.bg && d7 != d2) {
          d2 = 0.0D;
          d1 = 0.0D;
          d0 = 0.0D;
        }

        if (!this.bg && d6 != d1) {
          d2 = 0.0D;
          d1 = 0.0D;
          d0 = 0.0D;
        } else {
          d1 = (double) (-this.bs);

          for (k = 0; k < list.size(); ++k) {
            d1 = ((AxisAlignedBB) list.get(k)).b(this.boundingBox, d1);
          }

          this.boundingBox.d(0.0D, d1, 0.0D);
        }

        if (d9 * d9 + d11 * d11 >= d0 * d0 + d2 * d2) {
          d0 = d9;
          d1 = d10;
          d2 = d11;
          this.boundingBox.b(axisalignedbb1);
        } else {
          double d12 = this.boundingBox.b - (double) ((int) this.boundingBox.b);

          if (d12 > 0.0D) {
            this.br = (float) ((double) this.br + d12 + 0.01D);
          }
        }
      }

      this.locX = (this.boundingBox.a + this.boundingBox.d) / 2.0D;
      this.locY = this.boundingBox.b + (double) this.height - (double) this.br;
      this.locZ = (this.boundingBox.c + this.boundingBox.f) / 2.0D;
      this.positionChanged = d5 != d0 || d7 != d2;
      this.bc = d6 != d1;
      this.onGround = d6 != d1 && d6 < 0.0D;
      this.bd = this.positionChanged || this.bc;
      this.a(d1, this.onGround);
      if (d5 != d0) {
        this.motX = 0.0D;
      }

      if (d6 != d1) {
        this.motY = 0.0D;
      }

      if (d7 != d2) {
        this.motZ = 0.0D;
      }

      d9 = this.locX - d3;
      d10 = this.locZ - d4;
      int l;
      int i1;
      int j1;

      // CraftBukkit start
      if ((this.positionChanged) && (getBukkitEntity() instanceof Vehicle)) {
        Vehicle vehicle = (Vehicle) getBukkitEntity();
        org.bukkit.World wrld = ((WorldServer) world).getWorld();
        org.bukkit.block.Block block =
            wrld.getBlockAt(
                MathHelper.floor(locX),
                MathHelper.floor(locY - 0.20000000298023224D - (double) this.height),
                MathHelper.floor(locZ));

        if (d5 > d0) {
          block = block.getFace(BlockFace.SOUTH);
        } else if (d5 < d0) {
          block = block.getFace(BlockFace.NORTH);
        } else if (d7 > d2) {
          block = block.getFace(BlockFace.WEST);
        } else if (d7 < d2) {
          block = block.getFace(BlockFace.EAST);
        }

        VehicleBlockCollisionEvent event = new VehicleBlockCollisionEvent(vehicle, block);
        ((WorldServer) world).getServer().getPluginManager().callEvent(event);
      }
      // CraftBukkit end

      if (this.n() && !flag && this.vehicle == null) {
        this.bm = (float) ((double) this.bm + (double) MathHelper.a(d9 * d9 + d10 * d10) * 0.6D);
        l = MathHelper.floor(this.locX);
        i1 = MathHelper.floor(this.locY - 0.20000000298023224D - (double) this.height);
        j1 = MathHelper.floor(this.locZ);
        k = this.world.getTypeId(l, i1, j1);
        if (this.world.getTypeId(l, i1 - 1, j1) == Block.FENCE.id) {
          k = this.world.getTypeId(l, i1 - 1, j1);
        }

        if (this.bm > (float) this.b && k > 0) {
          ++this.b;
          StepSound stepsound = Block.byId[k].stepSound;

          if (this.world.getTypeId(l, i1 + 1, j1) == Block.SNOW.id) {
            stepsound = Block.SNOW.stepSound;
            this.world.makeSound(
                this, stepsound.getName(), stepsound.getVolume1() * 0.15F, stepsound.getVolume2());
          } else if (!Block.byId[k].material.isLiquid()) {
            this.world.makeSound(
                this, stepsound.getName(), stepsound.getVolume1() * 0.15F, stepsound.getVolume2());
          }

          Block.byId[k].b(this.world, l, i1, j1, this);
        }
      }

      l = MathHelper.floor(this.boundingBox.a + 0.0010D);
      i1 = MathHelper.floor(this.boundingBox.b + 0.0010D);
      j1 = MathHelper.floor(this.boundingBox.c + 0.0010D);
      k = MathHelper.floor(this.boundingBox.d - 0.0010D);
      int k1 = MathHelper.floor(this.boundingBox.e - 0.0010D);
      int l1 = MathHelper.floor(this.boundingBox.f - 0.0010D);

      if (this.world.a(l, i1, j1, k, k1, l1)) {
        for (int i2 = l; i2 <= k; ++i2) {
          for (int j2 = i1; j2 <= k1; ++j2) {
            for (int k2 = j1; k2 <= l1; ++k2) {
              int l2 = this.world.getTypeId(i2, j2, k2);

              if (l2 > 0) {
                Block.byId[l2].a(this.world, i2, j2, k2, this);
              }
            }
          }
        }
      }

      boolean flag2 = this.ab();

      if (this.world.d(this.boundingBox.shrink(0.0010D, 0.0010D, 0.0010D))) {
        this.a(1);
        if (!flag2) {
          ++this.fireTicks;
          // CraftBukkit start
          if (this.fireTicks <= 0) {
            // not on fire yet
            CraftServer server = ((WorldServer) this.world).getServer();
            org.bukkit.entity.Entity damagee = this.getBukkitEntity();

            EntityCombustEvent event = new EntityCombustEvent(damagee);
            server.getPluginManager().callEvent(event);

            if (!event.isCancelled()) {
              this.fireTicks = 300;
            }
          } else {
            // CraftBukkit end - reset fire level back to max
            this.fireTicks = 300;
          }
        }
      } else if (this.fireTicks <= 0) {
        this.fireTicks = -this.maxFireTicks;
      }

      if (flag2 && this.fireTicks > 0) {
        this.world.makeSound(
            this,
            "random.fizz",
            0.7F,
            1.6F + (this.random.nextFloat() - this.random.nextFloat()) * 0.4F);
        this.fireTicks = -this.maxFireTicks;
      }
    }
  }
Esempio n. 2
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;
    }
  }