package com.r3944realms.leashedplayer.content.items; import com.r3944realms.leashedplayer.LeashedPlayer; import net.minecraft.core.HolderLookup; import net.minecraft.core.registries.Registries; import net.minecraft.network.chat.Component; import net.minecraft.world.flag.FeatureFlagSet; import net.minecraft.world.item.CreativeModeTab; import net.minecraft.world.item.Item; import net.minecraft.world.item.Items; import net.minecraft.world.item.alchemy.Potion; import net.minecraft.world.item.alchemy.PotionContents; import net.neoforged.bus.api.IEventBus; import net.neoforged.neoforge.common.CommonHooks; import net.neoforged.neoforge.registries.DeferredRegister; import org.jetbrains.annotations.NotNull; import java.util.Objects; import java.util.function.Supplier; public class ModCreativeTab { public static final DeferredRegister CREATIVE_MODE_TABS = DeferredRegister.create(Registries.CREATIVE_MODE_TAB, LeashedPlayer.MOD_ID); public static final String LEASHED_PLAYER_TAB_STRING = "creativetab." + LeashedPlayer.MOD_ID; public static final String LEASHED_PLAYER_ITEM = "leashedplayer_tab"; public static final Supplier TEST_TAB = CREATIVE_MODE_TABS.register(LEASHED_PLAYER_ITEM,() -> CreativeModeTab.builder() .title(Component.translatable(getCreativeMod(LEASHED_PLAYER_ITEM))) .icon(() -> ModItemRegister.LEASH_ROPE_ARROW.get().getDefaultInstance()) .displayItems(((pParameters, pOutput) -> { pOutput.accept(Items.LEAD); pOutput.accept(Items.BOW); pOutput.accept(Items.CROSSBOW); pOutput.accept(ModItemRegister.LEASH_ROPE_ARROW.get()); pOutput.accept(ModItemRegister.SPECTRAL_LEASH_ROPE_ARROW.get()); pOutput.accept(ModItemRegister.AMETHYST_SHEARS.get()); pOutput.accept(ModItemRegister.NEOFORGE.get()); pParameters.holders() .lookup(Registries.POTION) .ifPresent(potionRegistryLookup1 -> potionRegistryLookup1.listElements() .filter(potionReference -> Objects.requireNonNull(potionReference.getKey()).location().getNamespace().equals(LeashedPlayer.MOD_ID)) .map(potionReference -> PotionContents.createItemStack(Items.POTION, potionReference)) .forEach(pOutput::accept)); pParameters.holders() .lookup(Registries.POTION) .ifPresent(potionRegistryLookup1 -> potionRegistryLookup1.listElements() .filter(potionReference -> Objects.requireNonNull(potionReference.getKey()).location().getNamespace().equals(LeashedPlayer.MOD_ID)) .map(potionReference -> PotionContents.createItemStack(Items.SPLASH_POTION, potionReference)) .forEach(pOutput::accept)); pParameters.holders() .lookup(Registries.POTION) .ifPresent(potionRegistryLookup1 -> potionRegistryLookup1.listElements() .filter(potionReference -> Objects.requireNonNull(potionReference.getKey()).location().getNamespace().equals(LeashedPlayer.MOD_ID)) .map(potionReference -> PotionContents.createItemStack(Items.LINGERING_POTION, potionReference)) .forEach(pOutput::accept)); pParameters.holders() .lookup(Registries.POTION) .ifPresent( pPotions -> generatePotionEffectTypes( pOutput, pPotions, ModItemRegister.TIPPED_LEASH_ROPE_ARROW.get(), CreativeModeTab.TabVisibility.PARENT_AND_SEARCH_TABS, pParameters.enabledFeatures() ) ); })).build()); private static void generatePotionEffectTypes( CreativeModeTab.Output pOutput, HolderLookup pPotions, Item pItem, CreativeModeTab.TabVisibility pTabVisibility, FeatureFlagSet pRequiredFeatures ) { pPotions.listElements() .filter(potionReference -> potionReference.value().isEnabled(pRequiredFeatures)) .map(potionReference -> PotionContents.createItemStack(pItem, potionReference)) .forEach(itemStack -> pOutput.accept(itemStack, pTabVisibility)); } public static String getCreativeMod(@NotNull String tabs) { return LEASHED_PLAYER_TAB_STRING + "." + tabs; } public static void register(IEventBus eventBus) { CREATIVE_MODE_TABS.register(eventBus); } }