Search in sources :

Example 46 with Entity

use of net.minecraft.server.v1_16_R2.Entity in project Citizens2 by CitizensDev.

the class NMSImpl method removeHookIfNecessary.

@Override
public void removeHookIfNecessary(NPCRegistry npcRegistry, FishHook entity) {
    if (FISHING_HOOK_HOOKED == null)
        return;
    EntityFishingHook hook = (EntityFishingHook) NMSImpl.getHandle(entity);
    Entity hooked = null;
    try {
        hooked = (Entity) FISHING_HOOK_HOOKED.invoke(hook);
    } catch (Throwable e) {
        e.printStackTrace();
    }
    if (hooked == null)
        return;
    NPC npc = npcRegistry.getNPC(hooked.getBukkitEntity());
    if (npc == null)
        return;
    if (npc.isProtected()) {
        try {
            FISHING_HOOK_HOOKED_SETTER.invoke(hook, null);
        } catch (Throwable e) {
            e.printStackTrace();
        }
        hook.die();
    }
}
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) EntityFishingHook(net.minecraft.server.v1_16_R3.EntityFishingHook)

Example 47 with Entity

use of net.minecraft.server.v1_16_R2.Entity 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 48 with Entity

use of net.minecraft.server.v1_16_R2.Entity in project Citizens2 by CitizensDev.

the class NMSImpl method tick.

@Override
public boolean tick(org.bukkit.entity.Entity next) {
    Entity entity = NMSImpl.getHandle(next);
    Entity entity1 = entity.getVehicle();
    if (entity1 != null) {
        if ((entity1.dead) || (!entity1.w(entity))) {
            entity.stopRiding();
        }
    } else {
        if (!entity.dead) {
            try {
                ((WorldServer) entity.world).entityJoinedWorld(entity);
            } catch (Throwable throwable) {
                CrashReport crashreport = CrashReport.a(throwable, "Ticking player");
                CrashReportSystemDetails crashreportsystemdetails = crashreport.a("Player being ticked");
                entity.appendEntityCrashDetails(crashreportsystemdetails);
                throw new ReportedException(crashreport);
            }
        }
        boolean removeFromPlayerList = ((NPCHolder) entity).getNPC().data().get("removefromplayerlist", Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean());
        if (entity.dead) {
            ((WorldServer) entity.world).removeEntity(entity);
            return true;
        } else if (!removeFromPlayerList) {
            if (!entity.world.getPlayers().contains(entity)) {
                List list = entity.world.getPlayers();
                list.add(entity);
            }
            return true;
        } else {
            entity.world.getPlayers().remove(entity);
        }
    }
    return false;
}
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) CrashReportSystemDetails(net.minecraft.server.v1_16_R3.CrashReportSystemDetails) CrashReport(net.minecraft.server.v1_16_R3.CrashReport) NPCHolder(net.citizensnpcs.npc.ai.NPCHolder) WorldServer(net.minecraft.server.v1_16_R3.WorldServer) ArrayList(java.util.ArrayList) List(java.util.List) ReportedException(net.minecraft.server.v1_16_R3.ReportedException)

Example 49 with Entity

use of net.minecraft.server.v1_16_R2.Entity 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 50 with Entity

use of net.minecraft.server.v1_16_R2.Entity 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)

Aggregations

Entity (org.hypertrace.entity.data.service.v1.Entity)110 Test (org.junit.jupiter.api.Test)95 LivingEntity (org.bukkit.entity.LivingEntity)94 SkinnableEntity (net.citizensnpcs.npc.skin.SkinnableEntity)88 Entity (com.google.datastore.v1.Entity)33 ArrayList (java.util.ArrayList)33 net.minecraft.world.entity (net.minecraft.world.entity)32 org.bukkit.entity (org.bukkit.entity)32 EnrichedEntity (org.hypertrace.entity.data.service.v1.EnrichedEntity)32 Location (org.bukkit.Location)30 Event (org.hypertrace.core.datamodel.Event)27 AttributeValue (org.hypertrace.core.datamodel.AttributeValue)22 BackendInfo (org.hypertrace.traceenricher.enrichment.enrichers.resolver.backend.BackendInfo)21 Entity (net.minecraft.server.v1_16_R3.Entity)19 NPCHolder (net.citizensnpcs.npc.ai.NPCHolder)18 AnnotateVideoProgress (com.google.cloud.videointelligence.v1.AnnotateVideoProgress)17 AnnotateVideoRequest (com.google.cloud.videointelligence.v1.AnnotateVideoRequest)17 AnnotateVideoResponse (com.google.cloud.videointelligence.v1.AnnotateVideoResponse)17 Entity (com.google.cloud.videointelligence.v1.Entity)17 VideoAnnotationResults (com.google.cloud.videointelligence.v1.VideoAnnotationResults)17