39 lines
1.4 KiB
Java
39 lines
1.4 KiB
Java
package net.minecraft.util.datafix.fixes;
|
|
|
|
import com.google.common.collect.Maps;
|
|
import com.mojang.datafixers.DSL;
|
|
import com.mojang.datafixers.DataFixUtils;
|
|
import com.mojang.datafixers.Typed;
|
|
import com.mojang.datafixers.schemas.Schema;
|
|
import com.mojang.serialization.Dynamic;
|
|
import java.util.Locale;
|
|
import java.util.Map;
|
|
import java.util.Optional;
|
|
import net.minecraft.util.datafix.schemas.NamespacedSchema;
|
|
|
|
public class EntityPaintingMotiveFix extends NamedEntityFix {
|
|
private static final Map<String, String> MAP = DataFixUtils.make(Maps.<String, String>newHashMap(), hashMap -> {
|
|
hashMap.put("donkeykong", "donkey_kong");
|
|
hashMap.put("burningskull", "burning_skull");
|
|
hashMap.put("skullandroses", "skull_and_roses");
|
|
});
|
|
|
|
public EntityPaintingMotiveFix(Schema outputSchema, boolean changesType) {
|
|
super(outputSchema, changesType, "EntityPaintingMotiveFix", References.ENTITY, "minecraft:painting");
|
|
}
|
|
|
|
public Dynamic<?> fixTag(Dynamic<?> tag) {
|
|
Optional<String> optional = tag.get("Motive").asString().result();
|
|
if (optional.isPresent()) {
|
|
String string = ((String)optional.get()).toLowerCase(Locale.ROOT);
|
|
return tag.set("Motive", tag.createString(NamespacedSchema.ensureNamespaced((String)MAP.getOrDefault(string, string))));
|
|
} else {
|
|
return tag;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
protected Typed<?> fix(Typed<?> typed) {
|
|
return typed.update(DSL.remainderFinder(), this::fixTag);
|
|
}
|
|
}
|