From 605eb2d48eb384958a9b93c302143eaa74da7912 Mon Sep 17 00:00:00 2001 From: MerchantPug <81167232+MerchantPug@users.noreply.github.com> Date: Thu, 18 May 2023 21:55:01 +1000 Subject: [PATCH] Apoli: Fix EdwinMindcraft/origins-architectury#312 Issue 2 --- .../configuration/ConfiguredItemCondition.java | 10 ++++++++++ .../configuration/RestrictArmorConfiguration.java | 13 ++++--------- 2 files changed, 14 insertions(+), 9 deletions(-) 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);