diff --git a/src/main/java/com/obsilab/mcsc/MCSC.java b/src/main/java/com/obsilab/mcsc/MCSC.java index fee0895..e6edd62 100644 --- a/src/main/java/com/obsilab/mcsc/MCSC.java +++ b/src/main/java/com/obsilab/mcsc/MCSC.java @@ -3,7 +3,9 @@ import com.mojang.logging.LogUtils; import com.obsilab.mcsc.block.ModBlocks; import com.obsilab.mcsc.block.custom.CrystalIngotBlock; +import com.obsilab.mcsc.event.CreativeTabEvents; import com.obsilab.mcsc.item.ModItems; +import com.obsilab.mcsc.networking.ModMessages; import com.obsilab.mcsc.world.feature.ModConfiguredFeatures; import com.obsilab.mcsc.world.feature.ModPlacedFeatures; import net.minecraft.client.Minecraft; @@ -91,8 +93,12 @@ public MCSC() // Register the commonSetup method for modloading modEventBus.addListener(this::commonSetup); + // Register the custom creative tab ("MCSC") event + modEventBus.addListener(CreativeTabEvents::onCreativeTabEvent); + // old: Register the item to a creative tab + // modEventBus.addListener(this::addCreative); - /* + /* see ModBlocks.java and ModItems.java // Register the Deferred Register to the mod event bus so blocks get registered BLOCKS.register(modEventBus); // Register the Deferred Register to the mod event bus so items get registered @@ -102,8 +108,6 @@ public MCSC() // Register ourselves for server and other game events we are interested in MinecraftForge.EVENT_BUS.register(this); - // Register the item to a creative tab - modEventBus.addListener(this::addCreative); /* CreativeModeTabs.tabs().add(new CreativeModeTabs("mcsc") { @@ -120,10 +124,19 @@ private void commonSetup(final FMLCommonSetupEvent event) // Some common setup code LOGGER.info("HELLO FROM COMMON SETUP"); LOGGER.info("DIRT BLOCK >> {}", ForgeRegistries.BLOCKS.getKey(Blocks.DIRT)); + + event.enqueueWork(() -> { + ModMessages.register(); + // ModVillagers.registerPOIs(); // to be implemented? + }); + } + /* replaced by CreativeTabEvents.java (custom tab) private void addCreative(CreativeModeTabEvent.BuildContents event) { + + Collection> ModItemsList = ModItems.ITEMS.getEntries(); Collection> ModBlocksList = ModBlocks.BLOCKS.getEntries(); if (event.getTab() == CreativeModeTabs.SEARCH) { @@ -144,14 +157,17 @@ private void addCreative(CreativeModeTabEvent.BuildContents event) { //event.accept(ModItems.EMPTY_WAFER_ITEM.get()); } - /* - if (event.getTab() == CreativeModeTabs.MCSC) { - event.accept(ModItems.EMPTY_WAFER_ITEM.get()); - } - */ + + //if (event.getTab() == CreativeModeTabs.MCSC) { + // event.accept(ModItems.EMPTY_WAFER_ITEM.get()); + //} + // + } - //! BELOW NOT WORKING RN + */ + + /* @SubscribeEvent public void buildContents(CreativeModeTabEvent.Register event) { event.registerCreativeModeTab(new ResourceLocation(MOD_ID, "mcsc"), builder -> @@ -167,6 +183,8 @@ public void buildContents(CreativeModeTabEvent.Register event) { ); } + */ + // You can use SubscribeEvent and let the Event Bus discover methods to call @SubscribeEvent public void onServerStarting(ServerStartingEvent event) diff --git a/src/main/java/com/obsilab/mcsc/event/CreativeTabEvents.java b/src/main/java/com/obsilab/mcsc/event/CreativeTabEvents.java new file mode 100644 index 0000000..0f53c61 --- /dev/null +++ b/src/main/java/com/obsilab/mcsc/event/CreativeTabEvents.java @@ -0,0 +1,50 @@ +package com.obsilab.mcsc.event; + +import com.obsilab.mcsc.MCSC; +import com.obsilab.mcsc.block.ModBlocks; +import com.obsilab.mcsc.block.custom.CrystalIngotBlock; +import com.obsilab.mcsc.item.ModItems; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.CreativeModeTab; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.Block; +import net.minecraftforge.event.CreativeModeTabEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.registries.RegistryObject; + +import java.util.Collection; + +public class CreativeTabEvents { + + public static CreativeModeTab MCSC_TAB; + + @SubscribeEvent + public static void onCreativeTabEvent(CreativeModeTabEvent.Register event) { + MCSC_TAB = event.registerCreativeModeTab(new ResourceLocation(MCSC.MOD_ID, "mcsc_tab"), + builder -> builder + .icon(() -> new ItemStack(ModItems.ETCHED_WAFER_ITEM.get())) + .title(Component.literal("item_group." + MCSC.MOD_ID + ".tab")) + .displayItems((enabledFlags, populator, hasPermissions) -> { + Collection> ModItemsList = ModItems.ITEMS.getEntries(); + Collection> ModBlocksList = ModBlocks.BLOCKS.getEntries(); + for (RegistryObject mod_item : ModItemsList) { + populator.accept(new ItemStack(mod_item.get())); + } + for (RegistryObject mod_block : ModBlocksList) { + //check if the block is a crop block + if (mod_block.get() instanceof CrystalIngotBlock) { // if(mod_block.get().getName().equals("crystal_ingot")) + //continue; // remove crop block, prevents crashing + } else { + populator.accept(new ItemStack(mod_block.get())); + } + + //event.accept(mod_block.get()); + } + }) + .build() + ); + } + +} diff --git a/src/main/resources/assets/mcsc/lang/en_us.json b/src/main/resources/assets/mcsc/lang/en_us.json index 4d304f1..5fdafa9 100644 --- a/src/main/resources/assets/mcsc/lang/en_us.json +++ b/src/main/resources/assets/mcsc/lang/en_us.json @@ -22,5 +22,5 @@ "block.mcsc.borax_ore": "Borax Ore", "block.mcsc.phosphate_ore": "Phosphate Ore", - "item_group.mcsc": "MCSC" + "item_group.mcsc.tab": "MCSC" } \ No newline at end of file