Skip to content

Commit

Permalink
feat(utils): item predicates
Browse files Browse the repository at this point in the history
  • Loading branch information
WakelessSloth56 committed Mar 28, 2022
1 parent fafca72 commit 58f30d5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
@@ -1,5 +1,7 @@
package org.auioc.mods.arnicalib.common.itemgroup.impl;

import org.auioc.mods.arnicalib.utils.game.ItemUtils;
import org.auioc.mods.arnicalib.utils.game.RegistryUtils;
import net.minecraft.core.NonNullList;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.ItemStack;
Expand All @@ -21,9 +23,9 @@ public ItemStack makeIcon() {
public void fillItemList(NonNullList<ItemStack> list) {
ForgeRegistries.ITEMS.getValues()
.stream()
.filter((item) -> item != Items.AIR)
.filter((item) -> item.getItemCategory() == null)
.filter((item) -> item.getRegistryName().getNamespace().equals("minecraft"))
.filter(ItemUtils.IS_AIR.negate())
.filter(ItemUtils.IS_CATEGORIZED.negate())
.filter(RegistryUtils.IS_VANILLA)
.map(ItemStack::new)
.forEach(list::add);
}
Expand Down
Expand Up @@ -13,6 +13,7 @@
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraftforge.registries.ForgeRegistries;

public interface ItemUtils {
Expand All @@ -35,6 +36,11 @@ static String getRegistryName(ItemStack itemStack) {
return getRegistryName(itemStack.getItem());
}

static Predicate<ItemStack> IS_VANILLA_ITEM = (itemStack) -> RegistryUtils.IS_VANILLA.test(itemStack.getItem());

static Predicate<Item> IS_AIR = (item) -> item == Items.AIR;

static Predicate<Item> IS_CATEGORIZED = (item) -> item.getItemCategory() != null;

@SuppressWarnings("deprecation")
static int getMaxStackSize(Item item) {
Expand Down

0 comments on commit 58f30d5

Please sign in to comment.