Jump to content

[Solved][1.19.4] Automatically add items and blocks into costume tab using addCreative() but excluding some


perromercenary00

Recommended Posts

i need some headstorm here 

1.19.4 change the way to add the items and blocks to  custome mod tabs now you have to use an event an manually add every item or block and thas a pain in <t> coze i have to many blocks 
soo i tell to miself what if i use a foor loop whith "DeferredRegister<Item> ITEMS" thing and it works it drops everything into the tab and i dont have to manually keep track of it if change something

 

Spoiler
				
			//agregar items y block a las tabs
		private void addCreative(CreativeModeTabEvent.BuildContents event)
		{
		    Item actualItem = null;
		    Block actualBlock = null;
		    int count = 0;
		
		    if( event.getTab() == tab.MERCBLKTAB ){
		        for ( RegistryObject<Item> ResourceKey : ItemInit.ITEMS.getEntries()) {
		            actualItem = ResourceKey.get();
		                if(!(actualBlock instanceof trampilla)) {
		                     event.accept(actualItem);
		                }
		            count++;
		        }
		    }
		}				
			

 

but i have some blocks and some items that are kinda metablocks/subitems basically the same block thing and i dont nedd/want them to be visible 

doortraps.png

 

i try to filter them by class but dint works coze in this stage they are already converted to item block soo i cannot filter using instance of 

	if(!(actualBlock instanceof trampilla)) {
event.accept(actualBlock);
}
	

 

Sooo any idea how i can mark this items blocks to be excluded from the tab ???

 

Edited by perromercenary00
Solved
Link to comment
Share on other sites

Is your "actualItem" a BlockItem? Then see Block.byItem()

 

Otherwise we can't help you without more information.

If you want help, you need to post a project on github that reproduces your problem.

Incomplete information posted in the forums will likely just mean your question gets ignored.

 

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

You also know you can have different DeferredRegisters for different internal categories of your items?

e.g. psuedo code:

    // Real items that should be shown in creative tabs
    public static final DeferredRegister<Item> REAL_ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MODID);
    public static final RegistryObject<Item> TEST = REAL_ITEMS.register("test", () -> new Item(new Item.Properties()));

    // Internal items the user shouldn't have direct access to
    public static final DeferredRegister<Item> META_ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MODID);
    public static final RegistryObject<Item> META = META_ITEMS.register("meta", () -> new Item(new Item.Properties()));

 

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

ya it makes sense 

itemblock is a subclass of item 

and from itemblock the block can be retrieved 

 

Spoiler

				
			//agregar items y block a las tabs
		private void addCreative(CreativeModeTabEvent.BuildContents event)
		{
		    Item actualItem = null;
		    Block actualBlock = null;
		    int count = 0;
		    boolean RegistrarEste = false;
		
		    if( event.getTab() == tab.MERCBLKTAB ){
		        for ( RegistryObject<Item> ResourceKey : ItemInit.ITEMS.getEntries()) {
		            RegistrarEste = true;
		            actualItem = ResourceKey.get();
		
		            if((actualItem instanceof BlockItem)) {
		                BlockItem actualBlockItem = (BlockItem)actualItem;
		
		                    if(actualBlockItem.getBlock() instanceof trampilla) {//ignore all the trampillas
		                        RegistrarEste = false;
		                    }
		                }
		
		                if(RegistrarEste) {
		                    event.accept(actualItem);
		                }
		                count++;
		            }
		        }				
			}				
			

2023-05-21-14-37-33.png

 

Thanks for your help again

Link to comment
Share on other sites

  • perromercenary00 changed the title to [Solved][1.19.4] Automatically add items and blocks into costume tab using addCreative() but excluding some

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.