| 1 | package net.minecraft.util.datafix.fixes;
|
| 2 |
|
| 3 | import com.mojang.datafixers.DSL;
|
| 4 | import com.mojang.datafixers.DataFix;
|
| 5 | import com.mojang.datafixers.OpticFinder;
|
| 6 | import com.mojang.datafixers.TypeRewriteRule;
|
| 7 | import com.mojang.datafixers.Typed;
|
| 8 | import com.mojang.datafixers.DSL.TypeReference;
|
| 9 | import com.mojang.datafixers.schemas.Schema;
|
| 10 |
|
| 11 | public abstract class NamedEntityFix extends DataFix {
|
| 12 | private final String name;
|
| 13 | protected final String entityName;
|
| 14 | protected final TypeReference type;
|
| 15 |
|
| 16 | public NamedEntityFix(final Schema outputSchema, final boolean changesType, final String name, final TypeReference type, final String entityName) {
|
| 17 | super(outputSchema, changesType);
|
| 18 | this.name = name;
|
| 19 | this.type = type;
|
| 20 | this.entityName = entityName;
|
| 21 | }
|
| 22 |
|
| 23 | @Override
|
| 24 | public TypeRewriteRule makeRule() {
|
| 25 | OpticFinder<?> entityF = DSL.namedChoice(this.entityName, this.getInputSchema().getChoiceType(this.type, this.entityName));
|
| 26 | return this.fixTypeEverywhereTyped(
|
| 27 | this.name,
|
| 28 | this.getInputSchema().getType(this.type),
|
| 29 | this.getOutputSchema().getType(this.type),
|
| 30 | input -> input.updateTyped(entityF, this.getOutputSchema().getChoiceType(this.type, this.entityName), this::fix)
|
| 31 | );
|
| 32 | }
|
| 33 |
|
| 34 | protected abstract Typed<?> fix(final Typed<?> entity);
|
| 35 | }
|
| 36 |
|