| 1 | package net.minecraft.util.datafix.fixes;
|
| 2 |
|
| 3 | import com.google.common.collect.ImmutableMap;
|
| 4 | import com.mojang.datafixers.DSL;
|
| 5 | import com.mojang.datafixers.DataFix;
|
| 6 | import com.mojang.datafixers.OpticFinder;
|
| 7 | import com.mojang.datafixers.TypeRewriteRule;
|
| 8 | import com.mojang.datafixers.schemas.Schema;
|
| 9 | import com.mojang.datafixers.types.Type;
|
| 10 | import com.mojang.serialization.Dynamic;
|
| 11 | import java.util.Map;
|
| 12 | import java.util.Objects;
|
| 13 |
|
| 14 | public class ChunkStatusFix2 extends DataFix {
|
| 15 | private static final Map<String, String> RENAMES_AND_DOWNGRADES = ImmutableMap.<String, String>builder()
|
| 16 | .put("structure_references", "empty")
|
| 17 | .put("biomes", "empty")
|
| 18 | .put("base", "surface")
|
| 19 | .put("carved", "carvers")
|
| 20 | .put("liquid_carved", "liquid_carvers")
|
| 21 | .put("decorated", "features")
|
| 22 | .put("lighted", "light")
|
| 23 | .put("mobs_spawned", "spawn")
|
| 24 | .put("finalized", "heightmaps")
|
| 25 | .put("fullchunk", "full")
|
| 26 | .build();
|
| 27 |
|
| 28 | public ChunkStatusFix2(final Schema schema, final boolean changesType) {
|
| 29 | super(schema, changesType);
|
| 30 | }
|
| 31 |
|
| 32 | @Override
|
| 33 | protected TypeRewriteRule makeRule() {
|
| 34 | Type<?> chunkType = this.getInputSchema().getType(References.CHUNK);
|
| 35 | Type<?> levelType = chunkType.findFieldType("Level");
|
| 36 | OpticFinder<?> levelF = DSL.fieldFinder("Level", levelType);
|
| 37 | return this.fixTypeEverywhereTyped(
|
| 38 | "ChunkStatusFix2", chunkType, this.getOutputSchema().getType(References.CHUNK), input -> input.updateTyped(levelF, level -> {
|
| 39 | Dynamic<?> tag = level.get(DSL.remainderFinder());
|
| 40 | String status = tag.get("Status").asString("empty");
|
| 41 | String newStatus = RENAMES_AND_DOWNGRADES.getOrDefault(status, "empty");
|
| 42 | return Objects.equals(status, newStatus) ? level : level.set(DSL.remainderFinder(), tag.set("Status", tag.createString(newStatus)));
|
| 43 | })
|
| 44 | );
|
| 45 | }
|
| 46 | }
|
| 47 |
|