| 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.Optional;
|
| 11 |
|
| 12 | public class HeightmapRenamingFix extends DataFix {
|
| 13 | public HeightmapRenamingFix(final Schema outputSchema, final boolean changesType) {
|
| 14 | super(outputSchema, changesType);
|
| 15 | }
|
| 16 |
|
| 17 | @Override
|
| 18 | protected TypeRewriteRule makeRule() {
|
| 19 | Type<?> inputType = this.getInputSchema().getType(References.CHUNK);
|
| 20 | OpticFinder<?> levelF = inputType.findField("Level");
|
| 21 | return this.fixTypeEverywhereTyped(
|
| 22 | "HeightmapRenamingFix", inputType, input -> input.updateTyped(levelF, level -> level.update(DSL.remainderFinder(), this::fix))
|
| 23 | );
|
| 24 | }
|
| 25 |
|
| 26 | private Dynamic<?> fix(final Dynamic<?> tag) {
|
| 27 | Optional<? extends Dynamic<?>> heightmaps = tag.get("Heightmaps").result();
|
| 28 | if (heightmaps.isEmpty()) {
|
| 29 | return tag;
|
| 30 | }
|
| 31 |
|
| 32 | Dynamic<?> heightmapsTag = (Dynamic<?>)heightmaps.get();
|
| 33 | Optional<? extends Dynamic<?>> liquid = heightmapsTag.get("LIQUID").result();
|
| 34 | if (liquid.isPresent()) {
|
| 35 | heightmapsTag = heightmapsTag.remove("LIQUID");
|
| 36 | heightmapsTag = heightmapsTag.set("WORLD_SURFACE_WG", (Dynamic<?>)liquid.get());
|
| 37 | }
|
| 38 |
|
| 39 | Optional<? extends Dynamic<?>> solid = heightmapsTag.get("SOLID").result();
|
| 40 | if (solid.isPresent()) {
|
| 41 | heightmapsTag = heightmapsTag.remove("SOLID");
|
| 42 | heightmapsTag = heightmapsTag.set("OCEAN_FLOOR_WG", (Dynamic<?>)solid.get());
|
| 43 | heightmapsTag = heightmapsTag.set("OCEAN_FLOOR", (Dynamic<?>)solid.get());
|
| 44 | }
|
| 45 |
|
| 46 | Optional<? extends Dynamic<?>> light = heightmapsTag.get("LIGHT").result();
|
| 47 | if (light.isPresent()) {
|
| 48 | heightmapsTag = heightmapsTag.remove("LIGHT");
|
| 49 | heightmapsTag = heightmapsTag.set("LIGHT_BLOCKING", (Dynamic<?>)light.get());
|
| 50 | }
|
| 51 |
|
| 52 | Optional<? extends Dynamic<?>> rain = heightmapsTag.get("RAIN").result();
|
| 53 | if (rain.isPresent()) {
|
| 54 | heightmapsTag = heightmapsTag.remove("RAIN");
|
| 55 | heightmapsTag = heightmapsTag.set("MOTION_BLOCKING", (Dynamic<?>)rain.get());
|
| 56 | heightmapsTag = heightmapsTag.set("MOTION_BLOCKING_NO_LEAVES", (Dynamic<?>)rain.get());
|
| 57 | }
|
| 58 |
|
| 59 | return tag.set("Heightmaps", heightmapsTag);
|
| 60 | }
|
| 61 | }
|
| 62 |
|