Fixed some items not appearing in their respective creative tabs

This commit is contained in:
Sollace 2022-10-09 00:22:51 +02:00
parent 06de83981e
commit 276e2f2b2a

View file

@ -1,6 +1,7 @@
package com.minelittlepony.unicopia.item; package com.minelittlepony.unicopia.item;
import java.util.function.Supplier; import java.util.function.Supplier;
import java.util.stream.Stream;
import com.minelittlepony.unicopia.UTags; import com.minelittlepony.unicopia.UTags;
import com.minelittlepony.unicopia.Unicopia; import com.minelittlepony.unicopia.Unicopia;
@ -16,21 +17,12 @@ import net.minecraft.util.collection.DefaultedList;
import net.minecraft.util.registry.Registry; import net.minecraft.util.registry.Registry;
public interface UItemGroups { public interface UItemGroups {
ItemGroup ALL_ITEMS = FabricItemGroupBuilder.create(Unicopia.id("items")).appendItems(list -> { ItemGroup ALL_ITEMS = create("items", UItems.EMPTY_JAR::getDefaultStack, () -> {
list.add(Items.APPLE.getDefaultStack()); return Stream.concat(Stream.of(Items.APPLE), UItems.ITEMS.stream().filter(item -> !(item instanceof ChameleonItem) || ((ChameleonItem)item).isFullyDisguised()));
});
DefaultedList<ItemStack> defs = DefaultedList.of(); ItemGroup HORSE_FEED = create("horsefeed", UItems.ZAP_APPLE::getDefaultStack, () -> {
UItems.ITEMS.stream() return Registry.ITEM.stream().filter(item -> ((ToxicHolder)item).getToxic(item.getDefaultStack()) != Toxic.EMPTY);
.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 EARTH_PONY_ITEMS = forTag("earth_pony", UItems.APPLE_PIE::getDefaultStack); ItemGroup EARTH_PONY_ITEMS = forTag("earth_pony", UItems.APPLE_PIE::getDefaultStack);
ItemGroup UNICORN_ITEMS = forTag("unicorn", UItems.SPELLBOOK::getDefaultStack); ItemGroup UNICORN_ITEMS = forTag("unicorn", UItems.SPELLBOOK::getDefaultStack);
@ -40,13 +32,19 @@ public interface UItemGroups {
static ItemGroup forTag(String name, Supplier<ItemStack> icon) { static ItemGroup forTag(String name, Supplier<ItemStack> icon) {
TagKey<Item> key = UTags.item("groups/" + name); TagKey<Item> key = UTags.item("groups/" + name);
return FabricItemGroupBuilder.create(Unicopia.id(name)).appendItems(list -> { return create(name, icon, () -> {
list.addAll(Registry.ITEM.getEntryList(key) return Registry.ITEM.getEntryList(key)
.stream() .stream()
.flatMap(named -> named.stream()) .flatMap(named -> named.stream())
.map(entry -> entry.value()) .map(entry -> entry.value());
.map(Item::getDefaultStack) });
.toList()); }
static ItemGroup create(String name, Supplier<ItemStack> icon, Supplier<Stream<Item>> items) {
return FabricItemGroupBuilder.create(Unicopia.id(name)).appendItems(list -> {
DefaultedList<ItemStack> defs = DefaultedList.of();
items.get().forEach(item -> item.appendStacks(ItemGroup.SEARCH, defs));
list.addAll(defs);
}).icon(icon).build(); }).icon(icon).build();
} }