Search in sources :

Example 66 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 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).L(), ((EntityInsentient) handle).K());
        while (((EntityLiving) handle).aS >= 180F) {
            ((EntityLiving) handle).aS -= 360F;
        }
        while (((EntityLiving) handle).aS < -180F) {
            ((EntityLiving) handle).aS += 360F;
        }
    } else if (handle instanceof EntityHumanNPC) {
        ((EntityHumanNPC) handle).setTargetLook(to);
    }
}
Also used : PathEntity(net.minecraft.server.v1_13_R2.PathEntity) LivingEntity(org.bukkit.entity.LivingEntity) SkinnableEntity(net.citizensnpcs.npc.skin.SkinnableEntity) CraftEntity(org.bukkit.craftbukkit.v1_13_R2.entity.CraftEntity) Entity(net.minecraft.server.v1_13_R2.Entity) EntityEnderDragon(net.minecraft.server.v1_13_R2.EntityEnderDragon) EntityInsentient(net.minecraft.server.v1_13_R2.EntityInsentient) EntityHumanNPC(net.citizensnpcs.nms.v1_13_R2.entity.EntityHumanNPC) Location(org.bukkit.Location)

Example 67 with EntityInsentient

use of net.minecraft.server.v1_13_R2.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.get(navigation);
        inst.setValue(pathfindingRange);
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
}
Also used : EntityLiving(net.minecraft.server.v1_13_R2.EntityLiving) AttributeInstance(net.minecraft.server.v1_13_R2.AttributeInstance) EntityInsentient(net.minecraft.server.v1_13_R2.EntityInsentient) NavigationAbstract(net.minecraft.server.v1_13_R2.NavigationAbstract) EntityHumanNPC(net.citizensnpcs.nms.v1_13_R2.entity.EntityHumanNPC)

Example 68 with EntityInsentient

use of net.minecraft.server.v1_13_R2.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.set(handle.getNavigation(), worldHandle);
    } catch (Exception e) {
        Messaging.logTr(Messages.ERROR_UPDATING_NAVIGATION_WORLD, e.getMessage());
    }
}
Also used : PathEntity(net.minecraft.server.v1_13_R2.PathEntity) LivingEntity(org.bukkit.entity.LivingEntity) SkinnableEntity(net.citizensnpcs.npc.skin.SkinnableEntity) CraftEntity(org.bukkit.craftbukkit.v1_13_R2.entity.CraftEntity) Entity(net.minecraft.server.v1_13_R2.Entity) EntityInsentient(net.minecraft.server.v1_13_R2.EntityInsentient) WorldServer(net.minecraft.server.v1_13_R2.WorldServer) CraftWorld(org.bukkit.craftbukkit.v1_13_R2.CraftWorld) ReportedException(net.minecraft.server.v1_13_R2.ReportedException) CommandException(net.citizensnpcs.api.command.exception.CommandException)

Example 69 with EntityInsentient

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

the class PlayerPathfinder method a.

private PathEntity a(IBlockAccess paramIBlockAccess, EntityInsentient paramEntityInsentient, double paramDouble1, double paramDouble2, double paramDouble3, float paramFloat) {
    this.a.a();
    this.d.a(paramIBlockAccess, paramEntityInsentient);
    PathPoint localPathPoint1 = this.d.b();
    PathPoint localPathPoint2 = this.d.a(paramDouble1, paramDouble2, paramDouble3);
    PathEntity localPathEntity = a(localPathPoint1, localPathPoint2, paramFloat);
    this.d.a();
    return localPathEntity;
}
Also used : PathPoint(net.minecraft.server.v1_13_R2.PathPoint) PathEntity(net.minecraft.server.v1_13_R2.PathEntity)

Example 70 with EntityInsentient

use of net.minecraft.server.v1_13_R2.EntityInsentient in project RoseStacker by Rosewood-Development.

the class NMSHandlerImpl method createCreature.

/**
 * Duplicate of {@link EntityTypes#createCreature(WorldServer, NBTTagCompound, IChatBaseComponent, EntityHuman, BlockPosition, EnumMobSpawn, boolean, boolean)}.
 * Contains a patch to prevent chicken jockeys from spawning and to not play the mob sound upon creation.
 */
private <T extends Entity> T createCreature(EntityTypes<T> entityTypes, WorldServer worldserver, NBTTagCompound nbttagcompound, IChatBaseComponent ichatbasecomponent, EntityHuman entityhuman, BlockPosition blockposition, EnumMobSpawn enummobspawn) {
    T newEntity;
    if (entityTypes == EntityTypes.SPIDER) {
        newEntity = (T) new SoloEntitySpider((EntityTypes<? extends EntitySpider>) entityTypes, worldserver);
    } else if (entityTypes == EntityTypes.STRIDER) {
        newEntity = (T) new SoloEntityStrider((EntityTypes<? extends EntityStrider>) entityTypes, worldserver);
    } else {
        newEntity = entityTypes.a(worldserver);
    }
    if (newEntity == null) {
        return null;
    } else {
        if (field_Entity_spawnReason != null) {
            try {
                field_Entity_spawnReason.set(newEntity, this.toBukkitSpawnReason(enummobspawn));
            } catch (IllegalAccessException ignored) {
            }
        }
        newEntity.setPositionRotation(blockposition.getX() + 0.5D, blockposition.getY(), blockposition.getZ() + 0.5D, MathHelper.g(worldserver.random.nextFloat() * 360.0F), 0.0F);
        if (newEntity instanceof EntityInsentient) {
            EntityInsentient entityinsentient = (EntityInsentient) newEntity;
            entityinsentient.aC = entityinsentient.yaw;
            entityinsentient.aA = entityinsentient.yaw;
            GroupDataEntity groupDataEntity = null;
            if (entityTypes == EntityTypes.DROWNED || entityTypes == EntityTypes.HUSK || entityTypes == EntityTypes.ZOMBIE_VILLAGER || entityTypes == EntityTypes.ZOMBIFIED_PIGLIN || entityTypes == EntityTypes.ZOMBIE) {
                // Don't allow chicken jockeys to spawn
                groupDataEntity = new EntityZombie.GroupDataZombie(EntityZombie.a(worldserver.getRandom()), false);
            }
            entityinsentient.prepare(worldserver, worldserver.getDamageScaler(entityinsentient.getChunkCoordinates()), enummobspawn, groupDataEntity, nbttagcompound);
        }
        if (ichatbasecomponent != null && newEntity instanceof EntityLiving) {
            newEntity.setCustomName(ichatbasecomponent);
        }
        try {
            EntityTypes.a(worldserver, entityhuman, newEntity, nbttagcompound);
        } catch (Throwable ignored) {
        }
        return newEntity;
    }
}
Also used : EntityTypes(net.minecraft.server.v1_16_R2.EntityTypes) SoloEntitySpider(dev.rosewood.rosestacker.nms.v1_16_R2.entity.SoloEntitySpider) SoloEntityStrider(dev.rosewood.rosestacker.nms.v1_16_R2.entity.SoloEntityStrider) EntityStrider(net.minecraft.server.v1_16_R2.EntityStrider) SoloEntityStrider(dev.rosewood.rosestacker.nms.v1_16_R2.entity.SoloEntityStrider) EntityLiving(net.minecraft.server.v1_16_R2.EntityLiving) EntityZombie(net.minecraft.server.v1_16_R2.EntityZombie) GroupDataEntity(net.minecraft.server.v1_16_R2.GroupDataEntity) EntityInsentient(net.minecraft.server.v1_16_R2.EntityInsentient)

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