From 276e2f2b2a9a8068da9e0ba21b299ee6ac38927a Mon Sep 17 00:00:00 2001 From: Sollace Date: Sun, 9 Oct 2022 00:22:51 +0200 Subject: [PATCH] Fixed some items not appearing in their respective creative tabs --- .../unicopia/item/UItemGroups.java | 38 +++++++++---------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/minelittlepony/unicopia/item/UItemGroups.java b/src/main/java/com/minelittlepony/unicopia/item/UItemGroups.java index ec50dee1..0280a792 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/UItemGroups.java +++ b/src/main/java/com/minelittlepony/unicopia/item/UItemGroups.java @@ -1,6 +1,7 @@ package com.minelittlepony.unicopia.item; import java.util.function.Supplier; +import java.util.stream.Stream; import com.minelittlepony.unicopia.UTags; import com.minelittlepony.unicopia.Unicopia; @@ -16,21 +17,12 @@ import net.minecraft.util.collection.DefaultedList; import net.minecraft.util.registry.Registry; public interface UItemGroups { - ItemGroup ALL_ITEMS = FabricItemGroupBuilder.create(Unicopia.id("items")).appendItems(list -> { - list.add(Items.APPLE.getDefaultStack()); - - DefaultedList defs = DefaultedList.of(); - UItems.ITEMS.stream() - .filter(item -> !(item instanceof ChameleonItem) || ((ChameleonItem)item).isFullyDisguised()) - .forEach(item -> item.appendStacks(ItemGroup.SEARCH, defs)); - list.addAll(defs); - }).icon(UItems.EMPTY_JAR::getDefaultStack).build(); - ItemGroup HORSE_FEED = FabricItemGroupBuilder.create(Unicopia.id("horsefeed")).appendItems(list -> { - list.addAll(Registry.ITEM.stream() - .map(Item::getDefaultStack) - .filter(stack -> ((ToxicHolder)stack.getItem()).getToxic(stack) != Toxic.EMPTY) - .toList()); - }).icon(UItems.ZAP_APPLE::getDefaultStack).build(); + ItemGroup ALL_ITEMS = create("items", UItems.EMPTY_JAR::getDefaultStack, () -> { + return Stream.concat(Stream.of(Items.APPLE), UItems.ITEMS.stream().filter(item -> !(item instanceof ChameleonItem) || ((ChameleonItem)item).isFullyDisguised())); + }); + ItemGroup HORSE_FEED = create("horsefeed", UItems.ZAP_APPLE::getDefaultStack, () -> { + return Registry.ITEM.stream().filter(item -> ((ToxicHolder)item).getToxic(item.getDefaultStack()) != Toxic.EMPTY); + }); ItemGroup EARTH_PONY_ITEMS = forTag("earth_pony", UItems.APPLE_PIE::getDefaultStack); ItemGroup UNICORN_ITEMS = forTag("unicorn", UItems.SPELLBOOK::getDefaultStack); @@ -40,13 +32,19 @@ public interface UItemGroups { static ItemGroup forTag(String name, Supplier icon) { TagKey key = UTags.item("groups/" + name); - return FabricItemGroupBuilder.create(Unicopia.id(name)).appendItems(list -> { - list.addAll(Registry.ITEM.getEntryList(key) + return create(name, icon, () -> { + return Registry.ITEM.getEntryList(key) .stream() .flatMap(named -> named.stream()) - .map(entry -> entry.value()) - .map(Item::getDefaultStack) - .toList()); + .map(entry -> entry.value()); + }); + } + + static ItemGroup create(String name, Supplier icon, Supplier> items) { + return FabricItemGroupBuilder.create(Unicopia.id(name)).appendItems(list -> { + DefaultedList defs = DefaultedList.of(); + items.get().forEach(item -> item.appendStacks(ItemGroup.SEARCH, defs)); + list.addAll(defs); }).icon(icon).build(); }