Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Is there a more efficient way of accepting mod items and blocks into a creative tab?

I've tried the following code:

for (Item item : ForgeRegistries.ITEMS.getValues()) {
    event.accept(item.asItem());
}

for (Block block : ForgeRegistries.BLOCKS.getValues()) {
    event.accept(block.asItem());
}

but the game crashes the second I enter inventory.

I think it's a problem with the stack size being over 1 as stated in the crash report. 

Any help?

Posting code snippets out of context and not showing the error isn't going to get you much help.

We have no psychic powers.

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

  • Author

The following is written in the main java class:

public void addCreative(CreativeModeTabEvent.BuildContents event) {
       if (event.getTab() == CreativeTabInit.BASE_TAB) {
           for (Item item : ForgeRegistries.ITEMS.getValues()) {
               event.accept(item.asItem());
           }

           for (Block block : ForgeRegistries.BLOCKS.getValues()) {
               event.accept(block.asItem());
           }
       }
}

The following is written in the constructor of the class:

modEventBus.addListener(this::addCreative);

 The following is the crash report:

---- Minecraft Crash Report ----
// Why did you do that?

Time: 2023-03-19 13:49:33
Description: Unexpected error

java.lang.IllegalArgumentException: Stack size must be exactly 1
	at net.minecraft.world.item.CreativeModeTab$ItemDisplayBuilder.accept(CreativeModeTab.java:308) ~[forge-1.19.3-44.1.0_mapped_official_1.19.3-recomp.jar:?] {re:classloading}
	at net.minecraftforge.client.ForgeHooksClient.onCreativeModeTabBuildContents(ForgeHooksClient.java:1212) ~[forge-1.19.3-44.1.0_mapped_official_1.19.3-recomp.jar:?] {re:classloading}
	at net.minecraft.world.item.CreativeModeTab.buildContents(CreativeModeTab.java:115) ~[forge-1.19.3-44.1.0_mapped_official_1.19.3-recomp.jar:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.world.item.CreativeModeTabs.lambda$buildAllTabContents$27(CreativeModeTabs.java:1553) ~[forge-1.19.3-44.1.0_mapped_official_1.19.3-recomp.jar:?] {re:classloading,pl:accesstransformer:B}
	at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183) ~[?:?] {}
	at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:179) ~[?:?] {}
	at java.util.Iterator.forEachRemaining(Iterator.java:133) ~[?:?] {}
	at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1845) ~[?:?] {}
	at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509) ~[?:?] {}
	at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499) ~[?:?] {}
	at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150) ~[?:?] {}
	at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173) ~[?:?] {}
	at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[?:?] {}
	at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596) ~[?:?] {}
	at net.minecraft.world.item.CreativeModeTabs.buildAllTabContents(CreativeModeTabs.java:1552) ~[forge-1.19.3-44.1.0_mapped_official_1.19.3-recomp.jar:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.world.item.CreativeModeTabs.tryRebuildTabContents(CreativeModeTabs.java:1572) ~[forge-1.19.3-44.1.0_mapped_official_1.19.3-recomp.jar:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.client.gui.screens.inventory.CreativeModeInventoryScreen.<init>(CreativeModeInventoryScreen.java:88) ~[forge-1.19.3-44.1.0_mapped_official_1.19.3-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.gui.screens.inventory.InventoryScreen.init(InventoryScreen.java:50) ~[forge-1.19.3-44.1.0_mapped_official_1.19.3-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.gui.screens.Screen.rebuildWidgets(Screen.java:429) ~[forge-1.19.3-44.1.0_mapped_official_1.19.3-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.gui.screens.Screen.init(Screen.java:419) ~[forge-1.19.3-44.1.0_mapped_official_1.19.3-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.Minecraft.setScreen(Minecraft.java:992) ~[forge-1.19.3-44.1.0_mapped_official_1.19.3-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.Minecraft.handleKeybinds(Minecraft.java:1928) ~[forge-1.19.3-44.1.0_mapped_official_1.19.3-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.Minecraft.tick(Minecraft.java:1793) ~[forge-1.19.3-44.1.0_mapped_official_1.19.3-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.Minecraft.runTick(Minecraft.java:1097) ~[forge-1.19.3-44.1.0_mapped_official_1.19.3-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.Minecraft.run(Minecraft.java:713) ~[forge-1.19.3-44.1.0_mapped_official_1.19.3-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.main.Main.run(Main.java:212) ~[forge-1.19.3-44.1.0_mapped_official_1.19.3-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.main.Main.main(Main.java:51) ~[forge-1.19.3-44.1.0_mapped_official_1.19.3-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?] {}
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[?:?] {}
	at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?] {}
	at java.lang.reflect.Method.invoke(Method.java:568) ~[?:?] {}
	at net.minecraftforge.fml.loading.targets.ForgeClientUserdevLaunchHandler.lambda$launchService$0(ForgeClientUserdevLaunchHandler.java:25) ~[fmlloader-1.19.3-44.1.0.jar:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:30) ~[modlauncher-10.0.8.jar:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:53) ~[modlauncher-10.0.8.jar:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:71) ~[modlauncher-10.0.8.jar:?] {}
	at cpw.mods.modlauncher.Launcher.run(Launcher.java:106) ~[modlauncher-10.0.8.jar:?] {}
	at cpw.mods.modlauncher.Launcher.main(Launcher.java:77) ~[modlauncher-10.0.8.jar:?] {}
	at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:26) ~[modlauncher-10.0.8.jar:?] {}
	at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:23) ~[modlauncher-10.0.8.jar:?] {}
	at cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:141) ~[bootstraplauncher-1.1.2.jar:?] {}

Add some debug for the results of your Block.asItem() calls.

I bet at least one of the is "minecraft:air", i.e. not registered/found so its count will be zero.

 

I would also guess that your ITEMS.getValues() contains those BlockItems anyway. Otherwise how are they are registered?

So the Block part is duplicate work.

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

  • Author

The following code worked but added all minecraft blocks and items to my creative tab.

for (Item item : ForgeRegistries.ITEMS.getValues()) {
        if (new ItemStack(item.asItem()).getCount() == 1) {
            event.accept(item.asItem());
        }
}

Is there any way I can filter them out?

Don't you have your own DeferredRegister that contains your items?

public static final DeferredRegister<Item> MY_ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MODID); 

then

for (RegistryObject<Item> itemRegistration : MY_ITEMS.getEntries()) {
  var item = itemRegistration.get();
  // do stuff
}

You also have the issue that you are adding every item to every tab. You need to check:

event.getTab()

is the tab you want.

Edited by warjort

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

  • Author

It finally worked! Thank you so much! :D

if (event.getTab() == CreativeTabInit.BASE_TAB) {
    for (RegistryObject<Item> item : ITEMS.getEntries()) {
        event.accept(item.get());
    }
}

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.