/* * Decompiled with CFR 0.152. * * Could not load the following classes: * com.mojang.datafixers.schemas.Schema * com.mojang.serialization.Dynamic * org.jspecify.annotations.Nullable */ package net.minecraft.util.datafix.fixes; import com.mojang.datafixers.schemas.Schema; import com.mojang.serialization.Dynamic; import java.util.Map; import java.util.Optional; import java.util.function.Predicate; import net.minecraft.util.datafix.fixes.DataComponentRemainderFix; import org.jspecify.annotations.Nullable; public class InvalidLockComponentFix extends DataComponentRemainderFix { private static final Optional INVALID_LOCK_CUSTOM_NAME = Optional.of("\"\""); public InvalidLockComponentFix(Schema outputSchema) { super(outputSchema, "InvalidLockComponentPredicateFix", "minecraft:lock"); } @Override protected @Nullable Dynamic fixComponent(Dynamic input) { return InvalidLockComponentFix.fixLock(input); } public static @Nullable Dynamic fixLock(Dynamic input) { return InvalidLockComponentFix.isBrokenLock(input) ? null : input; } private static boolean isBrokenLock(Dynamic input) { return InvalidLockComponentFix.isMapWithOneField(input, "components", components -> InvalidLockComponentFix.isMapWithOneField(components, "minecraft:custom_name", customName -> customName.asString().result().equals(INVALID_LOCK_CUSTOM_NAME))); } private static boolean isMapWithOneField(Dynamic input, String fieldName, Predicate> predicate) { Optional map = input.getMapValues().result(); if (map.isEmpty() || ((Map)map.get()).size() != 1) { return false; } return input.get(fieldName).result().filter(predicate).isPresent(); } }