| 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.DataFixUtils;
|
| 6 | import com.mojang.datafixers.TypeRewriteRule;
|
| 7 | import com.mojang.datafixers.schemas.Schema;
|
| 8 |
|
| 9 | public class OptionsGraphicsModeSplitFix extends DataFix {
|
| 10 | private final String newFieldName;
|
| 11 | private final String valueIfFast;
|
| 12 | private final String valueIfFancy;
|
| 13 | private final String valueIfFabulous;
|
| 14 |
|
| 15 | public OptionsGraphicsModeSplitFix(
|
| 16 | final Schema outputSchema, final String newFieldName, final String valueIfFast, final String valueIfFancy, final String valueIfFabulous
|
| 17 | ) {
|
| 18 | super(outputSchema, true);
|
| 19 | this.newFieldName = newFieldName;
|
| 20 | this.valueIfFast = valueIfFast;
|
| 21 | this.valueIfFancy = valueIfFancy;
|
| 22 | this.valueIfFabulous = valueIfFabulous;
|
| 23 | }
|
| 24 |
|
| 25 | @Override
|
| 26 | public TypeRewriteRule makeRule() {
|
| 27 | return this.fixTypeEverywhereTyped(
|
| 28 | "graphicsMode split to " + this.newFieldName,
|
| 29 | this.getInputSchema().getType(References.OPTIONS),
|
| 30 | input -> input.update(
|
| 31 | DSL.remainderFinder(),
|
| 32 | tag -> DataFixUtils.orElseGet(
|
| 33 | tag.get("graphicsMode").asString().map(mode -> tag.set(this.newFieldName, tag.createString(this.getValue(mode)))).result(),
|
| 34 | () -> tag.set(this.newFieldName, tag.createString(this.valueIfFancy))
|
| 35 | )
|
| 36 | )
|
| 37 | );
|
| 38 | }
|
| 39 |
|
| 40 | private String getValue(final String mode) {
|
| 41 | return switch (mode) {
|
| 42 | case "2" -> this.valueIfFabulous;
|
| 43 | case "0" -> this.valueIfFast;
|
| 44 | default -> this.valueIfFancy;
|
| 45 | };
|
| 46 | }
|
| 47 | }
|
| 48 |
|