| 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.types.Type;
|
| 8 | import com.mojang.datafixers.util.Pair;
|
| 9 | import com.mojang.serialization.Dynamic;
|
| 10 | import java.util.Objects;
|
| 11 |
|
| 12 | public class ForcePoiRebuild extends DataFix {
|
| 13 | public ForcePoiRebuild(final Schema outputSchema, final boolean changesType) {
|
| 14 | super(outputSchema, changesType);
|
| 15 | }
|
| 16 |
|
| 17 | @Override
|
| 18 | protected TypeRewriteRule makeRule() {
|
| 19 | Type<Pair<String, Dynamic<?>>> poiChunkType = DSL.named(References.POI_CHUNK.typeName(), DSL.remainderType());
|
| 20 | if (!Objects.equals(poiChunkType, this.getInputSchema().getType(References.POI_CHUNK))) {
|
| 21 | throw new IllegalStateException("Poi type is not what was expected.");
|
| 22 | } else {
|
| 23 | return this.fixTypeEverywhere("POI rebuild", poiChunkType, ops -> input -> input.mapSecond(ForcePoiRebuild::cap));
|
| 24 | }
|
| 25 | }
|
| 26 |
|
| 27 | private static <T> Dynamic<T> cap(final Dynamic<T> input) {
|
| 28 | return input.update("Sections", sections -> sections.updateMapValues(entry -> entry.mapSecond(section -> section.remove("Valid"))));
|
| 29 | }
|
| 30 | }
|
| 31 |
|