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;
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<ItemStack> 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<ItemStack> icon) {
TagKey<Item> 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<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();
}