diff --git a/src/main/java/de/mrjulsen/mineify/ModMain.java b/src/main/java/de/mrjulsen/mineify/ModMain.java index c1d7ce7..c158c32 100644 --- a/src/main/java/de/mrjulsen/mineify/ModMain.java +++ b/src/main/java/de/mrjulsen/mineify/ModMain.java @@ -7,6 +7,7 @@ import de.mrjulsen.mineify.commands.ModCommandArguments; import de.mrjulsen.mineify.config.ModClientConfig; import de.mrjulsen.mineify.config.ModCommonConfig; +import de.mrjulsen.mineify.events.ModCreativeTabs; import de.mrjulsen.mineify.items.ModItems; import de.mrjulsen.mineify.network.NetworkManager; import de.mrjulsen.mineify.network.UploaderUsercache; @@ -43,7 +44,8 @@ public ModMain() { NetworkManager.registerNetworkPackets(); MinecraftForge.EVENT_BUS.register(this); ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, ModClientConfig.SPEC, MOD_ID + "-client.toml"); - ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, ModCommonConfig.SPEC, MOD_ID + "-common.toml"); + ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, ModCommonConfig.SPEC, MOD_ID + "-common.toml"); + eventBus.addListener(ModCreativeTabs::register); UploaderUsercache.loadOrCreate(Constants.DEFAULT_USERCACHE_PATH); UploaderUsercache.INSTANCE.recacheNamesAsync(); diff --git a/src/main/java/de/mrjulsen/mineify/blocks/ModBlocks.java b/src/main/java/de/mrjulsen/mineify/blocks/ModBlocks.java index 603cb70..3ecc7e7 100644 --- a/src/main/java/de/mrjulsen/mineify/blocks/ModBlocks.java +++ b/src/main/java/de/mrjulsen/mineify/blocks/ModBlocks.java @@ -1,5 +1,6 @@ package de.mrjulsen.mineify.blocks; +import java.util.List; import java.util.function.Supplier; import de.mrjulsen.mineify.ModMain; @@ -20,19 +21,21 @@ public class ModBlocks { public static final DeferredRegister BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, ModMain.MOD_ID); - public static final RegistryObject SOUND_PLAYER = registerBlock("sound_player", () -> new SoundPlayer(), CreativeModeTabs.REDSTONE_BLOCKS); + public static final RegistryObject SOUND_PLAYER = registerBlock("sound_player", () -> new SoundPlayer(), List.of(CreativeModeTabs.REDSTONE_BLOCKS, CreativeModeTabs.FUNCTIONAL_BLOCKS)); - private static RegistryObject registerBlock(String name, Supplier block, ResourceKey tab) { + private static RegistryObject registerBlock(String name, Supplier block, List> tabs) { RegistryObject toReturn = BLOCKS.register(name, block); - registerBlockItem(name, toReturn, tab); + registerBlockItem(name, toReturn, tabs); return toReturn; } - private static RegistryObject registerBlockItem(String name, RegistryObject block, ResourceKey tab) { + private static RegistryObject registerBlockItem(String name, RegistryObject block, List> tabs) { return ModItems.ITEMS.register(name, () -> { BlockItem item = new BlockItem(block.get(), new Item.Properties()); - ModCreativeTabs.setCreativeTab(item, tab); + for (ResourceKey tab : tabs) { + ModCreativeTabs.setCreativeTab(item, tab); + } return item; }); } diff --git a/src/main/java/de/mrjulsen/mineify/events/ModCreativeTabs.java b/src/main/java/de/mrjulsen/mineify/events/ModCreativeTabs.java index 015b895..6cf1238 100644 --- a/src/main/java/de/mrjulsen/mineify/events/ModCreativeTabs.java +++ b/src/main/java/de/mrjulsen/mineify/events/ModCreativeTabs.java @@ -3,23 +3,17 @@ import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; -import de.mrjulsen.mineify.ModMain; import net.minecraft.resources.ResourceKey; import net.minecraft.world.item.CreativeModeTab; import net.minecraft.world.item.Item; import net.minecraft.world.level.ItemLike; import net.minecraftforge.event.BuildCreativeModeTabContentsEvent; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.common.Mod.EventBusSubscriber; -@EventBusSubscriber(modid = ModMain.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD) public class ModCreativeTabs { protected static Multimap, ItemLike> itemsPerCreativeTab = HashMultimap.create(); - @SubscribeEvent - public void register(BuildCreativeModeTabContentsEvent event) { + public static void register(BuildCreativeModeTabContentsEvent event) { ResourceKey tab = event.getTabKey(); if (itemsPerCreativeTab.containsKey(tab)) for (ItemLike il : itemsPerCreativeTab.get(tab)) {