File size: 2,998 Bytes
d46f4a3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package net.minecraft.util.datafix.fixes;

import com.google.common.collect.Maps;
import com.mojang.datafixers.DataFix;
import com.mojang.datafixers.DataFixUtils;
import com.mojang.datafixers.TypeRewriteRule;
import com.mojang.datafixers.schemas.Schema;
import com.mojang.datafixers.types.Type;
import com.mojang.datafixers.types.templates.TaggedChoice.TaggedChoiceType;
import com.mojang.datafixers.util.Pair;
import com.mojang.serialization.DynamicOps;
import java.util.HashMap;
import java.util.Map;

public class BlockEntityIdFix extends DataFix {
    private static final Map<String, String> ID_MAP = DataFixUtils.make(Maps.newHashMap(), p_14839_ -> {
        p_14839_.put("Airportal", "minecraft:end_portal");
        p_14839_.put("Banner", "minecraft:banner");
        p_14839_.put("Beacon", "minecraft:beacon");
        p_14839_.put("Cauldron", "minecraft:brewing_stand");
        p_14839_.put("Chest", "minecraft:chest");
        p_14839_.put("Comparator", "minecraft:comparator");
        p_14839_.put("Control", "minecraft:command_block");
        p_14839_.put("DLDetector", "minecraft:daylight_detector");
        p_14839_.put("Dropper", "minecraft:dropper");
        p_14839_.put("EnchantTable", "minecraft:enchanting_table");
        p_14839_.put("EndGateway", "minecraft:end_gateway");
        p_14839_.put("EnderChest", "minecraft:ender_chest");
        p_14839_.put("FlowerPot", "minecraft:flower_pot");
        p_14839_.put("Furnace", "minecraft:furnace");
        p_14839_.put("Hopper", "minecraft:hopper");
        p_14839_.put("MobSpawner", "minecraft:mob_spawner");
        p_14839_.put("Music", "minecraft:noteblock");
        p_14839_.put("Piston", "minecraft:piston");
        p_14839_.put("RecordPlayer", "minecraft:jukebox");
        p_14839_.put("Sign", "minecraft:sign");
        p_14839_.put("Skull", "minecraft:skull");
        p_14839_.put("Structure", "minecraft:structure_block");
        p_14839_.put("Trap", "minecraft:dispenser");
    });

    public BlockEntityIdFix(Schema p_14830_, boolean p_14831_) {
        super(p_14830_, p_14831_);
    }

    @Override
    public TypeRewriteRule makeRule() {
        Type<?> type = this.getInputSchema().getType(References.ITEM_STACK);
        Type<?> type1 = this.getOutputSchema().getType(References.ITEM_STACK);
        TaggedChoiceType<String> taggedchoicetype = (TaggedChoiceType<String>)this.getInputSchema().findChoiceType(References.BLOCK_ENTITY);
        TaggedChoiceType<String> taggedchoicetype1 = (TaggedChoiceType<String>)this.getOutputSchema().findChoiceType(References.BLOCK_ENTITY);
        return TypeRewriteRule.seq(
            this.convertUnchecked("item stack block entity name hook converter", type, type1),
            this.fixTypeEverywhere(
                "BlockEntityIdFix",
                taggedchoicetype,
                taggedchoicetype1,
                p_14835_ -> p_145135_ -> p_145135_.mapFirst(p_145137_ -> ID_MAP.getOrDefault(p_145137_, p_145137_))
            )
        );
    }
}