Ejemplo n.º 1
0
  public void setPathfinding() {
    try {
      this.petGoalSelector = new PetGoalSelector();
      this.getNavigation().b(true);

      petGoalSelector.addGoal(new PetGoalFloat(this), 0);
      petGoalSelector.addGoal(
          new PetGoalFollowOwner(
              this,
              this.getSizeCategory().getStartWalk(getPet().getPetType()),
              this.getSizeCategory().getStopWalk(getPet().getPetType()),
              this.getSizeCategory().getTeleport(getPet().getPetType())),
          1);
      petGoalSelector.addGoal(new PetGoalLookAtPlayer(this, EntityHuman.class), 2);

    } catch (Exception e) {
      Logger.log(Logger.LogLevel.WARNING, "Could not add PetGoals to Pet AI.", e, true);
    }
  }
Ejemplo n.º 2
0
  // EntityInsentient
  @Override
  public void e(float sideMot, float forwMot) {
    if (this.passenger == null || !(this.passenger instanceof EntityHuman)) {
      super.e(sideMot, forwMot);
      // https://github.com/Bukkit/mc-dev/blob/master/net/minecraft/server/EntityHorse.java#L914
      this.X = 0.5F;
      return;
    }
    EntityHuman human = (EntityHuman) this.passenger;
    if (human.getBukkitEntity() != this.getPlayerOwner().getPlayer()) {
      super.e(sideMot, forwMot);
      this.X = 0.5F;
      return;
    }

    this.X = 1.0F;

    this.lastYaw = this.yaw = this.passenger.yaw;
    this.pitch = this.passenger.pitch * 0.5F;
    this.b(this.yaw, this.pitch);
    this.aP = this.aN = this.yaw;

    sideMot = ((EntityLiving) this.passenger).be * 0.5F;
    forwMot = ((EntityLiving) this.passenger).bf;

    if (forwMot <= 0.0F) {
      forwMot *= 0.25F;
    }
    sideMot *= 0.75F;

    PetRideMoveEvent moveEvent = new PetRideMoveEvent(this.getPet(), forwMot, sideMot);
    EchoPet.getPlugin().getServer().getPluginManager().callEvent(moveEvent);
    if (moveEvent.isCancelled()) {
      return;
    }

    this.i(this.rideSpeed);
    super.e(moveEvent.getSidewardMotionSpeed(), moveEvent.getForwardMotionSpeed());

    PetType pt = this.getPet().getPetType();
    if (FIELD_JUMP != null && this.passenger != null) {
      if (EchoPet.getOptions().canFly(pt)) {
        try {
          if (((Player) (human.getBukkitEntity())).isFlying()) {
            ((Player) (human.getBukkitEntity())).setFlying(false);
          }
          if (FIELD_JUMP.getBoolean(this.passenger)) {
            PetRideJumpEvent rideEvent = new PetRideJumpEvent(this.getPet(), this.jumpHeight);
            EchoPet.getPlugin().getServer().getPluginManager().callEvent(rideEvent);
            if (!rideEvent.isCancelled()) {
              this.motY = 0.5F;
            }
          }
        } catch (IllegalArgumentException e) {
          Logger.log(
              Logger.LogLevel.WARNING,
              "Failed to initiate Pet Flying Motion for "
                  + this.getPlayerOwner().getName()
                  + "'s Pet.",
              e,
              true);
        } catch (IllegalAccessException e) {
          Logger.log(
              Logger.LogLevel.WARNING,
              "Failed to initiate Pet Flying Motion for "
                  + this.getPlayerOwner().getName()
                  + "'s Pet.",
              e,
              true);
        } catch (IllegalStateException e) {
          Logger.log(
              Logger.LogLevel.WARNING,
              "Failed to initiate Pet Flying Motion for "
                  + this.getPlayerOwner().getName()
                  + "'s Pet.",
              e,
              true);
        }
      } else if (this.onGround) {
        try {
          if (FIELD_JUMP.getBoolean(this.passenger)) {
            PetRideJumpEvent rideEvent = new PetRideJumpEvent(this.getPet(), this.jumpHeight);
            EchoPet.getPlugin().getServer().getPluginManager().callEvent(rideEvent);
            if (!rideEvent.isCancelled()) {
              this.motY = rideEvent.getJumpHeight();
              doJumpAnimation();
            }
          }
        } catch (IllegalArgumentException e) {
          Logger.log(
              Logger.LogLevel.WARNING,
              "Failed to initiate Pet Jumping Motion for "
                  + this.getPlayerOwner().getName()
                  + "'s Pet.",
              e,
              true);
        } catch (IllegalAccessException e) {
          Logger.log(
              Logger.LogLevel.WARNING,
              "Failed to initiate Pet Jumping Motion for "
                  + this.getPlayerOwner().getName()
                  + "'s Pet.",
              e,
              true);
        } catch (IllegalStateException e) {
          Logger.log(
              Logger.LogLevel.WARNING,
              "Failed to initiate Pet Jumping Motion for "
                  + this.getPlayerOwner().getName()
                  + "'s Pet.",
              e,
              true);
        }
      }
    }
  }