@Override
  public boolean a(EntityHuman entity) {
    if (this.getRemoteEntity() == null) return super.a(entity);

    if (!(entity.getBukkitEntity() instanceof Player)) return super.a(entity);

    return ((RemoteBaseEntity) this.m_remoteEntity).onInteract((Player) entity.getBukkitEntity())
        && super.a(entity);
  }
Пример #2
0
 // EntityInsentient
 @Override
 public boolean a(EntityHuman human) {
   if (human.getBukkitEntity() == this.getPlayerOwner().getPlayer()) {
     if (EchoPet.getConfig()
             .getBoolean(
                 "pets."
                     + this.getPet().getPetType().toString().toLowerCase().replace("_", " ")
                     + ".interactMenu",
                 true)
         && Perm.BASE_MENU.hasPerm(this.getPlayerOwner(), false, false)) {
       ArrayList<MenuOption> options = MenuUtil.createOptionList(getPet().getPetType());
       int size = this.getPet().getPetType() == PetType.HORSE ? 18 : 9;
       PetMenu menu = new PetMenu(getPet(), options, size);
       menu.open(true);
     }
     return true;
   }
   return false;
 }
  @Override
  public boolean update() {
    EntityHuman passenger = (EntityHuman) this.getEntityHandle().passenger;
    EntityLiving entity = this.getEntityHandle();
    float f = MathHelper.g(passenger.yaw - entity.yaw) * 0.5f;

    if (f > 5) f = 5;

    if (f < -5) f = -5;

    entity.yaw = MathHelper.g(entity.yaw + f);
    if (this.m_currentSpeed < this.m_maxSpeed)
      this.m_currentSpeed += (this.m_maxSpeed - this.m_currentSpeed) * 0.01;

    if (this.m_currentSpeed > this.m_maxSpeed) this.m_currentSpeed = this.m_maxSpeed;

    int x = MathHelper.floor(entity.locX);
    int y = MathHelper.floor(entity.locY);
    int z = MathHelper.floor(entity.locZ);
    float speed = this.m_currentSpeed;

    if (this.m_speedBoosted) {
      if (this.m_speedBoostTime++ > this.m_maxSpeedBoostTime) this.m_speedBoosted = false;

      speed +=
          speed
              * 1.15
              * MathHelper.sin(
                  (float) (this.m_speedBoostTime / this.m_maxSpeedBoostTime * Math.PI));
    }

    float f2 = 0.91f;
    if (entity.onGround) {
      f2 = 0.54600006F;
      Block block = entity.world.getType(MathHelper.d(x), MathHelper.d(y) - 1, MathHelper.d(z));
      if (block.getMaterial() != Material.AIR) f2 = block.frictionFactor * 0.91f;
    }

    float f3 = 0.16277136F / (f2 * f2 * f2);
    float f4 = MathHelper.sin(entity.yaw * 3.1415927F / 180.0F);
    float f5 = MathHelper.cos(entity.yaw * 3.1415927F / 180.0F);
    float f6 = entity.bl() * f3;
    float f7 = Math.max(speed, 1.0F);

    f7 = f6 / f7;
    float f8 = speed * f7;
    float f9 = -(f8 * f4);
    float f10 = f8 * f5;

    if (MathHelper.abs(f9) > MathHelper.abs(f10)) {
      if (f9 < 0.0F) {
        f9 -= entity.width / 2.0F;
      }

      if (f9 > 0.0F) {
        f9 += entity.width / 2.0F;
      }

      f10 = 0.0F;
    } else {
      f9 = 0.0F;
      if (f10 < 0.0F) {
        f10 -= entity.width / 2.0F;
      }

      if (f10 > 0.0F) {
        f10 += entity.width / 2.0F;
      }
    }

    int nextX = MathHelper.floor(entity.locX + f9);
    int nextZ = MathHelper.floor(entity.locZ + f10);
    PathPoint point =
        new PathPoint(
            MathHelper.d(entity.width + 1),
            MathHelper.d(entity.length + passenger.length + 1),
            MathHelper.d(entity.width + 1));
    if (x != nextX || z != nextZ) {
      Block type1 = entity.world.getType(x, y, z);
      Block type2 = entity.world.getType(x, y - 1, z);
      boolean isStep = this.isStep(type1) || type1 == null && this.isStep(type2);

      if (!isStep
          && Pathfinder.a(entity, nextX, y, nextZ, point, false, false, true) == 0
          && Pathfinder.a(entity, x, y + 1, z, point, false, false, true) == 1
          && Pathfinder.a(entity, nextX, y + 1, nextZ, point, false, false, true) == 1)
        NMSUtil.getControllerLook(entity).a();
    }

    if (!passenger.abilities.canInstantlyBuild
        && this.m_currentSpeed >= this.m_maxSpeed * 0.5
        && entity.aI().nextFloat() < 0.006f
        && !this.m_speedBoosted) {
      ItemStack item = passenger.be();

      if (item != null && item.getItem() == Items.CARROT_STICK) {
        item.damage(1, passenger);
        if (item.count == 0) {
          ItemStack newItem = new ItemStack(Items.FISHING_ROD);
          newItem.setTag(item.tag);
          passenger.inventory.items[passenger.inventory.itemInHandIndex] = newItem;
        }
      }
    }

    entity.e(0, speed);
    return true;
  }
Пример #4
0
  @Override
  public void e(float sideMot, float forMot) {
    if (this.passenger == null || !(this.passenger instanceof EntityHuman)) {
      super.e(sideMot, forMot);
      this.X = 0.5F; // Make sure the entity can walk over half slabs,
      // instead of jumping
      return;
    }

    EntityHuman human = (EntityHuman) this.passenger;
    if (!RideThaMob.control.contains(human.getBukkitEntity().getName())) {
      // Same as before
      super.e(sideMot, forMot);
      this.X = 0.5F;
      return;
    }

    this.lastYaw = this.yaw = this.passenger.yaw;
    this.pitch = this.passenger.pitch * 0.5F;

    // Set the entity's pitch, yaw, head rotation etc.
    this.b(this.yaw, this.pitch);
    this.aP = this.aN = this.yaw;

    this.X = 1.0F; // The custom entity will now automatically climb up 1
    // high blocks

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

    if (forMot <= 0.0F) {
      forMot *= 0.25F; // Make backwards slower
    }
    sideMot *= 0.75F; // Also make sideways slower

    float speed = 0.35F; // 0.2 is the default entity speed. I made it
    // slightly faster so that riding is better than
    // walking
    this.i(speed); // Apply the speed
    super.e(sideMot, forMot); // Apply the motion to the entity

    try {
      Field jump = null;
      jump = EntityLiving.class.getDeclaredField("bd");
      jump.setAccessible(true);

      if (jump != null && this.onGround) { // Wouldn't want it jumping
        // while
        // on the ground would we?
        try {
          if (jump.getBoolean(this.passenger)) {
            double jumpHeight = 0.5D;
            this.motY = jumpHeight; // Used all the time in NMS for
            // entity jumping
          }
        } catch (IllegalAccessException e) {
          e.printStackTrace();
        }
      }
    } catch (NoSuchFieldException e) {

    }
  }
Пример #5
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);
        }
      }
    }
  }