use of de.Keyle.MyPet.compat.v1_18_R1.entity.EntityMyPet in project MyPet by xXKeyleXx.
the class RangedAttack method shouldFinish.
@Override
public boolean shouldFinish() {
if (!entityMyPet.hasTarget() || myPet.getRangedDamage() <= 0 || !entityMyPet.canMove()) {
return true;
}
if (this.target.getBukkitEntity() != entityMyPet.getMyPetTarget()) {
return true;
}
double meleeDamage = myPet.getDamage();
if (meleeDamage > 0 && this.entityMyPet.distanceToSqr(target.getX(), this.target.getBoundingBox().minY, target.getZ()) < 4) {
Ranged rangedSkill = myPet.getSkills().get(Ranged.class);
if (meleeDamage > rangedSkill.getDamage().getValue().doubleValue()) {
return true;
}
}
Behavior behaviorSkill = myPet.getSkills().get(Behavior.class);
if (behaviorSkill != null && behaviorSkill.isActive()) {
if (behaviorSkill.getBehavior() == Behavior.BehaviorMode.Friendly) {
return true;
}
if (behaviorSkill.getBehavior() == Behavior.BehaviorMode.Raid) {
if (this.target instanceof TamableAnimal && ((TamableAnimal) this.target).isTame()) {
return true;
}
if (this.target instanceof EntityMyPet) {
return true;
}
return this.target instanceof ServerPlayer;
}
}
return false;
}
use of de.Keyle.MyPet.compat.v1_18_R1.entity.EntityMyPet in project MyPet by xXKeyleXx.
the class RangedAttack method shootProjectile.
public void shootProjectile(LivingEntity target, float damage, Projectile projectile) {
Level world = target.level;
double minY = this.target.getBoundingBox().minY;
switch(projectile) {
case Snowball:
{
MyPetSnowball snowball = new MyPetSnowball(world, entityMyPet);
double distanceX = target.getX() - entityMyPet.getX();
double distanceY = target.getY() + target.getEyeHeight() - 1.100000023841858D - snowball.getY();
double distanceZ = target.getZ() - entityMyPet.getZ();
double distance20percent = Mth.sqrt((float) (distanceX * distanceX + distanceZ * distanceZ)) * 0.2F;
snowball.setDamage(damage);
snowball.shoot(distanceX, distanceY + distance20percent, distanceZ, 1.6F, 1);
entityMyPet.makeSound("entity.arrow.shoot", 0.5F, 0.4F / (entityMyPet.getRandom().nextFloat() * 0.4F + 0.8F));
world.addFreshEntity(snowball);
break;
}
case Egg:
{
MyPetEgg egg = new MyPetEgg(world, entityMyPet);
double distanceX = target.getX() - entityMyPet.getX();
double distanceY = target.getY() + target.getEyeHeight() - 1.100000023841858D - egg.getY();
double distanceZ = target.getZ() - entityMyPet.getZ();
double distance20percent = Mth.sqrt((float) (distanceX * distanceX + distanceZ * distanceZ)) * 0.2F;
egg.setDamage(damage);
egg.shoot(distanceX, distanceY + distance20percent, distanceZ, 1.6F, 1);
entityMyPet.makeSound("entity.arrow.shoot", 0.5F, 0.4F / (entityMyPet.getRandom().nextFloat() * 0.4F + 0.8F));
world.addFreshEntity(egg);
break;
}
case LargeFireball:
{
double distanceX = this.target.getX() - entityMyPet.getX();
double distanceY = minY + (double) (this.target.getBbHeight() / 2.0F) - (0.5D + entityMyPet.getY() + (double) (entityMyPet.getBbHeight() / 2.0F));
double distanceZ = this.target.getZ() - entityMyPet.getZ();
MyPetLargeFireball largeFireball = new MyPetLargeFireball(world, entityMyPet, distanceX, distanceY, distanceZ);
largeFireball.setPosRaw(largeFireball.getX(), (entityMyPet.getY() + entityMyPet.getBbHeight() / 2.0F + 0.5D), largeFireball.getZ());
largeFireball.setDamage(damage);
world.addFreshEntity(largeFireball);
entityMyPet.makeSound("entity.ghast.shoot", 1.0F + entityMyPet.getRandom().nextFloat(), entityMyPet.getRandom().nextFloat() * 0.7F + 0.3F);
break;
}
case SmallFireball:
{
double distanceX = this.target.getX() - entityMyPet.getX();
double distanceY = minY + (this.target.getBbHeight() / 2.0F) - (0.5D + entityMyPet.getY() + (entityMyPet.getBbHeight() / 2.0F));
double distanceZ = this.target.getZ() - entityMyPet.getZ();
MyPetSmallFireball smallFireball = new MyPetSmallFireball(world, entityMyPet, distanceX, distanceY, distanceZ);
smallFireball.setPosRaw(smallFireball.getX(), (entityMyPet.getY() + entityMyPet.getBbHeight() / 2.0F + 0.5D), smallFireball.getZ());
smallFireball.setDamage(damage);
world.addFreshEntity(smallFireball);
entityMyPet.makeSound("entity.ghast.shoot", 1.0F + entityMyPet.getRandom().nextFloat(), entityMyPet.getRandom().nextFloat() * 0.7F + 0.3F);
break;
}
case WitherSkull:
{
double distanceX = this.target.getX() - entityMyPet.getX();
double distanceY = minY + (double) (this.target.getBbHeight() / 2.0F) - (0.5D + entityMyPet.getY() + (double) (entityMyPet.getBbHeight() / 2.0F));
double distanceZ = this.target.getZ() - entityMyPet.getZ();
MyPetWitherSkull witherSkull = new MyPetWitherSkull(world, entityMyPet, distanceX, distanceY, distanceZ);
witherSkull.setPosRaw(witherSkull.getX(), (entityMyPet.getY() + entityMyPet.getBbHeight() / 2.0F + 0.5D), witherSkull.getZ());
witherSkull.setDamage(damage);
world.addFreshEntity(witherSkull);
entityMyPet.makeSound("entity.wither.shoot", 1.0F + entityMyPet.getRandom().nextFloat(), entityMyPet.getRandom().nextFloat() * 0.7F + 0.3F);
break;
}
case DragonFireball:
{
double distanceX = this.target.getX() - entityMyPet.getX();
double distanceY = minY + (double) (this.target.getBbHeight() / 2.0F) - (0.5D + entityMyPet.getY() + (double) (entityMyPet.getBbHeight() / 2.0F));
double distanceZ = this.target.getZ() - entityMyPet.getZ();
MyPetDragonFireball dragonFireball = new MyPetDragonFireball(world, entityMyPet, distanceX, distanceY, distanceZ);
dragonFireball.setPosRaw(dragonFireball.getX(), (entityMyPet.getY() + entityMyPet.getBbHeight() / 2.0F + 0.5D), dragonFireball.getZ());
dragonFireball.setDamage(damage);
world.addFreshEntity(dragonFireball);
entityMyPet.makeSound("entity.ender_dragon.shoot", 1.0F + entityMyPet.getRandom().nextFloat(), entityMyPet.getRandom().nextFloat() * 0.7F + 0.3F);
break;
}
case Trident:
{
MyPetTrident trident = new MyPetTrident(world, entityMyPet);
trident.setBaseDamage(damage);
trident.setCritArrow(false);
entityMyPet.makeSound("item.trident.throw", 1.0F, 1.0F / (entityMyPet.getRandom().nextFloat() * 0.4F + 0.8F));
double distanceX = target.getX() - entityMyPet.getX();
double distanceY = target.getY() + target.getEyeHeight() - 1.100000023841858D - trident.getY();
double distanceZ = target.getZ() - entityMyPet.getZ();
double distance20percent = Mth.sqrt((float) (distanceX * distanceX + distanceZ * distanceZ)) * 0.2F;
trident.shoot(distanceX, distanceY + distance20percent, distanceZ, 1.6F, 1);
world.addFreshEntity(trident);
break;
}
case EnderPearl:
{
MyPetEnderPearl enderPearl = new MyPetEnderPearl(world, entityMyPet);
enderPearl.setDamage(damage);
entityMyPet.makeSound("entity.ender_pearl.throw", 1.0F, 1.0F / (entityMyPet.getRandom().nextFloat() * 0.4F + 0.8F));
double distanceX = target.getX() - entityMyPet.getX();
double distanceY = target.getY() + target.getEyeHeight() - 1.100000023841858D - enderPearl.getY();
double distanceZ = target.getZ() - entityMyPet.getZ();
double distance20percent = Mth.sqrt((float) (distanceX * distanceX + distanceZ * distanceZ)) * 0.2F;
enderPearl.shoot(distanceX, distanceY + distance20percent, distanceZ, 1.6F, 1);
world.addFreshEntity(enderPearl);
break;
}
case LlamaSpit:
{
MyPetLlamaSpit llamaSpit = new MyPetLlamaSpit(world, entityMyPet);
llamaSpit.setDamage(damage);
entityMyPet.makeSound("entity.llama.spit", 1.0F, 1.0F / (entityMyPet.getRandom().nextFloat() * 0.4F + 0.8F));
double distanceX = target.getX() - entityMyPet.getX();
double distanceY = target.getY() + (target.getEyeHeight() / 3.0F) - llamaSpit.getY();
double distanceZ = target.getZ() - entityMyPet.getZ();
double distance20percent = Mth.sqrt((float) (distanceX * distanceX + distanceZ * distanceZ)) * 0.2D;
llamaSpit.shoot(distanceX, distanceY + distance20percent, distanceZ, 1.5F, 10.0F);
world.addFreshEntity(llamaSpit);
break;
}
case Arrow:
default:
{
Arrow arrow = new MyPetArrow(world, entityMyPet);
arrow.setBaseDamage(damage);
arrow.setCritArrow(false);
entityMyPet.makeSound("entity.arrow.shoot", 1.0F, 1.0F / (entityMyPet.getRandom().nextFloat() * 0.4F + 0.8F));
double distanceX = target.getX() - entityMyPet.getX();
double distanceY = target.getY() + target.getEyeHeight() - 1.100000023841858D - arrow.getY();
double distanceZ = target.getZ() - entityMyPet.getZ();
double distance20percent = Mth.sqrt((float) (distanceX * distanceX + distanceZ * distanceZ)) * 0.2F;
arrow.shoot(distanceX, distanceY + distance20percent, distanceZ, 1.6F, 1);
world.addFreshEntity(arrow);
break;
}
}
}
use of de.Keyle.MyPet.compat.v1_18_R1.entity.EntityMyPet in project MyPet by xXKeyleXx.
the class VanillaNavigation method tick.
@Override
public void tick() {
// This switches between movesets enabling the pet to move naturally on land and water
EntityMyPet petEntity = (EntityMyPet) this.entityMyPet;
if (petEntity.isInWaterOrBubble() && this.entityMyPet instanceof EntityMyAquaticPet && !(petEntity.getMoveControl() instanceof MyPetAquaticMoveControl)) {
petEntity.switchMovement(new MyPetAquaticMoveControl(petEntity));
} else if (!petEntity.isInWaterOrBubble() && petEntity.getMoveControl() instanceof MyPetAquaticMoveControl) {
petEntity.switchMovement(new MoveControl(petEntity));
}
nav.tick();
}
use of de.Keyle.MyPet.compat.v1_18_R1.entity.EntityMyPet in project MyPet by xXKeyleXx.
the class BehaviorDuelTarget method shouldStart.
@Override
public boolean shouldStart() {
Behavior behaviorSkill = myPet.getSkills().get(Behavior.class);
if (!behaviorSkill.isActive() || behaviorSkill.getBehavior() != BehaviorMode.Duel) {
return false;
}
if (myPet.getDamage() <= 0 && myPet.getRangedDamage() <= 0) {
return false;
}
if (!petEntity.canMove()) {
return false;
}
if (petEntity.hasTarget()) {
return false;
}
if (duelOpponent != null) {
this.target = duelOpponent;
return true;
}
for (EntityMyPet entityMyPet : this.petEntity.level.getEntitiesOfClass(EntityMyPet.class, this.petOwnerEntity.getBoundingBox().inflate(range, range, range))) {
MyPet targetMyPet = entityMyPet.getMyPet();
if (entityMyPet != petEntity && entityMyPet.isAlive()) {
if (!targetMyPet.getSkills().isActive(BehaviorImpl.class) || !targetMyPet.getEntity().get().canMove()) {
continue;
}
BehaviorImpl targetbehavior = targetMyPet.getSkills().get(BehaviorImpl.class);
if (targetbehavior.getBehavior() != BehaviorMode.Duel) {
continue;
}
if (targetMyPet.getDamage() == 0) {
continue;
}
this.target = entityMyPet;
return true;
}
}
return false;
}
use of de.Keyle.MyPet.compat.v1_18_R1.entity.EntityMyPet in project MyPet by xXKeyleXx.
the class ControlTarget method shouldStart.
@Override
public boolean shouldStart() {
if (controlPathfinderGoal == null) {
if (petEntity.getPathfinder().hasGoal("Control")) {
controlPathfinderGoal = (Control) petEntity.getPathfinder().getGoal("Control");
}
}
if (controlPathfinderGoal == null) {
return false;
}
if (myPet.getDamage() <= 0 && myPet.getRangedDamage() <= 0) {
return false;
}
if (controlPathfinderGoal.moveTo != null && petEntity.canMove()) {
Behavior behaviorSkill = myPet.getSkills().get(Behavior.class);
if (behaviorSkill.isActive()) {
if (behaviorSkill.getBehavior() == BehaviorMode.Friendly) {
return false;
}
}
for (net.minecraft.world.entity.LivingEntity entityLiving : this.petEntity.level.getEntitiesOfClass(net.minecraft.world.entity.LivingEntity.class, this.petEntity.getBoundingBox().inflate(this.range, 4.0D, this.range))) {
if (entityLiving != petEntity && !(entityLiving instanceof ArmorStand)) {
if (entityLiving instanceof ServerPlayer) {
Player targetPlayer = (Player) entityLiving.getBukkitEntity();
if (myPet.getOwner().equals(targetPlayer)) {
continue;
} else if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), targetPlayer, true)) {
continue;
}
} else if (entityLiving instanceof TamableAnimal) {
TamableAnimal tameable = (TamableAnimal) entityLiving;
if (tameable.isTame() && tameable.getOwner() != null) {
Player tameableOwner = (Player) tameable.getOwner().getBukkitEntity();
if (myPet.getOwner().equals(tameableOwner)) {
continue;
} else if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), tameableOwner, true)) {
continue;
}
}
} else if (entityLiving instanceof EntityMyPet) {
MyPet targetMyPet = ((EntityMyPet) entityLiving).getMyPet();
if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), targetMyPet.getOwner().getPlayer(), true)) {
continue;
}
}
if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), entityLiving.getBukkitEntity())) {
continue;
}
if (behaviorSkill != null) {
if (behaviorSkill.getBehavior() == BehaviorMode.Raid) {
if (entityLiving instanceof TamableAnimal) {
continue;
} else if (entityLiving instanceof EntityMyPet) {
continue;
} else if (entityLiving instanceof ServerPlayer) {
continue;
}
}
}
controlPathfinderGoal.stopControl();
this.target = entityLiving;
return true;
}
}
}
return false;
}
Aggregations