use of net.minecraft.server.level.ServerPlayer 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 net.minecraft.server.level.ServerPlayer 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 net.minecraft.server.level.ServerPlayer in project MyPet by xXKeyleXx.
the class MeleeAttack method shouldStart.
@Override
public boolean shouldStart() {
if (myPet.getDamage() <= 0) {
return false;
}
if (!this.petEntity.hasTarget()) {
return false;
}
net.minecraft.world.entity.LivingEntity targetEntity = ((CraftLivingEntity) this.petEntity.getMyPetTarget()).getHandle();
if (targetEntity instanceof ArmorStand) {
return false;
}
if (petEntity.getMyPet().getRangedDamage() > 0 && this.petEntity.distanceToSqr(targetEntity.getX(), targetEntity.getBoundingBox().minY, targetEntity.getZ()) >= 20) {
return false;
}
Behavior behaviorSkill = myPet.getSkills().get(Behavior.class);
if (behaviorSkill != null && behaviorSkill.isActive()) {
if (behaviorSkill.getBehavior() == Behavior.BehaviorMode.Friendly) {
return false;
}
if (behaviorSkill.getBehavior() == Behavior.BehaviorMode.Raid) {
if (targetEntity instanceof TamableAnimal && ((TamableAnimal) targetEntity).isTame()) {
return false;
}
if (targetEntity instanceof EntityMyPet) {
return false;
}
if (targetEntity instanceof ServerPlayer) {
return false;
}
}
}
this.targetEntity = targetEntity;
return true;
}
use of net.minecraft.server.level.ServerPlayer in project MyPet by xXKeyleXx.
the class CustomInventory method open.
@Override
public void open(Player player) {
ServerPlayer entityPlayer = ((CraftPlayer) player).getHandle();
AbstractContainerMenu container = new CraftContainer(getBukkitInventory(), entityPlayer, entityPlayer.nextContainerCounter());
container = CraftEventFactory.callInventoryOpenEvent(entityPlayer, container);
if (container != null) {
MenuType<?> customSize = MenuType.GENERIC_9x1;
switch(this.getContainerSize()) {
case 18:
customSize = MenuType.GENERIC_9x2;
break;
case 27:
customSize = MenuType.GENERIC_9x3;
break;
case 36:
customSize = MenuType.GENERIC_9x4;
break;
case 45:
customSize = MenuType.GENERIC_9x5;
break;
case 54:
customSize = MenuType.GENERIC_9x6;
break;
}
entityPlayer.connection.send(new ClientboundOpenScreenPacket(container.containerId, customSize, new TextComponent(this.getName())));
entityPlayer.containerMenu = container;
entityPlayer.initMenu(container);
}
}
use of net.minecraft.server.level.ServerPlayer 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;
}
Aggregations