Search in sources :

Example 11 with EntityInsentient

use of net.minecraft.server.v1_16_R3.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 12 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.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 13 with EntityInsentient

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

the class PlayerControllerMove method a.

@Override
public void a() {
    this.a.aT = 0F;
    if (this.f) {
        this.f = false;
        int i = MathHelper.floor(this.a.getBoundingBox().minY + 0.5D);
        double d0 = this.b - this.a.locX();
        double d1 = this.d - this.a.locZ();
        double d2 = this.c - i;
        double d3 = d0 * d0 + d2 * d2 + d1 * d1;
        if (d3 < 2.500000277905201E-007D) {
            this.a.aT = 0.0F;
            return;
        }
        float f = (float) Math.toDegrees(Math.atan2(d1, d0)) - 90.0F;
        this.a.yaw = a(this.a.yaw, f, 90.0F);
        NMS.setHeadYaw(a.getBukkitEntity(), this.a.yaw);
        AttributeModifiable speed = this.a.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED);
        speed.setValue(0.3D * this.e);
        float movement = (float) (this.e * speed.getValue());
        this.a.q(movement);
        this.a.aT = movement;
        if (shouldSlimeJump() || (d2 >= NMS.getStepHeight(a.getBukkitEntity()) && (d0 * d0 + d1 * d1) < 1.0D)) {
            this.h = cg();
            this.h /= 3;
            if (this.a instanceof EntityHumanNPC) {
                ((EntityHumanNPC) this.a).getControllerJump().jump();
            } else {
                ((EntityInsentient) this.a).getControllerJump().jump();
            }
        }
    }
}
Also used : AttributeModifiable(net.minecraft.server.v1_16_R3.AttributeModifiable) EntityHumanNPC(net.citizensnpcs.nms.v1_16_R3.entity.EntityHumanNPC)

Example 14 with EntityInsentient

use of net.minecraft.server.v1_16_R3.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_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_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)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