mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-12-01 08:47:59 +01:00
50 lines
1.5 KiB
Java
50 lines
1.5 KiB
Java
|
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<Identifier, FoodGroupKey> 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<TagKey<Item>, 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<Identifier, FoodGroupKey> TAG_ID_LOOKUP = id -> TAG_LOOKUP.apply(TagKey.of(RegistryKeys.ITEM, id));
|
||
|
Codec<FoodGroupKey> CODEC = Identifier.CODEC.xmap(LOOKUP, FoodGroupKey::id);
|
||
|
Codec<FoodGroupKey> TAG_CODEC = TagKey.unprefixedCodec(RegistryKeys.ITEM).xmap(TAG_LOOKUP, k -> TagKey.of(RegistryKeys.ITEM, k.id()));
|
||
|
|
||
|
Identifier id();
|
||
|
|
||
|
boolean contains(ItemStack stack);
|
||
|
}
|