Search in sources :

Example 11 with EntityInsentient

use of net.minecraft.server.v1_13_R2.EntityInsentient in project Citizens2 by CitizensDev.

the class NMSImpl method updateAI.

public static void updateAI(EntityLiving entity) {
    if (entity instanceof EntityInsentient) {
        EntityInsentient handle = (EntityInsentient) entity;
        handle.getEntitySenses().a();
        NMSImpl.updateNavigation(handle.getNavigation());
        handle.getControllerMove().a();
        handle.getControllerLook().a();
        handle.getControllerJump().b();
    } else if (entity instanceof EntityHumanNPC) {
        ((EntityHumanNPC) entity).updateAI();
    }
}
Also used : EntityInsentient(net.minecraft.server.v1_12_R1.EntityInsentient) EntityHumanNPC(net.citizensnpcs.nms.v1_12_R1.entity.EntityHumanNPC)

Example 12 with EntityInsentient

use of net.minecraft.server.v1_13_R2.EntityInsentient in project Citizens2 by CitizensDev.

the class NMSImpl method setNoGravity.

@Override
public void setNoGravity(org.bukkit.entity.Entity entity, boolean enabled) {
    Entity handle = getHandle(entity);
    handle.setNoGravity(enabled);
    if (!(handle instanceof EntityInsentient) || !(entity instanceof NPCHolder))
        return;
    EntityInsentient mob = (EntityInsentient) handle;
    NPC npc = ((NPCHolder) entity).getNPC();
    if (!(mob.getControllerMove() instanceof ControllerMoveFlying) || npc.data().has("flying-nogravity-float"))
        return;
    try {
        if (enabled) {
            boolean old = (boolean) FLYING_MOVECONTROL_FLOAT_GETTER.invoke(mob.getControllerMove());
            FLYING_MOVECONTROL_FLOAT_SETTER.invoke(mob.getControllerMove(), true);
            npc.data().set("flying-nogravity-float", old);
        } else if (npc.data().has("flying-nogravity-float")) {
            FLYING_MOVECONTROL_FLOAT_SETTER.invoke(mob.getControllerMove(), npc.data().get("flying-nogravity-float"));
            npc.data().remove("flying-nogravity-float");
        }
    } catch (Throwable t) {
        t.printStackTrace();
    }
}
Also used : NPC(net.citizensnpcs.api.npc.NPC) EntityHumanNPC(net.citizensnpcs.nms.v1_16_R3.entity.EntityHumanNPC) Entity(net.minecraft.server.v1_16_R3.Entity) LivingEntity(org.bukkit.entity.LivingEntity) SkinnableEntity(net.citizensnpcs.npc.skin.SkinnableEntity) CraftEntity(org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity) PathEntity(net.minecraft.server.v1_16_R3.PathEntity) NPCHolder(net.citizensnpcs.npc.ai.NPCHolder) EntityInsentient(net.minecraft.server.v1_16_R3.EntityInsentient) ControllerMoveFlying(net.minecraft.server.v1_16_R3.ControllerMoveFlying)

Example 13 with EntityInsentient

use of net.minecraft.server.v1_13_R2.EntityInsentient in project Citizens2 by CitizensDev.

the class NMSImpl method look.

@Override
public void look(org.bukkit.entity.Entity entity, Location to, boolean headOnly, boolean immediate) {
    Entity handle = NMSImpl.getHandle(entity);
    if (immediate || headOnly || BAD_CONTROLLER_LOOK.contains(handle.getBukkitEntity().getType()) || (!(handle instanceof EntityInsentient) && !(handle instanceof EntityHumanNPC))) {
        Location fromLocation = entity.getLocation(FROM_LOCATION);
        double xDiff, yDiff, zDiff;
        xDiff = to.getX() - fromLocation.getX();
        yDiff = to.getY() - fromLocation.getY();
        zDiff = to.getZ() - fromLocation.getZ();
        double distanceXZ = Math.sqrt(xDiff * xDiff + zDiff * zDiff);
        double distanceY = Math.sqrt(distanceXZ * distanceXZ + yDiff * yDiff);
        double yaw = Math.toDegrees(Math.acos(xDiff / distanceXZ));
        double pitch = Math.toDegrees(Math.acos(yDiff / distanceY)) - (handle.getBukkitEntity().getType() == EntityType.PHANTOM ? 45 : 90);
        if (zDiff < 0.0)
            yaw += Math.abs(180 - yaw) * 2;
        if (handle.getBukkitEntity().getType() == EntityType.ENDER_DRAGON) {
            yaw = Util.getDragonYaw(handle.getBukkitEntity(), xDiff, zDiff);
        } else {
            yaw = yaw - 90;
        }
        if (headOnly) {
            setHeadYaw(entity, (float) yaw);
        } else {
            look(entity, (float) yaw, (float) pitch);
        }
        return;
    }
    if (handle instanceof EntityInsentient) {
        ((EntityInsentient) handle).getControllerLook().a(to.getX(), to.getY(), to.getZ(), ((EntityInsentient) handle).ep(), ((EntityInsentient) handle).O());
        while (((EntityLiving) handle).aC >= 180F) {
            ((EntityLiving) handle).aC -= 360F;
        }
        while (((EntityLiving) handle).aC < -180F) {
            ((EntityLiving) handle).aC += 360F;
        }
    } else if (handle instanceof EntityHumanNPC) {
        ((EntityHumanNPC) handle).setTargetLook(to);
    }
}
Also used : Entity(net.minecraft.server.v1_16_R3.Entity) LivingEntity(org.bukkit.entity.LivingEntity) SkinnableEntity(net.citizensnpcs.npc.skin.SkinnableEntity) CraftEntity(org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity) PathEntity(net.minecraft.server.v1_16_R3.PathEntity) EntityInsentient(net.minecraft.server.v1_16_R3.EntityInsentient) EntityHumanNPC(net.citizensnpcs.nms.v1_16_R3.entity.EntityHumanNPC) Location(org.bukkit.Location)

Example 14 with EntityInsentient

use of net.minecraft.server.v1_13_R2.EntityInsentient in project Citizens2 by CitizensDev.

the class NMSImpl method setNoGravity.

@Override
public void setNoGravity(org.bukkit.entity.Entity entity, boolean enabled) {
    Entity handle = getHandle(entity);
    handle.setNoGravity(enabled);
    if (!(handle instanceof EntityInsentient) || !(entity instanceof NPCHolder))
        return;
    EntityInsentient mob = (EntityInsentient) handle;
    NPC npc = ((NPCHolder) entity).getNPC();
    if (!(mob.getControllerMove() instanceof ControllerMoveFlying) || npc.data().has("flying-nogravity-float"))
        return;
    try {
        if (enabled) {
            boolean old = (boolean) FLYING_MOVECONTROL_FLOAT_GETTER.invoke(mob.getControllerMove());
            FLYING_MOVECONTROL_FLOAT_SETTER.invoke(mob.getControllerMove(), true);
            npc.data().set("flying-nogravity-float", old);
        } else if (npc.data().has("flying-nogravity-float")) {
            FLYING_MOVECONTROL_FLOAT_SETTER.invoke(mob.getControllerMove(), npc.data().get("flying-nogravity-float"));
            npc.data().remove("flying-nogravity-float");
        }
    } catch (Throwable t) {
        t.printStackTrace();
    }
}
Also used : EntityHumanNPC(net.citizensnpcs.nms.v1_15_R1.entity.EntityHumanNPC) NPC(net.citizensnpcs.api.npc.NPC) CraftEntity(org.bukkit.craftbukkit.v1_15_R1.entity.CraftEntity) LivingEntity(org.bukkit.entity.LivingEntity) Entity(net.minecraft.server.v1_15_R1.Entity) SkinnableEntity(net.citizensnpcs.npc.skin.SkinnableEntity) PathEntity(net.minecraft.server.v1_15_R1.PathEntity) NPCHolder(net.citizensnpcs.npc.ai.NPCHolder) EntityInsentient(net.minecraft.server.v1_15_R1.EntityInsentient) ControllerMoveFlying(net.minecraft.server.v1_15_R1.ControllerMoveFlying)

Example 15 with EntityInsentient

use of net.minecraft.server.v1_13_R2.EntityInsentient in project Citizens2 by CitizensDev.

the class NMSImpl method updateAI.

public static void updateAI(EntityLiving entity) {
    if (entity instanceof EntityInsentient) {
        EntityInsentient handle = (EntityInsentient) entity;
        handle.getEntitySenses().a();
        NMSImpl.updateNavigation(handle.getNavigation());
        handle.getControllerMove().a();
        handle.getControllerLook().a();
        handle.getControllerJump().b();
    } else if (entity instanceof EntityHumanNPC) {
        ((EntityHumanNPC) entity).updateAI();
    }
}
Also used : EntityInsentient(net.minecraft.server.v1_15_R1.EntityInsentient) EntityHumanNPC(net.citizensnpcs.nms.v1_15_R1.entity.EntityHumanNPC)

Aggregations

LivingEntity (org.bukkit.entity.LivingEntity)43 SkinnableEntity (net.citizensnpcs.npc.skin.SkinnableEntity)42 Location (org.bukkit.Location)18 EntityInsentient (net.minecraft.server.v1_16_R3.EntityInsentient)12 EntityInsentient (net.minecraft.server.v1_15_R1.EntityInsentient)11 NPCHolder (net.citizensnpcs.npc.ai.NPCHolder)9 CommandException (net.citizensnpcs.api.command.exception.CommandException)8 EntityHumanNPC (net.citizensnpcs.nms.v1_15_R1.entity.EntityHumanNPC)8 EntityHumanNPC (net.citizensnpcs.nms.v1_16_R3.entity.EntityHumanNPC)8 EntityInsentient (net.minecraft.server.v1_12_R1.EntityInsentient)8 EntityInsentient (net.minecraft.server.v1_14_R1.EntityInsentient)8 CancelReason (net.citizensnpcs.api.ai.event.CancelReason)7 EntityHumanNPC (net.citizensnpcs.nms.v1_12_R1.entity.EntityHumanNPC)7 EntityHumanNPC (net.citizensnpcs.nms.v1_14_R1.entity.EntityHumanNPC)7 MCNavigator (net.citizensnpcs.npc.ai.MCNavigationStrategy.MCNavigator)7 EntityInsentient (net.minecraft.server.v1_11_R1.EntityInsentient)7 PathEntity (net.minecraft.server.v1_13_R2.PathEntity)7 PathEntity (net.minecraft.server.v1_15_R1.PathEntity)7 PathEntity (net.minecraft.server.v1_16_R3.PathEntity)7 Vector (org.bukkit.util.Vector)7