File size: 1,317 Bytes
d46f4a3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package net.minecraft.util.datafix.fixes;

import com.mojang.datafixers.TypeRewriteRule;
import com.mojang.datafixers.Typed;
import com.mojang.datafixers.schemas.Schema;
import com.mojang.serialization.Dynamic;

public class BlockEntityUUIDFix extends AbstractUUIDFix {
    public BlockEntityUUIDFix(Schema p_14883_) {
        super(p_14883_, References.BLOCK_ENTITY);
    }

    @Override
    protected TypeRewriteRule makeRule() {
        return this.fixTypeEverywhereTyped("BlockEntityUUIDFix", this.getInputSchema().getType(this.typeReference), p_14885_ -> {
            p_14885_ = this.updateNamedChoice(p_14885_, "minecraft:conduit", this::updateConduit);
            return this.updateNamedChoice(p_14885_, "minecraft:skull", this::updateSkull);
        });
    }

    private Dynamic<?> updateSkull(Dynamic<?> p_14890_) {
        return p_14890_.get("Owner")
            .get()
            .map(p_14894_ -> replaceUUIDString((Dynamic<?>)p_14894_, "Id", "Id").orElse((Dynamic<?>)p_14894_))
            .<Dynamic<?>>map(p_14888_ -> p_14890_.remove("Owner").set("SkullOwner", (Dynamic<?>)p_14888_))
            .result()
            .orElse(p_14890_);
    }

    private Dynamic<?> updateConduit(Dynamic<?> p_14892_) {
        return replaceUUIDMLTag(p_14892_, "target_uuid", "Target").orElse(p_14892_);
    }
}