Search in sources :

Example 56 with EntityInsentient

use of net.minecraft.server.v1_16_R3.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_16_R3.EntityInsentient) EntityHumanNPC(net.citizensnpcs.nms.v1_16_R3.entity.EntityHumanNPC)

Example 57 with EntityInsentient

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

the class NMSImpl method setShouldJump.

@Override
public void setShouldJump(org.bukkit.entity.Entity entity) {
    Entity handle = NMSImpl.getHandle(entity);
    if (handle == null)
        return;
    if (handle instanceof EntityInsentient) {
        ControllerJump controller = ((EntityInsentient) handle).getControllerJump();
        controller.jump();
    } else if (handle instanceof EntityHumanNPC) {
        ((EntityHumanNPC) handle).setShouldJump();
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(net.minecraft.server.v1_14_R1.Entity) SkinnableEntity(net.citizensnpcs.npc.skin.SkinnableEntity) PathEntity(net.minecraft.server.v1_14_R1.PathEntity) CraftEntity(org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity) EntityInsentient(net.minecraft.server.v1_14_R1.EntityInsentient) ControllerJump(net.minecraft.server.v1_14_R1.ControllerJump) EntityHumanNPC(net.citizensnpcs.nms.v1_14_R1.entity.EntityHumanNPC)

Example 58 with EntityInsentient

use of net.minecraft.server.v1_16_R3.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 instanceof EntityEnderDragon) {
            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).dB(), ((EntityInsentient) handle).M());
        while (((EntityLiving) handle).aM >= 180F) {
            ((EntityLiving) handle).aM -= 360F;
        }
        while (((EntityLiving) handle).aM < -180F) {
            ((EntityLiving) handle).aM += 360F;
        }
    } else if (handle instanceof EntityHumanNPC) {
        ((EntityHumanNPC) handle).setTargetLook(to);
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(net.minecraft.server.v1_14_R1.Entity) SkinnableEntity(net.citizensnpcs.npc.skin.SkinnableEntity) PathEntity(net.minecraft.server.v1_14_R1.PathEntity) CraftEntity(org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity) EntityEnderDragon(net.minecraft.server.v1_14_R1.EntityEnderDragon) EntityInsentient(net.minecraft.server.v1_14_R1.EntityInsentient) EntityHumanNPC(net.citizensnpcs.nms.v1_14_R1.entity.EntityHumanNPC) Location(org.bukkit.Location)

Example 59 with EntityInsentient

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

the class NMSImpl method updateNavigationWorld.

@Override
public void updateNavigationWorld(org.bukkit.entity.Entity entity, World world) {
    if (NAVIGATION_WORLD_FIELD == null)
        return;
    Entity en = NMSImpl.getHandle(entity);
    if (en == null || !(en instanceof EntityInsentient))
        return;
    EntityInsentient handle = (EntityInsentient) en;
    WorldServer worldHandle = ((CraftWorld) world).getHandle();
    try {
        NAVIGATION_WORLD_FIELD.invoke(handle.getNavigation(), worldHandle);
    } catch (Exception e) {
        Messaging.logTr(Messages.ERROR_UPDATING_NAVIGATION_WORLD, e.getMessage());
    } catch (Throwable e) {
        e.printStackTrace();
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(net.minecraft.server.v1_14_R1.Entity) SkinnableEntity(net.citizensnpcs.npc.skin.SkinnableEntity) PathEntity(net.minecraft.server.v1_14_R1.PathEntity) CraftEntity(org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity) EntityInsentient(net.minecraft.server.v1_14_R1.EntityInsentient) WorldServer(net.minecraft.server.v1_14_R1.WorldServer) CraftWorld(org.bukkit.craftbukkit.v1_14_R1.CraftWorld) CommandException(net.citizensnpcs.api.command.exception.CommandException) ReportedException(net.minecraft.server.v1_14_R1.ReportedException)

Example 60 with EntityInsentient

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

the class NMSImpl method updatePathfindingRange.

@Override
public void updatePathfindingRange(NPC npc, float pathfindingRange) {
    if (!npc.isSpawned() || !npc.getEntity().getType().isAlive())
        return;
    EntityLiving en = NMSImpl.getHandle((LivingEntity) npc.getEntity());
    if (!(en instanceof EntityInsentient)) {
        if (en instanceof EntityHumanNPC) {
            ((EntityHumanNPC) en).updatePathfindingRange(pathfindingRange);
        }
        return;
    }
    if (PATHFINDING_RANGE == null)
        return;
    EntityInsentient handle = (EntityInsentient) en;
    NavigationAbstract navigation = handle.getNavigation();
    try {
        AttributeInstance inst = (AttributeInstance) PATHFINDING_RANGE.invoke(navigation);
        inst.setValue(pathfindingRange);
    } catch (Throwable e) {
        e.printStackTrace();
    }
}
Also used : EntityLiving(net.minecraft.server.v1_14_R1.EntityLiving) AttributeInstance(net.minecraft.server.v1_14_R1.AttributeInstance) EntityInsentient(net.minecraft.server.v1_14_R1.EntityInsentient) NavigationAbstract(net.minecraft.server.v1_14_R1.NavigationAbstract) EntityHumanNPC(net.citizensnpcs.nms.v1_14_R1.entity.EntityHumanNPC)

Aggregations

LivingEntity (org.bukkit.entity.LivingEntity)43 SkinnableEntity (net.citizensnpcs.npc.skin.SkinnableEntity)42 Location (org.bukkit.Location)20 EntityInsentient (net.minecraft.server.v1_16_R3.EntityInsentient)12 EntityInsentient (net.minecraft.server.v1_15_R1.EntityInsentient)11 EntityHumanNPC (net.citizensnpcs.nms.v1_16_R3.entity.EntityHumanNPC)9 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 EntityInsentient (net.minecraft.server.v1_12_R1.EntityInsentient)8 EntityInsentient (net.minecraft.server.v1_14_R1.EntityInsentient)8 PathEntity (net.minecraft.server.v1_16_R3.PathEntity)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_15_R1.PathEntity)7 Entity (net.minecraft.server.v1_16_R3.Entity)7 CraftEntity (org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity)7