35 lines
1.2 KiB
Java
35 lines
1.2 KiB
Java
package net.minecraft.util.datafix.fixes;
|
|
|
|
import com.mojang.datafixers.DSL;
|
|
import com.mojang.datafixers.DataFix;
|
|
import com.mojang.datafixers.DataFixUtils;
|
|
import com.mojang.datafixers.OpticFinder;
|
|
import com.mojang.datafixers.TypeRewriteRule;
|
|
import com.mojang.datafixers.schemas.Schema;
|
|
import com.mojang.datafixers.types.Type;
|
|
import com.mojang.serialization.Dynamic;
|
|
import net.minecraft.util.datafix.ComponentDataFixUtils;
|
|
|
|
public class ItemWrittenBookPagesStrictJsonFix extends DataFix {
|
|
public ItemWrittenBookPagesStrictJsonFix(Schema outputSchema, boolean changesType) {
|
|
super(outputSchema, changesType);
|
|
}
|
|
|
|
public Dynamic<?> fixTag(Dynamic<?> tag) {
|
|
return tag.update(
|
|
"pages",
|
|
dynamic2 -> DataFixUtils.orElse(
|
|
dynamic2.asStreamOpt().map(stream -> stream.map(ComponentDataFixUtils::rewriteFromLenient)).map(tag::createList).result(), tag.emptyList()
|
|
)
|
|
);
|
|
}
|
|
|
|
@Override
|
|
public TypeRewriteRule makeRule() {
|
|
Type<?> type = this.getInputSchema().getType(References.ITEM_STACK);
|
|
OpticFinder<?> opticFinder = type.findField("tag");
|
|
return this.fixTypeEverywhereTyped(
|
|
"ItemWrittenBookPagesStrictJsonFix", type, typed -> typed.updateTyped(opticFinder, typedx -> typedx.update(DSL.remainderFinder(), this::fixTag))
|
|
);
|
|
}
|
|
}
|