| 1 | package net.minecraft.util.datafix.fixes;
|
| 2 |
|
| 3 | import com.google.common.collect.Maps;
|
| 4 | import com.mojang.datafixers.DataFix;
|
| 5 | import com.mojang.datafixers.DataFixUtils;
|
| 6 | import com.mojang.datafixers.TypeRewriteRule;
|
| 7 | import com.mojang.datafixers.schemas.Schema;
|
| 8 | import com.mojang.datafixers.types.Type;
|
| 9 | import com.mojang.datafixers.types.templates.TaggedChoice.TaggedChoiceType;
|
| 10 | import java.util.Map;
|
| 11 |
|
| 12 | public class EntityIdFix extends DataFix {
|
| 13 | private static final Map<String, String> ID_MAP = DataFixUtils.make(Maps.newHashMap(), map -> {
|
| 14 | map.put("AreaEffectCloud", "minecraft:area_effect_cloud");
|
| 15 | map.put("ArmorStand", "minecraft:armor_stand");
|
| 16 | map.put("Arrow", "minecraft:arrow");
|
| 17 | map.put("Bat", "minecraft:bat");
|
| 18 | map.put("Blaze", "minecraft:blaze");
|
| 19 | map.put("Boat", "minecraft:boat");
|
| 20 | map.put("CaveSpider", "minecraft:cave_spider");
|
| 21 | map.put("Chicken", "minecraft:chicken");
|
| 22 | map.put("Cow", "minecraft:cow");
|
| 23 | map.put("Creeper", "minecraft:creeper");
|
| 24 | map.put("Donkey", "minecraft:donkey");
|
| 25 | map.put("DragonFireball", "minecraft:dragon_fireball");
|
| 26 | map.put("ElderGuardian", "minecraft:elder_guardian");
|
| 27 | map.put("EnderCrystal", "minecraft:ender_crystal");
|
| 28 | map.put("EnderDragon", "minecraft:ender_dragon");
|
| 29 | map.put("Enderman", "minecraft:enderman");
|
| 30 | map.put("Endermite", "minecraft:endermite");
|
| 31 | map.put("EyeOfEnderSignal", "minecraft:eye_of_ender_signal");
|
| 32 | map.put("FallingSand", "minecraft:falling_block");
|
| 33 | map.put("Fireball", "minecraft:fireball");
|
| 34 | map.put("FireworksRocketEntity", "minecraft:fireworks_rocket");
|
| 35 | map.put("Ghast", "minecraft:ghast");
|
| 36 | map.put("Giant", "minecraft:giant");
|
| 37 | map.put("Guardian", "minecraft:guardian");
|
| 38 | map.put("Horse", "minecraft:horse");
|
| 39 | map.put("Husk", "minecraft:husk");
|
| 40 | map.put("Item", "minecraft:item");
|
| 41 | map.put("ItemFrame", "minecraft:item_frame");
|
| 42 | map.put("LavaSlime", "minecraft:magma_cube");
|
| 43 | map.put("LeashKnot", "minecraft:leash_knot");
|
| 44 | map.put("MinecartChest", "minecraft:chest_minecart");
|
| 45 | map.put("MinecartCommandBlock", "minecraft:commandblock_minecart");
|
| 46 | map.put("MinecartFurnace", "minecraft:furnace_minecart");
|
| 47 | map.put("MinecartHopper", "minecraft:hopper_minecart");
|
| 48 | map.put("MinecartRideable", "minecraft:minecart");
|
| 49 | map.put("MinecartSpawner", "minecraft:spawner_minecart");
|
| 50 | map.put("MinecartTNT", "minecraft:tnt_minecart");
|
| 51 | map.put("Mule", "minecraft:mule");
|
| 52 | map.put("MushroomCow", "minecraft:mooshroom");
|
| 53 | map.put("Ozelot", "minecraft:ocelot");
|
| 54 | map.put("Painting", "minecraft:painting");
|
| 55 | map.put("Pig", "minecraft:pig");
|
| 56 | map.put("PigZombie", "minecraft:zombie_pigman");
|
| 57 | map.put("PolarBear", "minecraft:polar_bear");
|
| 58 | map.put("PrimedTnt", "minecraft:tnt");
|
| 59 | map.put("Rabbit", "minecraft:rabbit");
|
| 60 | map.put("Sheep", "minecraft:sheep");
|
| 61 | map.put("Shulker", "minecraft:shulker");
|
| 62 | map.put("ShulkerBullet", "minecraft:shulker_bullet");
|
| 63 | map.put("Silverfish", "minecraft:silverfish");
|
| 64 | map.put("Skeleton", "minecraft:skeleton");
|
| 65 | map.put("SkeletonHorse", "minecraft:skeleton_horse");
|
| 66 | map.put("Slime", "minecraft:slime");
|
| 67 | map.put("SmallFireball", "minecraft:small_fireball");
|
| 68 | map.put("SnowMan", "minecraft:snowman");
|
| 69 | map.put("Snowball", "minecraft:snowball");
|
| 70 | map.put("SpectralArrow", "minecraft:spectral_arrow");
|
| 71 | map.put("Spider", "minecraft:spider");
|
| 72 | map.put("Squid", "minecraft:squid");
|
| 73 | map.put("Stray", "minecraft:stray");
|
| 74 | map.put("ThrownEgg", "minecraft:egg");
|
| 75 | map.put("ThrownEnderpearl", "minecraft:ender_pearl");
|
| 76 | map.put("ThrownExpBottle", "minecraft:xp_bottle");
|
| 77 | map.put("ThrownPotion", "minecraft:potion");
|
| 78 | map.put("Villager", "minecraft:villager");
|
| 79 | map.put("VillagerGolem", "minecraft:villager_golem");
|
| 80 | map.put("Witch", "minecraft:witch");
|
| 81 | map.put("WitherBoss", "minecraft:wither");
|
| 82 | map.put("WitherSkeleton", "minecraft:wither_skeleton");
|
| 83 | map.put("WitherSkull", "minecraft:wither_skull");
|
| 84 | map.put("Wolf", "minecraft:wolf");
|
| 85 | map.put("XPOrb", "minecraft:xp_orb");
|
| 86 | map.put("Zombie", "minecraft:zombie");
|
| 87 | map.put("ZombieHorse", "minecraft:zombie_horse");
|
| 88 | map.put("ZombieVillager", "minecraft:zombie_villager");
|
| 89 | });
|
| 90 |
|
| 91 | public EntityIdFix(final Schema outputSchema, final boolean changesType) {
|
| 92 | super(outputSchema, changesType);
|
| 93 | }
|
| 94 |
|
| 95 | @Override
|
| 96 | public TypeRewriteRule makeRule() {
|
| 97 | TaggedChoiceType<String> oldType = (TaggedChoiceType<String>)this.getInputSchema().findChoiceType(References.ENTITY);
|
| 98 | TaggedChoiceType<String> newType = (TaggedChoiceType<String>)this.getOutputSchema().findChoiceType(References.ENTITY);
|
| 99 | Type<?> oldItemStackType = this.getInputSchema().getType(References.ITEM_STACK);
|
| 100 | Type<?> newItemStackType = this.getOutputSchema().getType(References.ITEM_STACK);
|
| 101 | return TypeRewriteRule.seq(
|
| 102 | this.convertUnchecked("item stack entity name hook converter", oldItemStackType, newItemStackType),
|
| 103 | this.fixTypeEverywhere("EntityIdFix", oldType, newType, ops -> input -> input.mapFirst(id -> ID_MAP.getOrDefault(id, id)))
|
| 104 | );
|
| 105 | }
|
| 106 | }
|
| 107 |
|