| 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.serialization.Dynamic;
|
| 8 |
|
| 9 | public class BlendingDataNoValueHeightFix extends DataFix {
|
| 10 | public BlendingDataNoValueHeightFix(final Schema outputSchema) {
|
| 11 | super(outputSchema, false);
|
| 12 | }
|
| 13 |
|
| 14 | @Override
|
| 15 | protected TypeRewriteRule makeRule() {
|
| 16 | return this.fixTypeEverywhereTyped(
|
| 17 | "BlendingDataNoValueHeightFix",
|
| 18 | this.getInputSchema().getType(References.CHUNK),
|
| 19 | chunk -> chunk.update(DSL.remainderFinder(), BlendingDataNoValueHeightFix::fix)
|
| 20 | );
|
| 21 | }
|
| 22 |
|
| 23 | private static Dynamic<?> fix(final Dynamic<?> chunk) {
|
| 24 | return chunk.update(
|
| 25 | "blending_data",
|
| 26 | blendingData -> blendingData.update("heights", heights -> heights.createList(heights.asStream().map(BlendingDataNoValueHeightFix::fixHeightValue)))
|
| 27 | );
|
| 28 | }
|
| 29 |
|
| 30 | private static Dynamic<?> fixHeightValue(final Dynamic<?> height) {
|
| 31 | double heightValue = height.asDouble(Double.MAX_VALUE);
|
| 32 | return heightValue == Double.MAX_VALUE ? height.createFloat(Float.MAX_VALUE) : height.createFloat((float)heightValue);
|
| 33 | }
|
| 34 | }
|
| 35 |
|