Skip to content

Commit

Permalink
Fixed: Items not available in creative inventory
Browse files Browse the repository at this point in the history
  • Loading branch information
MisterJulsen committed Oct 19, 2023
1 parent d7059c5 commit ac332f4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
4 changes: 3 additions & 1 deletion src/main/java/de/mrjulsen/mineify/ModMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
13 changes: 8 additions & 5 deletions src/main/java/de/mrjulsen/mineify/blocks/ModBlocks.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.mrjulsen.mineify.blocks;

import java.util.List;
import java.util.function.Supplier;

import de.mrjulsen.mineify.ModMain;
Expand All @@ -20,19 +21,21 @@ public class ModBlocks {
public static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, ModMain.MOD_ID);


public static final RegistryObject<Block> SOUND_PLAYER = registerBlock("sound_player", () -> new SoundPlayer(), CreativeModeTabs.REDSTONE_BLOCKS);
public static final RegistryObject<Block> SOUND_PLAYER = registerBlock("sound_player", () -> new SoundPlayer(), List.of(CreativeModeTabs.REDSTONE_BLOCKS, CreativeModeTabs.FUNCTIONAL_BLOCKS));


private static <T extends Block>RegistryObject<T> registerBlock(String name, Supplier<T> block, ResourceKey<CreativeModeTab> tab) {
private static <T extends Block>RegistryObject<T> registerBlock(String name, Supplier<T> block, List<ResourceKey<CreativeModeTab>> tabs) {
RegistryObject<T> toReturn = BLOCKS.register(name, block);
registerBlockItem(name, toReturn, tab);
registerBlockItem(name, toReturn, tabs);
return toReturn;
}

private static <T extends Block>RegistryObject<Item> registerBlockItem(String name, RegistryObject<T> block, ResourceKey<CreativeModeTab> tab) {
private static <T extends Block>RegistryObject<Item> registerBlockItem(String name, RegistryObject<T> block, List<ResourceKey<CreativeModeTab>> tabs) {
return ModItems.ITEMS.register(name, () -> {
BlockItem item = new BlockItem(block.get(), new Item.Properties());
ModCreativeTabs.setCreativeTab(item, tab);
for (ResourceKey<CreativeModeTab> tab : tabs) {
ModCreativeTabs.setCreativeTab(item, tab);
}
return item;
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ResourceKey<CreativeModeTab>, ItemLike> itemsPerCreativeTab = HashMultimap.create();

@SubscribeEvent
public void register(BuildCreativeModeTabContentsEvent event) {
public static void register(BuildCreativeModeTabContentsEvent event) {
ResourceKey<CreativeModeTab> tab = event.getTabKey();
if (itemsPerCreativeTab.containsKey(tab))
for (ItemLike il : itemsPerCreativeTab.get(tab)) {
Expand Down

0 comments on commit ac332f4

Please sign in to comment.