package com.minelittlepony.unicopia.diet; import java.util.function.Function; import com.mojang.serialization.Codec; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.registry.RegistryKeys; import net.minecraft.registry.tag.TagKey; import net.minecraft.util.Identifier; import net.minecraft.util.Util; public interface FoodGroupKey { Function LOOKUP = Util.memoize(id -> { return new FoodGroupKey() { @Override public Identifier id() { return id; } @Override public boolean contains(ItemStack stack) { var group = PonyDiets.getEffect(id); return group != null && group.test(stack); } }; }); Function, FoodGroupKey> TAG_LOOKUP = Util.memoize(tag -> { return new FoodGroupKey() { @Override public Identifier id() { return tag.id(); } @Override public boolean contains(ItemStack stack) { return stack.isIn(tag); } }; }); Function TAG_ID_LOOKUP = id -> TAG_LOOKUP.apply(TagKey.of(RegistryKeys.ITEM, id)); Codec CODEC = Identifier.CODEC.xmap(LOOKUP, FoodGroupKey::id); Codec TAG_CODEC = TagKey.unprefixedCodec(RegistryKeys.ITEM).xmap(TAG_LOOKUP, k -> TagKey.of(RegistryKeys.ITEM, k.id())); Identifier id(); boolean contains(ItemStack stack); }