package net.minecraft.util.datafix.fixes; import com.mojang.datafixers.DataFix; import com.mojang.datafixers.TypeRewriteRule; import com.mojang.datafixers.schemas.Schema; import com.mojang.datafixers.types.templates.TaggedChoice.TaggedChoiceType; import java.util.function.UnaryOperator; public class BlockEntityRenameFix extends DataFix { private final String name; private final UnaryOperator nameChangeLookup; private BlockEntityRenameFix(Schema outputSchema, String name, UnaryOperator nameChangeLookup) { super(outputSchema, true); this.name = name; this.nameChangeLookup = nameChangeLookup; } @Override public TypeRewriteRule makeRule() { TaggedChoiceType taggedChoiceType = (TaggedChoiceType)this.getInputSchema().findChoiceType(References.BLOCK_ENTITY); TaggedChoiceType taggedChoiceType2 = (TaggedChoiceType)this.getOutputSchema().findChoiceType(References.BLOCK_ENTITY); return this.fixTypeEverywhere(this.name, taggedChoiceType, taggedChoiceType2, dynamicOps -> pair -> pair.mapFirst(this.nameChangeLookup)); } public static DataFix create(Schema outputSchema, String name, UnaryOperator nameChangeLookup) { return new BlockEntityRenameFix(outputSchema, name, nameChangeLookup); } }