| 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 BlockEntityIdFix extends DataFix {
|
| 13 | public static final Map<String, String> ID_MAP = DataFixUtils.make(Maps.newHashMap(), map -> {
|
| 14 | map.put("Airportal", "minecraft:end_portal");
|
| 15 | map.put("Banner", "minecraft:banner");
|
| 16 | map.put("Beacon", "minecraft:beacon");
|
| 17 | map.put("Cauldron", "minecraft:brewing_stand");
|
| 18 | map.put("Chest", "minecraft:chest");
|
| 19 | map.put("Comparator", "minecraft:comparator");
|
| 20 | map.put("Control", "minecraft:command_block");
|
| 21 | map.put("DLDetector", "minecraft:daylight_detector");
|
| 22 | map.put("Dropper", "minecraft:dropper");
|
| 23 | map.put("EnchantTable", "minecraft:enchanting_table");
|
| 24 | map.put("EndGateway", "minecraft:end_gateway");
|
| 25 | map.put("EnderChest", "minecraft:ender_chest");
|
| 26 | map.put("FlowerPot", "minecraft:flower_pot");
|
| 27 | map.put("Furnace", "minecraft:furnace");
|
| 28 | map.put("Hopper", "minecraft:hopper");
|
| 29 | map.put("MobSpawner", "minecraft:mob_spawner");
|
| 30 | map.put("Music", "minecraft:noteblock");
|
| 31 | map.put("Piston", "minecraft:piston");
|
| 32 | map.put("RecordPlayer", "minecraft:jukebox");
|
| 33 | map.put("Sign", "minecraft:sign");
|
| 34 | map.put("Skull", "minecraft:skull");
|
| 35 | map.put("Structure", "minecraft:structure_block");
|
| 36 | map.put("Trap", "minecraft:dispenser");
|
| 37 | });
|
| 38 |
|
| 39 | public BlockEntityIdFix(final Schema outputSchema, final boolean changesType) {
|
| 40 | super(outputSchema, changesType);
|
| 41 | }
|
| 42 |
|
| 43 | @Override
|
| 44 | public TypeRewriteRule makeRule() {
|
| 45 | Type<?> oldItemStackType = this.getInputSchema().getType(References.ITEM_STACK);
|
| 46 | Type<?> newItemStackType = this.getOutputSchema().getType(References.ITEM_STACK);
|
| 47 | TaggedChoiceType<String> oldType = (TaggedChoiceType<String>)this.getInputSchema().findChoiceType(References.BLOCK_ENTITY);
|
| 48 | TaggedChoiceType<String> newType = (TaggedChoiceType<String>)this.getOutputSchema().findChoiceType(References.BLOCK_ENTITY);
|
| 49 | return TypeRewriteRule.seq(
|
| 50 | this.convertUnchecked("item stack block entity name hook converter", oldItemStackType, newItemStackType),
|
| 51 | this.fixTypeEverywhere("BlockEntityIdFix", oldType, newType, ops -> input -> input.mapFirst(id -> ID_MAP.getOrDefault(id, id)))
|
| 52 | );
|
| 53 | }
|
| 54 | }
|
| 55 |
|