Search in sources :

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

Example 9 with Node

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

the class PlayerNodeEvaluator method getNeighbors.

@Override
public int getNeighbors(Node[] var0, Node var1) {
    int var2 = 0;
    int var3 = 0;
    BlockPathTypes var4 = getCachedBlockType(this.mob, var1.x, var1.y + 1, var1.z);
    BlockPathTypes var5 = getCachedBlockType(this.mob, var1.x, var1.y, var1.z);
    if (this.mob.getPathfindingMalus(var4) >= 0.0F && var5 != BlockPathTypes.STICKY_HONEY)
        var3 = Mth.floor(Math.max(1.0F, this.mob.maxUpStep));
    double var6 = getFloorLevel(new BlockPos(var1.x, var1.y, var1.z));
    Node var8 = findAcceptedNode(var1.x, var1.y, var1.z + 1, var3, var6, Direction.SOUTH, var5);
    if (isNeighborValid(var8, var1))
        var0[var2++] = var8;
    Node var9 = findAcceptedNode(var1.x - 1, var1.y, var1.z, var3, var6, Direction.WEST, var5);
    if (isNeighborValid(var9, var1))
        var0[var2++] = var9;
    Node var10 = findAcceptedNode(var1.x + 1, var1.y, var1.z, var3, var6, Direction.EAST, var5);
    if (isNeighborValid(var10, var1))
        var0[var2++] = var10;
    Node var11 = findAcceptedNode(var1.x, var1.y, var1.z - 1, var3, var6, Direction.NORTH, var5);
    if (isNeighborValid(var11, var1))
        var0[var2++] = var11;
    Node var12 = findAcceptedNode(var1.x - 1, var1.y, var1.z - 1, var3, var6, Direction.NORTH, var5);
    if (isDiagonalValid(var1, var9, var11, var12))
        var0[var2++] = var12;
    Node var13 = findAcceptedNode(var1.x + 1, var1.y, var1.z - 1, var3, var6, Direction.NORTH, var5);
    if (isDiagonalValid(var1, var10, var11, var13))
        var0[var2++] = var13;
    Node var14 = findAcceptedNode(var1.x - 1, var1.y, var1.z + 1, var3, var6, Direction.SOUTH, var5);
    if (isDiagonalValid(var1, var9, var8, var14))
        var0[var2++] = var14;
    Node var15 = findAcceptedNode(var1.x + 1, var1.y, var1.z + 1, var3, var6, Direction.SOUTH, var5);
    if (isDiagonalValid(var1, var10, var8, var15))
        var0[var2++] = var15;
    return var2;
}
Also used : BlockPathTypes(net.minecraft.world.level.pathfinder.BlockPathTypes) Node(net.minecraft.world.level.pathfinder.Node) BlockPos(net.minecraft.core.BlockPos)

Example 10 with Node

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

the class PlayerNodeEvaluator method getStart.

@Override
public Node getStart() {
    BlockPos.MutableBlockPos var1 = new BlockPos.MutableBlockPos();
    int var0 = this.mob.getBlockY();
    BlockState var2 = this.level.getBlockState(var1.set(this.mob.getX(), var0, this.mob.getZ()));
    if (this.mob.canStandOnFluid(var2.getFluidState())) {
        while (this.mob.canStandOnFluid(var2.getFluidState())) {
            var0++;
            var2 = this.level.getBlockState(var1.set(this.mob.getX(), var0, this.mob.getZ()));
        }
        var0--;
    } else if (canFloat() && this.mob.isInWater()) {
        while (var2.is(Blocks.WATER) || var2.getFluidState() == Fluids.WATER.getSource(false)) {
            var0++;
            var2 = this.level.getBlockState(var1.set(this.mob.getX(), var0, this.mob.getZ()));
        }
        var0--;
    } else if (this.mob.isOnGround()) {
        var0 = Mth.floor(this.mob.getY() + 0.5D);
    } else {
        BlockPos blockPos = this.mob.blockPosition();
        while ((this.level.getBlockState(blockPos).isAir() || this.level.getBlockState(blockPos).isPathfindable(this.level, blockPos, PathComputationType.LAND)) && blockPos.getY() > this.mob.level.getMinBuildHeight()) blockPos = blockPos.below();
        var0 = blockPos.above().getY();
    }
    BlockPos var3 = this.mob.blockPosition();
    BlockPathTypes var4 = getCachedBlockType(this.mob, var3.getX(), var0, var3.getZ());
    if (this.mob.getPathfindingMalus(var4) < 0.0F) {
        AABB aABB = this.mob.getBoundingBox();
        if (hasPositiveMalus(var1.set(aABB.minX, var0, aABB.minZ)) || hasPositiveMalus(var1.set(aABB.minX, var0, aABB.maxZ)) || hasPositiveMalus(var1.set(aABB.maxX, var0, aABB.minZ)) || hasPositiveMalus(var1.set(aABB.maxX, var0, aABB.maxZ))) {
            Node var6 = getNode(var1);
            var6.type = getBlockPathType(this.mob, var6.asBlockPos());
            var6.costMalus = this.mob.getPathfindingMalus(var6.type);
            return var6;
        }
    }
    Node var5 = getNode(var3.getX(), var0, var3.getZ());
    var5.type = getBlockPathType(this.mob, var5.asBlockPos());
    var5.costMalus = this.mob.getPathfindingMalus(var5.type);
    return var5;
}
Also used : BlockPathTypes(net.minecraft.world.level.pathfinder.BlockPathTypes) BlockState(net.minecraft.world.level.block.state.BlockState) 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