Skip to content

Commit

Permalink
updated creative tab
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasPlacentino committed Jan 26, 2023
1 parent 865075e commit 2e69ace
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 99 deletions.
26 changes: 5 additions & 21 deletions src/main/java/com/obsilab/mcsc/MCSC.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,16 @@
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.fluid.ModFluidTypes;
import com.obsilab.mcsc.fluid.ModFluids;
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.ModFeatures;
import com.obsilab.mcsc.world.feature.ModPlacedFeatures;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.ItemBlockRenderTypes;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.CreativeModeTabs;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.material.Material;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.CreativeModeTabEvent;
Expand All @@ -34,17 +23,12 @@
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;
import org.slf4j.Logger;

import java.util.Collection;

import static com.obsilab.mcsc.event.CreativeTabEvents.MCSC_TAB;
import static net.minecraft.core.registries.Registries.BLOCK;
import static net.minecraft.core.registries.Registries.ITEM;

// The value here should match an entry in the META-INF/mods.toml file
@Mod(MCSC.MOD_ID)
public class MCSC
Expand Down Expand Up @@ -106,10 +90,10 @@ public MCSC()
modEventBus.addListener(this::commonSetup);

// Register the custom creative tab ("MCSC") event
modEventBus.addListener(CreativeTabEvents::onCreativeTabEvent);
modEventBus.addListener(CreativeTabEvents::onCreativeTabBuildContents);
//modEventBus.addListener(CreativeTabEvents::onCreativeTabEvent);
//modEventBus.addListener(CreativeTabEvents::onCreativeTabBuildContents);
// old: Register the item to a creative tab
// modEventBus.addListener(this::addCreative);
modEventBus.addListener(this::addCreative);

/* see ModBlocks.java and ModItems.java
// Register the Deferred Register to the mod event bus so blocks get registered
Expand Down Expand Up @@ -148,9 +132,9 @@ private void commonSetup(final FMLCommonSetupEvent event)
}

// duplicate of CreativeTabEvents.onCreativeTabBuildContents (custom tab)
private void addCreativeTab(CreativeModeTabEvent.BuildContents event) {
private void addCreative(CreativeModeTabEvent.BuildContents event) {

if (event.getTab() == MCSC_TAB || event.getTab() == CreativeModeTabs.SEARCH) {
if (event.getTab() == ModCreativeModeTabs.MCSC_TAB || event.getTab() == CreativeModeTabs.SEARCH) {

Collection<RegistryObject<Item>> ModItemsList = ModItems.ITEMS.getEntries();
Collection<RegistryObject<Block>> ModBlocksList = ModBlocks.BLOCKS.getEntries();
Expand Down
71 changes: 71 additions & 0 deletions src/main/java/com/obsilab/mcsc/ModCreativeModeTabs.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.obsilab.mcsc;

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.ItemStack;
import net.minecraftforge.event.CreativeModeTabEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

@Mod.EventBusSubscriber(modid = MCSC.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD)
public class ModCreativeModeTabs {

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.translatable("creativemodetab.mcsc_tab"))
/* moved to addCreative in MCSC.java : */
//.displayItems((features, output, hasPermissions) -> {
// //onCreativeTabBuildContents((CreativeModeTabEvent.BuildContents) output); //? doable?
// Collection<RegistryObject<Item>> ModItemsList = ModItems.ITEMS.getEntries();
// Collection<RegistryObject<Block>> ModBlocksList = ModBlocks.BLOCKS.getEntries();
// for (RegistryObject<Item> mod_item : ModItemsList) {
// output.accept(new ItemStack(mod_item.get()));
// }
// for (RegistryObject<Block> 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 {
// output.accept(new ItemStack(mod_block.get()));
// }
//
// //event.accept(mod_block.get());
// }
//})
//.build()
);
}


// OLD :
//? needed ?
//@SubscribeEvent
//public static void onCreativeTabBuildContents(CreativeModeTabEvent.BuildContents event) {
// if (event.getTab() == MCSC_TAB || event.getTab() == CreativeModeTabs.SEARCH) {
// Collection<RegistryObject<Item>> ModItemsList = ModItems.ITEMS.getEntries();
// Collection<RegistryObject<Block>> ModBlocksList = ModBlocks.BLOCKS.getEntries();
// //List ignoredBlocks = [CrystalIngotBlock]; //! test
// for (RegistryObject<Item> mod_item : ModItemsList) {
// event.accept(new ItemStack(mod_item.get()));
// }
// for (RegistryObject<Block> 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 {
// event.accept(new ItemStack(mod_block.get()));
// }
//
// //event.accept(mod_block.get());
// }
// }
//}

}
77 changes: 0 additions & 77 deletions src/main/java/com/obsilab/mcsc/event/CreativeTabEvents.java

This file was deleted.

2 changes: 1 addition & 1 deletion src/main/resources/assets/mcsc/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"block.mcsc.phosphate_ore": "Phosphate Ore",


"item_group.mcsc.tab": "MCSC",
"creativemodetab.mcsc_tab": "MCSC",



Expand Down

0 comments on commit 2e69ace

Please # to comment.