Search in sources :

Example 1 with MyAquaticPetPathNavigation

use of de.Keyle.MyPet.compat.v1_18_R1.entity.ai.navigation.MyAquaticPetPathNavigation in project MyPet by xXKeyleXx.

the class FollowOwner method applyWalkSpeed.

private void applyWalkSpeed() {
    float walkSpeed = owner.getAbilities().walkingSpeed;
    if (owner.getAbilities().flying) {
        // make the pet faster when the player is flying
        walkSpeed += owner.getAbilities().flyingSpeed;
    } else if (owner.isSprinting()) {
        // make the pet faster when the player is sprinting
        if (owner.getAttributes().getInstance(Attributes.MOVEMENT_SPEED) != null) {
            walkSpeed += owner.getAttributes().getInstance(Attributes.MOVEMENT_SPEED).getValue();
        }
    } else if (owner.isPassenger() && owner.getVehicle() instanceof LivingEntity) {
        // adjust the speed to the pet can catch up with the vehicle the player is in
        AttributeInstance vehicleSpeedAttribute = ((LivingEntity) owner.getVehicle()).getAttributes().getInstance(Attributes.MOVEMENT_SPEED);
        if (vehicleSpeedAttribute != null) {
            walkSpeed = (float) vehicleSpeedAttribute.getValue();
        }
    } else if (owner.hasEffect(MobEffects.MOVEMENT_SPEED)) {
        // make the pet faster when the player is has the SPEED effect
        walkSpeed += owner.getEffect(MobEffects.MOVEMENT_SPEED).getAmplifier() * 0.2 * walkSpeed;
    }
    // make aquatic pets faster - swimming is hard
    if (this.petEntity.isInWaterOrBubble() && this.petEntity.getNavigation() instanceof MyAquaticPetPathNavigation) {
        walkSpeed += 0.6f;
        if (owner.isSwimming()) {
            walkSpeed -= 0.035f;
        }
        if (owner.hasEffect(MobEffects.DOLPHINS_GRACE)) {
            walkSpeed += 0.08f;
        }
    }
    // make the pet a little bit faster than the player so it can catch up
    walkSpeed += 0.07f;
    nav.getParameters().addSpeedModifier("FollowOwner", walkSpeed);
}
Also used : LivingEntity(net.minecraft.world.entity.LivingEntity) MyAquaticPetPathNavigation(de.Keyle.MyPet.compat.v1_18_R1.entity.ai.navigation.MyAquaticPetPathNavigation) AttributeInstance(net.minecraft.world.entity.ai.attributes.AttributeInstance)

Example 2 with MyAquaticPetPathNavigation

use of de.Keyle.MyPet.compat.v1_18_R1.entity.ai.navigation.MyAquaticPetPathNavigation in project MyPet by xXKeyleXx.

the class FollowOwner method applyWalkSpeed.

private void applyWalkSpeed() {
    float walkSpeed = owner.getAbilities().walkingSpeed;
    if (owner.getAbilities().flying) {
        // make the pet faster when the player is flying
        walkSpeed += owner.getAbilities().flyingSpeed;
    } else if (owner.isSprinting()) {
        // make the pet faster when the player is sprinting
        if (owner.getAttributes().getInstance(Attributes.MOVEMENT_SPEED) != null) {
            walkSpeed += owner.getAttributes().getInstance(Attributes.MOVEMENT_SPEED).getValue();
        }
    } else if (owner.isPassenger() && owner.getVehicle() instanceof LivingEntity) {
        // adjust the speed to the pet can catch up with the vehicle the player is in
        AttributeInstance vehicleSpeedAttribute = ((LivingEntity) owner.getVehicle()).getAttributes().getInstance(Attributes.MOVEMENT_SPEED);
        if (vehicleSpeedAttribute != null) {
            walkSpeed = (float) vehicleSpeedAttribute.getValue();
        }
    } else if (owner.hasEffect(MobEffects.MOVEMENT_SPEED)) {
        // make the pet faster when the player is has the SPEED effect
        walkSpeed += owner.getEffect(MobEffects.MOVEMENT_SPEED).getAmplifier() * 0.2 * walkSpeed;
    }
    // make aquatic pets faster - swimming is hard
    if (this.petEntity.isInWaterOrBubble() && this.petEntity.getNavigation() instanceof MyAquaticPetPathNavigation) {
        walkSpeed += 0.6f;
        if (owner.isSwimming()) {
            walkSpeed -= 0.035f;
        }
        if (owner.hasEffect(MobEffects.DOLPHINS_GRACE)) {
            walkSpeed += 0.08f;
        }
    }
    // make the pet a little bit faster than the player so it can catch up
    walkSpeed += 0.07f;
    nav.getParameters().addSpeedModifier("FollowOwner", walkSpeed);
}
Also used : LivingEntity(net.minecraft.world.entity.LivingEntity) MyAquaticPetPathNavigation(de.Keyle.MyPet.compat.v1_17_R1.entity.ai.navigation.MyAquaticPetPathNavigation) AttributeInstance(net.minecraft.world.entity.ai.attributes.AttributeInstance)

Aggregations

LivingEntity (net.minecraft.world.entity.LivingEntity)2 AttributeInstance (net.minecraft.world.entity.ai.attributes.AttributeInstance)2 MyAquaticPetPathNavigation (de.Keyle.MyPet.compat.v1_17_R1.entity.ai.navigation.MyAquaticPetPathNavigation)1 MyAquaticPetPathNavigation (de.Keyle.MyPet.compat.v1_18_R1.entity.ai.navigation.MyAquaticPetPathNavigation)1