Search in sources :

Example 16 with Node

use of net.minecraft.world.level.pathfinder.Node in project Citizens2 by CitizensDev.

the class NMSImpl method getTargetNavigator.

@Override
public MCNavigator getTargetNavigator(org.bukkit.entity.Entity entity, Iterable<Vector> dest, final NavigatorParameters params) {
    List<Node> list = Lists.<Node>newArrayList(Iterables.<Vector, Node>transform(dest, (input) -> {
        return new Node(input.getBlockX(), input.getBlockY(), input.getBlockZ());
    }));
    Node last = list.size() > 0 ? list.get(list.size() - 1) : null;
    final Path path = new Path(list, last != null ? new BlockPos(last.x, last.y, last.z) : null, true);
    return getTargetNavigator(entity, params, (input) -> {
        return input.moveTo(path, params.speed());
    });
}
Also used : AABB(net.minecraft.world.phys.AABB) FireworkController(net.citizensnpcs.nms.v1_17_R1.entity.nonliving.FireworkController) VillagerController(net.citizensnpcs.nms.v1_17_R1.entity.VillagerController) FoxTrait(net.citizensnpcs.trait.versioned.FoxTrait) CreeperController(net.citizensnpcs.nms.v1_17_R1.entity.CreeperController) ArmorStandController(net.citizensnpcs.nms.v1_17_R1.entity.nonliving.ArmorStandController) WanderingTraderController(net.citizensnpcs.nms.v1_17_R1.entity.WanderingTraderController) Pose(net.minecraft.world.entity.Pose) JumpControl(net.minecraft.world.entity.ai.control.JumpControl) Location(org.bukkit.Location) BarColor(org.bukkit.boss.BarColor) Map(java.util.Map) PhantomController(net.citizensnpcs.nms.v1_17_R1.entity.PhantomController) EnumSet(java.util.EnumSet) HorseZombieController(net.citizensnpcs.nms.v1_17_R1.entity.HorseZombieController) SpiderController(net.citizensnpcs.nms.v1_17_R1.entity.SpiderController) FishingHookController(net.citizensnpcs.nms.v1_17_R1.entity.nonliving.FishingHookController) MarkerController(net.citizensnpcs.nms.v1_17_R1.entity.nonliving.MarkerController) PhantomTrait(net.citizensnpcs.trait.versioned.PhantomTrait) ClientboundPlayerInfoPacket(net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket) CaveSpiderController(net.citizensnpcs.nms.v1_17_R1.entity.CaveSpiderController) CowController(net.citizensnpcs.nms.v1_17_R1.entity.CowController) EntityDataAccessor(net.minecraft.network.syncher.EntityDataAccessor) EmptyChannel(net.citizensnpcs.nms.v1_17_R1.network.EmptyChannel) BlockBreaker(net.citizensnpcs.api.npc.BlockBreaker) PigController(net.citizensnpcs.nms.v1_17_R1.entity.PigController) RabbitController(net.citizensnpcs.nms.v1_17_R1.entity.RabbitController) CraftWorld(org.bukkit.craftbukkit.v1_17_R1.CraftWorld) Packet(net.minecraft.network.protocol.Packet) ShulkerBulletController(net.citizensnpcs.nms.v1_17_R1.entity.nonliving.ShulkerBulletController) CrashReport(net.minecraft.CrashReport) VoxelShape(net.minecraft.world.phys.shapes.VoxelShape) PaintingController(net.citizensnpcs.nms.v1_17_R1.entity.nonliving.PaintingController) GoalSelector(net.minecraft.world.entity.ai.goal.GoalSelector) MethodHandle(java.lang.invoke.MethodHandle) FoxController(net.citizensnpcs.nms.v1_17_R1.entity.FoxController) TNTPrimedController(net.citizensnpcs.nms.v1_17_R1.entity.nonliving.TNTPrimedController) Wither(org.bukkit.entity.Wither) PolarBearController(net.citizensnpcs.nms.v1_17_R1.entity.PolarBearController) GiantController(net.citizensnpcs.nms.v1_17_R1.entity.GiantController) CraftBlock(org.bukkit.craftbukkit.v1_17_R1.block.CraftBlock) CrashReportCategory(net.minecraft.CrashReportCategory) PiglinBruteController(net.citizensnpcs.nms.v1_17_R1.entity.PiglinBruteController) NPCRegistry(net.citizensnpcs.api.npc.NPCRegistry) EndDragonFight(net.minecraft.world.level.dimension.end.EndDragonFight) GlowItemFrameController(net.citizensnpcs.nms.v1_17_R1.entity.nonliving.GlowItemFrameController) ServerPlayer(net.minecraft.server.level.ServerPlayer) ParrotTrait(net.citizensnpcs.trait.versioned.ParrotTrait) Lists(com.google.common.collect.Lists) Dolphin(net.minecraft.world.entity.animal.Dolphin) AttributeInstance(net.minecraft.world.entity.ai.attributes.AttributeInstance) ChickenController(net.citizensnpcs.nms.v1_17_R1.entity.ChickenController) EnchantmentHelper(net.minecraft.world.item.enchantment.EnchantmentHelper) NPCHolder(net.citizensnpcs.npc.ai.NPCHolder) Turtle(net.minecraft.world.entity.animal.Turtle) TurtleController(net.citizensnpcs.nms.v1_17_R1.entity.TurtleController) BlazeController(net.citizensnpcs.nms.v1_17_R1.entity.BlazeController) BossBarTrait(net.citizensnpcs.trait.versioned.BossBarTrait) HoglinController(net.citizensnpcs.nms.v1_17_R1.entity.HoglinController) MinecartFurnaceController(net.citizensnpcs.nms.v1_17_R1.entity.nonliving.MinecartFurnaceController) GuardianElderController(net.citizensnpcs.nms.v1_17_R1.entity.GuardianElderController) YggdrasilAuthenticationService(com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService) LargeFireballController(net.citizensnpcs.nms.v1_17_R1.entity.nonliving.LargeFireballController) AbstractMinecart(net.minecraft.world.entity.vehicle.AbstractMinecart) CraftEntity(org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity) Field(java.lang.reflect.Field) SmallFireballController(net.citizensnpcs.nms.v1_17_R1.entity.nonliving.SmallFireballController) CraftBossBar(org.bukkit.craftbukkit.v1_17_R1.boss.CraftBossBar) PiglinController(net.citizensnpcs.nms.v1_17_R1.entity.PiglinController) TrackedEntity(net.minecraft.server.level.ChunkMap.TrackedEntity) TreeMap(java.util.TreeMap) BossBar(org.bukkit.boss.BossBar) EnderCrystalController(net.citizensnpcs.nms.v1_17_R1.entity.nonliving.EnderCrystalController) BlockBreakerConfiguration(net.citizensnpcs.api.npc.BlockBreaker.BlockBreakerConfiguration) MinecraftProfilePropertiesResponse(com.mojang.authlib.yggdrasil.response.MinecraftProfilePropertiesResponse) Preconditions(com.google.common.base.Preconditions) Mob(net.minecraft.world.entity.Mob) ZoglinController(net.citizensnpcs.nms.v1_17_R1.entity.ZoglinController) BeeController(net.citizensnpcs.nms.v1_17_R1.entity.BeeController) ShulkerTrait(net.citizensnpcs.trait.versioned.ShulkerTrait) CatTrait(net.citizensnpcs.trait.versioned.CatTrait) Messages(net.citizensnpcs.util.Messages) ResourceLocation(net.minecraft.resources.ResourceLocation) CraftPlayer(org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer) Commands(net.citizensnpcs.nms.v1_17_R1.trait.Commands) Items(net.minecraft.world.item.Items) NMS(net.citizensnpcs.util.NMS) Shulker(net.minecraft.world.entity.monster.Shulker) PlayerAdvancements(net.minecraft.server.PlayerAdvancements) Random(java.util.Random) IronGolemController(net.citizensnpcs.nms.v1_17_R1.entity.IronGolemController) Player(org.bukkit.entity.Player) PluginLoadOrder(org.bukkit.plugin.PluginLoadOrder) CitizensAPI(net.citizensnpcs.api.CitizensAPI) CancelReason(net.citizensnpcs.api.ai.event.CancelReason) IllusionerController(net.citizensnpcs.nms.v1_17_R1.entity.IllusionerController) AxolotlTrait(net.citizensnpcs.trait.versioned.AxolotlTrait) EnderDragon(net.minecraft.world.entity.boss.enderdragon.EnderDragon) BoundingBox(net.citizensnpcs.api.util.BoundingBox) EnderSignalController(net.citizensnpcs.nms.v1_17_R1.entity.nonliving.EnderSignalController) ThrownPotionController(net.citizensnpcs.nms.v1_17_R1.entity.nonliving.ThrownPotionController) YggdrasilMinecraftSessionService(com.mojang.authlib.yggdrasil.YggdrasilMinecraftSessionService) StriderController(net.citizensnpcs.nms.v1_17_R1.entity.StriderController) BlockPathTypes(net.minecraft.world.level.pathfinder.BlockPathTypes) Collection(java.util.Collection) PigZombieController(net.citizensnpcs.nms.v1_17_R1.entity.PigZombieController) EntityType(org.bukkit.entity.EntityType) EnderMan(net.minecraft.world.entity.monster.EnderMan) ClientboundTeleportEntityPacket(net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket) SalmonController(net.citizensnpcs.nms.v1_17_R1.entity.SalmonController) BoatController(net.citizensnpcs.nms.v1_17_R1.entity.nonliving.BoatController) Level(net.minecraft.world.level.Level) AbstractFish(net.minecraft.world.entity.animal.AbstractFish) PolarBear(net.minecraft.world.entity.animal.PolarBear) CommandManager(net.citizensnpcs.api.command.CommandManager) FallingBlockController(net.citizensnpcs.nms.v1_17_R1.entity.nonliving.FallingBlockController) HorseSkeletonController(net.citizensnpcs.nms.v1_17_R1.entity.HorseSkeletonController) ServerLevel(net.minecraft.server.level.ServerLevel) NPC(net.citizensnpcs.api.npc.NPC) Rabbit(net.minecraft.world.entity.animal.Rabbit) MinecraftSessionService(com.mojang.authlib.minecraft.MinecraftSessionService) TraderLlamaController(net.citizensnpcs.nms.v1_17_R1.entity.TraderLlamaController) SnowmanController(net.citizensnpcs.nms.v1_17_R1.entity.SnowmanController) VexController(net.citizensnpcs.nms.v1_17_R1.entity.VexController) BarStyle(org.bukkit.boss.BarStyle) SpawnReason(org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason) SheepController(net.citizensnpcs.nms.v1_17_R1.entity.SheepController) TamableAnimal(net.minecraft.world.entity.TamableAnimal) ReportedException(net.minecraft.ReportedException) CraftSound(org.bukkit.craftbukkit.v1_17_R1.CraftSound) NavigatorParameters(net.citizensnpcs.api.ai.NavigatorParameters) DolphinController(net.citizensnpcs.nms.v1_17_R1.entity.DolphinController) SkinnableEntity(net.citizensnpcs.npc.skin.SkinnableEntity) WolfController(net.citizensnpcs.nms.v1_17_R1.entity.WolfController) ZombieHuskController(net.citizensnpcs.nms.v1_17_R1.entity.ZombieHuskController) ItemFrameController(net.citizensnpcs.nms.v1_17_R1.entity.nonliving.ItemFrameController) PufferFishController(net.citizensnpcs.nms.v1_17_R1.entity.PufferFishController) Entity(net.minecraft.world.entity.Entity) Vec3(net.minecraft.world.phys.Vec3) AbstractHorse(net.minecraft.world.entity.animal.horse.AbstractHorse) CatController(net.citizensnpcs.nms.v1_17_R1.entity.CatController) Axolotl(net.minecraft.world.entity.animal.axolotl.Axolotl) ItemController(net.citizensnpcs.nms.v1_17_R1.entity.nonliving.ItemController) WitchController(net.citizensnpcs.nms.v1_17_R1.entity.WitchController) Arrays(java.util.Arrays) Path(net.minecraft.world.level.pathfinder.Path) VindicatorController(net.citizensnpcs.nms.v1_17_R1.entity.VindicatorController) GameProfile(com.mojang.authlib.GameProfile) Connection(net.minecraft.network.Connection) WitherBoss(net.minecraft.world.entity.boss.wither.WitherBoss) GuardianController(net.citizensnpcs.nms.v1_17_R1.entity.GuardianController) GameProfileRepository(com.mojang.authlib.GameProfileRepository) PathNavigation(net.minecraft.world.entity.ai.navigation.PathNavigation) World(org.bukkit.World) MinecartRideableController(net.citizensnpcs.nms.v1_17_R1.entity.nonliving.MinecartRideableController) RemovalReason(net.minecraft.world.entity.Entity.RemovalReason) DrownedController(net.citizensnpcs.nms.v1_17_R1.entity.DrownedController) Cat(net.minecraft.world.entity.animal.Cat) TropicalFishController(net.citizensnpcs.nms.v1_17_R1.entity.TropicalFishController) Material(org.bukkit.Material) EggController(net.citizensnpcs.nms.v1_17_R1.entity.nonliving.EggController) ThrownExpBottleController(net.citizensnpcs.nms.v1_17_R1.entity.nonliving.ThrownExpBottleController) BlockData(org.bukkit.block.data.BlockData) Set(java.util.Set) MinecartChestController(net.citizensnpcs.nms.v1_17_R1.entity.nonliving.MinecartChestController) ShulkerController(net.citizensnpcs.nms.v1_17_R1.entity.ShulkerController) MinecartTNTController(net.citizensnpcs.nms.v1_17_R1.entity.nonliving.MinecartTNTController) NMSBridge(net.citizensnpcs.util.NMSBridge) FishHook(org.bukkit.entity.FishHook) FluidState(net.minecraft.world.level.material.FluidState) GhastController(net.citizensnpcs.nms.v1_17_R1.entity.GhastController) ItemStack(net.minecraft.world.item.ItemStack) RavagerController(net.citizensnpcs.nms.v1_17_R1.entity.RavagerController) EvokerFangsController(net.citizensnpcs.nms.v1_17_R1.entity.nonliving.EvokerFangsController) MoverType(net.minecraft.world.entity.MoverType) UUIDTypeAdapter(com.mojang.util.UUIDTypeAdapter) EvokerController(net.citizensnpcs.nms.v1_17_R1.entity.EvokerController) Node(net.minecraft.world.level.pathfinder.Node) AreaEffectCloudController(net.citizensnpcs.nms.v1_17_R1.entity.nonliving.AreaEffectCloudController) Iterables(com.google.common.collect.Iterables) SquidController(net.citizensnpcs.nms.v1_17_R1.entity.SquidController) FishingHook(net.minecraft.world.entity.projectile.FishingHook) HorseMuleController(net.citizensnpcs.nms.v1_17_R1.entity.HorseMuleController) ClientboundSetPlayerTeamPacket(net.minecraft.network.protocol.game.ClientboundSetPlayerTeamPacket) Panda(net.minecraft.world.entity.animal.Panda) BlockState(net.minecraft.world.level.block.state.BlockState) PillagerController(net.citizensnpcs.nms.v1_17_R1.entity.PillagerController) MCNavigator(net.citizensnpcs.npc.ai.MCNavigationStrategy.MCNavigator) ChunkMap(net.minecraft.server.level.ChunkMap) MobEffects(net.minecraft.world.effect.MobEffects) ArrayList(java.util.ArrayList) GoatController(net.citizensnpcs.nms.v1_17_R1.entity.GoatController) EndermanController(net.citizensnpcs.nms.v1_17_R1.entity.EndermanController) LlamaSpitController(net.citizensnpcs.nms.v1_17_R1.entity.nonliving.LlamaSpitController) MushroomCowTrait(net.citizensnpcs.trait.versioned.MushroomCowTrait) OcelotController(net.citizensnpcs.nms.v1_17_R1.entity.OcelotController) ZombieVillagerController(net.citizensnpcs.nms.v1_17_R1.entity.ZombieVillagerController) PlayerTeam(net.minecraft.world.scores.PlayerTeam) GlowSquidController(net.citizensnpcs.nms.v1_17_R1.entity.GlowSquidController) SlimeController(net.citizensnpcs.nms.v1_17_R1.entity.SlimeController) ZombieController(net.citizensnpcs.nms.v1_17_R1.entity.ZombieController) EntityControllers(net.citizensnpcs.npc.EntityControllers) Vector(org.bukkit.util.Vector) BeeTrait(net.citizensnpcs.trait.versioned.BeeTrait) CodController(net.citizensnpcs.nms.v1_17_R1.entity.CodController) SmoothRotationTrait(net.citizensnpcs.trait.SmoothRotationTrait) PolarBearTrait(net.citizensnpcs.trait.versioned.PolarBearTrait) Attributes(net.minecraft.world.entity.ai.attributes.Attributes) CommandException(net.citizensnpcs.api.command.exception.CommandException) SpectralArrowController(net.citizensnpcs.nms.v1_17_R1.entity.nonliving.SpectralArrowController) EntityDimensions(net.minecraft.world.entity.EntityDimensions) Brain(net.minecraft.world.entity.ai.Brain) EndermiteController(net.citizensnpcs.nms.v1_17_R1.entity.EndermiteController) SnowmanTrait(net.citizensnpcs.trait.versioned.SnowmanTrait) SilverfishController(net.citizensnpcs.nms.v1_17_R1.entity.SilverfishController) LivingEntity(net.minecraft.world.entity.LivingEntity) SocketAddress(java.net.SocketAddress) URL(java.net.URL) CraftEventFactory(org.bukkit.craftbukkit.v1_17_R1.event.CraftEventFactory) TippedArrowController(net.citizensnpcs.nms.v1_17_R1.entity.nonliving.TippedArrowController) HorseController(net.citizensnpcs.nms.v1_17_R1.entity.HorseController) SkullMeta(org.bukkit.inventory.meta.SkullMeta) LlamaController(net.citizensnpcs.nms.v1_17_R1.entity.LlamaController) MagmaCubeController(net.citizensnpcs.nms.v1_17_R1.entity.MagmaCubeController) Registry(net.minecraft.core.Registry) AxolotlController(net.citizensnpcs.nms.v1_17_R1.entity.AxolotlController) ServerBossEvent(net.minecraft.server.level.ServerBossEvent) Bukkit(org.bukkit.Bukkit) Function(com.google.common.base.Function) MoveControl(net.minecraft.world.entity.ai.control.MoveControl) EnderDragonController(net.citizensnpcs.nms.v1_17_R1.entity.EnderDragonController) Sound(org.bukkit.Sound) HumanController(net.citizensnpcs.nms.v1_17_R1.entity.HumanController) TargetNavigator(net.citizensnpcs.npc.ai.MCTargetStrategy.TargetNavigator) List(java.util.List) ParrotController(net.citizensnpcs.nms.v1_17_R1.entity.ParrotController) BlockPos(net.minecraft.core.BlockPos) SoundEvent(net.minecraft.sounds.SoundEvent) FlyingMoveControl(net.minecraft.world.entity.ai.control.FlyingMoveControl) PandaController(net.citizensnpcs.nms.v1_17_R1.entity.PandaController) LeashController(net.citizensnpcs.nms.v1_17_R1.entity.nonliving.LeashController) PlayerAnimation(net.citizensnpcs.util.PlayerAnimation) SkeletonStrayController(net.citizensnpcs.nms.v1_17_R1.entity.SkeletonStrayController) CraftWither(org.bukkit.craftbukkit.v1_17_R1.entity.CraftWither) ThrownTridentController(net.citizensnpcs.nms.v1_17_R1.entity.nonliving.ThrownTridentController) ServerChunkCache(net.minecraft.server.level.ServerChunkCache) SkeletonWitherController(net.citizensnpcs.nms.v1_17_R1.entity.SkeletonWitherController) WitherSkullController(net.citizensnpcs.nms.v1_17_R1.entity.nonliving.WitherSkullController) PufferFishTrait(net.citizensnpcs.trait.versioned.PufferFishTrait) EnderPearlController(net.citizensnpcs.nms.v1_17_R1.entity.nonliving.EnderPearlController) DamageSource(net.minecraft.world.damagesource.DamageSource) HorseDonkeyController(net.citizensnpcs.nms.v1_17_R1.entity.HorseDonkeyController) DragonFireballController(net.citizensnpcs.nms.v1_17_R1.entity.nonliving.DragonFireballController) HttpAuthenticationService(com.mojang.authlib.HttpAuthenticationService) VillagerTrait(net.citizensnpcs.trait.versioned.VillagerTrait) MushroomCowController(net.citizensnpcs.nms.v1_17_R1.entity.MushroomCowController) WitherController(net.citizensnpcs.nms.v1_17_R1.entity.WitherController) SnowballController(net.citizensnpcs.nms.v1_17_R1.entity.nonliving.SnowballController) Team(org.bukkit.scoreboard.Team) Iterator(java.util.Iterator) TropicalFishTrait(net.citizensnpcs.trait.versioned.TropicalFishTrait) FluidTags(net.minecraft.tags.FluidTags) Setting(net.citizensnpcs.Settings.Setting) BatController(net.citizensnpcs.nms.v1_17_R1.entity.BatController) Maps(com.google.common.collect.Maps) Util(net.citizensnpcs.util.Util) TraitInfo(net.citizensnpcs.api.trait.TraitInfo) Messaging(net.citizensnpcs.api.util.Messaging) EntityHumanNPC(net.citizensnpcs.nms.v1_17_R1.entity.EntityHumanNPC) SkeletonController(net.citizensnpcs.nms.v1_17_R1.entity.SkeletonController) LlamaTrait(net.citizensnpcs.trait.versioned.LlamaTrait) Pufferfish(net.minecraft.world.entity.animal.Pufferfish) CraftServer(org.bukkit.craftbukkit.v1_17_R1.CraftServer) PandaTrait(net.citizensnpcs.trait.versioned.PandaTrait) AbstractSchoolingFish(net.minecraft.world.entity.animal.AbstractSchoolingFish) MinecartCommandController(net.citizensnpcs.nms.v1_17_R1.entity.nonliving.MinecartCommandController) Tameable(org.bukkit.entity.Tameable) MinecartHopperController(net.citizensnpcs.nms.v1_17_R1.entity.nonliving.MinecartHopperController) Mth(net.minecraft.util.Mth) Path(net.minecraft.world.level.pathfinder.Path) Node(net.minecraft.world.level.pathfinder.Node) BlockPos(net.minecraft.core.BlockPos)

Example 17 with Node

use of net.minecraft.world.level.pathfinder.Node in project Citizens2 by CitizensDev.

the class NMSImpl method getTargetNavigator.

private MCNavigator getTargetNavigator(final org.bukkit.entity.Entity entity, final NavigatorParameters params, final Function<PathNavigation, Boolean> function) {
    net.minecraft.world.entity.Entity raw = getHandle(entity);
    raw.setOnGround(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 PathNavigation navigation = NMSImpl.getNavigation(entity);
    final float oldWater = raw instanceof ServerPlayer ? ((EntityHumanNPC) raw).getPathfindingMalus(BlockPathTypes.WATER) : ((Mob) raw).getPathfindingMalus(BlockPathTypes.WATER);
    if (params.avoidWater() && oldWater >= 0) {
        if (raw instanceof ServerPlayer) {
            ((EntityHumanNPC) raw).setPathfindingMalus(BlockPathTypes.WATER, oldWater + 1F);
        } else {
            ((Mob) raw).setPathfindingMalus(BlockPathTypes.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() {
            Path path = getPathEntity(navigation);
            if (params.debug() && path != null) {
                for (Player player : Bukkit.getOnlinePlayers()) {
                    for (int i = 0; i < path.getNodeCount(); i++) {
                        Node pp = path.getNode(i);
                        org.bukkit.block.Block block = new Vector(pp.x, pp.y, pp.z).toLocation(player.getWorld()).getBlock();
                        player.sendBlockChange(block.getLocation(), block.getBlockData());
                    }
                }
            }
            if (oldWater >= 0) {
                if (raw instanceof ServerPlayer) {
                    ((EntityHumanNPC) raw).setPathfindingMalus(BlockPathTypes.WATER, oldWater);
                } else {
                    ((Mob) raw).setPathfindingMalus(BlockPathTypes.WATER, oldWater);
                }
            }
            navigation.stop();
        }

        @Override
        public boolean update() {
            if (params.speed() != lastSpeed) {
                if (Messaging.isDebugging() && lastSpeed > 0) {
                    Messaging.debug("Repathfinding " + ((NPCHolder) entity).getNPC().getId() + " due to speed change from", lastSpeed, "to", params.speed());
                }
                Entity handle = getHandle(entity);
                EntityDimensions size = null;
                try {
                    size = (EntityDimensions) SIZE_FIELD_GETTER.invoke(handle);
                    if (handle instanceof AbstractHorse) {
                        SIZE_FIELD_SETTER.invoke(handle, new EntityDimensions(Math.min(0.99F, size.width), size.height, false));
                    }
                } catch (Throwable e) {
                    e.printStackTrace();
                }
                if (!function.apply(navigation)) {
                    reason = CancelReason.STUCK;
                }
                try {
                    SIZE_FIELD_SETTER.invoke(handle, size);
                } catch (Throwable e) {
                    e.printStackTrace();
                // minecraft requires that an entity fit onto both blocks if width >= 1f, but we'd prefer to
                // make it just fit on 1 so hack around it a bit.
                }
                lastSpeed = params.speed();
            }
            if (params.debug() && !navigation.isDone()) {
                BlockData data = Material.DANDELION.createBlockData();
                Path path = getPathEntity(navigation);
                for (Player player : Bukkit.getOnlinePlayers()) {
                    for (int i = 0; i < path.getNodeCount(); i++) {
                        Node pp = path.getNode(i);
                        player.sendBlockChange(new Vector(pp.x, pp.y, pp.z).toLocation(player.getWorld()), data);
                    }
                }
            }
            navigation.setSpeedModifier(params.speed());
            return navigation.isDone();
        }
    };
}
Also used : CraftEntity(org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity) TrackedEntity(net.minecraft.server.level.ChunkMap.TrackedEntity) SkinnableEntity(net.citizensnpcs.npc.skin.SkinnableEntity) Entity(net.minecraft.world.entity.Entity) LivingEntity(net.minecraft.world.entity.LivingEntity) EntityDimensions(net.minecraft.world.entity.EntityDimensions) AbstractHorse(net.minecraft.world.entity.animal.horse.AbstractHorse) Node(net.minecraft.world.level.pathfinder.Node) PathNavigation(net.minecraft.world.entity.ai.navigation.PathNavigation) EntityHumanNPC(net.citizensnpcs.nms.v1_17_R1.entity.EntityHumanNPC) BlockData(org.bukkit.block.data.BlockData) Vector(org.bukkit.util.Vector) Path(net.minecraft.world.level.pathfinder.Path) Mob(net.minecraft.world.entity.Mob) ServerPlayer(net.minecraft.server.level.ServerPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer) Player(org.bukkit.entity.Player) NPCHolder(net.citizensnpcs.npc.ai.NPCHolder) MCNavigator(net.citizensnpcs.npc.ai.MCNavigationStrategy.MCNavigator) Entity(net.minecraft.world.entity.Entity) CancelReason(net.citizensnpcs.api.ai.event.CancelReason) ServerPlayer(net.minecraft.server.level.ServerPlayer)

Example 18 with Node

use of net.minecraft.world.level.pathfinder.Node in project Citizens2 by CitizensDev.

the class PlayerNavigation method supertrimPath.

protected void supertrimPath() {
    if (this.path == null)
        return;
    for (int var0 = 0; var0 < this.path.getNodeCount(); var0++) {
        Node var1 = this.path.getNode(var0);
        Node var2 = (var0 + 1 < this.path.getNodeCount()) ? this.path.getNode(var0 + 1) : null;
        BlockState var3 = this.level.getBlockState(new BlockPos(var1.x, var1.y, var1.z));
        if (var3.is(BlockTags.CAULDRONS)) {
            this.path.replaceNode(var0, var1.cloneAndMove(var1.x, var1.y + 1, var1.z));
            if (var2 != null && var1.y >= var2.y)
                this.path.replaceNode(var0 + 1, var1.cloneAndMove(var2.x, var1.y + 1, var2.z));
        }
    }
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) Node(net.minecraft.world.level.pathfinder.Node) BlockPos(net.minecraft.core.BlockPos)

Example 19 with Node

use of net.minecraft.world.level.pathfinder.Node in project Citizens2 by CitizensDev.

the class PlayerNavigation method recomputePath.

@Override
public void recomputePath(BlockPos var0) {
    if (this.path == null || this.path.isDone() || this.path.getNodeCount() == 0)
        return;
    Node var1 = this.path.getEndNode();
    Vec3 var2 = new Vec3((var1.x + this.mob.getX()) / 2.0D, (var1.y + this.mob.getY()) / 2.0D, (var1.z + this.mob.getZ()) / 2.0D);
    if (var0.closerThan(var2, (this.path.getNodeCount() - this.path.getNextNodeIndex())))
        recomputePath();
}
Also used : Node(net.minecraft.world.level.pathfinder.Node) Vec3(net.minecraft.world.phys.Vec3)

Example 20 with Node

use of net.minecraft.world.level.pathfinder.Node in project Citizens2 by CitizensDev.

the class PlayerNodeEvaluator method findAcceptedNode.

protected Node findAcceptedNode(int var0, int var1, int var2, int var3, double var4, Direction var6, BlockPathTypes var7) {
    Node var8 = null;
    BlockPos.MutableBlockPos var9 = new BlockPos.MutableBlockPos();
    double var10 = getFloorLevel(var9.set(var0, var1, var2));
    if (var10 - var4 > 1.125D)
        return null;
    BlockPathTypes var12 = getCachedBlockType(this.mob, var0, var1, var2);
    float var13 = this.mob.getPathfindingMalus(var12);
    double var14 = this.mob.getBbWidth() / 2.0D;
    if (var13 >= 0.0F) {
        var8 = getNode(var0, var1, var2);
        var8.type = var12;
        var8.costMalus = Math.max(var8.costMalus, var13);
    }
    if (var7 == BlockPathTypes.FENCE && var8 != null && var8.costMalus >= 0.0F && !canReachWithoutCollision(var8))
        var8 = null;
    if (var12 == BlockPathTypes.WALKABLE || (isAmphibious() && var12 == BlockPathTypes.WATER))
        return var8;
    if ((var8 == null || var8.costMalus < 0.0F) && var3 > 0 && var12 != BlockPathTypes.FENCE && var12 != BlockPathTypes.UNPASSABLE_RAIL && var12 != BlockPathTypes.TRAPDOOR && var12 != BlockPathTypes.POWDER_SNOW) {
        var8 = findAcceptedNode(var0, var1 + 1, var2, var3 - 1, var4, var6, var7);
        if (var8 != null && (var8.type == BlockPathTypes.OPEN || var8.type == BlockPathTypes.WALKABLE) && this.mob.getBbWidth() < 1.0F) {
            double var16 = (var0 - var6.getStepX()) + 0.5D;
            double var18 = (var2 - var6.getStepZ()) + 0.5D;
            AABB var20 = new AABB(var16 - var14, getFloorLevel(this.level, var9.set(var16, (var1 + 1), var18)) + 0.001D, var18 - var14, var16 + var14, this.mob.getBbHeight() + getFloorLevel(this.level, var9.set(var8.x, var8.y, var8.z)) - 0.002D, var18 + var14);
            if (hasCollisions(var20))
                var8 = null;
        }
    }
    if (!isAmphibious() && var12 == BlockPathTypes.WATER && !canFloat()) {
        if (getCachedBlockType(this.mob, var0, var1 - 1, var2) != BlockPathTypes.WATER)
            return var8;
        while (var1 > this.mob.level.getMinBuildHeight()) {
            var1--;
            var12 = getCachedBlockType(this.mob, var0, var1, var2);
            if (var12 == BlockPathTypes.WATER) {
                var8 = getNode(var0, var1, var2);
                var8.type = var12;
                var8.costMalus = Math.max(var8.costMalus, this.mob.getPathfindingMalus(var12));
                continue;
            }
            return var8;
        }
    }
    if (var12 == BlockPathTypes.OPEN) {
        int var16 = 0;
        int var17 = var1;
        while (var12 == BlockPathTypes.OPEN) {
            var1--;
            if (var1 < this.mob.level.getMinBuildHeight()) {
                Node var18 = getNode(var0, var17, var2);
                var18.type = BlockPathTypes.BLOCKED;
                var18.costMalus = -1.0F;
                return var18;
            }
            if (var16++ >= Setting.MC_NAVIGATION_MAX_FALL_DISTANCE.asInt() || var16++ >= this.mob.getMaxFallDistance()) {
                Node var18 = getNode(var0, var1, var2);
                var18.type = BlockPathTypes.BLOCKED;
                var18.costMalus = -1.0F;
                return var18;
            }
            var12 = getCachedBlockType(this.mob, var0, var1, var2);
            var13 = this.mob.getPathfindingMalus(var12);
            if (var12 != BlockPathTypes.OPEN && var13 >= 0.0F) {
                var8 = getNode(var0, var1, var2);
                var8.type = var12;
                var8.costMalus = Math.max(var8.costMalus, var13);
                break;
            }
            if (var13 < 0.0F) {
                Node var18 = getNode(var0, var1, var2);
                var18.type = BlockPathTypes.BLOCKED;
                var18.costMalus = -1.0F;
                return var18;
            }
        }
    }
    if (var12 == BlockPathTypes.FENCE) {
        var8 = getNode(var0, var1, var2);
        var8.closed = true;
        var8.type = var12;
        var8.costMalus = var12.getMalus();
    }
    return var8;
}
Also used : BlockPathTypes(net.minecraft.world.level.pathfinder.BlockPathTypes) Node(net.minecraft.world.level.pathfinder.Node) BlockPos(net.minecraft.core.BlockPos) AABB(net.minecraft.world.phys.AABB)

Aggregations

Node (net.minecraft.world.level.pathfinder.Node)24 BlockPos (net.minecraft.core.BlockPos)16 Path (net.minecraft.world.level.pathfinder.Path)14 BlockPathTypes (net.minecraft.world.level.pathfinder.BlockPathTypes)9 Mob (net.minecraft.world.entity.Mob)8 Lists (com.google.common.collect.Lists)6 List (java.util.List)6 Map (java.util.Map)6 Set (java.util.Set)6 Setting (net.citizensnpcs.Settings.Setting)6 BlockState (net.minecraft.world.level.block.state.BlockState)6 Target (net.minecraft.world.level.pathfinder.Target)6 AABB (net.minecraft.world.phys.AABB)6 PathNavigation (net.minecraft.world.entity.ai.navigation.PathNavigation)5 PathFinder (net.minecraft.world.level.pathfinder.PathFinder)5 Sets (com.google.common.collect.Sets)4 Comparator (java.util.Comparator)4 Optional (java.util.Optional)4 Function (java.util.function.Function)4 Collectors (java.util.stream.Collectors)4