diff --git a/src/main/java/io/github/edwinmindcraft/apoli/api/power/configuration/ConfiguredItemCondition.java b/src/main/java/io/github/edwinmindcraft/apoli/api/power/configuration/ConfiguredItemCondition.java index 4f35a1137..ad232b7e7 100644 --- a/src/main/java/io/github/edwinmindcraft/apoli/api/power/configuration/ConfiguredItemCondition.java +++ b/src/main/java/io/github/edwinmindcraft/apoli/api/power/configuration/ConfiguredItemCondition.java @@ -12,6 +12,8 @@ import io.github.edwinmindcraft.calio.api.network.CalioCodecHelper; import io.github.edwinmindcraft.calio.api.network.CodecSet; import net.minecraft.core.Holder; +import net.minecraft.resources.ResourceKey; +import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; @@ -30,6 +32,14 @@ public final class ConfiguredItemCondition>> optional(String name, ResourceKey> value) { + return CalioCodecHelper.registryField(HOLDER, name, value, ApoliDynamicRegistries.CONFIGURED_ITEM_CONDITION_KEY, ApoliBuiltinRegistries.CONFIGURED_ITEM_CONDITIONS); + } + + public static MapCodec>> optional(String name, ResourceLocation key) { + return CalioCodecHelper.registryField(HOLDER, name, ResourceKey.create(ApoliDynamicRegistries.CONFIGURED_ITEM_CONDITION_KEY, key), ApoliDynamicRegistries.CONFIGURED_ITEM_CONDITION_KEY, ApoliBuiltinRegistries.CONFIGURED_ITEM_CONDITIONS); + } + public static boolean check(Holder> condition, Level level, ItemStack stack) { return !condition.isBound() || condition.value().check(level, stack); } diff --git a/src/main/java/io/github/edwinmindcraft/apoli/common/power/configuration/RestrictArmorConfiguration.java b/src/main/java/io/github/edwinmindcraft/apoli/common/power/configuration/RestrictArmorConfiguration.java index 6d6127250..37f82329e 100644 --- a/src/main/java/io/github/edwinmindcraft/apoli/common/power/configuration/RestrictArmorConfiguration.java +++ b/src/main/java/io/github/edwinmindcraft/apoli/common/power/configuration/RestrictArmorConfiguration.java @@ -6,7 +6,6 @@ import com.mojang.serialization.codecs.RecordCodecBuilder; import io.github.edwinmindcraft.apoli.api.IDynamicFeatureConfiguration; import io.github.edwinmindcraft.apoli.api.power.configuration.ConfiguredItemCondition; -import io.github.edwinmindcraft.apoli.api.registry.ApoliBuiltinRegistries; import io.github.edwinmindcraft.apoli.api.registry.ApoliDynamicRegistries; import io.github.edwinmindcraft.calio.api.network.CalioCodecHelper; import net.minecraft.core.Holder; @@ -18,19 +17,15 @@ import net.minecraft.world.level.Level; import java.util.Map; -import java.util.Optional; public record RestrictArmorConfiguration(Map>> conditions, int tickRate) implements IDynamicFeatureConfiguration { - private static Holder> itemDefault() { - return ApoliBuiltinRegistries.CONFIGURED_ITEM_CONDITIONS.get().getHolder(ApoliDynamicRegistries.DENY).orElseThrow(); - } private static final MapCodec>>> EQUIPMENT_MAP_CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( - ConfiguredItemCondition.optional("head").forGetter(x -> Optional.ofNullable(x.get(EquipmentSlot.HEAD)).orElseGet(RestrictArmorConfiguration::itemDefault)), - ConfiguredItemCondition.optional("chest").forGetter(x -> Optional.ofNullable(x.get(EquipmentSlot.CHEST)).orElseGet(RestrictArmorConfiguration::itemDefault)), - ConfiguredItemCondition.optional("legs").forGetter(x -> Optional.ofNullable(x.get(EquipmentSlot.LEGS)).orElseGet(RestrictArmorConfiguration::itemDefault)), - ConfiguredItemCondition.optional("feet").forGetter(x -> Optional.ofNullable(x.get(EquipmentSlot.FEET)).orElseGet(RestrictArmorConfiguration::itemDefault)) + ConfiguredItemCondition.optional("head", ApoliDynamicRegistries.DENY).forGetter(x -> x.get(EquipmentSlot.HEAD)), + ConfiguredItemCondition.optional("chest", ApoliDynamicRegistries.DENY).forGetter(x -> x.get(EquipmentSlot.CHEST)), + ConfiguredItemCondition.optional("legs", ApoliDynamicRegistries.DENY).forGetter(x -> x.get(EquipmentSlot.LEGS)), + ConfiguredItemCondition.optional("feet", ApoliDynamicRegistries.DENY).forGetter(x -> x.get(EquipmentSlot.FEET)) ).apply(instance, (head, chest, legs, feet) -> { ImmutableMap.Builder>> builder = ImmutableMap.builder(); builder.put(EquipmentSlot.HEAD, head);