Jump to content

Automaticlly accept all mod items and blocks into creative tab


LyricCrayon8311

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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:?] {}
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

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