Paper/Spigot-Server-Patches/0465-Implement-Mob-Goal-API.patch
Jake Potrebic 29bf6cd416 Updated Upstream (CraftBukkit)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing

CraftBukkit Changes:
51e2981b #831: Reload unloaded main worlds correctly
2021-05-12 11:26:31 +02:00

1171 lines
52 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MiniDigger <admin@minidigger.me>
Date: Fri, 3 Jan 2020 16:26:19 +0100
Subject: [PATCH] Implement Mob Goal API
diff --git a/pom.xml b/pom.xml
index 325dc0a46666d5e0cd050fd1fb793c08866c2a43..ab57297272c2d6f3d21067081bcaf8775b8fff09 100644
--- a/pom.xml
+++ b/pom.xml
@@ -149,6 +149,13 @@
<version>1.3</version>
<scope>test</scope>
</dependency>
+ <!-- for vanilla goal scanning -->
+ <dependency>
+ <groupId>io.github.classgraph</groupId>
+ <artifactId>classgraph</artifactId>
+ <version>4.8.47</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<!-- This builds a completely 'ready to start' jar with all dependencies inside -->
diff --git a/src/main/java/com/destroystokyo/paper/entity/ai/MobGoalHelper.java b/src/main/java/com/destroystokyo/paper/entity/ai/MobGoalHelper.java
new file mode 100644
index 0000000000000000000000000000000000000000..f62d0ee49ebda2b0c7a136562b24ee038502d048
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/entity/ai/MobGoalHelper.java
@@ -0,0 +1,530 @@
+package com.destroystokyo.paper.entity.ai;
+
+import com.destroystokyo.paper.entity.RangedEntity;
+import com.destroystokyo.paper.util.set.OptimizedSmallEnumSet;
+import com.google.common.collect.BiMap;
+import com.google.common.collect.HashBiMap;
+import java.lang.reflect.Constructor;
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import net.minecraft.world.entity.EntityAgeable;
+import net.minecraft.world.entity.EntityCreature;
+import net.minecraft.world.entity.EntityFlying;
+import net.minecraft.world.entity.EntityInsentient;
+import net.minecraft.world.entity.EntityTameableAnimal;
+import net.minecraft.world.entity.ai.goal.PathfinderGoal;
+import net.minecraft.world.entity.ambient.EntityAmbient;
+import net.minecraft.world.entity.ambient.EntityBat;
+import net.minecraft.world.entity.animal.EntityAnimal;
+import net.minecraft.world.entity.animal.EntityBee;
+import net.minecraft.world.entity.animal.EntityCat;
+import net.minecraft.world.entity.animal.EntityChicken;
+import net.minecraft.world.entity.animal.EntityCod;
+import net.minecraft.world.entity.animal.EntityCow;
+import net.minecraft.world.entity.animal.EntityDolphin;
+import net.minecraft.world.entity.animal.EntityFish;
+import net.minecraft.world.entity.animal.EntityFishSchool;
+import net.minecraft.world.entity.animal.EntityFox;
+import net.minecraft.world.entity.animal.EntityGolem;
+import net.minecraft.world.entity.animal.EntityIronGolem;
+import net.minecraft.world.entity.animal.EntityMushroomCow;
+import net.minecraft.world.entity.animal.EntityOcelot;
+import net.minecraft.world.entity.animal.EntityPanda;
+import net.minecraft.world.entity.animal.EntityParrot;
+import net.minecraft.world.entity.animal.EntityPerchable;
+import net.minecraft.world.entity.animal.EntityPig;
+import net.minecraft.world.entity.animal.EntityPolarBear;
+import net.minecraft.world.entity.animal.EntityPufferFish;
+import net.minecraft.world.entity.animal.EntityRabbit;
+import net.minecraft.world.entity.animal.EntitySalmon;
+import net.minecraft.world.entity.animal.EntitySheep;
+import net.minecraft.world.entity.animal.EntitySnowman;
+import net.minecraft.world.entity.animal.EntitySquid;
+import net.minecraft.world.entity.animal.EntityTropicalFish;
+import net.minecraft.world.entity.animal.EntityTurtle;
+import net.minecraft.world.entity.animal.EntityWaterAnimal;
+import net.minecraft.world.entity.animal.EntityWolf;
+import net.minecraft.world.entity.animal.horse.EntityHorse;
+import net.minecraft.world.entity.animal.horse.EntityHorseAbstract;
+import net.minecraft.world.entity.animal.horse.EntityHorseChestedAbstract;
+import net.minecraft.world.entity.animal.horse.EntityHorseDonkey;
+import net.minecraft.world.entity.animal.horse.EntityHorseMule;
+import net.minecraft.world.entity.animal.horse.EntityHorseSkeleton;
+import net.minecraft.world.entity.animal.horse.EntityHorseZombie;
+import net.minecraft.world.entity.animal.horse.EntityLlama;
+import net.minecraft.world.entity.animal.horse.EntityLlamaTrader;
+import net.minecraft.world.entity.boss.enderdragon.EntityEnderDragon;
+import net.minecraft.world.entity.boss.wither.EntityWither;
+import net.minecraft.world.entity.monster.EntityBlaze;
+import net.minecraft.world.entity.monster.EntityCaveSpider;
+import net.minecraft.world.entity.monster.EntityCreeper;
+import net.minecraft.world.entity.monster.EntityDrowned;
+import net.minecraft.world.entity.monster.EntityEnderman;
+import net.minecraft.world.entity.monster.EntityEndermite;
+import net.minecraft.world.entity.monster.EntityEvoker;
+import net.minecraft.world.entity.monster.EntityGhast;
+import net.minecraft.world.entity.monster.EntityGiantZombie;
+import net.minecraft.world.entity.monster.EntityGuardian;
+import net.minecraft.world.entity.monster.EntityGuardianElder;
+import net.minecraft.world.entity.monster.EntityIllagerAbstract;
+import net.minecraft.world.entity.monster.EntityIllagerIllusioner;
+import net.minecraft.world.entity.monster.EntityIllagerWizard;
+import net.minecraft.world.entity.monster.EntityMagmaCube;
+import net.minecraft.world.entity.monster.EntityMonster;
+import net.minecraft.world.entity.monster.EntityMonsterPatrolling;
+import net.minecraft.world.entity.monster.EntityPhantom;
+import net.minecraft.world.entity.monster.EntityPigZombie;
+import net.minecraft.world.entity.monster.EntityPillager;
+import net.minecraft.world.entity.monster.EntityRavager;
+import net.minecraft.world.entity.monster.EntityShulker;
+import net.minecraft.world.entity.monster.EntitySilverfish;
+import net.minecraft.world.entity.monster.EntitySkeleton;
+import net.minecraft.world.entity.monster.EntitySkeletonAbstract;
+import net.minecraft.world.entity.monster.EntitySkeletonStray;
+import net.minecraft.world.entity.monster.EntitySkeletonWither;
+import net.minecraft.world.entity.monster.EntitySlime;
+import net.minecraft.world.entity.monster.EntitySpider;
+import net.minecraft.world.entity.monster.EntityStrider;
+import net.minecraft.world.entity.monster.EntityVex;
+import net.minecraft.world.entity.monster.EntityVindicator;
+import net.minecraft.world.entity.monster.EntityWitch;
+import net.minecraft.world.entity.monster.EntityZoglin;
+import net.minecraft.world.entity.monster.EntityZombie;
+import net.minecraft.world.entity.monster.EntityZombieHusk;
+import net.minecraft.world.entity.monster.EntityZombieVillager;
+import net.minecraft.world.entity.monster.IRangedEntity;
+import net.minecraft.world.entity.monster.hoglin.EntityHoglin;
+import net.minecraft.world.entity.monster.piglin.EntityPiglin;
+import net.minecraft.world.entity.monster.piglin.EntityPiglinAbstract;
+import net.minecraft.world.entity.monster.piglin.EntityPiglinBrute;
+import net.minecraft.world.entity.npc.EntityVillager;
+import net.minecraft.world.entity.npc.EntityVillagerAbstract;
+import net.minecraft.world.entity.npc.EntityVillagerTrader;
+import net.minecraft.world.entity.raid.EntityRaider;
+import org.bukkit.NamespacedKey;
+import org.bukkit.entity.AbstractHorse;
+import org.bukkit.entity.AbstractVillager;
+import org.bukkit.entity.Ageable;
+import org.bukkit.entity.Ambient;
+import org.bukkit.entity.Animals;
+import org.bukkit.entity.Bat;
+import org.bukkit.entity.Bee;
+import org.bukkit.entity.Blaze;
+import org.bukkit.entity.Cat;
+import org.bukkit.entity.CaveSpider;
+import org.bukkit.entity.ChestedHorse;
+import org.bukkit.entity.Chicken;
+import org.bukkit.entity.Cod;
+import org.bukkit.entity.Cow;
+import org.bukkit.entity.Creature;
+import org.bukkit.entity.Creeper;
+import org.bukkit.entity.Dolphin;
+import org.bukkit.entity.Donkey;
+import org.bukkit.entity.Drowned;
+import org.bukkit.entity.ElderGuardian;
+import org.bukkit.entity.EnderDragon;
+import org.bukkit.entity.Enderman;
+import org.bukkit.entity.Endermite;
+import org.bukkit.entity.Evoker;
+import org.bukkit.entity.Fish;
+import org.bukkit.entity.Flying;
+import org.bukkit.entity.Fox;
+import org.bukkit.entity.Ghast;
+import org.bukkit.entity.Giant;
+import org.bukkit.entity.Golem;
+import org.bukkit.entity.Guardian;
+import org.bukkit.entity.Hoglin;
+import org.bukkit.entity.Horse;
+import org.bukkit.entity.Husk;
+import org.bukkit.entity.Illager;
+import org.bukkit.entity.Illusioner;
+import org.bukkit.entity.IronGolem;
+import org.bukkit.entity.Llama;
+import org.bukkit.entity.MagmaCube;
+import org.bukkit.entity.Mob;
+import org.bukkit.entity.Monster;
+import org.bukkit.entity.Mule;
+import org.bukkit.entity.MushroomCow;
+import org.bukkit.entity.Ocelot;
+import org.bukkit.entity.Panda;
+import org.bukkit.entity.Parrot;
+import org.bukkit.entity.Phantom;
+import org.bukkit.entity.Pig;
+import org.bukkit.entity.PigZombie;
+import org.bukkit.entity.Piglin;
+import org.bukkit.entity.PiglinAbstract;
+import org.bukkit.entity.PiglinBrute;
+import org.bukkit.entity.Pillager;
+import org.bukkit.entity.PolarBear;
+import org.bukkit.entity.PufferFish;
+import org.bukkit.entity.Rabbit;
+import org.bukkit.entity.Raider;
+import org.bukkit.entity.Ravager;
+import org.bukkit.entity.Salmon;
+import org.bukkit.entity.Sheep;
+import org.bukkit.entity.Shulker;
+import org.bukkit.entity.Silverfish;
+import org.bukkit.entity.Skeleton;
+import org.bukkit.entity.SkeletonHorse;
+import org.bukkit.entity.Slime;
+import org.bukkit.entity.Snowman;
+import org.bukkit.entity.Spellcaster;
+import org.bukkit.entity.Spider;
+import org.bukkit.entity.Squid;
+import org.bukkit.entity.Stray;
+import org.bukkit.entity.Strider;
+import org.bukkit.entity.Tameable;
+import org.bukkit.entity.TraderLlama;
+import org.bukkit.entity.TropicalFish;
+import org.bukkit.entity.Turtle;
+import org.bukkit.entity.Vex;
+import org.bukkit.entity.Villager;
+import org.bukkit.entity.Vindicator;
+import org.bukkit.entity.WanderingTrader;
+import org.bukkit.entity.WaterMob;
+import org.bukkit.entity.Witch;
+import org.bukkit.entity.Wither;
+import org.bukkit.entity.WitherSkeleton;
+import org.bukkit.entity.Wolf;
+import org.bukkit.entity.Zoglin;
+import org.bukkit.entity.Zombie;
+import org.bukkit.entity.ZombieHorse;
+import org.bukkit.entity.ZombieVillager;
+
+public class MobGoalHelper {
+
+ private static final BiMap<String, String> deobfuscationMap = HashBiMap.create();
+ private static final Map<Class<? extends PathfinderGoal>, Class<? extends Mob>> entityClassCache = new HashMap<>();
+ private static final Map<Class<? extends EntityInsentient>, Class<? extends Mob>> bukkitMap = new HashMap<>();
+
+ static final Set<String> ignored = new HashSet<>();
+
+ static {
+ // TODO these kinda should be checked on each release, in case obfuscation changes
+ deobfuscationMap.put("bee_b", "bee_attack");
+ deobfuscationMap.put("bee_c", "bee_become_angry");
+ deobfuscationMap.put("bee_d", "bee_enter_hive");
+ deobfuscationMap.put("bee_e", "bee_go_to_hive");
+ deobfuscationMap.put("bee_f", "bee_go_to_known_flower");
+ deobfuscationMap.put("bee_g", "bee_grow_crop");
+ deobfuscationMap.put("bee_h", "bee_hurt_by_other");
+ deobfuscationMap.put("bee_i", "bee_locate_hive");
+ deobfuscationMap.put("bee_k", "bee_pollinate");
+ deobfuscationMap.put("bee_l", "bee_wander");
+ deobfuscationMap.put("cat_a", "cat_avoid_entity");
+ deobfuscationMap.put("cat_b", "cat_relax_on_owner");
+ deobfuscationMap.put("dolphin_b", "dolphin_swim_to_treasure");
+ deobfuscationMap.put("dolphin_c", "dolphin_swim_with_player");
+ deobfuscationMap.put("dolphin_d", "dolphin_play_with_items");
+ deobfuscationMap.put("drowned_a", "drowned_attack");
+ deobfuscationMap.put("drowned_b", "drowned_goto_beach");
+ deobfuscationMap.put("drowned_c", "drowned_goto_water");
+ deobfuscationMap.put("drowned_e", "drowned_swim_up");
+ deobfuscationMap.put("drowned_f", "drowned_trident_attack");
+ deobfuscationMap.put("enderman_a", "enderman_freeze_when_looked_at");
+ deobfuscationMap.put("evoker_a", "evoker_attack_spell");
+ deobfuscationMap.put("evoker_b", "evoker_cast_spell");
+ deobfuscationMap.put("evoker_c", "evoker_summon_spell");
+ deobfuscationMap.put("evoker_d", "evoker_wololo_spell");
+ deobfuscationMap.put("fish_b", "fish_swim");
+ deobfuscationMap.put("fox_a", "fox_defend_trusted");
+ deobfuscationMap.put("fox_b", "fox_faceplant");
+ deobfuscationMap.put("fox_e", "fox_breed");
+ deobfuscationMap.put("fox_f", "fox_eat_berries");
+ deobfuscationMap.put("fox_g", "fox_float");
+ deobfuscationMap.put("fox_h", "fox_follow_parent");
+ deobfuscationMap.put("fox_j", "fox_look_at_player");
+ deobfuscationMap.put("fox_l", "fox_melee_attack");
+ deobfuscationMap.put("fox_n", "fox_panic");
+ deobfuscationMap.put("fox_o", "fox_pounce");
+ deobfuscationMap.put("fox_p", "fox_search_for_items");
+ deobfuscationMap.put("fox_q", "fox_stroll_through_village");
+ deobfuscationMap.put("fox_r", "fox_perch_and_search");
+ deobfuscationMap.put("fox_s", "fox_seek_shelter");
+ deobfuscationMap.put("fox_t", "fox_sleep");
+ deobfuscationMap.put("fox_u", "fox_stalk_prey");
+ deobfuscationMap.put("illager_abstract_b", "raider_open_door");
+ deobfuscationMap.put("illager_illusioner_a", "illusioner_blindness_spell");
+ deobfuscationMap.put("illager_illusioner_b", "illusioner_mirror_spell");
+ deobfuscationMap.put("illager_wizard_b", "spellcaster_cast_spell");
+ deobfuscationMap.put("llama_a", "llama_attack_wolf");
+ deobfuscationMap.put("llama_c", "llama_hurt_by");
+ deobfuscationMap.put("llama_trader_a", "llamatrader_defended_wandering_trader");
+ deobfuscationMap.put("monster_patrolling_a", "long_distance_patrol");
+ deobfuscationMap.put("ocelot_a", "ocelot_avoid_entity");
+ deobfuscationMap.put("ocelot_b", "ocelot_tempt");
+ deobfuscationMap.put("panda_b", "panda_attack");
+ deobfuscationMap.put("panda_c", "panda_avoid");
+ deobfuscationMap.put("panda_d", "panda_breed");
+ deobfuscationMap.put("panda_e", "panda_hurt_by_target");
+ deobfuscationMap.put("panda_f", "panda_lie_on_back");
+ deobfuscationMap.put("panda_g", "panda_look_at_player");
+ deobfuscationMap.put("panda_i", "panda_panic");
+ deobfuscationMap.put("panda_j", "panda_roll");
+ deobfuscationMap.put("panda_k", "panda_sit");
+ deobfuscationMap.put("panda_l", "panda_sneeze");
+ deobfuscationMap.put("phantom_b", "phantom_attack_player");
+ deobfuscationMap.put("phantom_c", "phantom_attack_strategy");
+ deobfuscationMap.put("phantom_e", "phantom_circle_around_anchor");
+ deobfuscationMap.put("phantom_i", "phantom_sweep_attack");
+ deobfuscationMap.put("polar_bear_a", "polarbear_attack_players");
+ deobfuscationMap.put("polar_bear_b", "polarbear_hurt_by");
+ deobfuscationMap.put("polar_bear_c", "polarbear_melee");
+ deobfuscationMap.put("polar_bear_d", "polarbear_panic");
+ deobfuscationMap.put("puffer_fish_a", "pufferfish_puff");
+ deobfuscationMap.put("raider_a", "raider_hold_ground");
+ deobfuscationMap.put("raider_b", "raider_obtain_banner");
+ deobfuscationMap.put("raider_c", "raider_celebration");
+ deobfuscationMap.put("raider_d", "raider_move_through_village");
+ deobfuscationMap.put("ravager_a", "ravager_melee_attack");
+ deobfuscationMap.put("shulker_a", "shulker_attack");
+ deobfuscationMap.put("shulker_c", "shulker_defense");
+ deobfuscationMap.put("shulker_d", "shulker_nearest");
+ deobfuscationMap.put("shulker_e", "shulker_peek");
+ deobfuscationMap.put("squid_a", "squid_flee");
+ deobfuscationMap.put("skeleton_abstract_1", "skeleton_melee");
+ deobfuscationMap.put("strider_a", "strider_go_to_lava");
+ deobfuscationMap.put("turtle_a", "turtle_breed");
+ deobfuscationMap.put("turtle_b", "turtle_go_home");
+ deobfuscationMap.put("turtle_c", "turtle_goto_water");
+ deobfuscationMap.put("turtle_d", "turtle_lay_egg");
+ deobfuscationMap.put("turtle_f", "turtle_panic");
+ deobfuscationMap.put("turtle_h", "turtle_random_stroll");
+ deobfuscationMap.put("turtle_i", "turtle_tempt");
+ deobfuscationMap.put("turtle_j", "turtle_travel");
+ deobfuscationMap.put("vex_a", "vex_charge_attack");
+ deobfuscationMap.put("vex_b", "vex_copy_target_of_owner");
+ deobfuscationMap.put("vex_d", "vex_random_move");
+ deobfuscationMap.put("villager_trader_a", "villagertrader_wander_to_position");
+ deobfuscationMap.put("vindicator_a", "vindicator_break_door");
+ deobfuscationMap.put("vindicator_b", "vindicator_johnny_attack");
+ deobfuscationMap.put("vindicator_c", "vindicator_melee_attack");
+ deobfuscationMap.put("wither_a", "wither_do_nothing");
+ deobfuscationMap.put("wolf_a", "wolf_avoid_entity");
+ deobfuscationMap.put("zombie_a", "zombie_attack_turtle_egg");
+
+ ignored.add("selector_1");
+ ignored.add("selector_2");
+ ignored.add("wrapped");
+
+ bukkitMap.put(EntityInsentient.class, Mob.class);
+ bukkitMap.put(EntityAgeable.class, Ageable.class);
+ bukkitMap.put(EntityAmbient.class, Ambient.class);
+ bukkitMap.put(EntityAnimal.class, Animals.class);
+ bukkitMap.put(EntityBat.class, Bat.class);
+ bukkitMap.put(EntityBee.class, Bee.class);
+ bukkitMap.put(EntityBlaze.class, Blaze.class);
+ bukkitMap.put(EntityCat.class, Cat.class);
+ bukkitMap.put(EntityCaveSpider.class, CaveSpider.class);
+ bukkitMap.put(EntityChicken.class, Chicken.class);
+ bukkitMap.put(EntityCod.class, Cod.class);
+ bukkitMap.put(EntityCow.class, Cow.class);
+ bukkitMap.put(EntityCreature.class, Creature.class);
+ bukkitMap.put(EntityCreeper.class, Creeper.class);
+ bukkitMap.put(EntityDolphin.class, Dolphin.class);
+ bukkitMap.put(EntityDrowned.class, Drowned.class);
+ bukkitMap.put(EntityEnderDragon.class, EnderDragon.class);
+ bukkitMap.put(EntityEnderman.class, Enderman.class);
+ bukkitMap.put(EntityEndermite.class, Endermite.class);
+ bukkitMap.put(EntityEvoker.class, Evoker.class);
+ bukkitMap.put(EntityFish.class, Fish.class);
+ bukkitMap.put(EntityFishSchool.class, Fish.class); // close enough
+ bukkitMap.put(EntityFlying.class, Flying.class);
+ bukkitMap.put(EntityFox.class, Fox.class);
+ bukkitMap.put(EntityGhast.class, Ghast.class);
+ bukkitMap.put(EntityGiantZombie.class, Giant.class);
+ bukkitMap.put(EntityGolem.class, Golem.class);
+ bukkitMap.put(EntityGuardian.class, Guardian.class);
+ bukkitMap.put(EntityGuardianElder.class, ElderGuardian.class);
+ bukkitMap.put(EntityHorse.class, Horse.class);
+ bukkitMap.put(EntityHorseAbstract.class, AbstractHorse.class);
+ bukkitMap.put(EntityHorseChestedAbstract.class, ChestedHorse.class);
+ bukkitMap.put(EntityHorseDonkey.class, Donkey.class);
+ bukkitMap.put(EntityHorseMule.class, Mule.class);
+ bukkitMap.put(EntityHorseSkeleton.class, SkeletonHorse.class);
+ bukkitMap.put(EntityHorseZombie.class, ZombieHorse.class);
+ bukkitMap.put(EntityIllagerAbstract.class, Illager.class);
+ bukkitMap.put(EntityIllagerIllusioner.class, Illusioner.class);
+ bukkitMap.put(EntityIllagerWizard.class, Spellcaster.class);
+ bukkitMap.put(EntityIronGolem.class, IronGolem.class);
+ bukkitMap.put(EntityLlama.class, Llama.class);
+ bukkitMap.put(EntityLlamaTrader.class, TraderLlama.class);
+ bukkitMap.put(EntityMagmaCube.class, MagmaCube.class);
+ bukkitMap.put(EntityMonster.class, Monster.class);
+ bukkitMap.put(EntityMonsterPatrolling.class, Monster.class); // close enough
+ bukkitMap.put(EntityMushroomCow.class, MushroomCow.class);
+ bukkitMap.put(EntityOcelot.class, Ocelot.class);
+ bukkitMap.put(EntityPanda.class, Panda.class);
+ bukkitMap.put(EntityParrot.class, Parrot.class);
+ bukkitMap.put(EntityPerchable.class, Parrot.class); // close enough
+ bukkitMap.put(EntityPhantom.class, Phantom.class);
+ bukkitMap.put(EntityPig.class, Pig.class);
+ bukkitMap.put(EntityPigZombie.class, PigZombie.class);
+ bukkitMap.put(EntityPillager.class, Pillager.class);
+ bukkitMap.put(EntityPolarBear.class, PolarBear.class);
+ bukkitMap.put(EntityPufferFish.class, PufferFish.class);
+ bukkitMap.put(EntityRabbit.class, Rabbit.class);
+ bukkitMap.put(EntityRaider.class, Raider.class);
+ bukkitMap.put(EntityRavager.class, Ravager.class);
+ bukkitMap.put(EntitySalmon.class, Salmon.class);
+ bukkitMap.put(EntitySheep.class, Sheep.class);
+ bukkitMap.put(EntityShulker.class, Shulker.class);
+ bukkitMap.put(EntitySilverfish.class, Silverfish.class);
+ bukkitMap.put(EntitySkeleton.class, Skeleton.class);
+ bukkitMap.put(EntitySkeletonAbstract.class, Skeleton.class);
+ bukkitMap.put(EntitySkeletonStray.class, Stray.class);
+ bukkitMap.put(EntitySkeletonWither.class, WitherSkeleton.class);
+ bukkitMap.put(EntitySlime.class, Slime.class);
+ bukkitMap.put(EntitySnowman.class, Snowman.class);
+ bukkitMap.put(EntitySpider.class, Spider.class);
+ bukkitMap.put(EntitySquid.class, Squid.class);
+ bukkitMap.put(EntityTameableAnimal.class, Tameable.class);
+ bukkitMap.put(EntityTropicalFish.class, TropicalFish.class);
+ bukkitMap.put(EntityTurtle.class, Turtle.class);
+ bukkitMap.put(EntityVex.class, Vex.class);
+ bukkitMap.put(EntityVillager.class, Villager.class);
+ bukkitMap.put(EntityVillagerAbstract.class, AbstractVillager.class);
+ bukkitMap.put(EntityVillagerTrader.class, WanderingTrader.class);
+ bukkitMap.put(EntityVindicator.class, Vindicator.class);
+ bukkitMap.put(EntityWaterAnimal.class, WaterMob.class);
+ bukkitMap.put(EntityWitch.class, Witch.class);
+ bukkitMap.put(EntityWither.class, Wither.class);
+ bukkitMap.put(EntityWolf.class, Wolf.class);
+ bukkitMap.put(EntityZombie.class, Zombie.class);
+ bukkitMap.put(EntityZombieHusk.class, Husk.class);
+ bukkitMap.put(EntityZombieVillager.class, ZombieVillager.class);
+ bukkitMap.put(EntityHoglin.class, Hoglin.class);
+ bukkitMap.put(EntityPiglin.class, Piglin.class);
+ bukkitMap.put(EntityPiglinAbstract.class, PiglinAbstract.class);
+ bukkitMap.put(EntityPiglinBrute.class, PiglinBrute.class);
+ bukkitMap.put(EntityStrider.class, Strider.class);
+ bukkitMap.put(EntityZoglin.class, Zoglin.class);
+ }
+
+ public static String getUsableName(Class<?> clazz) {
+ String name = clazz.getName();
+ name = name.substring(name.lastIndexOf(".") + 1);
+ boolean flag = false;
+ // inner classes
+ if (name.contains("$")) {
+ String cut = name.substring(name.indexOf("$") + 1);
+ if (cut.length() <= 2) {
+ name = name.replace("Entity", "");
+ name = name.replace("$", "_");
+ flag = true;
+ } else {
+ // mapped, wooo
+ name = cut;
+ }
+ }
+ name = name.replace("PathfinderGoal", "");
+ StringBuilder sb = new StringBuilder();
+ for (char c : name.toCharArray()) {
+ if (c >= 'A' && c <= 'Z') {
+ sb.append("_");
+ sb.append(Character.toLowerCase(c));
+ } else {
+ sb.append(c);
+ }
+ }
+ name = sb.toString();
+ name = name.replaceFirst("_", "");
+
+ if (flag && !deobfuscationMap.containsKey(name.toLowerCase()) && !ignored.contains(name)) {
+ System.out.println("need to map " + clazz.getName() + " (" + name.toLowerCase() + ")");
+ }
+
+ // did we rename this key?
+ return deobfuscationMap.getOrDefault(name, name);
+ }
+
+ public static EnumSet<GoalType> vanillaToPaper(OptimizedSmallEnumSet<PathfinderGoal.Type> types) {
+ EnumSet<GoalType> goals = EnumSet.noneOf(GoalType.class);
+ for (GoalType type : GoalType.values()) {
+ if (types.hasElement(paperToVanilla(type))) {
+ goals.add(type);
+ }
+ }
+ return goals;
+ }
+
+ public static GoalType vanillaToPaper(PathfinderGoal.Type type) {
+ switch (type) {
+ case MOVE:
+ return GoalType.MOVE;
+ case LOOK:
+ return GoalType.LOOK;
+ case JUMP:
+ return GoalType.JUMP;
+ case UNKNOWN_BEHAVIOR:
+ return GoalType.UNKNOWN_BEHAVIOR;
+ case TARGET:
+ return GoalType.TARGET;
+ default:
+ throw new IllegalArgumentException("Unknown vanilla mob goal type " + type.name());
+ }
+ }
+
+ public static EnumSet<PathfinderGoal.Type> paperToVanilla(EnumSet<GoalType> types) {
+ EnumSet<PathfinderGoal.Type> goals = EnumSet.noneOf(PathfinderGoal.Type.class);
+ for (GoalType type : types) {
+ goals.add(paperToVanilla(type));
+ }
+ return goals;
+ }
+
+ public static PathfinderGoal.Type paperToVanilla(GoalType type) {
+ switch (type) {
+ case MOVE:
+ return PathfinderGoal.Type.MOVE;
+ case LOOK:
+ return PathfinderGoal.Type.LOOK;
+ case JUMP:
+ return PathfinderGoal.Type.JUMP;
+ case UNKNOWN_BEHAVIOR:
+ return PathfinderGoal.Type.UNKNOWN_BEHAVIOR;
+ case TARGET:
+ return PathfinderGoal.Type.TARGET;
+ default:
+ throw new IllegalArgumentException("Unknown paper mob goal type " + type.name());
+ }
+ }
+
+ public static <T extends Mob> GoalKey<T> getKey(Class<? extends PathfinderGoal> goalClass) {
+ String name = getUsableName(goalClass);
+ if (ignored.contains(name)) {
+ //noinspection unchecked
+ return (GoalKey<T>) GoalKey.of(Mob.class, NamespacedKey.minecraft(name));
+ }
+ return GoalKey.of(getEntity(goalClass), NamespacedKey.minecraft(name));
+ }
+
+ public static <T extends Mob> Class<T> getEntity(Class<? extends PathfinderGoal> goalClass) {
+ //noinspection unchecked
+ return (Class<T>) entityClassCache.computeIfAbsent(goalClass, key -> {
+ for (Constructor<?> ctor : key.getDeclaredConstructors()) {
+ for (int i = 0; i < ctor.getParameterCount(); i++) {
+ Class<?> param = ctor.getParameterTypes()[i];
+ if (EntityInsentient.class.isAssignableFrom(param)) {
+ //noinspection unchecked
+ return toBukkitClass((Class<? extends EntityInsentient>) param);
+ } else if (IRangedEntity.class.isAssignableFrom(param)) {
+ return RangedEntity.class;
+ }
+ }
+ }
+ throw new RuntimeException("Can't figure out applicable entity for mob goal " + goalClass); // maybe just return EntityInsentient?
+ });
+ }
+
+ public static Class<? extends Mob> toBukkitClass(Class<? extends EntityInsentient> nmsClass) {
+ Class<? extends Mob> bukkitClass = bukkitMap.get(nmsClass);
+ if (bukkitClass == null) {
+ throw new RuntimeException("Can't figure out applicable bukkit entity for nms entity " + nmsClass); // maybe just return Mob?
+ }
+ return bukkitClass;
+ }
+}
diff --git a/src/main/java/com/destroystokyo/paper/entity/ai/PaperCustomGoal.java b/src/main/java/com/destroystokyo/paper/entity/ai/PaperCustomGoal.java
new file mode 100644
index 0000000000000000000000000000000000000000..0b963f80857209bc73ece917203447d8839860b6
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/entity/ai/PaperCustomGoal.java
@@ -0,0 +1,54 @@
+package com.destroystokyo.paper.entity.ai;
+
+import net.minecraft.world.entity.ai.goal.PathfinderGoal;
+import org.bukkit.entity.Mob;
+
+/**
+ * Wraps api in vanilla
+ */
+public class PaperCustomGoal<T extends Mob> extends PathfinderGoal {
+
+ private final Goal<T> handle;
+
+ public PaperCustomGoal(Goal<T> handle) {
+ this.handle = handle;
+
+ this.setTypes(MobGoalHelper.paperToVanilla(handle.getTypes()));
+ if (this.getGoalTypes().size() == 0) {
+ this.getGoalTypes().addUnchecked(Type.UNKNOWN_BEHAVIOR);
+ }
+ }
+
+ @Override
+ public boolean shouldActivate() {
+ return handle.shouldActivate();
+ }
+
+ @Override
+ public boolean shouldStayActive() {
+ return handle.shouldStayActive();
+ }
+
+ @Override
+ public void start() {
+ handle.start();
+ }
+
+ @Override
+ public void onTaskReset() {
+ handle.stop();
+ }
+
+ @Override
+ public void tick() {
+ handle.tick();
+ }
+
+ public Goal<T> getHandle() {
+ return handle;
+ }
+
+ public GoalKey<T> getKey() {
+ return handle.getKey();
+ }
+}
diff --git a/src/main/java/com/destroystokyo/paper/entity/ai/PaperMobGoals.java b/src/main/java/com/destroystokyo/paper/entity/ai/PaperMobGoals.java
new file mode 100644
index 0000000000000000000000000000000000000000..bf792c013fe3b9a0b5800a35308b9aaa36e5350d
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/entity/ai/PaperMobGoals.java
@@ -0,0 +1,222 @@
+package com.destroystokyo.paper.entity.ai;
+
+import java.util.Collection;
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import net.minecraft.world.entity.ai.goal.PathfinderGoal;
+import net.minecraft.world.entity.ai.goal.PathfinderGoalSelector;
+import net.minecraft.world.entity.ai.goal.PathfinderGoalWrapped;
+import org.bukkit.craftbukkit.entity.CraftMob;
+import org.bukkit.entity.Mob;
+
+public class PaperMobGoals implements MobGoals {
+
+ private final Map<PathfinderGoal, PaperVanillaGoal<?>> instanceCache = new HashMap<>();
+
+ @Override
+ public <T extends Mob> void addGoal(T mob, int priority, Goal<T> goal) {
+ CraftMob craftMob = (CraftMob) mob;
+ getHandle(craftMob, goal.getTypes()).addGoal(priority, new PaperCustomGoal<>(goal));
+ }
+
+ @Override
+ public <T extends Mob> void removeGoal(T mob, Goal<T> goal) {
+ CraftMob craftMob = (CraftMob) mob;
+ if (goal instanceof PaperCustomGoal) {
+ getHandle(craftMob, goal.getTypes()).removeGoal((PathfinderGoal) goal);
+ } else if (goal instanceof PaperVanillaGoal) {
+ getHandle(craftMob, goal.getTypes()).removeGoal(((PaperVanillaGoal<?>) goal).getHandle());
+ } else {
+ List<PathfinderGoal> toRemove = new LinkedList<>();
+ for (PathfinderGoalWrapped item : getHandle(craftMob, goal.getTypes()).getTasks()) {
+ if (item.getGoal() instanceof PaperCustomGoal) {
+ //noinspection unchecked
+ if (((PaperCustomGoal<T>) item.getGoal()).getHandle() == goal) {
+ toRemove.add(item.getGoal());
+ }
+ }
+ }
+
+ for (PathfinderGoal g : toRemove) {
+ getHandle(craftMob, goal.getTypes()).removeGoal(g);
+ }
+ }
+ }
+
+ @Override
+ public <T extends Mob> void removeAllGoals(T mob) {
+ for (GoalType type : GoalType.values()) {
+ removeAllGoals(mob, type);
+ }
+ }
+
+ @Override
+ public <T extends Mob> void removeAllGoals(T mob, GoalType type) {
+ for (Goal<T> goal : getAllGoals(mob, type)) {
+ removeGoal(mob, goal);
+ }
+ }
+
+ @Override
+ public <T extends Mob> void removeGoal(T mob, GoalKey<T> key) {
+ for (Goal<T> goal : getGoals(mob, key)) {
+ removeGoal(mob, goal);
+ }
+ }
+
+ @Override
+ public <T extends Mob> boolean hasGoal(T mob, GoalKey<T> key) {
+ for (Goal<T> g : getAllGoals(mob)) {
+ if (g.getKey().equals(key)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public <T extends Mob> Goal<T> getGoal(T mob, GoalKey<T> key) {
+ for (Goal<T> g : getAllGoals(mob)) {
+ if (g.getKey().equals(key)) {
+ return g;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public <T extends Mob> Collection<Goal<T>> getGoals(T mob, GoalKey<T> key) {
+ Set<Goal<T>> goals = new HashSet<>();
+ for (Goal<T> g : getAllGoals(mob)) {
+ if (g.getKey().equals(key)) {
+ goals.add(g);
+ }
+ }
+ return goals;
+ }
+
+ @Override
+ public <T extends Mob> Collection<Goal<T>> getAllGoals(T mob) {
+ Set<Goal<T>> goals = new HashSet<>();
+ for (GoalType type : GoalType.values()) {
+ goals.addAll(getAllGoals(mob, type));
+ }
+ return goals;
+ }
+
+ @Override
+ public <T extends Mob> Collection<Goal<T>> getAllGoals(T mob, GoalType type) {
+ CraftMob craftMob = (CraftMob) mob;
+ Set<Goal<T>> goals = new HashSet<>();
+ for (PathfinderGoalWrapped item : getHandle(craftMob, type).getTasks()) {
+ if (!item.getGoal().getGoalTypes().hasElement(MobGoalHelper.paperToVanilla(type))) {
+ continue;
+ }
+
+ if (item.getGoal() instanceof PaperCustomGoal) {
+ //noinspection unchecked
+ goals.add(((PaperCustomGoal<T>) item.getGoal()).getHandle());
+ } else {
+ //noinspection unchecked
+ goals.add((Goal<T>) instanceCache.computeIfAbsent(item.getGoal(), PaperVanillaGoal::new));
+ }
+ }
+ return goals;
+ }
+
+ @Override
+ public <T extends Mob> Collection<Goal<T>> getAllGoalsWithout(T mob, GoalType type) {
+ CraftMob craftMob = (CraftMob) mob;
+ Set<Goal<T>> goals = new HashSet<>();
+ for (GoalType internalType : GoalType.values()) {
+ if (internalType == type) {
+ continue;
+ }
+ for (PathfinderGoalWrapped item : getHandle(craftMob, internalType).getTasks()) {
+ if (item.getGoal().getGoalTypes().hasElement(MobGoalHelper.paperToVanilla(type))) {
+ continue;
+ }
+
+ if (item.getGoal() instanceof PaperCustomGoal) {
+ //noinspection unchecked
+ goals.add(((PaperCustomGoal<T>) item.getGoal()).getHandle());
+ } else {
+ //noinspection unchecked
+ goals.add((Goal<T>) instanceCache.computeIfAbsent(item.getGoal(), PaperVanillaGoal::new));
+ }
+ }
+ }
+ return goals;
+ }
+
+ @Override
+ public <T extends Mob> Collection<Goal<T>> getRunningGoals(T mob) {
+ Set<Goal<T>> goals = new HashSet<>();
+ for (GoalType type : GoalType.values()) {
+ goals.addAll(getRunningGoals(mob, type));
+ }
+ return goals;
+ }
+
+ @Override
+ public <T extends Mob> Collection<Goal<T>> getRunningGoals(T mob, GoalType type) {
+ CraftMob craftMob = (CraftMob) mob;
+ Set<Goal<T>> goals = new HashSet<>();
+ getHandle(craftMob, type).getExecutingGoals()
+ .filter(item -> item.getGoal().getGoalTypes().hasElement(MobGoalHelper.paperToVanilla(type)))
+ .forEach(item -> {
+ if (item.getGoal() instanceof PaperCustomGoal) {
+ //noinspection unchecked
+ goals.add(((PaperCustomGoal<T>) item.getGoal()).getHandle());
+ } else {
+ //noinspection unchecked
+ goals.add((Goal<T>) instanceCache.computeIfAbsent(item.getGoal(), PaperVanillaGoal::new));
+ }
+ });
+ return goals;
+ }
+
+ @Override
+ public <T extends Mob> Collection<Goal<T>> getRunningGoalsWithout(T mob, GoalType type) {
+ CraftMob craftMob = (CraftMob) mob;
+ Set<Goal<T>> goals = new HashSet<>();
+ for (GoalType internalType : GoalType.values()) {
+ if (internalType == type) {
+ continue;
+ }
+ getHandle(craftMob, internalType).getExecutingGoals()
+ .filter(item -> !item.getGoal().getGoalTypes().hasElement(MobGoalHelper.paperToVanilla(type)))
+ .forEach(item -> {
+ if (item.getGoal() instanceof PaperCustomGoal) {
+ //noinspection unchecked
+ goals.add(((PaperCustomGoal<T>) item.getGoal()).getHandle());
+ } else {
+ //noinspection unchecked
+ goals.add((Goal<T>) instanceCache.computeIfAbsent(item.getGoal(), PaperVanillaGoal::new));
+ }
+ });
+ }
+ return goals;
+ }
+
+ private PathfinderGoalSelector getHandle(CraftMob mob, EnumSet<GoalType> types) {
+ if (types.contains(GoalType.TARGET)) {
+ return mob.getHandle().targetSelector;
+ } else {
+ return mob.getHandle().goalSelector;
+ }
+ }
+
+ private PathfinderGoalSelector getHandle(CraftMob mob, GoalType type) {
+ if (type == GoalType.TARGET) {
+ return mob.getHandle().targetSelector;
+ } else {
+ return mob.getHandle().goalSelector;
+ }
+ }
+}
diff --git a/src/main/java/com/destroystokyo/paper/entity/ai/PaperVanillaGoal.java b/src/main/java/com/destroystokyo/paper/entity/ai/PaperVanillaGoal.java
new file mode 100644
index 0000000000000000000000000000000000000000..1ed6e7273bc84a406ca843bc47bb69314bb2dd74
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/entity/ai/PaperVanillaGoal.java
@@ -0,0 +1,62 @@
+package com.destroystokyo.paper.entity.ai;
+
+import java.util.EnumSet;
+
+import net.minecraft.world.entity.ai.goal.PathfinderGoal;
+import org.bukkit.entity.Mob;
+
+/**
+ * Wraps vanilla in api
+ */
+public class PaperVanillaGoal<T extends Mob> implements VanillaGoal<T> {
+
+ private final PathfinderGoal handle;
+ private final GoalKey<T> key;
+
+ private final EnumSet<GoalType> types;
+
+ public PaperVanillaGoal(PathfinderGoal handle) {
+ this.handle = handle;
+ this.key = MobGoalHelper.getKey(handle.getClass());
+ this.types = MobGoalHelper.vanillaToPaper(handle.getGoalTypes());
+ }
+
+ public PathfinderGoal getHandle() {
+ return handle;
+ }
+
+ @Override
+ public boolean shouldActivate() {
+ return handle.shouldActivate2();
+ }
+
+ @Override
+ public boolean shouldStayActive() {
+ return handle.shouldStayActive2();
+ }
+
+ @Override
+ public void start() {
+ handle.start();
+ }
+
+ @Override
+ public void stop() {
+ handle.onTaskReset();
+ }
+
+ @Override
+ public void tick() {
+ handle.tick();
+ }
+
+ @Override
+ public GoalKey<T> getKey() {
+ return key;
+ }
+
+ @Override
+ public EnumSet<GoalType> getTypes() {
+ return types;
+ }
+}
diff --git a/src/main/java/com/destroystokyo/paper/util/set/OptimizedSmallEnumSet.java b/src/main/java/com/destroystokyo/paper/util/set/OptimizedSmallEnumSet.java
index 9df0006c1a283f77c4d01d9fce9062fc1c9bbb1f..b3329c6fcd6758a781a51f5ba8f5052ac1c77b49 100644
--- a/src/main/java/com/destroystokyo/paper/util/set/OptimizedSmallEnumSet.java
+++ b/src/main/java/com/destroystokyo/paper/util/set/OptimizedSmallEnumSet.java
@@ -64,4 +64,8 @@ public final class OptimizedSmallEnumSet<E extends Enum<E>> {
public boolean hasCommonElements(final OptimizedSmallEnumSet<E> other) {
return (other.backingSet & this.backingSet) != 0;
}
+
+ public boolean hasElement(final E element) {
+ return (this.backingSet & (1L << element.ordinal())) != 0;
+ }
}
diff --git a/src/main/java/net/minecraft/world/entity/ai/goal/PathfinderGoal.java b/src/main/java/net/minecraft/world/entity/ai/goal/PathfinderGoal.java
index 5c32cbe81c47fcb9ae347faa6fc007c5d28d79bf..59ea1432152051ce8a60c0a526db787593f0e744 100644
--- a/src/main/java/net/minecraft/world/entity/ai/goal/PathfinderGoal.java
+++ b/src/main/java/net/minecraft/world/entity/ai/goal/PathfinderGoal.java
@@ -8,11 +8,17 @@ public abstract class PathfinderGoal {
private final EnumSet<PathfinderGoal.Type> a = EnumSet.noneOf(PathfinderGoal.Type.class); // Paper unused, but dummy to prevent plugins from crashing as hard. Theyll need to support paper in a special case if this is super important, but really doesn't seem like it would be.
private final OptimizedSmallEnumSet<Type> goalTypes = new OptimizedSmallEnumSet<>(PathfinderGoal.Type.class); // Paper - remove streams from pathfindergoalselector
- public PathfinderGoal() {}
+ // Paper start make sure goaltypes is never empty
+ public PathfinderGoal() {
+ if (this.goalTypes.size() == 0) {
+ this.goalTypes.addUnchecked(Type.UNKNOWN_BEHAVIOR);
+ }
+ }
+ // paper end
- public abstract boolean a();
+ public boolean a() { return this.shouldActivate(); } public boolean shouldActivate() { return false;} public boolean shouldActivate2() { return a(); } // Paper - OBFHELPER, for both directions...
- public boolean b() {
+ public boolean b() { return this.shouldStayActive(); } public boolean shouldStayActive2() { return b(); } public boolean shouldStayActive() { // Paper - OBFHELPER, for both directions...
return this.a();
}
@@ -20,19 +26,23 @@ public abstract class PathfinderGoal {
return true;
}
- public void c() {}
+ public void c() { this.start(); } public void start() {} // Paper - OBFHELPER
public void d() {
onTaskReset(); // Paper
}
public void onTaskReset() {} // Paper
- public void e() {}
+ public void e() { this.tick(); } public void tick() {} // Paper OBFHELPER
- public void a(EnumSet<PathfinderGoal.Type> enumset) {
+ public void a(EnumSet<PathfinderGoal.Type> enumset) { this.setTypes(enumset); } public void setTypes(EnumSet<PathfinderGoal.Type> enumset) { // Paper - OBFHELPER
// Paper start - remove streams from pathfindergoalselector
this.goalTypes.clear();
this.goalTypes.addAllUnchecked(enumset);
+ // make sure its never empty
+ if (this.goalTypes.size() == 0) {
+ this.goalTypes.addUnchecked(Type.UNKNOWN_BEHAVIOR);
+ }
// Paper end - remove streams from pathfindergoalselector
}
@@ -48,7 +58,7 @@ public abstract class PathfinderGoal {
public static enum Type {
- MOVE, LOOK, JUMP, TARGET;
+ MOVE, LOOK, JUMP, TARGET, UNKNOWN_BEHAVIOR; // Paper - add unknown
private Type() {}
}
diff --git a/src/main/java/net/minecraft/world/entity/ai/goal/PathfinderGoalSelector.java b/src/main/java/net/minecraft/world/entity/ai/goal/PathfinderGoalSelector.java
index 385cd079e264a7e66e91ab3b70b90afb59688dcd..637928664f8c7b1c694a234e507c20724294e450 100644
--- a/src/main/java/net/minecraft/world/entity/ai/goal/PathfinderGoalSelector.java
+++ b/src/main/java/net/minecraft/world/entity/ai/goal/PathfinderGoalSelector.java
@@ -28,7 +28,7 @@ public class PathfinderGoalSelector {
}
};
private final Map<PathfinderGoal.Type, PathfinderGoalWrapped> c = new EnumMap(PathfinderGoal.Type.class);
- private final Set<PathfinderGoalWrapped> d = Sets.newLinkedHashSet(); private Set<PathfinderGoalWrapped> getTasks() { return d; }// Paper - OBFHELPER
+ private final Set<PathfinderGoalWrapped> d = Sets.newLinkedHashSet(); public final Set<PathfinderGoalWrapped> getTasks() { return d; }// Paper - OBFHELPER // Paper - private -> public
private final Supplier<GameProfilerFiller> e;
private final EnumSet<PathfinderGoal.Type> f = EnumSet.noneOf(PathfinderGoal.Type.class); // Paper unused, but dummy to prevent plugins from crashing as hard. Theyll need to support paper in a special case if this is super important, but really doesn't seem like it would be.
private final OptimizedSmallEnumSet<PathfinderGoal.Type> goalTypes = new OptimizedSmallEnumSet<>(PathfinderGoal.Type.class); // Paper - remove streams from pathfindergoalselector
@@ -39,7 +39,7 @@ public class PathfinderGoalSelector {
this.e = supplier;
}
- public void a(int i, PathfinderGoal pathfindergoal) {
+ public void addGoal(int priority, PathfinderGoal goal) {a(priority, goal);} public void a(int i, PathfinderGoal pathfindergoal) { // Paper - OBFHELPER
this.d.add(new PathfinderGoalWrapped(i, pathfindergoal));
}
@@ -58,7 +58,7 @@ public class PathfinderGoalSelector {
}
// Paper end
- public void a(PathfinderGoal pathfindergoal) {
+ public void removeGoal(PathfinderGoal goal) {a(goal);} public void a(PathfinderGoal pathfindergoal) { // Paper - OBFHELPER
// Paper start - remove streams from pathfindergoalselector
for (Iterator<PathfinderGoalWrapped> iterator = this.d.iterator(); iterator.hasNext();) {
PathfinderGoalWrapped goalWrapped = iterator.next();
@@ -154,6 +154,7 @@ public class PathfinderGoalSelector {
gameprofilerfiller.exit();
}
+ public final Stream<PathfinderGoalWrapped> getExecutingGoals() { return d(); } // Paper - OBFHELPER
public Stream<PathfinderGoalWrapped> d() {
return this.d.stream().filter(PathfinderGoalWrapped::g);
}
diff --git a/src/main/java/net/minecraft/world/entity/ai/goal/PathfinderGoalWrapped.java b/src/main/java/net/minecraft/world/entity/ai/goal/PathfinderGoalWrapped.java
index 8c8e39d35fb56aa6cf7d456adab01dff5d13a60d..bcf6c924894f49f1c602b83b501f904e553235fd 100644
--- a/src/main/java/net/minecraft/world/entity/ai/goal/PathfinderGoalWrapped.java
+++ b/src/main/java/net/minecraft/world/entity/ai/goal/PathfinderGoalWrapped.java
@@ -5,8 +5,8 @@ import javax.annotation.Nullable;
public class PathfinderGoalWrapped extends PathfinderGoal {
- private final PathfinderGoal a;
- private final int b;
+ private final PathfinderGoal a; public PathfinderGoal getGoal() {return a;} // Paper - OBFHELPER
+ private final int b; public int getPriority() {return b;} // Paper - OBFHELPER
private boolean c;
public PathfinderGoalWrapped(int i, PathfinderGoal pathfindergoal) {
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index 688bf56b331cc4b6b9664365f97a98720ec522a9..3b7a7791a221aaf39b4b6974b2f37efd403e4b25 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -2392,5 +2392,11 @@ public final class CraftServer implements Server {
public boolean isStopping() {
return net.minecraft.server.MinecraftServer.getServer().hasStopped();
}
+
+ private com.destroystokyo.paper.entity.ai.MobGoals mobGoals = new com.destroystokyo.paper.entity.ai.PaperMobGoals();
+ @Override
+ public com.destroystokyo.paper.entity.ai.MobGoals getMobGoals() {
+ return mobGoals;
+ }
// Paper end
}
diff --git a/src/test/java/com/destroystokyo/paper/entity/ai/VanillaMobGoalTest.java b/src/test/java/com/destroystokyo/paper/entity/ai/VanillaMobGoalTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..c0525216a8469613c3e0d4b5774a82f69e70fb16
--- /dev/null
+++ b/src/test/java/com/destroystokyo/paper/entity/ai/VanillaMobGoalTest.java
@@ -0,0 +1,104 @@
+package com.destroystokyo.paper.entity.ai;
+
+import net.minecraft.world.entity.EntityInsentient;
+import net.minecraft.world.entity.ai.goal.PathfinderGoal;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import org.bukkit.entity.Mob;
+
+import io.github.classgraph.ClassGraph;
+import io.github.classgraph.ScanResult;
+
+public class VanillaMobGoalTest {
+
+ @Test
+ public void testKeys() {
+ List<GoalKey<?>> deprecated = new ArrayList<>();
+ List<GoalKey<?>> keys = new ArrayList<>();
+ for (Field field : VanillaGoal.class.getFields()) {
+ if (field.getType().equals(GoalKey.class)) {
+ try {
+ GoalKey<?> goalKey = (GoalKey<?>) field.get(null);
+ if (field.getAnnotation(Deprecated.class) != null) {
+ deprecated.add(goalKey);
+ } else {
+ keys.add(goalKey);
+ }
+ } catch (IllegalAccessException e) {
+ System.out.println("Skipping " + field.getName() + ": " + e.getMessage());
+ }
+ }
+ }
+
+ List<Class<?>> classes;
+ try (ScanResult scanResult = new ClassGraph().enableAllInfo().whitelistPackages("net.minecraft").scan()) {
+ classes = scanResult.getSubclasses(PathfinderGoal.class.getName()).loadClasses();
+ }
+
+ List<GoalKey<?>> vanillaNames = classes.stream()
+ .filter(VanillaMobGoalTest::hasNoEnclosingClass)
+ .filter(clazz -> !Modifier.isAbstract(clazz.getModifiers()))
+ .map(goalClass -> MobGoalHelper.getKey((Class<? extends PathfinderGoal>) goalClass))
+ .collect(Collectors.toList());
+
+ List<GoalKey<?>> missingFromAPI = new ArrayList<>(vanillaNames);
+ missingFromAPI.removeAll(keys);
+ missingFromAPI.removeIf(k -> MobGoalHelper.ignored.contains(k.getNamespacedKey().getKey()));
+ List<GoalKey<?>> missingFromVanilla = new ArrayList<>(keys);
+ missingFromVanilla.removeAll(vanillaNames);
+
+ boolean shouldFail = false;
+ if (missingFromAPI.size() != 0) {
+ System.out.println("Missing from API: ");
+ for (GoalKey<?> key : missingFromAPI) {
+ System.out.println("GoalKey<" + key.getEntityClass().getSimpleName() + "> " + key.getNamespacedKey().getKey().toUpperCase() +
+ " = GoalKey.of(" + key.getEntityClass().getSimpleName() + ".class, NamespacedKey.minecraft(\"" + key.getNamespacedKey().getKey() + "\"));");
+ }
+ shouldFail = true;
+ }
+ if (missingFromVanilla.size() != 0) {
+ System.out.println("Missing from vanilla: ");
+ missingFromVanilla.forEach(System.out::println);
+ shouldFail = true;
+ }
+
+ if (deprecated.size() != 0) {
+ System.out.println("Deprecated (might want to remove them at some point): ");
+ deprecated.forEach(System.out::println);
+ }
+
+ if (shouldFail) Assert.fail("See above");
+ }
+
+ private static boolean hasNoEnclosingClass(Class<?> clazz) {
+ return clazz.getEnclosingClass() == null || hasNoEnclosingClass(clazz.getSuperclass());
+ }
+
+ @Test
+ public void testBukkitMap() {
+ List<Class<?>> classes;
+ try (ScanResult scanResult = new ClassGraph().enableAllInfo().whitelistPackages("net.minecraft.world.entity").scan()) {
+ classes = scanResult.getSubclasses("net.minecraft.world.entity.EntityInsentient").loadClasses();
+ }
+ Assert.assertNotEquals("There are supposed to be more than 0 entity types!", Collections.emptyList(), classes);
+
+ boolean shouldFail = false;
+ for (Class<?> nmsClass : classes) {
+ Class<? extends Mob> bukkitClass = MobGoalHelper.toBukkitClass((Class<? extends EntityInsentient>) nmsClass);
+ if (bukkitClass == null) {
+ shouldFail = true;
+ System.out.println("Missing bukkitMap.put(" + nmsClass.getSimpleName() + ".class, " + nmsClass.getSimpleName().replace("Entity", "") + ".class);");
+ }
+ }
+
+ if (shouldFail) Assert.fail("See above");
+ }
+}