Search in sources :

Example 76 with ui.ex1.entity

use of ui.ex1.entity in project Denizen by DenizenScript.

the class EntityHelperImpl method follow.

@Override
public void follow(final Entity target, final Entity follower, final double speed, final double lead, final double maxRange, final boolean allowWander, final boolean teleport) {
    if (target == null || follower == null) {
        return;
    }
    final net.minecraft.world.entity.Entity nmsEntityFollower = ((CraftEntity) follower).getHandle();
    if (!(nmsEntityFollower instanceof Mob)) {
        return;
    }
    final Mob nmsFollower = (Mob) nmsEntityFollower;
    final PathNavigation followerNavigation = nmsFollower.getNavigation();
    UUID uuid = follower.getUniqueId();
    if (followTasks.containsKey(uuid)) {
        followTasks.get(uuid).cancel();
    }
    final int locationNearInt = (int) Math.floor(lead);
    final boolean hasMax = maxRange > lead;
    followTasks.put(follower.getUniqueId(), new BukkitRunnable() {

        private boolean inRadius = false;

        public void run() {
            if (!target.isValid() || !follower.isValid()) {
                this.cancel();
            }
            followerNavigation.setSpeedModifier(2D);
            Location targetLocation = target.getLocation();
            Path path;
            if (hasMax && !Utilities.checkLocation(targetLocation, follower.getLocation(), maxRange) && !target.isDead() && target.isOnGround()) {
                if (!inRadius) {
                    if (teleport) {
                        follower.teleport(Utilities.getWalkableLocationNear(targetLocation, locationNearInt));
                    } else {
                        cancel();
                    }
                } else {
                    inRadius = false;
                    path = followerNavigation.createPath(targetLocation.getX(), targetLocation.getY(), targetLocation.getZ(), 0);
                    if (path != null) {
                        followerNavigation.moveTo(path, 1D);
                        followerNavigation.setSpeedModifier(2D);
                    }
                }
            } else if (!inRadius && !Utilities.checkLocation(targetLocation, follower.getLocation(), lead)) {
                path = followerNavigation.createPath(targetLocation.getX(), targetLocation.getY(), targetLocation.getZ(), 0);
                if (path != null) {
                    followerNavigation.moveTo(path, 1D);
                    followerNavigation.setSpeedModifier(2D);
                }
            } else {
                inRadius = true;
            }
            if (inRadius && !allowWander) {
                followerNavigation.stop();
            }
            nmsFollower.getAttribute(Attributes.MOVEMENT_SPEED).setBaseValue(speed);
        }
    }.runTaskTimer(NMSHandler.getJavaPlugin(), 0, 10));
}
Also used : Path(net.minecraft.world.level.pathfinder.Path) Mob(net.minecraft.world.entity.Mob) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) PathNavigation(net.minecraft.world.entity.ai.navigation.PathNavigation) org.bukkit.entity(org.bukkit.entity) net.minecraft.world.entity(net.minecraft.world.entity) org.bukkit.craftbukkit.v1_18_R2.entity(org.bukkit.craftbukkit.v1_18_R2.entity) ResourceLocation(net.minecraft.resources.ResourceLocation) Location(org.bukkit.Location)

Example 77 with ui.ex1.entity

use of ui.ex1.entity in project UltraCosmetics by iSach.

the class PlayerFollower method follow.

@Override
public void follow(Player player) {
    if (player == null) {
        return;
    }
    if (UltraCosmeticsData.get().getPlugin().getPlayerManager().getUltraPlayer(player).getCurrentTreasureChest() != null) {
        return;
    }
    Entity petEntity;
    if (pet.isCustomEntity()) {
        petEntity = ((CustomEntityPet) pet).getCustomEntity();
    } else {
        petEntity = ((CraftEntity) pet.getEntity()).getHandle();
    }
    // Run in sync... To enhance :S
    Bukkit.getScheduler().runTask(UltraCosmeticsData.get().getPlugin(), () -> {
        if (!player.isOnline())
            return;
        if (!player.getWorld().equals(petEntity.getBukkitEntity().getWorld())) {
            petEntity.getBukkitEntity().teleport(player.getLocation());
            return;
        }
        ((EntityInsentient) petEntity).getNavigation().a(2d);
        Location targetLocation = player.getLocation();
        PathEntity path = ((EntityInsentient) petEntity).getNavigation().a(targetLocation.getX() + 1, targetLocation.getY(), targetLocation.getZ() + 1, 1);
        try {
            int distance = (int) Bukkit.getPlayer(player.getName()).getLocation().distance(petEntity.getBukkitEntity().getLocation());
            if (distance > 10 && petEntity.valid && player.isOnGround()) {
                petEntity.setLocation(targetLocation.getBlockX(), targetLocation.getBlockY(), targetLocation.getBlockZ(), 0, 0);
            }
            if (path != null && distance > 1.3) {
                double speed = 1.15d;
                if (pet.getType().getEntityType() == EntityType.ZOMBIE) {
                    speed *= 1.3;
                }
                ((EntityInsentient) petEntity).getNavigation().a(path, speed);
                ((EntityInsentient) petEntity).getNavigation().a(speed);
            }
        } catch (IllegalArgumentException exception) {
            petEntity.setLocation(targetLocation.getBlockX(), targetLocation.getBlockY(), targetLocation.getBlockZ(), 0, 0);
        // exception.printStackTrace();
        }
    });
}
Also used : PathEntity(net.minecraft.server.v1_14_R1.PathEntity) Entity(net.minecraft.server.v1_14_R1.Entity) CraftEntity(org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity) PathEntity(net.minecraft.server.v1_14_R1.PathEntity) Location(org.bukkit.Location)

Example 78 with ui.ex1.entity

use of ui.ex1.entity in project UltraCosmetics by iSach.

the class PlayerFollower method follow.

@Override
public void follow(Player player) {
    if (player == null)
        return;
    if (UltraCosmeticsData.get().getPlugin().getPlayerManager().getUltraPlayer(player).getCurrentTreasureChest() != null)
        return;
    Entity petEntity;
    if (pet.isCustomEntity()) {
        petEntity = ((CustomEntityPet) pet).getCustomEntity();
    } else {
        petEntity = ((CraftEntity) pet.getEntity()).getHandle();
    }
    ((EntityInsentient) petEntity).getNavigation().a(2);
    Location targetLocation = player.getLocation();
    PathEntity path;
    path = ((EntityInsentient) petEntity).getNavigation().a(targetLocation.getX() + 1, targetLocation.getY(), targetLocation.getZ() + 1);
    try {
        int distance = (int) Bukkit.getPlayer(player.getName()).getLocation().distance(petEntity.getBukkitEntity().getLocation());
        if (distance > 10 && petEntity.valid && player.isOnGround()) {
            petEntity.setLocation(targetLocation.getBlockX(), targetLocation.getBlockY(), targetLocation.getBlockZ(), 0, 0);
        }
        if (path != null && distance > 3.3) {
            double speed = 1.05d;
            if (pet.getType().getEntityType() == EntityType.ZOMBIE)
                speed *= 1.5;
            ((EntityInsentient) petEntity).getNavigation().a(path, speed);
            ((EntityInsentient) petEntity).getNavigation().a(speed);
        }
    } catch (IllegalArgumentException exception) {
        petEntity.setLocation(targetLocation.getBlockX(), targetLocation.getBlockY(), targetLocation.getBlockZ(), 0, 0);
    }
}
Also used : PathEntity(net.minecraft.server.v1_8_R3.PathEntity) CraftEntity(org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity) Entity(net.minecraft.server.v1_8_R3.Entity) EntityInsentient(net.minecraft.server.v1_8_R3.EntityInsentient) PathEntity(net.minecraft.server.v1_8_R3.PathEntity) Location(org.bukkit.Location)

Example 79 with ui.ex1.entity

use of ui.ex1.entity in project UltraCosmetics by iSach.

the class PlayerFollower method follow.

@Override
public void follow(Player player) {
    if (player == null) {
        return;
    }
    if (UltraCosmeticsData.get().getPlugin().getPlayerManager().getUltraPlayer(player).getCurrentTreasureChest() != null) {
        return;
    }
    Entity petEntity;
    if (pet.isCustomEntity()) {
        petEntity = ((CustomEntityPet) pet).getCustomEntity();
    } else {
        petEntity = ((CraftEntity) pet.getEntity()).getHandle();
    }
    if (petEntity == null) {
        return;
    }
    // Run in sync... To enhance :S
    Bukkit.getScheduler().runTask(UltraCosmeticsData.get().getPlugin(), () -> {
        if (!player.isOnline())
            return;
        if (!player.getWorld().equals(petEntity.getBukkitEntity().getWorld())) {
            petEntity.getBukkitEntity().teleport(player.getLocation());
            return;
        }
        ((EntityInsentient) petEntity).getNavigation().a(2d);
        Location targetLocation = player.getLocation();
        PathEntity path = ((EntityInsentient) petEntity).getNavigation().a(targetLocation.getX() + 1, targetLocation.getY(), targetLocation.getZ() + 1, 1);
        try {
            int distance = (int) Bukkit.getPlayer(player.getName()).getLocation().distance(petEntity.getBukkitEntity().getLocation());
            if (distance > 10 && petEntity.valid && player.isOnGround()) {
                petEntity.setLocation(targetLocation.getBlockX(), targetLocation.getBlockY(), targetLocation.getBlockZ(), 0, 0);
            }
            if (path != null && distance > 1.3) {
                double speed = 1.15d;
                if (pet.getType().getEntityType() == EntityType.ZOMBIE) {
                    speed *= 1.3;
                }
                ((EntityInsentient) petEntity).getNavigation().a(path, speed);
                ((EntityInsentient) petEntity).getNavigation().a(speed);
            }
        } catch (IllegalArgumentException exception) {
            petEntity.setLocation(targetLocation.getBlockX(), targetLocation.getBlockY(), targetLocation.getBlockZ(), 0, 0);
        // exception.printStackTrace();
        }
    });
}
Also used : CraftEntity(org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity) PathEntity(net.minecraft.server.v1_16_R3.PathEntity) Entity(net.minecraft.server.v1_16_R3.Entity) PathEntity(net.minecraft.server.v1_16_R3.PathEntity) Location(org.bukkit.Location)

Example 80 with ui.ex1.entity

use of ui.ex1.entity in project geowave by locationtech.

the class OsmXmlLoader method process.

// Sink implementation
@Override
public void process(final EntityContainer entityContainer) {
    final Entity entity = entityContainer.getEntity();
    if (entity instanceof Node) {
        final Node node = (Node) entity;
        nodes.add(node);
        nodeById.put(node.getId(), node);
    } else if (entity instanceof Way) {
        final Way way = (Way) entity;
        ways.add(way);
    } else if (entity instanceof Relation) {
        final Relation rel = (Relation) entity;
        relations.add(rel);
    }
}
Also used : Entity(org.openstreetmap.osmosis.core.domain.v0_6.Entity) Relation(org.openstreetmap.osmosis.core.domain.v0_6.Relation) WayNode(org.openstreetmap.osmosis.core.domain.v0_6.WayNode) Node(org.openstreetmap.osmosis.core.domain.v0_6.Node) Way(org.openstreetmap.osmosis.core.domain.v0_6.Way)

Aggregations

LivingEntity (org.bukkit.entity.LivingEntity)94 SkinnableEntity (net.citizensnpcs.npc.skin.SkinnableEntity)88 Entity (org.hypertrace.entity.data.service.v1.Entity)44 Test (org.junit.jupiter.api.Test)43 net.minecraft.world.entity (net.minecraft.world.entity)32 org.bukkit.entity (org.bukkit.entity)32 Entity (com.google.datastore.v1.Entity)31 Location (org.bukkit.Location)29 Event (org.hypertrace.core.datamodel.Event)27 AttributeValue (org.hypertrace.core.datamodel.AttributeValue)22 ArrayList (java.util.ArrayList)21 BackendInfo (org.hypertrace.traceenricher.enrichment.enrichers.resolver.backend.BackendInfo)21 Test (org.junit.Test)21 Entity (net.minecraft.server.v1_12_R1.Entity)20 Entity (net.minecraft.server.v1_16_R3.Entity)19 NPCHolder (net.citizensnpcs.npc.ai.NPCHolder)18 Entity (net.minecraft.server.v1_8_R3.Entity)17 Entity (net.minecraft.server.v1_11_R1.Entity)16 Mob (net.minecraft.world.entity.Mob)16 CraftEntity (org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity)16