Search in sources :

Example 1 with EntityMySeat

use of de.Keyle.MyPet.compat.v1_12_R1.entity.types.EntityMySeat in project MyPet by xXKeyleXx.

the class EntityMyPet method a.

public void a(float motionSideways, float motionForward, float f) {
    if (!hasRider || !this.isVehicle()) {
        super.a(motionSideways, motionForward, f);
        return;
    }
    if (this.onGround && this.isFlying) {
        isFlying = false;
        this.fallDistance = 0;
    }
    EntityLiving passenger = null;
    if (!indirectRiding) {
        passenger = (EntityLiving) this.bw();
    } else {
        if (this.bw().bF().isEmpty()) {
            super.a(motionSideways, motionForward, f);
            return;
        } else {
            passenger = (EntityLiving) this.bw().bF().get(0);
        }
    }
    Ride rideSkill = myPet.getSkills().get(RideImpl.class);
    if (rideSkill == null || !rideSkill.getActive().getValue()) {
        passenger.stopRiding();
        return;
    }
    // Rotations are fun
    if (indirectRiding) {
        if (this.bw() instanceof EntityMySeat) {
            EntityMySeat seat = (EntityMySeat) this.bw();
            seat.lastYaw = (seat.yaw = passenger.yaw);
            seat.pitch = passenger.pitch * 0.5F;
            seat.aP = (this.aN = this.yaw);
        }
    }
    // apply pitch & yaw
    this.lastYaw = (this.yaw = passenger.yaw);
    this.pitch = passenger.pitch * 0.5F;
    setYawPitch(this.yaw, this.pitch);
    this.aP = (this.aN = this.yaw);
    // get motion from passenger (player)
    motionSideways = passenger.be * 0.5F;
    motionForward = passenger.bg;
    // 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, f, 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()) {
        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.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) {
                    if (this.motY < ascendSpeed) {
                        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);
            double factor = Math.log10(myPet.getSaturation()) / 2;
            getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue((0.22222F * (1F + (rideSkill.getSpeedIncrease().getValue() / 100F))) * factor);
        }
    }
}
Also used : PlayerMoveEvent(org.bukkit.event.player.PlayerMoveEvent) EntityMySeat(de.Keyle.MyPet.compat.v1_12_R1.entity.types.EntityMySeat) Ride(de.Keyle.MyPet.api.skill.skills.Ride) BigDecimal(java.math.BigDecimal) Location(org.bukkit.Location)

Example 2 with EntityMySeat

use of de.Keyle.MyPet.compat.v1_12_R1.entity.types.EntityMySeat in project MyPet by xXKeyleXx.

the class EntityMyPet method onLivingUpdate.

public void onLivingUpdate() {
    if (hasRider) {
        if (!isVehicle()) {
            hasRider = false;
            // climb height -> halfslab
            this.P = 0.5F;
            Location playerLoc = getOwner().getPlayer().getLocation();
            Location petLoc = getBukkitEntity().getLocation();
            petLoc.setYaw(playerLoc.getYaw());
            petLoc.setPitch(playerLoc.getPitch());
            getOwner().getPlayer().teleport(petLoc);
        }
    } else {
        if (isVehicle()) {
            for (Entity e : passengers) {
                Entity ridingEntity = (e instanceof EntityMySeat) ? e.bF().get(0) : e;
                if (ridingEntity instanceof EntityPlayer && getOwner().equals(ridingEntity)) {
                    hasRider = true;
                    // climb height -> 1 block
                    this.P = 1.0F;
                    petTargetSelector.finish();
                    petPathfinderSelector.finish();
                } else {
                    // just the owner can ride a pet
                    ridingEntity.stopRiding();
                }
            }
        }
    }
    if (sitPathfinder.isSitting() && sitCounter-- <= 0) {
        MyPetApi.getPlatformHelper().playParticleEffect(getOwner().getPlayer(), this.getBukkitEntity().getLocation().add(0, getHeadHeight() + 1, 0), ParticleCompat.BARRIER.get(), 0F, 0F, 0F, 5F, 1, 32);
        sitCounter = 60;
    }
    Player p = myPet.getOwner().getPlayer();
    if (p != null && p.isOnline() && !p.isDead()) {
        if (p.isSneaking() != isSneaking()) {
            this.setSneaking(!isSneaking());
        }
        if (Configuration.Misc.INVISIBLE_LIKE_OWNER) {
            if (!isInvisible && p.hasPotionEffect(PotionEffectType.INVISIBILITY)) {
                isInvisible = true;
                getBukkitEntity().addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, Integer.MAX_VALUE, 1, false));
            } else if (isInvisible && !p.hasPotionEffect(PotionEffectType.INVISIBILITY)) {
                getBukkitEntity().removePotionEffect(PotionEffectType.INVISIBILITY);
                isInvisible = false;
            }
        }
        if (!this.isInvisible() && getOwner().getDonationRank() != DonateCheck.DonationRank.None && donatorParticleCounter-- <= 0) {
            donatorParticleCounter = 20 + getRandom().nextInt(10);
            MyPetApi.getPlatformHelper().playParticleEffect(this.getBukkitEntity().getLocation().add(0, 1, 0), ParticleCompat.VILLAGER_HAPPY.get(), 0.4F, 0.4F, 0.4F, 0.4F, 5, 10);
        }
    }
}
Also used : CraftLivingEntity(org.bukkit.craftbukkit.v1_12_R1.entity.CraftLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer) PotionEffect(org.bukkit.potion.PotionEffect) EntityMySeat(de.Keyle.MyPet.compat.v1_12_R1.entity.types.EntityMySeat) Location(org.bukkit.Location)

Example 3 with EntityMySeat

use of de.Keyle.MyPet.compat.v1_12_R1.entity.types.EntityMySeat in project MyPet by xXKeyleXx.

the class EntityMyPet method onLivingUpdate.

public void onLivingUpdate() {
    if (hasRider) {
        if (!isVehicle()) {
            hasRider = false;
            // climb height -> halfslab
            this.G = 0.5F;
            Location playerLoc = getOwner().getPlayer().getLocation();
            Location petLoc = getBukkitEntity().getLocation();
            petLoc.setYaw(playerLoc.getYaw());
            petLoc.setPitch(playerLoc.getPitch());
            getOwner().getPlayer().teleport(petLoc);
        }
    } else {
        if (isVehicle()) {
            for (Entity e : passengers) {
                Entity ridingEntity = (e instanceof EntityMySeat) ? e.getPassengers().get(0) : e;
                if (ridingEntity instanceof EntityPlayer && getOwner().equals(ridingEntity)) {
                    hasRider = true;
                    // climb height -> 1 block
                    this.G = 1.0F;
                    petTargetSelector.finish();
                    petPathfinderSelector.finish();
                } else {
                    // just the owner can ride a pet
                    ridingEntity.stopRiding();
                }
            }
        }
    }
    if (sitPathfinder.isSitting() && sitCounter-- <= 0) {
        MyPetApi.getPlatformHelper().playParticleEffect(getOwner().getPlayer(), this.getBukkitEntity().getLocation().add(0, getHeadHeight() + 1, 0), ParticleCompat.BARRIER.get(), 0F, 0F, 0F, 5F, 1, 32);
        sitCounter = 60;
    }
    Player p = myPet.getOwner().getPlayer();
    if (p != null && p.isOnline() && !p.isDead()) {
        if (p.isSneaking() != isSneaking()) {
            this.setSneaking(!isSneaking());
        }
        if (Configuration.Misc.INVISIBLE_LIKE_OWNER) {
            if (!isInvisible && p.hasPotionEffect(PotionEffectType.INVISIBILITY)) {
                isInvisible = true;
                getBukkitEntity().addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, Integer.MAX_VALUE, 1, false));
            } else if (isInvisible && !p.hasPotionEffect(PotionEffectType.INVISIBILITY)) {
                getBukkitEntity().removePotionEffect(PotionEffectType.INVISIBILITY);
                isInvisible = false;
            }
        }
        if (!this.isInvisible() && getOwner().getDonationRank() != DonateCheck.DonationRank.None && donatorParticleCounter-- <= 0) {
            donatorParticleCounter = 20 + getRandom().nextInt(10);
            MyPetApi.getPlatformHelper().playParticleEffect(this.getBukkitEntity().getLocation().add(0, 1, 0), ParticleCompat.VILLAGER_HAPPY.get(), 0.4F, 0.4F, 0.4F, 0.4F, 5, 10);
        }
    }
}
Also used : CraftEntity(org.bukkit.craftbukkit.v1_16_R1.entity.CraftEntity) LivingEntity(org.bukkit.entity.LivingEntity) CraftLivingEntity(org.bukkit.craftbukkit.v1_16_R1.entity.CraftLivingEntity) Player(org.bukkit.entity.Player) MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_16_R1.entity.CraftPlayer) PotionEffect(org.bukkit.potion.PotionEffect) EntityMySeat(de.Keyle.MyPet.compat.v1_16_R1.entity.types.EntityMySeat) Location(org.bukkit.Location)

Example 4 with EntityMySeat

use of de.Keyle.MyPet.compat.v1_12_R1.entity.types.EntityMySeat in project MyPet by xXKeyleXx.

the class EntityMyPet method addPassenger.

@Override
protected boolean addPassenger(Entity entity) {
    boolean returnVal = false;
    // don't allow anything but the owner to ride this entity
    Ride rideSkill = myPet.getSkills().get(RideImpl.class);
    if (rideSkill != null && entity instanceof EntityPlayer && getOwner().equals(entity)) {
        if (entity.getVehicle() != this) {
            throw new IllegalStateException("Use x.startRiding(y), not y.addPassenger(x)");
        } else {
            Preconditions.checkState(!entity.passengers.contains(this), "Circular entity riding! %s %s", this, entity);
            boolean cancelled = false;
            if (MyPetApi.getPlatformHelper().isSpigot()) {
                cancelled = MountEventWrapper.callEvent(entity.getBukkitEntity(), this.getBukkitEntity());
            }
            if (cancelled) {
                returnVal = false;
            } else {
                returnVal = mountOwner(entity);
            }
        }
    /* this should not matter anymore but I'm leaving it in here in case it is relevant
            if (this instanceof IJumpable) {
                double factor = 1;
                if (Configuration.HungerSystem.USE_HUNGER_SYSTEM && Configuration.HungerSystem.AFFECT_RIDE_SPEED) {
                    factor = Math.log10(myPet.getSaturation()) / 2;
                }
                getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue((0.22222F * (1F + (rideSkill.getSpeedIncrease().getValue() / 100F))) * factor);
            } */
    }
    if (rideSkill != null && entity instanceof EntityMySeat) {
        if (entity.getVehicle() != this) {
            throw new IllegalStateException("Use x.startRiding(y), not y.addPassenger(x)");
        } else {
            Preconditions.checkState(!entity.getPassengers().contains(this), "Circular entity riding! %s %s", this, entity);
            boolean cancelled = false;
            if (MyPetApi.getPlatformHelper().isSpigot()) {
                cancelled = MountEventWrapper.callEvent(entity.getBukkitEntity(), this.getBukkitEntity());
            }
            if (cancelled) {
                returnVal = false;
            } else {
                returnVal = super.addPassenger(entity);
            }
        }
    }
    return returnVal;
}
Also used : EntityMySeat(de.Keyle.MyPet.compat.v1_16_R1.entity.types.EntityMySeat) Ride(de.Keyle.MyPet.api.skill.skills.Ride)

Example 5 with EntityMySeat

use of de.Keyle.MyPet.compat.v1_12_R1.entity.types.EntityMySeat in project MyPet by xXKeyleXx.

the class EntityMyPet method onLivingUpdate.

public void onLivingUpdate() {
    if (hasRider) {
        if (!isVehicle()) {
            hasRider = false;
            // climb height -> halfslab
            this.G = 0.5F;
            Location playerLoc = getOwner().getPlayer().getLocation();
            Location petLoc = getBukkitEntity().getLocation();
            petLoc.setYaw(playerLoc.getYaw());
            petLoc.setPitch(playerLoc.getPitch());
            getOwner().getPlayer().teleport(petLoc);
        }
    } else {
        if (isVehicle()) {
            for (Entity e : passengers) {
                Entity ridingEntity = (e instanceof EntityMySeat) ? e.getPassengers().get(0) : e;
                if (ridingEntity instanceof EntityPlayer && getOwner().equals(ridingEntity)) {
                    hasRider = true;
                    // climb height -> 1 block
                    this.G = 1.0F;
                    petTargetSelector.finish();
                    petPathfinderSelector.finish();
                } else {
                    // just the owner can ride a pet
                    ridingEntity.stopRiding();
                }
            }
        }
    }
    if (sitPathfinder.isSitting() && sitCounter-- <= 0) {
        MyPetApi.getPlatformHelper().playParticleEffect(getOwner().getPlayer(), this.getBukkitEntity().getLocation().add(0, getHeadHeight() + 1, 0), ParticleCompat.BARRIER.get(), 0F, 0F, 0F, 5F, 1, 32);
        sitCounter = 60;
    }
    Player p = myPet.getOwner().getPlayer();
    if (p != null && p.isOnline() && !p.isDead()) {
        if (p.isSneaking() != isSneaking()) {
            this.setSneaking(!isSneaking());
        }
        if (Configuration.Misc.INVISIBLE_LIKE_OWNER) {
            if (!isInvisible && p.hasPotionEffect(PotionEffectType.INVISIBILITY)) {
                isInvisible = true;
                getBukkitEntity().addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, Integer.MAX_VALUE, 1, false));
            } else if (isInvisible && !p.hasPotionEffect(PotionEffectType.INVISIBILITY)) {
                getBukkitEntity().removePotionEffect(PotionEffectType.INVISIBILITY);
                isInvisible = false;
            }
        }
        if (!this.isInvisible() && getOwner().getDonationRank() != DonateCheck.DonationRank.None && donatorParticleCounter-- <= 0) {
            donatorParticleCounter = 20 + getRandom().nextInt(10);
            MyPetApi.getPlatformHelper().playParticleEffect(this.getBukkitEntity().getLocation().add(0, 1, 0), ParticleCompat.VILLAGER_HAPPY.get(), 0.4F, 0.4F, 0.4F, 0.4F, 5, 10);
        }
    }
}
Also used : CraftEntity(org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity) LivingEntity(org.bukkit.entity.LivingEntity) CraftLivingEntity(org.bukkit.craftbukkit.v1_16_R3.entity.CraftLivingEntity) Player(org.bukkit.entity.Player) MyPetPlayer(de.Keyle.MyPet.api.player.MyPetPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer) PotionEffect(org.bukkit.potion.PotionEffect) EntityMySeat(de.Keyle.MyPet.compat.v1_16_R3.entity.types.EntityMySeat) Location(org.bukkit.Location)

Aggregations

Location (org.bukkit.Location)6 Ride (de.Keyle.MyPet.api.skill.skills.Ride)5 MyPetPlayer (de.Keyle.MyPet.api.player.MyPetPlayer)3 EntityMySeat (de.Keyle.MyPet.compat.v1_16_R1.entity.types.EntityMySeat)3 EntityMySeat (de.Keyle.MyPet.compat.v1_16_R3.entity.types.EntityMySeat)3 BigDecimal (java.math.BigDecimal)3 LivingEntity (org.bukkit.entity.LivingEntity)3 Player (org.bukkit.entity.Player)3 PlayerMoveEvent (org.bukkit.event.player.PlayerMoveEvent)3 PotionEffect (org.bukkit.potion.PotionEffect)3 EntityMySeat (de.Keyle.MyPet.compat.v1_12_R1.entity.types.EntityMySeat)2 CraftLivingEntity (org.bukkit.craftbukkit.v1_12_R1.entity.CraftLivingEntity)1 CraftPlayer (org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer)1 CraftEntity (org.bukkit.craftbukkit.v1_16_R1.entity.CraftEntity)1 CraftLivingEntity (org.bukkit.craftbukkit.v1_16_R1.entity.CraftLivingEntity)1 CraftPlayer (org.bukkit.craftbukkit.v1_16_R1.entity.CraftPlayer)1 CraftEntity (org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity)1 CraftLivingEntity (org.bukkit.craftbukkit.v1_16_R3.entity.CraftLivingEntity)1 CraftPlayer (org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer)1