Search in sources :

Example 16 with EntityHumanNPC

use of net.citizensnpcs.nms.v1_18_R2.entity.EntityHumanNPC in project Citizens2 by CitizensDev.

the class NMSImpl method replaceTrackerEntry.

@Override
public void replaceTrackerEntry(Player player) {
    ServerLevel server = (ServerLevel) NMSImpl.getHandle(player).level;
    TrackedEntity entry = server.getChunkProvider().chunkMap.G.get(player.getEntityId());
    if (entry == null)
        return;
    PlayerlistTracker replace = new PlayerlistTracker(server.getChunkProvider().chunkMap, entry);
    server.getChunkProvider().chunkMap.G.put(player.getEntityId(), replace);
    if (getHandle(player) instanceof EntityHumanNPC) {
        ((EntityHumanNPC) getHandle(player)).setTracked(replace);
    }
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) TrackedEntity(net.minecraft.server.level.ChunkMap.TrackedEntity) EntityHumanNPC(net.citizensnpcs.nms.v1_17_R1.entity.EntityHumanNPC)

Example 17 with EntityHumanNPC

use of net.citizensnpcs.nms.v1_18_R2.entity.EntityHumanNPC in project Citizens2 by CitizensDev.

the class PlayerMoveControl method tick.

@Override
public void tick() {
    this.entity.zza = 0;
    if (this.moving) {
        this.moving = false;
        double dX = this.tx - this.entity.getX();
        double dZ = this.tz - this.entity.getZ();
        double dY = this.ty - this.entity.getY();
        double dXZ = dX * dX + dZ * dZ;
        if (Math.abs(dY) < 1.0 && dXZ < 0.0075) {
            this.entity.zza = 0.0F;
            return;
        }
        float f = (float) (Mth.atan2(dZ, dX) * 57.2957763671875D) - 90.0F;
        this.entity.setYRot(rotlerp(this.entity.getYRot(), f, 90.0F));
        NMS.setHeadYaw(entity.getBukkitEntity(), this.entity.getYRot());
        AttributeInstance speed = this.entity.getAttribute(Attributes.MOVEMENT_SPEED);
        float movement = (float) (this.speed * speed.getValue());
        this.entity.setSpeed(movement);
        this.entity.zza = movement;
        if (shouldJump() || (dY >= NMS.getStepHeight(entity.getBukkitEntity()) && dXZ < 1.0D)) {
            this.jumpTicks = jumpTicks();
            this.jumpTicks /= 3;
            if (this.entity instanceof EntityHumanNPC) {
                ((EntityHumanNPC) this.entity).getControllerJump().jump();
            } else {
                ((Mob) this.entity).getJumpControl().jump();
            }
        }
    }
}
Also used : AttributeInstance(net.minecraft.world.entity.ai.attributes.AttributeInstance) EntityHumanNPC(net.citizensnpcs.nms.v1_17_R1.entity.EntityHumanNPC)

Example 18 with EntityHumanNPC

use of net.citizensnpcs.nms.v1_18_R2.entity.EntityHumanNPC 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 Mob) && !(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 = distanceXZ == 0 ? 0 : Math.toDegrees(Math.acos(xDiff / distanceXZ));
        double pitch = distanceY == 0 ? 0 : 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 Mob) {
        ((Mob) handle).getLookControl().setLookAt(to.getX(), to.getY(), to.getZ(), ((Mob) handle).getHeadRotSpeed(), ((Mob) handle).getMaxHeadXRot());
        while (((LivingEntity) handle).yHeadRot >= 180F) {
            ((LivingEntity) handle).yHeadRot -= 360F;
        }
        while (((LivingEntity) handle).yHeadRot < -180F) {
            ((LivingEntity) handle).yHeadRot += 360F;
        }
    } else if (handle instanceof EntityHumanNPC) {
        ((EntityHumanNPC) handle).getNPC().getOrAddTrait(SmoothRotationTrait.class).rotateToFace(to);
    }
}
Also used : TrackedEntity(net.minecraft.server.level.ChunkMap.TrackedEntity) FallingBlockEntity(net.minecraft.world.entity.item.FallingBlockEntity) SkinnableEntity(net.citizensnpcs.npc.skin.SkinnableEntity) Entity(net.minecraft.world.entity.Entity) CraftEntity(org.bukkit.craftbukkit.v1_18_R2.entity.CraftEntity) LivingEntity(net.minecraft.world.entity.LivingEntity) Mob(net.minecraft.world.entity.Mob) EntityHumanNPC(net.citizensnpcs.nms.v1_18_R2.entity.EntityHumanNPC) Location(org.bukkit.Location) ResourceLocation(net.minecraft.resources.ResourceLocation)

Example 19 with EntityHumanNPC

use of net.citizensnpcs.nms.v1_18_R2.entity.EntityHumanNPC 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;
    LivingEntity en = NMSImpl.getHandle((org.bukkit.entity.LivingEntity) npc.getEntity());
    if (!(en instanceof Mob)) {
        if (en instanceof EntityHumanNPC) {
            ((EntityHumanNPC) en).updatePathfindingRange(pathfindingRange);
        }
        return;
    }
    if (NAVIGATION_PATHFINDER == null)
        return;
    PathNavigation navigation = ((Mob) en).getNavigation();
    AttributeInstance inst = en.getAttribute(Attributes.FOLLOW_RANGE);
    inst.setBaseValue(pathfindingRange);
    int mc = Mth.floor(en.getAttributeBaseValue(Attributes.FOLLOW_RANGE) * 16.0D);
    try {
        NAVIGATION_PATHFINDER.invoke(navigation, NAVIGATION_CREATE_PATHFINDER.invoke(navigation, mc));
    } catch (Throwable e) {
        e.printStackTrace();
    }
}
Also used : LivingEntity(net.minecraft.world.entity.LivingEntity) Mob(net.minecraft.world.entity.Mob) AttributeInstance(net.minecraft.world.entity.ai.attributes.AttributeInstance) PathNavigation(net.minecraft.world.entity.ai.navigation.PathNavigation) EntityHumanNPC(net.citizensnpcs.nms.v1_18_R2.entity.EntityHumanNPC)

Example 20 with EntityHumanNPC

use of net.citizensnpcs.nms.v1_18_R2.entity.EntityHumanNPC 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 Mob) {
        JumpControl controller = ((Mob) handle).getJumpControl();
        controller.jump();
    } else if (handle instanceof EntityHumanNPC) {
        ((EntityHumanNPC) handle).setShouldJump();
    }
}
Also used : TrackedEntity(net.minecraft.server.level.ChunkMap.TrackedEntity) FallingBlockEntity(net.minecraft.world.entity.item.FallingBlockEntity) SkinnableEntity(net.citizensnpcs.npc.skin.SkinnableEntity) Entity(net.minecraft.world.entity.Entity) CraftEntity(org.bukkit.craftbukkit.v1_18_R2.entity.CraftEntity) LivingEntity(net.minecraft.world.entity.LivingEntity) Mob(net.minecraft.world.entity.Mob) JumpControl(net.minecraft.world.entity.ai.control.JumpControl) EntityHumanNPC(net.citizensnpcs.nms.v1_18_R2.entity.EntityHumanNPC)

Aggregations

SkinnableEntity (net.citizensnpcs.npc.skin.SkinnableEntity)44 LivingEntity (org.bukkit.entity.LivingEntity)32 Location (org.bukkit.Location)20 Mob (net.minecraft.world.entity.Mob)14 Player (org.bukkit.entity.Player)12 Set (java.util.Set)10 EntityHumanNPC (net.citizensnpcs.nms.v1_12_R1.entity.EntityHumanNPC)10 TrackedEntity (net.minecraft.server.level.ChunkMap.TrackedEntity)10 LivingEntity (net.minecraft.world.entity.LivingEntity)10 CancelReason (net.citizensnpcs.api.ai.event.CancelReason)9 EntityHumanNPC (net.citizensnpcs.nms.v1_10_R1.entity.EntityHumanNPC)9 EntityHumanNPC (net.citizensnpcs.nms.v1_14_R1.entity.EntityHumanNPC)9 EntityHumanNPC (net.citizensnpcs.nms.v1_15_R1.entity.EntityHumanNPC)9 EntityHumanNPC (net.citizensnpcs.nms.v1_17_R1.entity.EntityHumanNPC)9 EntityHumanNPC (net.citizensnpcs.nms.v1_18_R2.entity.EntityHumanNPC)9 EntityHumanNPC (net.citizensnpcs.nms.v1_8_R3.entity.EntityHumanNPC)8 Entity (net.minecraft.world.entity.Entity)8 EntityHumanNPC (net.citizensnpcs.nms.v1_11_R1.entity.EntityHumanNPC)7 EntityHumanNPC (net.citizensnpcs.nms.v1_16_R3.entity.EntityHumanNPC)7 MCNavigator (net.citizensnpcs.npc.ai.MCNavigationStrategy.MCNavigator)7