Skip to content

Commit

Permalink
fix creative tab
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasPlacentino committed Jan 1, 2023
1 parent 2dcf49d commit 8d1bb62
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 62 deletions.
49 changes: 23 additions & 26 deletions src/main/java/com/obsilab/mcsc/MCSC.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
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;
Expand Down Expand Up @@ -38,6 +39,7 @@

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;

Expand All @@ -47,6 +49,7 @@ public class MCSC
{
// Define mod id in a common place for everything to reference
public static final String MOD_ID = "mcsc";
public static final String MODID = MOD_ID;
public static final String MCSC = MOD_ID; // 🤷‍♂️
// Directly reference a slf4j logger
private static final Logger LOGGER = LogUtils.getLogger();
Expand Down Expand Up @@ -85,16 +88,20 @@ public MCSC()
{
IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();

ModItems.register(modEventBus);
ModBlocks.register(modEventBus);
ModItems.register(modEventBus); // registers items
ModBlocks.register(modEventBus); // registers blocks

ModConfiguredFeatures.register(modEventBus);
ModPlacedFeatures.register(modEventBus);
//ModConfiguredFeatures.register(modEventBus); // registers configured features
//ModPlacedFeatures.register(modEventBus); // registers placed features

//ModFeatures.register(modEventBus); // registers features

// Register the commonSetup method for modloading
modEventBus.addListener(this::commonSetup);

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

Expand Down Expand Up @@ -127,46 +134,37 @@ private void commonSetup(final FMLCommonSetupEvent event)

event.enqueueWork(() -> {
ModMessages.register();
//? ModPlacedFeatures.register((IEventBus) event);
//? ModPlacedFeatures.register((IEventBus) event);
// ModVillagers.registerPOIs(); // to be implemented?
});

}

/* replaced by CreativeTabEvents.java (custom tab)
private void addCreative(CreativeModeTabEvent.BuildContents event) {
// duplicate of CreativeTabEvents.onCreativeTabBuildContents (custom tab)
private void addCreativeTab(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();
if (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(mod_item.get());
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
//continue; // remove crop block, prevents crashing
} else {
event.accept(mod_block.get());
event.accept(new ItemStack(mod_block.get()));
}

//event.accept(mod_block.get());
}
//event.accept(ModItems.EMPTY_WAFER_ITEM.get());
}
//if (event.getTab() == CreativeModeTabs.MCSC) {
// event.accept(ModItems.EMPTY_WAFER_ITEM.get());
//}
//
}

*/

/*
@SubscribeEvent
public void buildContents(CreativeModeTabEvent.Register event) {
Expand Down Expand Up @@ -205,7 +203,6 @@ public static void onClientSetup(FMLClientSetupEvent event)
LOGGER.info("HELLO FROM CLIENT SETUP");
LOGGER.info("MINECRAFT NAME >> {}", Minecraft.getInstance().getUser().getName());

//ItemBlockRenderTypes.setRenderLayer(ModBlocks.CRYSTAL_INGOT_BLOCK.get(), RenderType.cutout()); // deprecated, replaced by "render_layer": "cutout" in block model json
}
}
}
33 changes: 30 additions & 3 deletions src/main/java/com/obsilab/mcsc/event/CreativeTabEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.CreativeModeTab;
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;
Expand All @@ -15,6 +16,7 @@
import net.minecraftforge.registries.RegistryObject;

import java.util.Collection;
import java.util.List;

public class CreativeTabEvents {

Expand All @@ -26,18 +28,19 @@ public static void onCreativeTabEvent(CreativeModeTabEvent.Register event) {
builder -> builder
.icon(() -> new ItemStack(ModItems.ETCHED_WAFER_ITEM.get()))
.title(Component.literal("item_group." + MCSC.MOD_ID + ".tab"))
.displayItems((enabledFlags, populator, hasPermissions) -> {
.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) {
populator.accept(new ItemStack(mod_item.get()));
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 {
populator.accept(new ItemStack(mod_block.get()));
output.accept(new ItemStack(mod_block.get()));
}

//event.accept(mod_block.get());
Expand All @@ -47,4 +50,28 @@ public static void onCreativeTabEvent(CreativeModeTabEvent.Register event) {
);
}


//? 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());
}
}
}

}
33 changes: 0 additions & 33 deletions src/main/java/com/obsilab/mcsc/item/ModCreativeModeTab.java

This file was deleted.

0 comments on commit 8d1bb62

Please # to comment.