Search in sources :

Example 21 with Goal

use of net.minecraft.world.entity.ai.goal.Goal in project MagicPlugin by elBukkit.

the class MagicGoal method canContinueToUse.

@Override
public boolean canContinueToUse() {
    boolean interrupt = false;
    boolean continuing = false;
    for (Goal goal : goals) {
        if (goal == currentGoal) {
            boolean canContinue = goal.canContinueToUse();
            if (canContinue) {
                continuing = true;
            } else {
                interrupt = true;
            }
        } else {
            // A higher-priority goal can interrupt
            boolean canUse = goal.canUse();
            if (canUse && !continuing && (currentGoal == null || currentGoal.isInterruptable())) {
                interrupt = true;
            }
        }
        if (interrupt) {
            return false;
        }
    }
    return true;
}
Also used : Goal(net.minecraft.world.entity.ai.goal.Goal)

Example 22 with Goal

use of net.minecraft.world.entity.ai.goal.Goal in project MagicPlugin by elBukkit.

the class MobUtils method getGoal.

private Goal getGoal(GoalType goalType, Entity entity, Mob mob, ConfigurationSection config) {
    final String classType = config.getString("entity_class", "player");
    final double speed = config.getDouble("speed", 1);
    final double sprintSpeed = config.getDouble("sprint_speed", 1);
    final float distance = (float) config.getDouble("distance", 16);
    final boolean doors = config.getBoolean("doors", true);
    final boolean interruptable = config.getBoolean("interruptable", true);
    final boolean see = config.getBoolean("see", true);
    final boolean reach = config.getBoolean("reach", false);
    final float startDistance = (float) config.getDouble("start_distance", 5);
    final float stopDistance = (float) config.getDouble("stop_distance", 1);
    final float radius = (float) config.getDouble("radius", 16);
    final PathfinderMob pathfinder = mob instanceof PathfinderMob ? (PathfinderMob) mob : null;
    int interval = config.getInt("interval", 1000);
    // Interval is specified in ms, but needed in ticks
    interval = interval / 50;
    MageController controller = platform.getController();
    Mage mage;
    List<Goal> goals;
    switch(goalType) {
        case AVOID_ENTITY:
            if (pathfinder == null)
                return null;
            return new AvoidEntityGoal<>(pathfinder, getMobClass(classType), distance, sprintSpeed, sprintSpeed);
        case BEG:
            if (mob instanceof Wolf) {
                return new BegGoal((Wolf) mob, distance);
            }
            return null;
        case BREAK_DOOR:
            return new BreakDoorGoal(mob, difficulty -> true);
        case BREATHE_AIR:
            if (pathfinder == null)
                return null;
            return new BreathAirGoal(pathfinder);
        case BREED:
            if (mob instanceof Animal) {
                return new BreedGoal((Animal) mob, speed);
            }
            return null;
        case EAT_BLOCK:
            return new EatBlockGoal(mob);
        case FLEE_SUN:
            if (pathfinder == null)
                return null;
            return new FleeSunGoal(pathfinder, speed);
        case FLOAT:
            return new FloatGoal(mob);
        case FOLLOW_BOAT:
            if (pathfinder == null)
                return null;
            return new FollowBoatGoal(pathfinder);
        case FOLLOW_FLOCK_LEADER:
            if (mob instanceof AbstractSchoolingFish) {
                return new FollowFlockLeaderGoal((AbstractSchoolingFish) mob);
            }
            return null;
        case FOLLOW_MOB:
            return new FollowMobGoal(mob, speed, distance, radius);
        case FOLLOW_OWNER:
            if (mob instanceof TamableAnimal) {
                return new FollowOwnerGoal((TamableAnimal) mob, speed, startDistance, stopDistance, config.getBoolean("fly", false));
            }
        // Intentional fall-through
        case MAGIC_FOLLOW_OWNER:
            return new MagicFollowOwnerGoal(platform, mob, speed, startDistance, stopDistance, interval, config);
        case FOLLOW_PARENT:
            if (mob instanceof Animal) {
                return new FollowParentGoal((Animal) mob, speed);
            }
            return null;
        case GOLEM_RANDOM_STROLL_IN_VILLAGE:
            if (pathfinder == null)
                return null;
            return new GolemRandomStrollInVillageGoal(pathfinder, speed);
        case INTERACT:
            return new InteractGoal(mob, getMobClass(classType), distance, (float) config.getDouble("probability", 1));
        case LAND_ON_OWNERS_SHOULDER:
            if (mob instanceof ShoulderRidingEntity) {
                return new LandOnOwnersShoulderGoal((ShoulderRidingEntity) mob);
            }
            return null;
        case LEAP_AT_TARGET:
            return new LeapAtTargetGoal(mob, (float) config.getDouble("y_offset", 0.4));
        case LOOK_AT_PLAYER:
            return new LookAtPlayerGoal(mob, getMobClass(classType), distance, (float) config.getDouble("probability", 1), config.getBoolean("horizontal"));
        case MELEE_ATTACK:
            if (pathfinder == null)
                return null;
            return new MeleeAttackGoal(pathfinder, speed, config.getBoolean("follow", true));
        case MOVE_BACK_TO_VILLAGE:
            if (pathfinder == null)
                return null;
            return new MoveBackToVillageGoal(pathfinder, speed, config.getBoolean("check", true));
        case MOVE_THROUGH_VILLAGE:
            if (pathfinder == null)
                return null;
            return new MoveThroughVillageGoal(pathfinder, speed, config.getBoolean("night", true), (int) distance, (BooleanSupplier) () -> doors);
        case MOVE_TOWARDS_RESTRICTION:
            if (pathfinder == null)
                return null;
            return new MoveTowardsRestrictionGoal(pathfinder, speed);
        case MOVE_TOWARDS_TARGET:
            if (pathfinder == null)
                return null;
            return new MoveTowardsTargetGoal(pathfinder, speed, distance);
        case OCELOT_ATTACK:
            return new OcelotAttackGoal(mob);
        case OFFER_FLOWER:
            if (mob instanceof IronGolem) {
                return new OfferFlowerGoal((IronGolem) mob);
            }
            return null;
        case OPEN_DOOR:
            return new OpenDoorGoal(mob, config.getBoolean("close", false));
        case PANIC_FIRE:
            if (pathfinder == null)
                return null;
            return new PanicGoal(pathfinder, speed);
        case PANIC:
        case MAGIC_PANIC:
            if (pathfinder == null)
                return null;
            return new MagicPanicGoal(pathfinder, speed, config.getInt("panic", 3000), config.getInt("calm", 5000), interruptable);
        case RANDOM_LOOK_AROUND:
            return new RandomLookAroundGoal(mob);
        case RANDOM_STROLL:
            if (pathfinder == null)
                return null;
            return new RandomStrollGoal(pathfinder, speed, interval);
        case RANDOM_SWIMMING:
            if (pathfinder == null)
                return null;
            return new RandomSwimmingGoal(pathfinder, speed, interval);
        case RESTRICT_SUN:
            if (pathfinder == null)
                return null;
            return new RestrictSunGoal(pathfinder);
        case RUN_AROUND_LIKE_CRAZY:
            if (mob instanceof Horse) {
                return new RunAroundLikeCrazyGoal((Horse) mob, speed);
            }
            return null;
        case STROLL_THROUGH_VILLAGE:
            if (pathfinder == null)
                return null;
            return new StrollThroughVillageGoal(pathfinder, interval);
        case SWELL:
            if (mob instanceof Creeper) {
                return new SwellGoal((Creeper) mob);
            }
            return null;
        case TEMPT:
            if (pathfinder == null)
                return null;
            String itemKey = config.getString("item", "EMERALD");
            try {
                Material material = Material.valueOf(itemKey.toUpperCase());
                org.bukkit.inventory.ItemStack itemStack = new org.bukkit.inventory.ItemStack(material);
                ItemUtils itemUtils = platform.getItemUtils();
                itemStack = itemUtils.makeReal(itemStack);
                ItemStack nms = (ItemStack) itemUtils.getHandle(itemStack);
                if (nms == null) {
                    platform.getLogger().warning("Invalid item from material in temp goal: " + itemKey);
                    return null;
                }
                boolean scare = config.getBoolean("scare", false);
                return new TemptGoal(pathfinder, speed, Ingredient.of(nms), scare);
            } catch (Exception ex) {
                platform.getLogger().warning("Invalid material in temp goal: " + itemKey);
                return null;
            }
        case TRY_FIND_WATER:
            if (pathfinder == null)
                return null;
            return new TryFindWaterGoal(pathfinder);
        case WATER_AVOIDING_RANDOM_FLYING:
            if (pathfinder == null)
                return null;
            return new WaterAvoidingRandomFlyingGoal(pathfinder, speed);
        case WATER_AVOIDING_RANDOM_STROLL:
            if (pathfinder == null)
                return null;
            return new WaterAvoidingRandomStrollGoal(pathfinder, speed);
        case ZOMBIE_ATTACK:
            if (mob instanceof Zombie) {
                return new ZombieAttackGoal((Zombie) mob, speed, config.getBoolean("follow", true));
            }
            return null;
        // Target
        case DEFEND_VILLAGE_TARGET:
            if (mob instanceof IronGolem) {
                return new DefendVillageTargetGoal((IronGolem) mob);
            }
            return null;
        case HURT_BY_TARGET:
            if (pathfinder == null)
                return null;
            return new HurtByTargetGoal(pathfinder);
        case NEAREST_ATTACKABLE_TARGET:
            return new NearestAttackableTargetGoal<>(mob, getMobClass(classType), see, reach);
        case OWNER_HURT_BY_TARGET:
            if (mob instanceof TamableAnimal) {
                return new OwnerHurtByTargetGoal((TamableAnimal) mob);
            }
        // Intentional fall-through
        case MAGIC_OWNER_HURT_BY_TARGET:
            return new MagicOwnerHurtByTargetGoal(platform, mob, entity, see, reach);
        case OWNER_HURT_TARGET:
            if (mob instanceof TamableAnimal) {
                return new OwnerHurtTargetGoal((TamableAnimal) mob);
            }
        // Intentional fall-through
        case MAGIC_OWNER_HURT_TARGET:
            return new MagicOwnerHurtTargetGoal(platform, mob, entity, see, reach);
        // Magic add-ons
        case FOLLOW_ENTITY:
        case MAGIC_FOLLOW_MOB:
            Class<? extends LivingEntity> mobClass = getMobClass(classType);
            if (mobClass == null) {
                platform.getLogger().warning("Unsupported entity_class in magic_follow_mob goal: " + classType);
                return null;
            }
            return new MagicFollowMobGoal(mob, speed, radius, distance, interval, mobClass);
        case REQUIREMENT:
        case REQUIREMENTS:
            if (pathfinder == null)
                return null;
            mage = controller.getMage(entity);
            Collection<Requirement> requirements = controller.getRequirements(config);
            goals = getGoals(entity, mob, config, "magic requirement goal");
            return new RequirementsGoal(mage, goals, interruptable, requirements);
        case GROUP:
            goals = getGoals(entity, mob, config, "magic group goal");
            return new MagicGoal(goals, interruptable);
        case TRIGGER:
            mage = controller.getMage(entity);
            goals = getGoals(entity, mob, config, "magic trigger goal");
            return new TriggerGoal(mage, goals, interruptable, config.getString("trigger", "goal"), interval);
        case FIND_OWNER:
            return new MagicFindOwnerGoal(platform, mob, radius, getMobClass(classType));
        case CHECK_OWNER:
            return new MagicCheckOwnerGoal(platform, mob);
        case IDLE:
            return new IdleGoal();
        default:
            platform.getLogger().warning("Unsupported goal type: " + goalType);
            return null;
    }
}
Also used : TryFindWaterGoal(net.minecraft.world.entity.ai.goal.TryFindWaterGoal) TriggerGoal(com.elmakers.mine.bukkit.utility.platform.v1_17_1.goal.TriggerGoal) IdleGoal(com.elmakers.mine.bukkit.utility.platform.v1_17_1.goal.IdleGoal) NearestAttackableTargetGoal(net.minecraft.world.entity.ai.goal.target.NearestAttackableTargetGoal) MagicGoal(com.elmakers.mine.bukkit.utility.platform.v1_17_1.goal.MagicGoal) MageController(com.elmakers.mine.bukkit.api.magic.MageController) AvoidEntityGoal(net.minecraft.world.entity.ai.goal.AvoidEntityGoal) FollowBoatGoal(net.minecraft.world.entity.ai.goal.FollowBoatGoal) StrollThroughVillageGoal(net.minecraft.world.entity.ai.goal.StrollThroughVillageGoal) OcelotAttackGoal(net.minecraft.world.entity.ai.goal.OcelotAttackGoal) MagicOwnerHurtByTargetGoal(com.elmakers.mine.bukkit.utility.platform.v1_17_1.goal.MagicOwnerHurtByTargetGoal) IdleGoal(com.elmakers.mine.bukkit.utility.platform.v1_17_1.goal.IdleGoal) AvoidEntityGoal(net.minecraft.world.entity.ai.goal.AvoidEntityGoal) TriggerGoal(com.elmakers.mine.bukkit.utility.platform.v1_17_1.goal.TriggerGoal) MagicPanicGoal(com.elmakers.mine.bukkit.utility.platform.v1_17_1.goal.MagicPanicGoal) BreedGoal(net.minecraft.world.entity.ai.goal.BreedGoal) FollowMobGoal(net.minecraft.world.entity.ai.goal.FollowMobGoal) LandOnOwnersShoulderGoal(net.minecraft.world.entity.ai.goal.LandOnOwnersShoulderGoal) BreathAirGoal(net.minecraft.world.entity.ai.goal.BreathAirGoal) FloatGoal(net.minecraft.world.entity.ai.goal.FloatGoal) PanicGoal(net.minecraft.world.entity.ai.goal.PanicGoal) OwnerHurtTargetGoal(net.minecraft.world.entity.ai.goal.target.OwnerHurtTargetGoal) WrappedGoal(net.minecraft.world.entity.ai.goal.WrappedGoal) MagicCheckOwnerGoal(com.elmakers.mine.bukkit.utility.platform.v1_17_1.goal.MagicCheckOwnerGoal) FollowOwnerGoal(net.minecraft.world.entity.ai.goal.FollowOwnerGoal) RandomSwimmingGoal(net.minecraft.world.entity.ai.goal.RandomSwimmingGoal) GolemRandomStrollInVillageGoal(net.minecraft.world.entity.ai.goal.GolemRandomStrollInVillageGoal) WaterAvoidingRandomFlyingGoal(net.minecraft.world.entity.ai.goal.WaterAvoidingRandomFlyingGoal) RequirementsGoal(com.elmakers.mine.bukkit.utility.platform.v1_17_1.goal.RequirementsGoal) OpenDoorGoal(net.minecraft.world.entity.ai.goal.OpenDoorGoal) RandomLookAroundGoal(net.minecraft.world.entity.ai.goal.RandomLookAroundGoal) RandomStrollGoal(net.minecraft.world.entity.ai.goal.RandomStrollGoal) TryFindWaterGoal(net.minecraft.world.entity.ai.goal.TryFindWaterGoal) MagicOwnerHurtTargetGoal(com.elmakers.mine.bukkit.utility.platform.v1_17_1.goal.MagicOwnerHurtTargetGoal) MoveTowardsRestrictionGoal(net.minecraft.world.entity.ai.goal.MoveTowardsRestrictionGoal) MagicFindOwnerGoal(com.elmakers.mine.bukkit.utility.platform.v1_17_1.goal.MagicFindOwnerGoal) MoveTowardsTargetGoal(net.minecraft.world.entity.ai.goal.MoveTowardsTargetGoal) DefendVillageTargetGoal(net.minecraft.world.entity.ai.goal.target.DefendVillageTargetGoal) EatBlockGoal(net.minecraft.world.entity.ai.goal.EatBlockGoal) FollowParentGoal(net.minecraft.world.entity.ai.goal.FollowParentGoal) OfferFlowerGoal(net.minecraft.world.entity.ai.goal.OfferFlowerGoal) OwnerHurtByTargetGoal(net.minecraft.world.entity.ai.goal.target.OwnerHurtByTargetGoal) TemptGoal(net.minecraft.world.entity.ai.goal.TemptGoal) MeleeAttackGoal(net.minecraft.world.entity.ai.goal.MeleeAttackGoal) FollowBoatGoal(net.minecraft.world.entity.ai.goal.FollowBoatGoal) RestrictSunGoal(net.minecraft.world.entity.ai.goal.RestrictSunGoal) NearestAttackableTargetGoal(net.minecraft.world.entity.ai.goal.target.NearestAttackableTargetGoal) TargetGoal(net.minecraft.world.entity.ai.goal.target.TargetGoal) LookAtPlayerGoal(net.minecraft.world.entity.ai.goal.LookAtPlayerGoal) MoveThroughVillageGoal(net.minecraft.world.entity.ai.goal.MoveThroughVillageGoal) LeapAtTargetGoal(net.minecraft.world.entity.ai.goal.LeapAtTargetGoal) HurtByTargetGoal(net.minecraft.world.entity.ai.goal.target.HurtByTargetGoal) BreakDoorGoal(net.minecraft.world.entity.ai.goal.BreakDoorGoal) SwellGoal(net.minecraft.world.entity.ai.goal.SwellGoal) Goal(net.minecraft.world.entity.ai.goal.Goal) RunAroundLikeCrazyGoal(net.minecraft.world.entity.ai.goal.RunAroundLikeCrazyGoal) ZombieAttackGoal(net.minecraft.world.entity.ai.goal.ZombieAttackGoal) MagicFollowMobGoal(com.elmakers.mine.bukkit.utility.platform.v1_17_1.goal.MagicFollowMobGoal) FleeSunGoal(net.minecraft.world.entity.ai.goal.FleeSunGoal) MagicGoal(com.elmakers.mine.bukkit.utility.platform.v1_17_1.goal.MagicGoal) MagicFollowOwnerGoal(com.elmakers.mine.bukkit.utility.platform.v1_17_1.goal.MagicFollowOwnerGoal) FollowFlockLeaderGoal(net.minecraft.world.entity.ai.goal.FollowFlockLeaderGoal) MoveBackToVillageGoal(net.minecraft.world.entity.ai.goal.MoveBackToVillageGoal) WaterAvoidingRandomStrollGoal(net.minecraft.world.entity.ai.goal.WaterAvoidingRandomStrollGoal) BegGoal(net.minecraft.world.entity.ai.goal.BegGoal) InteractGoal(net.minecraft.world.entity.ai.goal.InteractGoal) BegGoal(net.minecraft.world.entity.ai.goal.BegGoal) MeleeAttackGoal(net.minecraft.world.entity.ai.goal.MeleeAttackGoal) RestrictSunGoal(net.minecraft.world.entity.ai.goal.RestrictSunGoal) Horse(net.minecraft.world.entity.animal.horse.Horse) ZombieHorse(net.minecraft.world.entity.animal.horse.ZombieHorse) AbstractChestedHorse(net.minecraft.world.entity.animal.horse.AbstractChestedHorse) AbstractHorse(net.minecraft.world.entity.animal.horse.AbstractHorse) ZombieAttackGoal(net.minecraft.world.entity.ai.goal.ZombieAttackGoal) InteractGoal(net.minecraft.world.entity.ai.goal.InteractGoal) BreathAirGoal(net.minecraft.world.entity.ai.goal.BreathAirGoal) MoveBackToVillageGoal(net.minecraft.world.entity.ai.goal.MoveBackToVillageGoal) Zombie(net.minecraft.world.entity.monster.Zombie) MagicOwnerHurtByTargetGoal(com.elmakers.mine.bukkit.utility.platform.v1_17_1.goal.MagicOwnerHurtByTargetGoal) MagicOwnerHurtByTargetGoal(com.elmakers.mine.bukkit.utility.platform.v1_17_1.goal.MagicOwnerHurtByTargetGoal) OwnerHurtByTargetGoal(net.minecraft.world.entity.ai.goal.target.OwnerHurtByTargetGoal) MagicOwnerHurtTargetGoal(com.elmakers.mine.bukkit.utility.platform.v1_17_1.goal.MagicOwnerHurtTargetGoal) MagicCheckOwnerGoal(com.elmakers.mine.bukkit.utility.platform.v1_17_1.goal.MagicCheckOwnerGoal) Requirement(com.elmakers.mine.bukkit.api.requirements.Requirement) Mage(com.elmakers.mine.bukkit.api.magic.Mage) Animal(net.minecraft.world.entity.animal.Animal) TamableAnimal(net.minecraft.world.entity.TamableAnimal) MagicFollowMobGoal(com.elmakers.mine.bukkit.utility.platform.v1_17_1.goal.MagicFollowMobGoal) LandOnOwnersShoulderGoal(net.minecraft.world.entity.ai.goal.LandOnOwnersShoulderGoal) BreedGoal(net.minecraft.world.entity.ai.goal.BreedGoal) LeapAtTargetGoal(net.minecraft.world.entity.ai.goal.LeapAtTargetGoal) MoveThroughVillageGoal(net.minecraft.world.entity.ai.goal.MoveThroughVillageGoal) ItemStack(net.minecraft.world.item.ItemStack) FollowOwnerGoal(net.minecraft.world.entity.ai.goal.FollowOwnerGoal) MagicFollowOwnerGoal(com.elmakers.mine.bukkit.utility.platform.v1_17_1.goal.MagicFollowOwnerGoal) MoveTowardsTargetGoal(net.minecraft.world.entity.ai.goal.MoveTowardsTargetGoal) DefendVillageTargetGoal(net.minecraft.world.entity.ai.goal.target.DefendVillageTargetGoal) MagicFollowOwnerGoal(com.elmakers.mine.bukkit.utility.platform.v1_17_1.goal.MagicFollowOwnerGoal) RunAroundLikeCrazyGoal(net.minecraft.world.entity.ai.goal.RunAroundLikeCrazyGoal) WaterAvoidingRandomStrollGoal(net.minecraft.world.entity.ai.goal.WaterAvoidingRandomStrollGoal) MoveTowardsRestrictionGoal(net.minecraft.world.entity.ai.goal.MoveTowardsRestrictionGoal) StrollThroughVillageGoal(net.minecraft.world.entity.ai.goal.StrollThroughVillageGoal) SwellGoal(net.minecraft.world.entity.ai.goal.SwellGoal) TamableAnimal(net.minecraft.world.entity.TamableAnimal) Creeper(net.minecraft.world.entity.monster.Creeper) TemptGoal(net.minecraft.world.entity.ai.goal.TemptGoal) FollowFlockLeaderGoal(net.minecraft.world.entity.ai.goal.FollowFlockLeaderGoal) OwnerHurtTargetGoal(net.minecraft.world.entity.ai.goal.target.OwnerHurtTargetGoal) MagicOwnerHurtTargetGoal(com.elmakers.mine.bukkit.utility.platform.v1_17_1.goal.MagicOwnerHurtTargetGoal) IronGolem(net.minecraft.world.entity.animal.IronGolem) FleeSunGoal(net.minecraft.world.entity.ai.goal.FleeSunGoal) ShoulderRidingEntity(net.minecraft.world.entity.animal.ShoulderRidingEntity) EatBlockGoal(net.minecraft.world.entity.ai.goal.EatBlockGoal) LookAtPlayerGoal(net.minecraft.world.entity.ai.goal.LookAtPlayerGoal) Wolf(net.minecraft.world.entity.animal.Wolf) OpenDoorGoal(net.minecraft.world.entity.ai.goal.OpenDoorGoal) RandomStrollGoal(net.minecraft.world.entity.ai.goal.RandomStrollGoal) WaterAvoidingRandomStrollGoal(net.minecraft.world.entity.ai.goal.WaterAvoidingRandomStrollGoal) BreakDoorGoal(net.minecraft.world.entity.ai.goal.BreakDoorGoal) FollowParentGoal(net.minecraft.world.entity.ai.goal.FollowParentGoal) MagicOwnerHurtByTargetGoal(com.elmakers.mine.bukkit.utility.platform.v1_17_1.goal.MagicOwnerHurtByTargetGoal) OwnerHurtByTargetGoal(net.minecraft.world.entity.ai.goal.target.OwnerHurtByTargetGoal) HurtByTargetGoal(net.minecraft.world.entity.ai.goal.target.HurtByTargetGoal) GolemRandomStrollInVillageGoal(net.minecraft.world.entity.ai.goal.GolemRandomStrollInVillageGoal) Material(org.bukkit.Material) WaterAvoidingRandomFlyingGoal(net.minecraft.world.entity.ai.goal.WaterAvoidingRandomFlyingGoal) MagicPanicGoal(com.elmakers.mine.bukkit.utility.platform.v1_17_1.goal.MagicPanicGoal) PanicGoal(net.minecraft.world.entity.ai.goal.PanicGoal) MagicPanicGoal(com.elmakers.mine.bukkit.utility.platform.v1_17_1.goal.MagicPanicGoal) RandomLookAroundGoal(net.minecraft.world.entity.ai.goal.RandomLookAroundGoal) MagicFindOwnerGoal(com.elmakers.mine.bukkit.utility.platform.v1_17_1.goal.MagicFindOwnerGoal) RequirementsGoal(com.elmakers.mine.bukkit.utility.platform.v1_17_1.goal.RequirementsGoal) OcelotAttackGoal(net.minecraft.world.entity.ai.goal.OcelotAttackGoal) AbstractSchoolingFish(net.minecraft.world.entity.animal.AbstractSchoolingFish) FollowMobGoal(net.minecraft.world.entity.ai.goal.FollowMobGoal) MagicFollowMobGoal(com.elmakers.mine.bukkit.utility.platform.v1_17_1.goal.MagicFollowMobGoal) RandomSwimmingGoal(net.minecraft.world.entity.ai.goal.RandomSwimmingGoal) PathfinderMob(net.minecraft.world.entity.PathfinderMob) ItemUtils(com.elmakers.mine.bukkit.utility.platform.ItemUtils) FloatGoal(net.minecraft.world.entity.ai.goal.FloatGoal) OfferFlowerGoal(net.minecraft.world.entity.ai.goal.OfferFlowerGoal)

Example 23 with Goal

use of net.minecraft.world.entity.ai.goal.Goal in project MagicPlugin by elBukkit.

the class MobUtils method addGoal.

protected boolean addGoal(GoalSelector selector, Mob mob, Entity entity, GoalType goalType, int priority, ConfigurationSection config) {
    try {
        Goal goal = getGoal(goalType, entity, mob, config);
        if (goal == null) {
            return false;
        }
        selector.addGoal(priority, goal);
    } catch (Exception ex) {
        platform.getLogger().log(Level.WARNING, "Error creating goal: " + goalType + " on " + entity.getType(), ex);
        return false;
    }
    return true;
}
Also used : StrollThroughVillageGoal(net.minecraft.world.entity.ai.goal.StrollThroughVillageGoal) OcelotAttackGoal(net.minecraft.world.entity.ai.goal.OcelotAttackGoal) MagicOwnerHurtByTargetGoal(com.elmakers.mine.bukkit.utility.platform.v1_17_1.goal.MagicOwnerHurtByTargetGoal) IdleGoal(com.elmakers.mine.bukkit.utility.platform.v1_17_1.goal.IdleGoal) AvoidEntityGoal(net.minecraft.world.entity.ai.goal.AvoidEntityGoal) TriggerGoal(com.elmakers.mine.bukkit.utility.platform.v1_17_1.goal.TriggerGoal) MagicPanicGoal(com.elmakers.mine.bukkit.utility.platform.v1_17_1.goal.MagicPanicGoal) BreedGoal(net.minecraft.world.entity.ai.goal.BreedGoal) FollowMobGoal(net.minecraft.world.entity.ai.goal.FollowMobGoal) LandOnOwnersShoulderGoal(net.minecraft.world.entity.ai.goal.LandOnOwnersShoulderGoal) BreathAirGoal(net.minecraft.world.entity.ai.goal.BreathAirGoal) FloatGoal(net.minecraft.world.entity.ai.goal.FloatGoal) PanicGoal(net.minecraft.world.entity.ai.goal.PanicGoal) OwnerHurtTargetGoal(net.minecraft.world.entity.ai.goal.target.OwnerHurtTargetGoal) WrappedGoal(net.minecraft.world.entity.ai.goal.WrappedGoal) MagicCheckOwnerGoal(com.elmakers.mine.bukkit.utility.platform.v1_17_1.goal.MagicCheckOwnerGoal) FollowOwnerGoal(net.minecraft.world.entity.ai.goal.FollowOwnerGoal) RandomSwimmingGoal(net.minecraft.world.entity.ai.goal.RandomSwimmingGoal) GolemRandomStrollInVillageGoal(net.minecraft.world.entity.ai.goal.GolemRandomStrollInVillageGoal) WaterAvoidingRandomFlyingGoal(net.minecraft.world.entity.ai.goal.WaterAvoidingRandomFlyingGoal) RequirementsGoal(com.elmakers.mine.bukkit.utility.platform.v1_17_1.goal.RequirementsGoal) OpenDoorGoal(net.minecraft.world.entity.ai.goal.OpenDoorGoal) RandomLookAroundGoal(net.minecraft.world.entity.ai.goal.RandomLookAroundGoal) RandomStrollGoal(net.minecraft.world.entity.ai.goal.RandomStrollGoal) TryFindWaterGoal(net.minecraft.world.entity.ai.goal.TryFindWaterGoal) MagicOwnerHurtTargetGoal(com.elmakers.mine.bukkit.utility.platform.v1_17_1.goal.MagicOwnerHurtTargetGoal) MoveTowardsRestrictionGoal(net.minecraft.world.entity.ai.goal.MoveTowardsRestrictionGoal) MagicFindOwnerGoal(com.elmakers.mine.bukkit.utility.platform.v1_17_1.goal.MagicFindOwnerGoal) MoveTowardsTargetGoal(net.minecraft.world.entity.ai.goal.MoveTowardsTargetGoal) DefendVillageTargetGoal(net.minecraft.world.entity.ai.goal.target.DefendVillageTargetGoal) EatBlockGoal(net.minecraft.world.entity.ai.goal.EatBlockGoal) FollowParentGoal(net.minecraft.world.entity.ai.goal.FollowParentGoal) OfferFlowerGoal(net.minecraft.world.entity.ai.goal.OfferFlowerGoal) OwnerHurtByTargetGoal(net.minecraft.world.entity.ai.goal.target.OwnerHurtByTargetGoal) TemptGoal(net.minecraft.world.entity.ai.goal.TemptGoal) MeleeAttackGoal(net.minecraft.world.entity.ai.goal.MeleeAttackGoal) FollowBoatGoal(net.minecraft.world.entity.ai.goal.FollowBoatGoal) RestrictSunGoal(net.minecraft.world.entity.ai.goal.RestrictSunGoal) NearestAttackableTargetGoal(net.minecraft.world.entity.ai.goal.target.NearestAttackableTargetGoal) TargetGoal(net.minecraft.world.entity.ai.goal.target.TargetGoal) LookAtPlayerGoal(net.minecraft.world.entity.ai.goal.LookAtPlayerGoal) MoveThroughVillageGoal(net.minecraft.world.entity.ai.goal.MoveThroughVillageGoal) LeapAtTargetGoal(net.minecraft.world.entity.ai.goal.LeapAtTargetGoal) HurtByTargetGoal(net.minecraft.world.entity.ai.goal.target.HurtByTargetGoal) BreakDoorGoal(net.minecraft.world.entity.ai.goal.BreakDoorGoal) SwellGoal(net.minecraft.world.entity.ai.goal.SwellGoal) Goal(net.minecraft.world.entity.ai.goal.Goal) RunAroundLikeCrazyGoal(net.minecraft.world.entity.ai.goal.RunAroundLikeCrazyGoal) ZombieAttackGoal(net.minecraft.world.entity.ai.goal.ZombieAttackGoal) MagicFollowMobGoal(com.elmakers.mine.bukkit.utility.platform.v1_17_1.goal.MagicFollowMobGoal) FleeSunGoal(net.minecraft.world.entity.ai.goal.FleeSunGoal) MagicGoal(com.elmakers.mine.bukkit.utility.platform.v1_17_1.goal.MagicGoal) MagicFollowOwnerGoal(com.elmakers.mine.bukkit.utility.platform.v1_17_1.goal.MagicFollowOwnerGoal) FollowFlockLeaderGoal(net.minecraft.world.entity.ai.goal.FollowFlockLeaderGoal) MoveBackToVillageGoal(net.minecraft.world.entity.ai.goal.MoveBackToVillageGoal) WaterAvoidingRandomStrollGoal(net.minecraft.world.entity.ai.goal.WaterAvoidingRandomStrollGoal) BegGoal(net.minecraft.world.entity.ai.goal.BegGoal) InteractGoal(net.minecraft.world.entity.ai.goal.InteractGoal)

Example 24 with Goal

use of net.minecraft.world.entity.ai.goal.Goal in project MagicPlugin by elBukkit.

the class MobUtils method removeGoal.

protected boolean removeGoal(GoalSelector selector, Mob mob, Entity entity, GoalType goalType) {
    // TODO: Is there a cleaner way?
    try {
        Goal targetGoal = getGoal(goalType, entity, mob, new MemoryConfiguration());
        Collection<WrappedGoal> available = selector.getAvailableGoals();
        List<Goal> found = new ArrayList<>();
        for (WrappedGoal wrappedGoal : available) {
            if (targetGoal.getClass().isAssignableFrom(wrappedGoal.getGoal().getClass())) {
                found.add(wrappedGoal.getGoal());
            }
        }
        for (Goal removeGoal : found) {
            selector.removeGoal(removeGoal);
        }
    } catch (Exception ex) {
        platform.getLogger().log(Level.WARNING, "Error removing goal: " + goalType + " from " + entity.getType(), ex);
        return false;
    }
    return true;
}
Also used : StrollThroughVillageGoal(net.minecraft.world.entity.ai.goal.StrollThroughVillageGoal) OcelotAttackGoal(net.minecraft.world.entity.ai.goal.OcelotAttackGoal) MagicOwnerHurtByTargetGoal(com.elmakers.mine.bukkit.utility.platform.v1_17_1.goal.MagicOwnerHurtByTargetGoal) IdleGoal(com.elmakers.mine.bukkit.utility.platform.v1_17_1.goal.IdleGoal) AvoidEntityGoal(net.minecraft.world.entity.ai.goal.AvoidEntityGoal) TriggerGoal(com.elmakers.mine.bukkit.utility.platform.v1_17_1.goal.TriggerGoal) MagicPanicGoal(com.elmakers.mine.bukkit.utility.platform.v1_17_1.goal.MagicPanicGoal) BreedGoal(net.minecraft.world.entity.ai.goal.BreedGoal) FollowMobGoal(net.minecraft.world.entity.ai.goal.FollowMobGoal) LandOnOwnersShoulderGoal(net.minecraft.world.entity.ai.goal.LandOnOwnersShoulderGoal) BreathAirGoal(net.minecraft.world.entity.ai.goal.BreathAirGoal) FloatGoal(net.minecraft.world.entity.ai.goal.FloatGoal) PanicGoal(net.minecraft.world.entity.ai.goal.PanicGoal) OwnerHurtTargetGoal(net.minecraft.world.entity.ai.goal.target.OwnerHurtTargetGoal) WrappedGoal(net.minecraft.world.entity.ai.goal.WrappedGoal) MagicCheckOwnerGoal(com.elmakers.mine.bukkit.utility.platform.v1_17_1.goal.MagicCheckOwnerGoal) FollowOwnerGoal(net.minecraft.world.entity.ai.goal.FollowOwnerGoal) RandomSwimmingGoal(net.minecraft.world.entity.ai.goal.RandomSwimmingGoal) GolemRandomStrollInVillageGoal(net.minecraft.world.entity.ai.goal.GolemRandomStrollInVillageGoal) WaterAvoidingRandomFlyingGoal(net.minecraft.world.entity.ai.goal.WaterAvoidingRandomFlyingGoal) RequirementsGoal(com.elmakers.mine.bukkit.utility.platform.v1_17_1.goal.RequirementsGoal) OpenDoorGoal(net.minecraft.world.entity.ai.goal.OpenDoorGoal) RandomLookAroundGoal(net.minecraft.world.entity.ai.goal.RandomLookAroundGoal) RandomStrollGoal(net.minecraft.world.entity.ai.goal.RandomStrollGoal) TryFindWaterGoal(net.minecraft.world.entity.ai.goal.TryFindWaterGoal) MagicOwnerHurtTargetGoal(com.elmakers.mine.bukkit.utility.platform.v1_17_1.goal.MagicOwnerHurtTargetGoal) MoveTowardsRestrictionGoal(net.minecraft.world.entity.ai.goal.MoveTowardsRestrictionGoal) MagicFindOwnerGoal(com.elmakers.mine.bukkit.utility.platform.v1_17_1.goal.MagicFindOwnerGoal) MoveTowardsTargetGoal(net.minecraft.world.entity.ai.goal.MoveTowardsTargetGoal) DefendVillageTargetGoal(net.minecraft.world.entity.ai.goal.target.DefendVillageTargetGoal) EatBlockGoal(net.minecraft.world.entity.ai.goal.EatBlockGoal) FollowParentGoal(net.minecraft.world.entity.ai.goal.FollowParentGoal) OfferFlowerGoal(net.minecraft.world.entity.ai.goal.OfferFlowerGoal) OwnerHurtByTargetGoal(net.minecraft.world.entity.ai.goal.target.OwnerHurtByTargetGoal) TemptGoal(net.minecraft.world.entity.ai.goal.TemptGoal) MeleeAttackGoal(net.minecraft.world.entity.ai.goal.MeleeAttackGoal) FollowBoatGoal(net.minecraft.world.entity.ai.goal.FollowBoatGoal) RestrictSunGoal(net.minecraft.world.entity.ai.goal.RestrictSunGoal) NearestAttackableTargetGoal(net.minecraft.world.entity.ai.goal.target.NearestAttackableTargetGoal) TargetGoal(net.minecraft.world.entity.ai.goal.target.TargetGoal) LookAtPlayerGoal(net.minecraft.world.entity.ai.goal.LookAtPlayerGoal) MoveThroughVillageGoal(net.minecraft.world.entity.ai.goal.MoveThroughVillageGoal) LeapAtTargetGoal(net.minecraft.world.entity.ai.goal.LeapAtTargetGoal) HurtByTargetGoal(net.minecraft.world.entity.ai.goal.target.HurtByTargetGoal) BreakDoorGoal(net.minecraft.world.entity.ai.goal.BreakDoorGoal) SwellGoal(net.minecraft.world.entity.ai.goal.SwellGoal) Goal(net.minecraft.world.entity.ai.goal.Goal) RunAroundLikeCrazyGoal(net.minecraft.world.entity.ai.goal.RunAroundLikeCrazyGoal) ZombieAttackGoal(net.minecraft.world.entity.ai.goal.ZombieAttackGoal) MagicFollowMobGoal(com.elmakers.mine.bukkit.utility.platform.v1_17_1.goal.MagicFollowMobGoal) FleeSunGoal(net.minecraft.world.entity.ai.goal.FleeSunGoal) MagicGoal(com.elmakers.mine.bukkit.utility.platform.v1_17_1.goal.MagicGoal) MagicFollowOwnerGoal(com.elmakers.mine.bukkit.utility.platform.v1_17_1.goal.MagicFollowOwnerGoal) FollowFlockLeaderGoal(net.minecraft.world.entity.ai.goal.FollowFlockLeaderGoal) MoveBackToVillageGoal(net.minecraft.world.entity.ai.goal.MoveBackToVillageGoal) WaterAvoidingRandomStrollGoal(net.minecraft.world.entity.ai.goal.WaterAvoidingRandomStrollGoal) BegGoal(net.minecraft.world.entity.ai.goal.BegGoal) InteractGoal(net.minecraft.world.entity.ai.goal.InteractGoal) ArrayList(java.util.ArrayList) MemoryConfiguration(org.bukkit.configuration.MemoryConfiguration) WrappedGoal(net.minecraft.world.entity.ai.goal.WrappedGoal)

Example 25 with Goal

use of net.minecraft.world.entity.ai.goal.Goal in project MagicPlugin by elBukkit.

the class MobUtils method getGoals.

private List<Goal> getGoals(Entity entity, Mob mob, ConfigurationSection config, String logContext) {
    List<Goal> goals = new ArrayList<>();
    List<GoalConfiguration> goalConfigurations = GoalConfiguration.fromList(config, "goals", platform.getLogger(), logContext);
    if (goalConfigurations != null) {
        Collections.sort(goalConfigurations);
        for (GoalConfiguration goalConfig : goalConfigurations) {
            try {
                Goal goal = getGoal(goalConfig.getGoalType(), entity, mob, goalConfig.getConfiguration());
                if (goal != null) {
                    goals.add(goal);
                }
            } catch (Exception ex) {
                platform.getLogger().log(Level.WARNING, "Error creating goal: " + goalConfig.getGoalType() + " on mob " + entity.getType(), ex);
            }
        }
    }
    if (goals.isEmpty()) {
        goals.add(new IdleGoal());
    }
    return goals;
}
Also used : GoalConfiguration(com.elmakers.mine.bukkit.mob.GoalConfiguration) StrollThroughVillageGoal(net.minecraft.world.entity.ai.goal.StrollThroughVillageGoal) OcelotAttackGoal(net.minecraft.world.entity.ai.goal.OcelotAttackGoal) MagicOwnerHurtByTargetGoal(com.elmakers.mine.bukkit.utility.platform.v1_17_1.goal.MagicOwnerHurtByTargetGoal) IdleGoal(com.elmakers.mine.bukkit.utility.platform.v1_17_1.goal.IdleGoal) AvoidEntityGoal(net.minecraft.world.entity.ai.goal.AvoidEntityGoal) TriggerGoal(com.elmakers.mine.bukkit.utility.platform.v1_17_1.goal.TriggerGoal) MagicPanicGoal(com.elmakers.mine.bukkit.utility.platform.v1_17_1.goal.MagicPanicGoal) BreedGoal(net.minecraft.world.entity.ai.goal.BreedGoal) FollowMobGoal(net.minecraft.world.entity.ai.goal.FollowMobGoal) LandOnOwnersShoulderGoal(net.minecraft.world.entity.ai.goal.LandOnOwnersShoulderGoal) BreathAirGoal(net.minecraft.world.entity.ai.goal.BreathAirGoal) FloatGoal(net.minecraft.world.entity.ai.goal.FloatGoal) PanicGoal(net.minecraft.world.entity.ai.goal.PanicGoal) OwnerHurtTargetGoal(net.minecraft.world.entity.ai.goal.target.OwnerHurtTargetGoal) WrappedGoal(net.minecraft.world.entity.ai.goal.WrappedGoal) MagicCheckOwnerGoal(com.elmakers.mine.bukkit.utility.platform.v1_17_1.goal.MagicCheckOwnerGoal) FollowOwnerGoal(net.minecraft.world.entity.ai.goal.FollowOwnerGoal) RandomSwimmingGoal(net.minecraft.world.entity.ai.goal.RandomSwimmingGoal) GolemRandomStrollInVillageGoal(net.minecraft.world.entity.ai.goal.GolemRandomStrollInVillageGoal) WaterAvoidingRandomFlyingGoal(net.minecraft.world.entity.ai.goal.WaterAvoidingRandomFlyingGoal) RequirementsGoal(com.elmakers.mine.bukkit.utility.platform.v1_17_1.goal.RequirementsGoal) OpenDoorGoal(net.minecraft.world.entity.ai.goal.OpenDoorGoal) RandomLookAroundGoal(net.minecraft.world.entity.ai.goal.RandomLookAroundGoal) RandomStrollGoal(net.minecraft.world.entity.ai.goal.RandomStrollGoal) TryFindWaterGoal(net.minecraft.world.entity.ai.goal.TryFindWaterGoal) MagicOwnerHurtTargetGoal(com.elmakers.mine.bukkit.utility.platform.v1_17_1.goal.MagicOwnerHurtTargetGoal) MoveTowardsRestrictionGoal(net.minecraft.world.entity.ai.goal.MoveTowardsRestrictionGoal) MagicFindOwnerGoal(com.elmakers.mine.bukkit.utility.platform.v1_17_1.goal.MagicFindOwnerGoal) MoveTowardsTargetGoal(net.minecraft.world.entity.ai.goal.MoveTowardsTargetGoal) DefendVillageTargetGoal(net.minecraft.world.entity.ai.goal.target.DefendVillageTargetGoal) EatBlockGoal(net.minecraft.world.entity.ai.goal.EatBlockGoal) FollowParentGoal(net.minecraft.world.entity.ai.goal.FollowParentGoal) OfferFlowerGoal(net.minecraft.world.entity.ai.goal.OfferFlowerGoal) OwnerHurtByTargetGoal(net.minecraft.world.entity.ai.goal.target.OwnerHurtByTargetGoal) TemptGoal(net.minecraft.world.entity.ai.goal.TemptGoal) MeleeAttackGoal(net.minecraft.world.entity.ai.goal.MeleeAttackGoal) FollowBoatGoal(net.minecraft.world.entity.ai.goal.FollowBoatGoal) RestrictSunGoal(net.minecraft.world.entity.ai.goal.RestrictSunGoal) NearestAttackableTargetGoal(net.minecraft.world.entity.ai.goal.target.NearestAttackableTargetGoal) TargetGoal(net.minecraft.world.entity.ai.goal.target.TargetGoal) LookAtPlayerGoal(net.minecraft.world.entity.ai.goal.LookAtPlayerGoal) MoveThroughVillageGoal(net.minecraft.world.entity.ai.goal.MoveThroughVillageGoal) LeapAtTargetGoal(net.minecraft.world.entity.ai.goal.LeapAtTargetGoal) HurtByTargetGoal(net.minecraft.world.entity.ai.goal.target.HurtByTargetGoal) BreakDoorGoal(net.minecraft.world.entity.ai.goal.BreakDoorGoal) SwellGoal(net.minecraft.world.entity.ai.goal.SwellGoal) Goal(net.minecraft.world.entity.ai.goal.Goal) RunAroundLikeCrazyGoal(net.minecraft.world.entity.ai.goal.RunAroundLikeCrazyGoal) ZombieAttackGoal(net.minecraft.world.entity.ai.goal.ZombieAttackGoal) MagicFollowMobGoal(com.elmakers.mine.bukkit.utility.platform.v1_17_1.goal.MagicFollowMobGoal) FleeSunGoal(net.minecraft.world.entity.ai.goal.FleeSunGoal) MagicGoal(com.elmakers.mine.bukkit.utility.platform.v1_17_1.goal.MagicGoal) MagicFollowOwnerGoal(com.elmakers.mine.bukkit.utility.platform.v1_17_1.goal.MagicFollowOwnerGoal) FollowFlockLeaderGoal(net.minecraft.world.entity.ai.goal.FollowFlockLeaderGoal) MoveBackToVillageGoal(net.minecraft.world.entity.ai.goal.MoveBackToVillageGoal) WaterAvoidingRandomStrollGoal(net.minecraft.world.entity.ai.goal.WaterAvoidingRandomStrollGoal) BegGoal(net.minecraft.world.entity.ai.goal.BegGoal) InteractGoal(net.minecraft.world.entity.ai.goal.InteractGoal) IdleGoal(com.elmakers.mine.bukkit.utility.platform.v1_17_1.goal.IdleGoal) ArrayList(java.util.ArrayList)

Aggregations

Goal (net.minecraft.world.entity.ai.goal.Goal)28 AvoidEntityGoal (net.minecraft.world.entity.ai.goal.AvoidEntityGoal)20 BegGoal (net.minecraft.world.entity.ai.goal.BegGoal)20 BreakDoorGoal (net.minecraft.world.entity.ai.goal.BreakDoorGoal)20 BreathAirGoal (net.minecraft.world.entity.ai.goal.BreathAirGoal)20 BreedGoal (net.minecraft.world.entity.ai.goal.BreedGoal)20 EatBlockGoal (net.minecraft.world.entity.ai.goal.EatBlockGoal)20 FleeSunGoal (net.minecraft.world.entity.ai.goal.FleeSunGoal)20 FloatGoal (net.minecraft.world.entity.ai.goal.FloatGoal)20 FollowBoatGoal (net.minecraft.world.entity.ai.goal.FollowBoatGoal)20 FollowFlockLeaderGoal (net.minecraft.world.entity.ai.goal.FollowFlockLeaderGoal)20 FollowMobGoal (net.minecraft.world.entity.ai.goal.FollowMobGoal)20 FollowOwnerGoal (net.minecraft.world.entity.ai.goal.FollowOwnerGoal)20 FollowParentGoal (net.minecraft.world.entity.ai.goal.FollowParentGoal)20 GolemRandomStrollInVillageGoal (net.minecraft.world.entity.ai.goal.GolemRandomStrollInVillageGoal)20 InteractGoal (net.minecraft.world.entity.ai.goal.InteractGoal)20 LandOnOwnersShoulderGoal (net.minecraft.world.entity.ai.goal.LandOnOwnersShoulderGoal)20 LeapAtTargetGoal (net.minecraft.world.entity.ai.goal.LeapAtTargetGoal)20 LookAtPlayerGoal (net.minecraft.world.entity.ai.goal.LookAtPlayerGoal)20 MeleeAttackGoal (net.minecraft.world.entity.ai.goal.MeleeAttackGoal)20