Search in sources :

Example 6 with Ride

use of de.Keyle.MyPet.api.skill.skills.Ride in project MyPet by xXKeyleXx.

the class EntityMyPet method doMyPetTick.

/**
 * Entity AI tick method
 * -> updateAITasks()
 */
protected void doMyPetTick() {
    try {
        ++this.ticksFarFromPlayer;
        if (isAlive()) {
            // sensing
            getEntitySenses().a();
            Player p = getOwner().getPlayer();
            if (p == null || !p.isOnline()) {
                this.die();
                return;
            }
            if (!hasRider()) {
                // target selector
                petTargetSelector.tick();
                // pathfinder selector
                petPathfinderSelector.tick();
                // navigation
                petNavigation.tick();
            }
            Ride rideSkill = myPet.getSkills().get(RideImpl.class);
            if (this.onGround && rideSkill.getFlyLimit().getValue().doubleValue() > 0) {
                limitCounter += rideSkill.getFlyRegenRate().getValue().doubleValue();
                if (limitCounter > rideSkill.getFlyLimit().getValue().doubleValue()) {
                    limitCounter = rideSkill.getFlyLimit().getValue().floatValue();
                }
            }
        }
        mobTick();
        // controls
        // move
        getControllerMove().a();
        // look
        getControllerLook().a();
        // jump
        getControllerJump().b();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Player(org.bukkit.entity.Player) MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_16_R1.entity.CraftPlayer) Ride(de.Keyle.MyPet.api.skill.skills.Ride)

Example 7 with Ride

use of de.Keyle.MyPet.api.skill.skills.Ride in project MyPet by xXKeyleXx.

the class EntityMyPet method f.

/**
 * -> travel
 */
public void f(Vec3D vec3d) {
    if (!hasRider || !this.isVehicle()) {
        super.f(vec3d);
        return;
    }
    if (this.onGround && this.isFlying) {
        isFlying = false;
        this.fallDistance = 0;
    }
    EntityLiving passenger = null;
    if (!indirectRiding) {
        passenger = (EntityLiving) this.getFirstPassenger();
    } else {
        if (this.getFirstPassenger().getPassengers().isEmpty()) {
            super.f(vec3d);
            return;
        } else {
            passenger = (EntityLiving) this.getFirstPassenger().getPassengers().get(0);
        }
    }
    if (this.a(TagsFluid.WATER)) {
        this.setMot(this.getMot().add(0, 0.4, 0));
    }
    Ride rideSkill = myPet.getSkills().get(RideImpl.class);
    if (rideSkill == null || !rideSkill.getActive().getValue()) {
        passenger.stopRiding();
        return;
    }
    // Rotations are fun
    if (indirectRiding) {
        if (this.getFirstPassenger() instanceof EntityMySeat) {
            EntityMySeat seat = (EntityMySeat) this.getFirstPassenger();
            seat.lastYaw = (seat.yaw = passenger.yaw);
            seat.pitch = passenger.pitch * 0.5F;
            seat.aJ = (this.aH = this.yaw);
        }
    }
    // apply pitch & yaw
    this.lastYaw = (this.yaw = passenger.yaw);
    this.pitch = passenger.pitch * 0.5F;
    setYawPitch(this.yaw, this.pitch);
    this.aJ = (this.aH = this.yaw);
    // get motion from passenger (player)
    double motionSideways = passenger.aY * 0.5F;
    double motionForward = passenger.ba;
    // backwards is slower
    if (motionForward <= 0.0F) {
        motionForward *= 0.25F;
    }
    // sideways is slower too but not as slow as backwards
    motionSideways *= 0.85F;
    float speed = 0.22222F * (1F + (rideSkill.getSpeedIncrease().getValue() / 100F));
    double jumpHeight = Util.clamp(1 + rideSkill.getJumpHeight().getValue().doubleValue(), 0, 10);
    float ascendSpeed = 0.2f;
    if (Configuration.HungerSystem.USE_HUNGER_SYSTEM && Configuration.HungerSystem.AFFECT_RIDE_SPEED) {
        double factor = Math.log10(myPet.getSaturation()) / 2;
        speed *= factor;
        jumpHeight *= factor;
        ascendSpeed *= factor;
    }
    // apply motion
    ride(motionSideways, motionForward, vec3d.y, speed);
    // throw player move event
    if (Configuration.Misc.THROW_PLAYER_MOVE_EVENT_WHILE_RIDING) {
        double delta = Math.pow(this.locX() - this.lastX, 2.0D) + Math.pow(this.locY() - this.lastY, 2.0D) + Math.pow(this.locZ() - this.lastZ, 2.0D);
        float deltaAngle = Math.abs(this.yaw - lastYaw) + Math.abs(this.pitch - lastPitch);
        if (delta > 0.00390625D || deltaAngle > 10.0F) {
            Location to = getBukkitEntity().getLocation();
            Location from = new Location(world.getWorld(), this.lastX, this.lastY, this.lastZ, this.lastYaw, this.lastPitch);
            if (from.getX() != Double.MAX_VALUE) {
                Location oldTo = to.clone();
                PlayerMoveEvent event = new PlayerMoveEvent((Player) passenger.getBukkitEntity(), from, to);
                Bukkit.getPluginManager().callEvent(event);
                if (event.isCancelled()) {
                    passenger.getBukkitEntity().teleport(from);
                    return;
                }
                if ((!oldTo.equals(event.getTo())) && (!event.isCancelled())) {
                    passenger.getBukkitEntity().teleport(event.getTo(), PlayerTeleportEvent.TeleportCause.UNKNOWN);
                    return;
                }
            }
        }
    }
    if (jump != null && this.isVehicle()) {
        // TODO why?
        this.getBlockJumpFactor();
        boolean doJump = false;
        if (jump != null) {
            try {
                doJump = jump.getBoolean(passenger);
            } catch (IllegalAccessException ignored) {
            }
        }
        if (doJump) {
            if (onGround) {
                jumpHeight = new BigDecimal(jumpHeight).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue();
                String jumpHeightString = JumpHelper.JUMP_FORMAT.format(jumpHeight);
                Double jumpVelocity = JumpHelper.JUMP_MAP.get(jumpHeightString);
                jumpVelocity = jumpVelocity == null ? 0.44161199999510264 : jumpVelocity;
                this.setMot(this.getMot().x, jumpVelocity, this.getMot().z);
            } else if (rideSkill.getCanFly().getValue()) {
                if (limitCounter <= 0 && rideSkill.getFlyLimit().getValue().doubleValue() > 0) {
                    canFly = false;
                } else if (flyCheckCounter-- <= 0) {
                    canFly = MyPetApi.getHookHelper().canMyPetFlyAt(getBukkitEntity().getLocation());
                    if (canFly && !Permissions.hasExtended(getOwner().getPlayer(), "MyPet.extended.ride.fly")) {
                        canFly = false;
                    }
                    flyCheckCounter = 5;
                }
                if (canFly) {
                    if (this.getMot().y < ascendSpeed) {
                        this.setMot(this.getMot().x, ascendSpeed, this.getMot().z);
                        this.fallDistance = 0;
                        this.isFlying = true;
                    }
                }
            }
        } else {
            flyCheckCounter = 0;
        }
    }
    if (Configuration.HungerSystem.USE_HUNGER_SYSTEM && Configuration.Skilltree.Skill.Ride.HUNGER_PER_METER > 0) {
        double dX = locX() - lastX;
        double dY = Math.max(0, locY() - lastY);
        double dZ = locZ() - lastZ;
        if (dX != 0 || dY != 0 || dZ != 0) {
            double distance = Math.sqrt(dX * dX + dY * dY + dZ * dZ);
            if (isFlying && rideSkill.getFlyLimit().getValue().doubleValue() > 0) {
                limitCounter -= distance;
            }
            myPet.decreaseSaturation(Configuration.Skilltree.Skill.Ride.HUNGER_PER_METER * distance);
            double factor = Math.log10(myPet.getSaturation()) / 2;
            getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue((0.22222F * (1F + (rideSkill.getSpeedIncrease().getValue() / 100F))) * factor);
            this.n((float) this.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).getValue());
        }
    }
}
Also used : PlayerMoveEvent(org.bukkit.event.player.PlayerMoveEvent) EntityMySeat(de.Keyle.MyPet.compat.v1_16_R1.entity.types.EntityMySeat) Ride(de.Keyle.MyPet.api.skill.skills.Ride) BigDecimal(java.math.BigDecimal) Location(org.bukkit.Location)

Example 8 with Ride

use of de.Keyle.MyPet.api.skill.skills.Ride in project MyPet by xXKeyleXx.

the class EntityMyPet method g.

public void g(float motionSideways, float motionForward) {
    if (!hasRider || this.passenger == null) {
        super.g(motionSideways, motionForward);
        return;
    }
    if (this.onGround && this.isFlying) {
        isFlying = false;
        this.fallDistance = 0;
    }
    Ride rideSkill = myPet.getSkills().get(RideImpl.class);
    if (rideSkill == null || !rideSkill.getActive().getValue()) {
        this.passenger.mount(null);
        return;
    }
    // apply pitch & yaw
    this.lastYaw = (this.yaw = this.passenger.yaw);
    this.pitch = this.passenger.pitch * 0.5F;
    setYawPitch(this.yaw, this.pitch);
    this.aI = (this.aG = this.yaw);
    // get motion from passenger (player)
    motionSideways = ((EntityLiving) this.passenger).aZ * 0.5F;
    motionForward = ((EntityLiving) this.passenger).ba;
    // backwards is slower
    if (motionForward <= 0.0F) {
        motionForward *= 0.25F;
    }
    // sideways is slower too but not as slow as backwards
    motionSideways *= 0.85F;
    float speed = 0.22222F * (1F + (rideSkill.getSpeedIncrease().getValue() / 100F));
    double jumpHeight = Util.clamp(1 + rideSkill.getJumpHeight().getValue().doubleValue(), 0, 10);
    float ascendSpeed = 0.2f;
    if (Configuration.HungerSystem.USE_HUNGER_SYSTEM && Configuration.HungerSystem.AFFECT_RIDE_SPEED) {
        double factor = Math.log10(myPet.getSaturation()) / 2;
        speed *= factor;
        jumpHeight *= factor;
        ascendSpeed *= factor;
    }
    // apply motion
    ride(motionSideways, motionForward, speed);
    // jump when the player jumps
    if (jump != null && this.passenger != null) {
        boolean doJump = false;
        try {
            doJump = jump.getBoolean(this.passenger);
        } catch (IllegalAccessException ignored) {
        }
        if (doJump) {
            if (onGround) {
                jumpHeight = new BigDecimal(jumpHeight).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue();
                String jumpHeightString = JumpHelper.JUMP_FORMAT.format(jumpHeight);
                Double jumpVelocity = JumpHelper.JUMP_MAP.get(jumpHeightString);
                jumpVelocity = jumpVelocity == null ? 0.44161199999510264 : jumpVelocity;
                this.motY = jumpVelocity;
            } else if (rideSkill.getCanFly().getValue()) {
                if (limitCounter <= 0 && rideSkill.getFlyLimit().getValue().doubleValue() > 0) {
                    canFly = false;
                } else if (flyCheckCounter-- <= 0) {
                    canFly = MyPetApi.getHookHelper().canMyPetFlyAt(getBukkitEntity().getLocation());
                    if (canFly && !Permissions.hasExtended(getOwner().getPlayer(), "MyPet.extended.ride.fly")) {
                        canFly = false;
                    }
                    flyCheckCounter = 5;
                }
                if (canFly) {
                    this.motY = ascendSpeed;
                    this.fallDistance = 0;
                    this.isFlying = true;
                }
            }
        } else {
            flyCheckCounter = 0;
        }
    }
    if (Configuration.HungerSystem.USE_HUNGER_SYSTEM && Configuration.Skilltree.Skill.Ride.HUNGER_PER_METER > 0) {
        double dX = locX - lastX;
        double dY = Math.max(0, locY - lastY);
        double dZ = locZ - lastZ;
        if (dX != 0 || dY != 0 || dZ != 0) {
            double distance = Math.sqrt(dX * dX + dY * dY + dZ * dZ);
            if (isFlying && rideSkill.getFlyLimit().getValue().doubleValue() > 0) {
                limitCounter -= distance;
            }
            myPet.decreaseSaturation(Configuration.Skilltree.Skill.Ride.HUNGER_PER_METER * distance);
        }
    }
}
Also used : Ride(de.Keyle.MyPet.api.skill.skills.Ride) BigDecimal(java.math.BigDecimal)

Example 9 with Ride

use of de.Keyle.MyPet.api.skill.skills.Ride in project MyPet by xXKeyleXx.

the class EntityMyPet method doMyPetTick.

/**
 * Entity AI tick method
 * -> updateAITasks()
 */
protected void doMyPetTick() {
    try {
        ++this.ticksFarFromPlayer;
        if (isAlive()) {
            // sensing
            getEntitySenses().a();
            Player p = getOwner().getPlayer();
            if (p == null || !p.isOnline()) {
                MyPetApi.getLogger().warning("==========================================");
                MyPetApi.getLogger().warning("Please report this to the MyPet developer!");
                MyPetApi.getLogger().warning("MyPet: " + getMyPet());
                MyPetApi.getLogger().warning("MyPetOwner: " + getOwner());
                MyPetApi.getLogger().warning("Owner online: " + (getOwner() != null ? getOwner().isOnline() : "null"));
                MyPetApi.getLogger().warning("==========================================");
                this.die();
                return;
            }
            if (!hasRider()) {
                // target selector
                petTargetSelector.tick();
                // pathfinder selector
                petPathfinderSelector.tick();
                // navigation
                petNavigation.tick();
            }
            Ride rideSkill = myPet.getSkills().get(RideImpl.class);
            if (this.onGround && rideSkill.getFlyLimit().getValue().doubleValue() > 0) {
                limitCounter += rideSkill.getFlyRegenRate().getValue().doubleValue();
                if (limitCounter > rideSkill.getFlyLimit().getValue().doubleValue()) {
                    limitCounter = rideSkill.getFlyLimit().getValue().floatValue();
                }
            }
        }
        // "mob tick"
        E();
        // controls
        // move
        getControllerMove().c();
        // look
        getControllerLook().a();
        // jump
        getControllerJump().b();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Player(org.bukkit.entity.Player) MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) Ride(de.Keyle.MyPet.api.skill.skills.Ride)

Example 10 with Ride

use of de.Keyle.MyPet.api.skill.skills.Ride in project MyPet by xXKeyleXx.

the class EntityMyPet method g.

/**
 * -> travel
 */
public void g(Vec3D vec3d) {
    if (!hasRider || !this.isVehicle()) {
        super.g(vec3d);
        return;
    }
    if (this.onGround && this.isFlying) {
        isFlying = false;
        this.fallDistance = 0;
    }
    EntityLiving passenger = null;
    if (!indirectRiding) {
        passenger = (EntityLiving) this.getFirstPassenger();
    } else {
        if (this.getFirstPassenger().getPassengers().isEmpty()) {
            super.g(vec3d);
            return;
        } else {
            passenger = (EntityLiving) this.getFirstPassenger().getPassengers().get(0);
        }
    }
    if (this.a(TagsFluid.WATER)) {
        this.setMot(this.getMot().add(0, 0.4, 0));
    }
    Ride rideSkill = myPet.getSkills().get(RideImpl.class);
    if (rideSkill == null || !rideSkill.getActive().getValue()) {
        passenger.stopRiding();
        return;
    }
    // Rotations are fun
    if (indirectRiding) {
        if (this.getFirstPassenger() instanceof EntityMySeat) {
            EntityMySeat seat = (EntityMySeat) this.getFirstPassenger();
            seat.lastYaw = (seat.yaw = passenger.yaw);
            seat.pitch = passenger.pitch * 0.5F;
            seat.aC = (this.aA = this.yaw);
        }
    }
    // apply pitch & yaw
    this.lastYaw = (this.yaw = passenger.yaw);
    this.pitch = passenger.pitch * 0.5F;
    setYawPitch(this.yaw, this.pitch);
    this.aC = (this.aA = this.yaw);
    // get motion from passenger (player)
    double motionSideways = passenger.aR * 0.5F;
    double motionForward = passenger.aT;
    // backwards is slower
    if (motionForward <= 0.0F) {
        motionForward *= 0.25F;
    }
    // sideways is slower too but not as slow as backwards
    motionSideways *= 0.85F;
    float speed = 0.22222F * (1F + (rideSkill.getSpeedIncrease().getValue() / 100F));
    double jumpHeight = Util.clamp(1 + rideSkill.getJumpHeight().getValue().doubleValue(), 0, 10);
    float ascendSpeed = 0.2f;
    if (Configuration.HungerSystem.USE_HUNGER_SYSTEM && Configuration.HungerSystem.AFFECT_RIDE_SPEED) {
        double factor = Math.log10(myPet.getSaturation()) / 2;
        speed *= factor;
        jumpHeight *= factor;
        ascendSpeed *= factor;
    }
    // apply motion
    ride(motionSideways, motionForward, vec3d.y, speed);
    // throw player move event
    if (Configuration.Misc.THROW_PLAYER_MOVE_EVENT_WHILE_RIDING) {
        double delta = Math.pow(this.locX() - this.lastX, 2.0D) + Math.pow(this.locY() - this.lastY, 2.0D) + Math.pow(this.locZ() - this.lastZ, 2.0D);
        float deltaAngle = Math.abs(this.yaw - lastYaw) + Math.abs(this.pitch - lastPitch);
        if (delta > 0.00390625D || deltaAngle > 10.0F) {
            Location to = getBukkitEntity().getLocation();
            Location from = new Location(world.getWorld(), this.lastX, this.lastY, this.lastZ, this.lastYaw, this.lastPitch);
            if (from.getX() != Double.MAX_VALUE) {
                Location oldTo = to.clone();
                PlayerMoveEvent event = new PlayerMoveEvent((Player) passenger.getBukkitEntity(), from, to);
                Bukkit.getPluginManager().callEvent(event);
                if (event.isCancelled()) {
                    passenger.getBukkitEntity().teleport(from);
                    return;
                }
                if ((!oldTo.equals(event.getTo())) && (!event.isCancelled())) {
                    passenger.getBukkitEntity().teleport(event.getTo(), PlayerTeleportEvent.TeleportCause.UNKNOWN);
                    return;
                }
            }
        }
    }
    if (jump != null && this.isVehicle()) {
        // TODO why?
        this.getBlockJumpFactor();
        boolean doJump = false;
        if (jump != null) {
            try {
                doJump = jump.getBoolean(passenger);
            } catch (IllegalAccessException ignored) {
            }
        }
        if (doJump) {
            if (onGround) {
                jumpHeight = new BigDecimal(jumpHeight).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue();
                String jumpHeightString = JumpHelper.JUMP_FORMAT.format(jumpHeight);
                Double jumpVelocity = JumpHelper.JUMP_MAP.get(jumpHeightString);
                jumpVelocity = jumpVelocity == null ? 0.44161199999510264 : jumpVelocity;
                this.setMot(this.getMot().x, jumpVelocity, this.getMot().z);
            } else if (rideSkill.getCanFly().getValue()) {
                if (limitCounter <= 0 && rideSkill.getFlyLimit().getValue().doubleValue() > 0) {
                    canFly = false;
                } else if (flyCheckCounter-- <= 0) {
                    canFly = MyPetApi.getHookHelper().canMyPetFlyAt(getBukkitEntity().getLocation());
                    if (canFly && !Permissions.hasExtended(getOwner().getPlayer(), "MyPet.extended.ride.fly")) {
                        canFly = false;
                    }
                    flyCheckCounter = 5;
                }
                if (canFly) {
                    if (this.getMot().y < ascendSpeed) {
                        this.setMot(this.getMot().x, ascendSpeed, this.getMot().z);
                        this.fallDistance = 0;
                        this.isFlying = true;
                    }
                }
            }
        } else {
            flyCheckCounter = 0;
        }
    }
    if (Configuration.HungerSystem.USE_HUNGER_SYSTEM && Configuration.Skilltree.Skill.Ride.HUNGER_PER_METER > 0) {
        double dX = locX() - lastX;
        double dY = Math.max(0, locY() - lastY);
        double dZ = locZ() - lastZ;
        if (dX != 0 || dY != 0 || dZ != 0) {
            double distance = Math.sqrt(dX * dX + dY * dY + dZ * dZ);
            if (isFlying && rideSkill.getFlyLimit().getValue().doubleValue() > 0) {
                limitCounter -= distance;
            }
            myPet.decreaseSaturation(Configuration.Skilltree.Skill.Ride.HUNGER_PER_METER * distance);
            double factor = Math.log10(myPet.getSaturation()) / 2;
            getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue((0.22222F * (1F + (rideSkill.getSpeedIncrease().getValue() / 100F))) * factor);
            this.n((float) this.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).getValue());
        }
    }
}
Also used : PlayerMoveEvent(org.bukkit.event.player.PlayerMoveEvent) EntityMySeat(de.Keyle.MyPet.compat.v1_16_R3.entity.types.EntityMySeat) Ride(de.Keyle.MyPet.api.skill.skills.Ride) BigDecimal(java.math.BigDecimal) Location(org.bukkit.Location)

Aggregations

Ride (de.Keyle.MyPet.api.skill.skills.Ride)13 MyPetPlayer (de.Keyle.MyPet.api.player.MyPetPlayer)5 BigDecimal (java.math.BigDecimal)5 Player (org.bukkit.entity.Player)5 Location (org.bukkit.Location)4 PlayerMoveEvent (org.bukkit.event.player.PlayerMoveEvent)4 EntityMySeat (de.Keyle.MyPet.compat.v1_16_R1.entity.types.EntityMySeat)2 EntityMySeat (de.Keyle.MyPet.compat.v1_16_R3.entity.types.EntityMySeat)2 EntityMySeat (de.Keyle.MyPet.compat.v1_12_R1.entity.types.EntityMySeat)1 EntityMyHorse (de.Keyle.MyPet.compat.v1_9_R2.entity.types.EntityMyHorse)1 CraftPlayer (org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer)1 CraftPlayer (org.bukkit.craftbukkit.v1_16_R1.entity.CraftPlayer)1 CraftPlayer (org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer)1 CraftPlayer (org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer)1