| 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.schemas.Schema;
|
| 8 | import com.mojang.datafixers.types.Type;
|
| 9 | import com.mojang.serialization.Dynamic;
|
| 10 | import java.util.Objects;
|
| 11 |
|
| 12 | public class ChunkStatusFix extends DataFix {
|
| 13 | public ChunkStatusFix(final Schema schema, final boolean changesType) {
|
| 14 | super(schema, changesType);
|
| 15 | }
|
| 16 |
|
| 17 | @Override
|
| 18 | protected TypeRewriteRule makeRule() {
|
| 19 | Type<?> chunkType = this.getInputSchema().getType(References.CHUNK);
|
| 20 | Type<?> levelType = chunkType.findFieldType("Level");
|
| 21 | OpticFinder<?> levelF = DSL.fieldFinder("Level", levelType);
|
| 22 | return this.fixTypeEverywhereTyped(
|
| 23 | "ChunkStatusFix", chunkType, this.getOutputSchema().getType(References.CHUNK), input -> input.updateTyped(levelF, level -> {
|
| 24 | Dynamic<?> tag = level.get(DSL.remainderFinder());
|
| 25 | String status = tag.get("Status").asString("empty");
|
| 26 | if (Objects.equals(status, "postprocessed")) {
|
| 27 | tag = tag.set("Status", tag.createString("fullchunk"));
|
| 28 | }
|
| 29 |
|
| 30 | return level.set(DSL.remainderFinder(), tag);
|
| 31 | })
|
| 32 | );
|
| 33 | }
|
| 34 | }
|
| 35 |
|