package net.minecraft.util.datafix.fixes; import java.util.function.Function; import com.mojang.datafixers.types.DynamicOps; import com.mojang.datafixers.types.templates.TaggedChoice; import com.mojang.datafixers.util.Pair; import com.mojang.datafixers.Typed; import com.mojang.datafixers.types.Type; import com.mojang.datafixers.TypeRewriteRule; import com.mojang.datafixers.schemas.Schema; import com.mojang.datafixers.DataFix; public abstract class EntityRenameFix extends DataFix { protected final String name; public EntityRenameFix(final String string, final Schema schema, final boolean boolean3) { super(schema, boolean3); this.name = string; } public TypeRewriteRule makeRule() { final TaggedChoice.TaggedChoiceType taggedChoiceType2 = (TaggedChoice.TaggedChoiceType)this.getInputSchema().findChoiceType(References.ENTITY); final TaggedChoice.TaggedChoiceType taggedChoiceType3 = (TaggedChoice.TaggedChoiceType)this.getOutputSchema().findChoiceType(References.ENTITY); final String string6; final TaggedChoice.TaggedChoiceType taggedChoiceType4; final Type type7; final Pair> pair2; final TaggedChoice.TaggedChoiceType taggedChoiceType5; final Type type8; final IllegalStateException ex; return this.fixTypeEverywhere(this.name, (Type)taggedChoiceType2, (Type)taggedChoiceType3, dynamicOps -> pair -> { string6 = (String)pair.getFirst(); type7 = taggedChoiceType4.types().get(string6); pair2 = this.fix(string6, this.getEntity(pair.getSecond(), dynamicOps, type7)); type8 = taggedChoiceType5.types().get(pair2.getFirst()); if (!type8.equals(((Typed)pair2.getSecond()).getType(), true, true)) { new IllegalStateException(String.format("Dynamic type check failed: %s not equal to %s", type8, ((Typed)pair2.getSecond()).getType())); throw ex; } else { return Pair.of(pair2.getFirst(), ((Typed)pair2.getSecond()).getValue()); } }); } private Typed getEntity(final Object object, final DynamicOps dynamicOps, final Type type) { return (Typed)new Typed((Type)type, (DynamicOps)dynamicOps, object); } protected abstract Pair> fix(final String string, final Typed typed); }