package net.minecraft.util.datafix.fixes; import com.mojang.datafixers.TypeRewriteRule; import com.mojang.datafixers.schemas.Schema; import com.mojang.serialization.Dynamic; public class BlockEntityUUIDFix extends AbstractUUIDFix { public BlockEntityUUIDFix(final Schema outputSchema) { super(outputSchema, References.BLOCK_ENTITY); } @Override protected TypeRewriteRule makeRule() { return this.fixTypeEverywhereTyped("BlockEntityUUIDFix", this.getInputSchema().getType(this.typeReference), input -> { input = this.updateNamedChoice(input, "minecraft:conduit", this::updateConduit); return this.updateNamedChoice(input, "minecraft:skull", this::updateSkull); }); } private Dynamic updateSkull(final Dynamic tag) { return (Dynamic)tag.get("Owner") .get() .map(ownerTag -> (Dynamic)replaceUUIDString(ownerTag, "Id", "Id").orElse(ownerTag)) .map(ownerTag -> tag.remove("Owner").set("SkullOwner", ownerTag)) .result() .orElse(tag); } private Dynamic updateConduit(final Dynamic tag) { return (Dynamic)replaceUUIDMLTag(tag, "target_uuid", "Target").orElse(tag); } }