| 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.TypeRewriteRule;
|
| 6 | import com.mojang.datafixers.schemas.Schema;
|
| 7 | import com.mojang.datafixers.util.Pair;
|
| 8 | import java.util.stream.Collectors;
|
| 9 |
|
| 10 | public class OptionsKeyTranslationFix extends DataFix {
|
| 11 | public OptionsKeyTranslationFix(final Schema outputSchema, final boolean changesType) {
|
| 12 | super(outputSchema, changesType);
|
| 13 | }
|
| 14 |
|
| 15 | @Override
|
| 16 | public TypeRewriteRule makeRule() {
|
| 17 | return this.fixTypeEverywhereTyped(
|
| 18 | "OptionsKeyTranslationFix",
|
| 19 | this.getInputSchema().getType(References.OPTIONS),
|
| 20 | input -> input.update(DSL.remainderFinder(), tag -> tag.getMapValues().map(map1 -> tag.createMap(map1.entrySet().stream().map(entry -> {
|
| 21 | if (entry.getKey().asString("").startsWith("key_")) {
|
| 22 | String oldValue = entry.getValue().asString("");
|
| 23 | if (!oldValue.startsWith("key.mouse") && !oldValue.startsWith("scancode.")) {
|
| 24 | return Pair.of(entry.getKey(), tag.createString("key.keyboard." + oldValue.substring("key.".length())));
|
| 25 | }
|
| 26 | }
|
| 27 |
|
| 28 | return Pair.of(entry.getKey(), entry.getValue());
|
| 29 | }).collect(Collectors.toMap(Pair::getFirst, Pair::getSecond)))).result().orElse(tag))
|
| 30 | );
|
| 31 | }
|
| 32 | }
|
| 33 |
|