diff --git a/paper-generator/src/main/java/io/papermc/generator/Rewriters.java b/paper-generator/src/main/java/io/papermc/generator/Rewriters.java index f0588cb65928..70c7ec930392 100644 --- a/paper-generator/src/main/java/io/papermc/generator/Rewriters.java +++ b/paper-generator/src/main/java/io/papermc/generator/Rewriters.java @@ -22,6 +22,7 @@ import io.papermc.generator.rewriter.types.simple.StatisticRewriter; import io.papermc.generator.rewriter.types.simple.trial.DataComponentTypesRewriter; import io.papermc.generator.rewriter.types.simple.trial.VillagerProfessionRewriter; +import io.papermc.generator.types.goal.MobGoalNames; import io.papermc.generator.utils.Formatting; import io.papermc.paper.datacomponent.DataComponentTypes; import io.papermc.paper.datacomponent.item.consumable.ItemUseAnimation; @@ -29,11 +30,14 @@ import io.papermc.typewriter.preset.model.EnumValue; import java.util.Map; import java.util.function.Consumer; +import io.papermc.typewriter.replace.SearchMetadata; +import io.papermc.typewriter.replace.SearchReplaceRewriter; import javax.lang.model.SourceVersion; import net.kyori.adventure.text.format.NamedTextColor; import net.minecraft.core.Holder; import net.minecraft.core.registries.Registries; import net.minecraft.tags.TagKey; +import net.minecraft.world.entity.Mob; import net.minecraft.world.item.Rarity; import org.bukkit.Art; import org.bukkit.FeatureFlag; @@ -209,7 +213,18 @@ private static void bootstrapServer(PatternSourceSetRewriter sourceSet) { holder("CraftPotionUtil#upgradeable", new CraftPotionUtilRewriter("strong")), holder("CraftPotionUtil#extendable", new CraftPotionUtilRewriter("long")) )) - .register("PaperFeatureFlagProviderImpl#FLAGS", Types.PAPER_FEATURE_FLAG_PROVIDER_IMPL, new PaperFeatureFlagMapping()); + .register("PaperFeatureFlagProviderImpl#FLAGS", Types.PAPER_FEATURE_FLAG_PROVIDER_IMPL, new PaperFeatureFlagMapping()) + .register("MobGoalHelper#bukkitMap", Types.MOB_GOAL_HELPER, new SearchReplaceRewriter() { + @Override + protected void insert(SearchMetadata metadata, StringBuilder builder) { + for (Map.Entry, Class> entry : MobGoalNames.bukkitMap.entrySet()) { + builder.append(metadata.indent()).append("bukkitMap.put(%s.class, %s.class);".formatted( + entry.getKey().getCanonicalName(), this.importCollector.getShortName(entry.getValue()) + )); + builder.append('\n'); + } + } + }); RegistryBootstrapper.bootstrapServer(sourceSet); } } diff --git a/paper-generator/src/main/java/io/papermc/generator/rewriter/types/Types.java b/paper-generator/src/main/java/io/papermc/generator/rewriter/types/Types.java index 6c01870971d1..f733d019dc07 100644 --- a/paper-generator/src/main/java/io/papermc/generator/rewriter/types/Types.java +++ b/paper-generator/src/main/java/io/papermc/generator/rewriter/types/Types.java @@ -23,4 +23,6 @@ public final class Types { public static final ClassNamed PAPER_FEATURE_FLAG_PROVIDER_IMPL = ClassNamed.of("io.papermc.paper.world.flag", "PaperFeatureFlagProviderImpl"); public static final ClassNamed PAPER_SIMPLE_REGISTRY = ClassNamed.of("io.papermc.paper.registry", "PaperSimpleRegistry"); + + public static final ClassNamed MOB_GOAL_HELPER = ClassNamed.of("com.destroystokyo.paper.entity.ai", "MobGoalHelper"); } diff --git a/paper-generator/src/main/java/io/papermc/generator/types/goal/MobGoalNames.java b/paper-generator/src/main/java/io/papermc/generator/types/goal/MobGoalNames.java index 0c5e2ee798be..261763fb53f5 100644 --- a/paper-generator/src/main/java/io/papermc/generator/types/goal/MobGoalNames.java +++ b/paper-generator/src/main/java/io/papermc/generator/types/goal/MobGoalNames.java @@ -7,6 +7,7 @@ import io.papermc.paper.entity.SchoolableFish; import java.lang.reflect.Constructor; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.Map; import net.minecraft.world.entity.ai.goal.Goal; import net.minecraft.world.entity.monster.RangedAttackMob; @@ -19,7 +20,7 @@ public final class MobGoalNames { // todo sync with MobGoalHelper ideally this should not be duplicated private static final Map, Class> entityClassCache = new HashMap<>(); - public static final Map, Class> bukkitMap = new HashMap<>(); + public static final Map, Class> bukkitMap = new LinkedHashMap<>(); static { // diff --git a/paper-server/src/main/java/com/destroystokyo/paper/entity/ai/MobGoalHelper.java b/paper-server/src/main/java/com/destroystokyo/paper/entity/ai/MobGoalHelper.java index 5d4d9efd0cda..92db9afa23a7 100644 --- a/paper-server/src/main/java/com/destroystokyo/paper/entity/ai/MobGoalHelper.java +++ b/paper-server/src/main/java/com/destroystokyo/paper/entity/ai/MobGoalHelper.java @@ -3,6 +3,7 @@ import com.destroystokyo.paper.entity.RangedEntity; import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; +import io.papermc.paper.entity.SchoolableFish; import io.papermc.paper.util.ObfHelper; import java.lang.reflect.Constructor; import java.util.EnumSet; @@ -33,6 +34,9 @@ public class MobGoalHelper { ignored.add("selector_2"); ignored.add("wrapped"); + // + // Paper start - Generated/MobGoalHelper#bukkitMap + // @GeneratedFrom 1.21.4 bukkitMap.put(net.minecraft.world.entity.Mob.class, Mob.class); bukkitMap.put(net.minecraft.world.entity.AgeableMob.class, Ageable.class); bukkitMap.put(net.minecraft.world.entity.ambient.AmbientCreature.class, Ambient.class); @@ -54,7 +58,7 @@ public class MobGoalHelper { bukkitMap.put(net.minecraft.world.entity.monster.Endermite.class, Endermite.class); bukkitMap.put(net.minecraft.world.entity.monster.Evoker.class, Evoker.class); bukkitMap.put(net.minecraft.world.entity.animal.AbstractFish.class, Fish.class); - bukkitMap.put(net.minecraft.world.entity.animal.AbstractSchoolingFish.class, io.papermc.paper.entity.SchoolableFish.class); + bukkitMap.put(net.minecraft.world.entity.animal.AbstractSchoolingFish.class, SchoolableFish.class); bukkitMap.put(net.minecraft.world.entity.FlyingMob.class, Flying.class); bukkitMap.put(net.minecraft.world.entity.animal.Fox.class, Fox.class); bukkitMap.put(net.minecraft.world.entity.monster.Ghast.class, Ghast.class); @@ -69,7 +73,7 @@ public class MobGoalHelper { bukkitMap.put(net.minecraft.world.entity.animal.horse.Mule.class, Mule.class); bukkitMap.put(net.minecraft.world.entity.animal.horse.SkeletonHorse.class, SkeletonHorse.class); bukkitMap.put(net.minecraft.world.entity.animal.horse.ZombieHorse.class, ZombieHorse.class); - bukkitMap.put(net.minecraft.world.entity.animal.camel.Camel.class, org.bukkit.entity.Camel.class); + bukkitMap.put(net.minecraft.world.entity.animal.camel.Camel.class, Camel.class); bukkitMap.put(net.minecraft.world.entity.monster.AbstractIllager.class, Illager.class); bukkitMap.put(net.minecraft.world.entity.monster.Illusioner.class, Illusioner.class); bukkitMap.put(net.minecraft.world.entity.monster.SpellcasterIllager.class, Spellcaster.class); @@ -78,12 +82,12 @@ public class MobGoalHelper { bukkitMap.put(net.minecraft.world.entity.animal.horse.TraderLlama.class, TraderLlama.class); bukkitMap.put(net.minecraft.world.entity.monster.MagmaCube.class, MagmaCube.class); bukkitMap.put(net.minecraft.world.entity.monster.Monster.class, Monster.class); - bukkitMap.put(net.minecraft.world.entity.monster.PatrollingMonster.class, Raider.class); // close enough + bukkitMap.put(net.minecraft.world.entity.monster.PatrollingMonster.class, Raider.class); bukkitMap.put(net.minecraft.world.entity.animal.MushroomCow.class, MushroomCow.class); bukkitMap.put(net.minecraft.world.entity.animal.Ocelot.class, Ocelot.class); bukkitMap.put(net.minecraft.world.entity.animal.Panda.class, Panda.class); bukkitMap.put(net.minecraft.world.entity.animal.Parrot.class, Parrot.class); - bukkitMap.put(net.minecraft.world.entity.animal.ShoulderRidingEntity.class, Parrot.class); // close enough + bukkitMap.put(net.minecraft.world.entity.animal.ShoulderRidingEntity.class, Parrot.class); bukkitMap.put(net.minecraft.world.entity.monster.Phantom.class, Phantom.class); bukkitMap.put(net.minecraft.world.entity.animal.Pig.class, Pig.class); bukkitMap.put(net.minecraft.world.entity.monster.ZombifiedPiglin.class, PigZombie.class); @@ -138,7 +142,9 @@ public class MobGoalHelper { bukkitMap.put(net.minecraft.world.entity.animal.armadillo.Armadillo.class, Armadillo.class); bukkitMap.put(net.minecraft.world.entity.monster.Bogged.class, Bogged.class); bukkitMap.put(net.minecraft.world.entity.monster.creaking.Creaking.class, Creaking.class); - bukkitMap.put(net.minecraft.world.entity.animal.AgeableWaterCreature.class, Squid.class); // close enough + bukkitMap.put(net.minecraft.world.entity.animal.AgeableWaterCreature.class, Squid.class); + // Paper end - Generated/MobGoalHelper#bukkitMap + // } public static String getUsableName(Class clazz) { @@ -157,7 +163,6 @@ public static String getUsableName(Class clazz) { name = cut; } } - name = name.replace("PathfinderGoal", ""); name = name.replace("TargetGoal", ""); name = name.replace("Goal", ""); StringBuilder sb = new StringBuilder();