ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyTabs.java

48 lines
2.1 KiB
Java
Raw Normal View History

2024-03-03 01:20:53 +01:00
package de.ellpeck.actuallyadditions.mod;
2024-03-07 00:18:32 +01:00
import de.ellpeck.actuallyadditions.mod.attachments.ActuallyAttachments;
2024-03-03 01:20:53 +01:00
import de.ellpeck.actuallyadditions.mod.items.ActuallyItems;
import de.ellpeck.actuallyadditions.mod.items.base.ItemEnergy;
2024-03-07 01:56:39 +01:00
import de.ellpeck.actuallyadditions.mod.tile.CustomEnergyStorage;
2024-03-03 01:20:53 +01:00
import net.minecraft.core.registries.Registries;
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.CreativeModeTabs;
import net.minecraft.world.item.ItemStack;
2024-03-04 20:21:48 +01:00
import net.neoforged.bus.api.IEventBus;
import net.neoforged.neoforge.registries.DeferredRegister;
2024-03-03 01:20:53 +01:00
import java.util.List;
import java.util.function.Supplier;
2024-03-07 00:18:32 +01:00
import java.util.stream.Collectors;
2024-03-03 01:20:53 +01:00
public class ActuallyTabs {
public static final DeferredRegister<CreativeModeTab> CREATIVE_MODE_TABS = DeferredRegister.create(Registries.CREATIVE_MODE_TAB, ActuallyAdditions.MODID);
public static final Supplier<CreativeModeTab> GROUP = CREATIVE_MODE_TABS.register("tab", () -> CreativeModeTab.builder()
.icon(() -> ActuallyItems.ITEM_BOOKLET.get().getDefaultInstance())
.withTabsBefore(CreativeModeTabs.SPAWN_EGGS)
.title(Component.translatable("itemGroup.actuallyadditions"))
.displayItems((parameters, output) -> {
2024-03-07 00:18:32 +01:00
List<ItemStack> stacks = ActuallyItems.ITEMS.getEntries().stream().map(reg -> new ItemStack(reg.get())).collect(Collectors.toList());
//Add charged versions of all energy items
List<ItemStack> charged = ActuallyItems.ITEMS.getEntries().stream().map(reg -> new ItemStack(reg.get()))
.filter(stack -> stack.getItem() instanceof ItemEnergy).toList();
charged.forEach(stack -> {
2024-03-03 01:20:53 +01:00
if(stack.getItem() instanceof ItemEnergy itemEnergy) {
2024-03-07 01:56:39 +01:00
CustomEnergyStorage storage = new CustomEnergyStorage(itemEnergy.maxPower, itemEnergy.transfer, itemEnergy.transfer);
storage.setEnergyStored(itemEnergy.maxPower);
2024-03-07 00:18:32 +01:00
stack.setData(ActuallyAttachments.ENERGY_STORAGE.get(), storage);
2024-03-03 01:20:53 +01:00
}
});
2024-03-07 00:18:32 +01:00
stacks.addAll(charged);
2024-03-03 01:20:53 +01:00
output.acceptAll(stacks);
}).build());
public static void init(IEventBus evt) {
CREATIVE_MODE_TABS.register(evt);
}
}