Skip to content

Commit

Permalink
clone bukkitMap
Browse files Browse the repository at this point in the history
  • Loading branch information
Lulu13022002 committed Jan 6, 2025
1 parent 0a5cdd0 commit b91d217
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,22 @@
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;
import io.papermc.typewriter.preset.EnumCloneRewriter;
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;
Expand Down Expand Up @@ -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<? extends Mob>, Class<? extends org.bukkit.entity.Mob>> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -19,7 +20,7 @@
public final class MobGoalNames { // todo sync with MobGoalHelper ideally this should not be duplicated

private static final Map<Class<? extends Goal>, Class<? extends Mob>> entityClassCache = new HashMap<>();
public static final Map<Class<? extends net.minecraft.world.entity.Mob>, Class<? extends Mob>> bukkitMap = new HashMap<>();
public static final Map<Class<? extends net.minecraft.world.entity.Mob>, Class<? extends Mob>> bukkitMap = new LinkedHashMap<>();

static {
//<editor-fold defaultstate="collapsed" desc="bukkitMap Entities">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -33,6 +34,9 @@ public class MobGoalHelper {
ignored.add("selector_2");
ignored.add("wrapped");

//<editor-fold defaultstate="collapsed" desc="bukkitMap Entities">
// 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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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
//</editor-fold>
}

public static String getUsableName(Class<?> clazz) {
Expand All @@ -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();
Expand Down

0 comments on commit b91d217

Please sign in to comment.