use of de.Keyle.MyPet.compat.v1_17_R1.entity.EntityMyPet in project MyPet by xXKeyleXx.
the class HurtByTarget method shouldStart.
@Override
public boolean shouldStart() {
if (myPet.getDamage() <= 0 && myPet.getRangedDamage() <= 0) {
return false;
}
if (petEntity.getLastHurtByMob() == null) {
return false;
}
if (target != petEntity.getLastHurtByMob()) {
target = petEntity.getLastHurtByMob();
}
if (target == petEntity) {
return false;
}
if (target instanceof ArmorStand) {
return false;
}
if (target instanceof ServerPlayer) {
Player targetPlayer = (Player) target.getBukkitEntity();
if (targetPlayer == myPet.getOwner().getPlayer()) {
return false;
} else if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), targetPlayer, true)) {
return false;
}
} else if (target instanceof EntityMyPet) {
MyPet targetMyPet = ((EntityMyPet) target).getMyPet();
if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), targetMyPet.getOwner().getPlayer(), true)) {
return false;
}
} else if (target instanceof TamableAnimal) {
// Method: getOwner -> mojang mapping maps that to fx() even tho it still is getOwner.
Method getOwnerReflect = ReflectionUtil.getMethod(TamableAnimal.class, "getOwner");
TamableAnimal tameable = (TamableAnimal) target;
try {
if (tameable.isTame() && getOwnerReflect.invoke(tameable, null) != null) {
Player tameableOwner = (Player) ((net.minecraft.world.entity.player.Player) getOwnerReflect.invoke(tameable, null)).getBukkitEntity();
if (myPet.getOwner().equals(tameableOwner)) {
return false;
}
}
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
}
return MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), target.getBukkitEntity());
}
use of de.Keyle.MyPet.compat.v1_17_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_17_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_17_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_17_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