use of net.minecraft.world.entity.animal.Wolf in project SpongeCommon by SpongePowered.
the class WolfData method register.
// @formatter:off
public static void register(final DataProviderRegistrator registrator) {
registrator.asMutable(Wolf.class).create(Keys.DYE_COLOR).get(h -> (DyeColor) (Object) h.getCollarColor()).set((h, v) -> h.setCollarColor((net.minecraft.world.item.DyeColor) (Object) v)).create(Keys.IS_BEGGING_FOR_FOOD).get(Wolf::isInterested).set(Wolf::setIsInterested).create(Keys.IS_WET).get(h -> ((WolfAccessor) h).accessor$isWet() || ((WolfAccessor) h).accessor$isShaking()).set((h, v) -> {
final WolfAccessor accessor = (WolfAccessor) h;
accessor.accessor$isWet(v);
accessor.accessor$isShaking(v);
accessor.accessor$shakeAnim(0f);
accessor.accessor$shakeAnimO(0f);
});
}
use of net.minecraft.world.entity.animal.Wolf 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();
case SPIN:
return new SpinGoal(mob, (float) config.getDouble("degrees", 10));
default:
platform.getLogger().warning("Unsupported goal type: " + goalType);
return null;
}
}
use of net.minecraft.world.entity.animal.Wolf 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;
}
}
use of net.minecraft.world.entity.animal.Wolf 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();
case SPIN:
return new SpinGoal(mob, (float) config.getDouble("degrees", 10));
default:
platform.getLogger().warning("Unsupported goal type: " + goalType);
return null;
}
}
use of net.minecraft.world.entity.animal.Wolf 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;
}
}
Aggregations