/* * Decompiled with CFR 0.152. * * Could not load the following classes: * com.mojang.datafixers.DSL * com.mojang.datafixers.DataFix * com.mojang.datafixers.OpticFinder * com.mojang.datafixers.TypeRewriteRule * com.mojang.datafixers.schemas.Schema * com.mojang.datafixers.types.Type * com.mojang.datafixers.types.templates.TaggedChoice$TaggedChoiceType */ package net.minecraft.util.datafix.fixes; import com.mojang.datafixers.DSL; import com.mojang.datafixers.DataFix; import com.mojang.datafixers.OpticFinder; import com.mojang.datafixers.TypeRewriteRule; import com.mojang.datafixers.schemas.Schema; import com.mojang.datafixers.types.Type; import com.mojang.datafixers.types.templates.TaggedChoice; import java.util.Map; import net.minecraft.util.datafix.fixes.References; import net.minecraft.util.datafix.schemas.NamespacedSchema; public class StatsRenameFix extends DataFix { private final String name; private final Map renames; public StatsRenameFix(Schema outputSchema, String name, Map renames) { super(outputSchema, false); this.name = name; this.renames = renames; } protected TypeRewriteRule makeRule() { return TypeRewriteRule.seq((TypeRewriteRule)this.createStatRule(), (TypeRewriteRule)this.createCriteriaRule()); } private TypeRewriteRule createCriteriaRule() { Type outputType = this.getOutputSchema().getType(References.OBJECTIVE); Type inputType = this.getInputSchema().getType(References.OBJECTIVE); OpticFinder criteriaTypeFinder = inputType.findField("CriteriaType"); TaggedChoice.TaggedChoiceType choiceType = (TaggedChoice.TaggedChoiceType)criteriaTypeFinder.type().findChoiceType("type", -1).orElseThrow(() -> new IllegalStateException("Can't find choice type for criteria")); Type customFieldType = (Type)choiceType.types().get("minecraft:custom"); if (customFieldType == null) { throw new IllegalStateException("Failed to find custom criterion type variant"); } OpticFinder customTypeFinder = DSL.namedChoice((String)"minecraft:custom", (Type)customFieldType); OpticFinder idFinder = DSL.fieldFinder((String)"id", NamespacedSchema.namespacedString()); return this.fixTypeEverywhereTyped(this.name, inputType, outputType, input -> input.updateTyped(criteriaTypeFinder, stats -> stats.updateTyped(customTypeFinder, custom -> custom.update(idFinder, value -> this.renames.getOrDefault(value, (String)value))))); } private TypeRewriteRule createStatRule() { Type outputType = this.getOutputSchema().getType(References.STATS); Type inputType = this.getInputSchema().getType(References.STATS); OpticFinder statsFinder = inputType.findField("stats"); OpticFinder customFinder = statsFinder.type().findField("minecraft:custom"); OpticFinder nameFinder = NamespacedSchema.namespacedString().finder(); return this.fixTypeEverywhereTyped(this.name, inputType, outputType, input -> input.updateTyped(statsFinder, stats -> stats.updateTyped(customFinder, custom -> custom.update(nameFinder, value -> this.renames.getOrDefault(value, (String)value))))); } }