Search in sources :

Example 61 with EntityInsentient

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

the class PlayerPathfinder method a.

@Override
public PathEntity a(IWorldReader var0, EntityInsentient var1, Set<BlockPosition> var2, float var3, int var4) {
    this.a.a();
    this.e.a(var0, var1);
    PathPoint var5 = this.e.b();
    Map var6 = var2.stream().collect(Collectors.toMap((var0x) -> {
        return this.e.a((double) var0x.getX(), (double) var0x.getY(), (double) var0x.getZ());
    }, Function.identity()));
    PathEntity var7 = this.a(var5, var6, var3, var4);
    this.e.a();
    return var7;
}
Also used : PathEntity(net.minecraft.server.v1_14_R1.PathEntity) BlockPosition(net.minecraft.server.v1_14_R1.BlockPosition) Iterator(java.util.Iterator) Path(net.minecraft.server.v1_14_R1.Path) Pathfinder(net.minecraft.server.v1_14_R1.Pathfinder) Set(java.util.Set) Setting(net.citizensnpcs.Settings.Setting) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) EntityHumanNPC(net.citizensnpcs.nms.v1_14_R1.entity.EntityHumanNPC) List(java.util.List) Stream(java.util.stream.Stream) Lists(com.google.common.collect.Lists) PathDestination(net.minecraft.server.v1_14_R1.PathDestination) Map(java.util.Map) Optional(java.util.Optional) EntityInsentient(net.minecraft.server.v1_14_R1.EntityInsentient) Comparator(java.util.Comparator) IWorldReader(net.minecraft.server.v1_14_R1.IWorldReader) PathPoint(net.minecraft.server.v1_14_R1.PathPoint) PathPoint(net.minecraft.server.v1_14_R1.PathPoint) PathEntity(net.minecraft.server.v1_14_R1.PathEntity) Map(java.util.Map)

Example 62 with EntityInsentient

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

the class NMSImpl method getTargetNavigator.

private MCNavigator getTargetNavigator(final org.bukkit.entity.Entity entity, final NavigatorParameters params, final Function<NavigationAbstract, Boolean> function) {
    net.minecraft.server.v1_12_R1.Entity raw = getHandle(entity);
    raw.onGround = true;
    // not sure of a better way around this - if onGround is false, then
    // navigation won't execute, and calling entity.move doesn't
    // entirely fix the problem.
    final NavigationAbstract navigation = NMSImpl.getNavigation(entity);
    final float oldWater = raw instanceof EntityPlayer ? ((EntityHumanNPC) raw).a(PathType.WATER) : ((EntityInsentient) raw).a(PathType.WATER);
    if (params.avoidWater() && oldWater >= 0) {
        if (raw instanceof EntityPlayer) {
            ((EntityHumanNPC) raw).a(PathType.WATER, oldWater + 1F);
        } else {
            ((EntityInsentient) raw).a(PathType.WATER, oldWater + 1F);
        }
    }
    return new MCNavigator() {

        float lastSpeed;

        CancelReason reason;

        @Override
        public CancelReason getCancelReason() {
            return reason;
        }

        @Override
        public Iterable<Vector> getPath() {
            return new NavigationIterable(navigation);
        }

        @Override
        public void stop() {
            if (params.debug() && navigation.l() != null) {
                for (Player player : Bukkit.getOnlinePlayers()) {
                    for (int i = 0; i < navigation.l().d(); i++) {
                        PathPoint pp = navigation.l().a(i);
                        org.bukkit.block.Block block = new Vector(pp.a, pp.b, pp.c).toLocation(player.getWorld()).getBlock();
                        player.sendBlockChange(block.getLocation(), block.getType(), block.getData());
                    }
                }
            }
            if (oldWater >= 0) {
                if (raw instanceof EntityPlayer) {
                    ((EntityHumanNPC) raw).a(PathType.WATER, oldWater);
                } else {
                    ((EntityInsentient) raw).a(PathType.WATER, oldWater);
                }
            }
            stopNavigation(navigation);
        }

        @Override
        public boolean update() {
            if (params.speed() != lastSpeed) {
                if (Messaging.isDebugging() && lastSpeed > 0) {
                    Messaging.debug("Repathfinding " + ((NPCHolder) entity).getNPC().getId() + " due to speed change");
                }
                Entity handle = getHandle(entity);
                float oldWidth = handle.width;
                if (handle instanceof EntityHorse) {
                    handle.width = Math.min(0.99f, oldWidth);
                }
                if (!function.apply(navigation)) {
                    reason = CancelReason.STUCK;
                }
                // minecraft requires that an entity fit onto both blocks if width >= 1f,
                handle.width = oldWidth;
                // but we'd prefer to make it just fit on 1 so hack around it a bit.
                lastSpeed = params.speed();
            }
            if (params.debug() && !NMSImpl.isNavigationFinished(navigation)) {
                for (Player player : Bukkit.getOnlinePlayers()) {
                    for (int i = 0; i < navigation.l().d(); i++) {
                        PathPoint pp = navigation.l().a(i);
                        player.sendBlockChange(new Vector(pp.a, pp.b, pp.c).toLocation(player.getWorld()), Material.YELLOW_FLOWER, (byte) 0);
                    }
                }
            }
            navigation.a(params.speed());
            return NMSImpl.isNavigationFinished(navigation);
        }
    };
}
Also used : PathEntity(net.minecraft.server.v1_12_R1.PathEntity) LivingEntity(org.bukkit.entity.LivingEntity) SkinnableEntity(net.citizensnpcs.npc.skin.SkinnableEntity) CraftEntity(org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity) Entity(net.minecraft.server.v1_12_R1.Entity) Player(org.bukkit.entity.Player) EntityPlayer(net.minecraft.server.v1_12_R1.EntityPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer) NPCHolder(net.citizensnpcs.npc.ai.NPCHolder) EntityInsentient(net.minecraft.server.v1_12_R1.EntityInsentient) NavigationAbstract(net.minecraft.server.v1_12_R1.NavigationAbstract) PathPoint(net.minecraft.server.v1_12_R1.PathPoint) EntityHumanNPC(net.citizensnpcs.nms.v1_12_R1.entity.EntityHumanNPC) Entity(net.minecraft.server.v1_12_R1.Entity) PathPoint(net.minecraft.server.v1_12_R1.PathPoint) MCNavigator(net.citizensnpcs.npc.ai.MCNavigationStrategy.MCNavigator) EntityHorse(net.minecraft.server.v1_12_R1.EntityHorse) CancelReason(net.citizensnpcs.api.ai.event.CancelReason) EntityPlayer(net.minecraft.server.v1_12_R1.EntityPlayer) Vector(org.bukkit.util.Vector)

Example 63 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 from, org.bukkit.entity.Entity to) {
    Entity handle = NMSImpl.getHandle(from), target = NMSImpl.getHandle(to);
    BAD_CONTROLLER_LOOK.add(EntityType.SHULKER);
    if (BAD_CONTROLLER_LOOK.contains(handle.getBukkitEntity().getType()) || (!(handle instanceof EntityInsentient) && !(handle instanceof EntityHumanNPC))) {
        if (to instanceof LivingEntity) {
            look(from, ((LivingEntity) to).getEyeLocation(), false, true);
        } else {
            look(from, to.getLocation(), false, true);
        }
    } else if (handle instanceof EntityInsentient) {
        ((EntityInsentient) handle).getControllerLook().a(target, ((EntityInsentient) handle).O(), ((EntityInsentient) handle).N());
        while (((EntityLiving) handle).aP >= 180F) {
            ((EntityLiving) handle).aP -= 360F;
        }
        while (((EntityLiving) handle).aP < -180F) {
            ((EntityLiving) handle).aP += 360F;
        }
    } else if (handle instanceof EntityHumanNPC) {
        ((EntityHumanNPC) handle).setTargetLook(target, 10F, 40F);
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) PathEntity(net.minecraft.server.v1_12_R1.PathEntity) LivingEntity(org.bukkit.entity.LivingEntity) SkinnableEntity(net.citizensnpcs.npc.skin.SkinnableEntity) CraftEntity(org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity) Entity(net.minecraft.server.v1_12_R1.Entity) EntityLiving(net.minecraft.server.v1_12_R1.EntityLiving) EntityInsentient(net.minecraft.server.v1_12_R1.EntityInsentient) EntityHumanNPC(net.citizensnpcs.nms.v1_12_R1.entity.EntityHumanNPC)

Example 64 with EntityInsentient

use of net.minecraft.server.v1_16_R3.EntityInsentient 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 EntityInsentient) {
        ControllerJump controller = ((EntityInsentient) handle).getControllerJump();
        controller.a();
    } else if (handle instanceof EntityHumanNPC) {
        ((EntityHumanNPC) handle).setShouldJump();
    }
}
Also used : PathEntity(net.minecraft.server.v1_12_R1.PathEntity) LivingEntity(org.bukkit.entity.LivingEntity) SkinnableEntity(net.citizensnpcs.npc.skin.SkinnableEntity) CraftEntity(org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity) Entity(net.minecraft.server.v1_12_R1.Entity) EntityInsentient(net.minecraft.server.v1_12_R1.EntityInsentient) ControllerJump(net.minecraft.server.v1_12_R1.ControllerJump) EntityHumanNPC(net.citizensnpcs.nms.v1_12_R1.entity.EntityHumanNPC)

Example 65 with EntityInsentient

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

the class NMSImpl method getDestination.

@Override
public Location getDestination(org.bukkit.entity.Entity entity) {
    Entity handle = getHandle(entity);
    ControllerMove controller = handle instanceof EntityInsentient ? ((EntityInsentient) handle).getControllerMove() : handle instanceof EntityHumanNPC ? ((EntityHumanNPC) handle).getControllerMove() : null;
    return new Location(entity.getWorld(), controller.d(), controller.e(), controller.f());
}
Also used : PathEntity(net.minecraft.server.v1_12_R1.PathEntity) LivingEntity(org.bukkit.entity.LivingEntity) SkinnableEntity(net.citizensnpcs.npc.skin.SkinnableEntity) CraftEntity(org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity) Entity(net.minecraft.server.v1_12_R1.Entity) EntityInsentient(net.minecraft.server.v1_12_R1.EntityInsentient) ControllerMove(net.minecraft.server.v1_12_R1.ControllerMove) EntityHumanNPC(net.citizensnpcs.nms.v1_12_R1.entity.EntityHumanNPC) Location(org.bukkit.Location)

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