Jump to content

Recommended Posts

Posted

Hi,

 

I've been testing basic modding in 1.13 and getting trouble connecting to the model files for items & blocks

I believe I am correctly assigning rResourceLocations, and the files are in the right place, but the logs indicate IO errors locating them

 

This is an excerpt from my class for creating items.  itemList is an ArrayList<Item> which will be assigned to a static list in the main method (ChickenMod.ITEMS) iterated in another class for registration

(The iteration of the <Block> Array (ChickenMod.BLOCKS) is to add the required ItemBlocks to the registration list.

private static void NewItem(String name, ItemGroup tab) {
		Item thisItem = new Item(new Properties().group(tab))
				.setRegistryName(ChickenMOD.MODID,name);
		itemList.add(thisItem);
  
  
  	public static List<Item> MakeItems() {
		ChickenMod.LOGGER.info("HELLO from MakeItems");
		NewItem ("test_item", ItemGroup.MISC);
		
		for (Block thisBlock:ChickenMod.BLOCKS) {
			Item thisItem = new ItemBlock(thisBlock, new Properties().group(ChickenMod.ITEMTAB)).setRegistryName(thisBlock.getRegistryName());
			ChickenMod.LOGGER.info("HELLO from MakeItems-> block tab registry" );
			itemList.add(thisItem);
		}
		return itemList;
	}

 

The static Method is triggered by a field assignment in the main class:

 


	public static List<Item> ITEMS = ModItems.MakeItems();
	

 

The list is later iterated for Event Registration:

	//Register Items
	@SubscribeEvent
	public static void registerItems(final RegistryEvent.Register<Item> event)  {
		ChickenMOD.LOGGER.info("HELLO from Registry :: ITEMS");
		for (Item thisItem : ChickenMod.ITEMS) {
			event.getRegistry().register(thisItem);
			}
		}

 

I'm using a similar method for custom blocks: trigger a static method (via field assignment) to a list (of type <Block>) which is later iterated to register to the appropriate Event Bus (with similar results)

 

The Items and blocks are being registered (I can access them in game), but they get the generic texture assignment which indicates the resources were no properly loaded.

 

An excerpt from the log file:

[26May2019 20:38:49.568] [Client thread/WARN] [net.minecraft.client.renderer.model.ModelBakery/]: Exception loading blockstate definition: chicken_mod:blockstates/test_block.json: java.io.FileNotFoundException: chicken_mod:blockstates/test_block.json
[26May2019 20:38:50.410] [Client thread/WARN] [net.minecraft.client.renderer.model.ModelBakery/]: Unable to load model: 'chicken_mod:test_item#inventory' referenced from: chicken_mod:test_item#inventory: java.io.FileNotFoundException: chicken_mod:models/item/test_item.json
[26May2019 20:38:50.410] [Client thread/WARN] [net.minecraft.client.renderer.model.ModelBakery/]: Unable to load model: 'chicken_mod:test_block#inventory' referenced from: chicken_mod:test_block#inventory: java.io.FileNotFoundException: chicken_mod:models/item/test_block.json

 

The project as a whole can be found here:

https://github.com/pchonacky/randombits.git 

 

I am aware there are probably more graceful ways to do this, but I am still working out what will work best - just trying to get it to work for now.

 

Thanks in advance for your replies.

/Philip

Posted

Your system will not work.

Registry entries MUST be instantinated in the appropriate registry event, now more than ever. Don't ever use static inializers for registry entries. Rework this right now, before it gets too big.

You will also make your code much more readable and will write way less code.

 

The code in your repository doesn't match the code you've posted.

So yeah, fix the static initializer issue first, then I can debug your repository.

Posted
7 minutes ago, PhilipChonacky said:

ChickenMod.LOGGER.info("HELLO from MakeItems-> block tab registry" );

Please remove useless loggings like this when you release the mod.

 

As far as I could tell, the console warnings does not match your current repo. Please update your repo if they are not up to date.

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

Posted (edited)
1 hour ago, V0idWa1k3r said:

Your system will not work.

Registry entries MUST be instantinated in the appropriate registry event, now more than ever. Don't ever use static inializers for registry entries. Rework this right now, before it gets too big.

You will also make your code much more readable and will write way less code.

 

The code in your repository doesn't match the code you've posted.

So yeah, fix the static initializer issue first, then I can debug your repository.

It looks like my issue was I hadn't refreshed the assets folder in my IDE (eclipse) after making changes to the JSON files - it works now. 

...as to the other issue: Are you implying I should register in the same classes where I initialize (after making non-static)? or just use non-static fields for my entries?

 

BTW- The repository was updated after I posted the clips, so the clips can be ignored - repository is more up to date

 

/Philip

Edited by PhilipChonacky
clarification
Posted (edited)
19 minutes ago, PhilipChonacky said:

...as to the other issue: Are you implying I should register in the same classes where I initialize (after making non-static)? or just use non-static fields for my entries?

 

Instantinate in the registry event.

event.registerAll(new BlockA(), new BlockB(), new Block(Material.IRON).setRegistryName(...), new ...)

 

19 minutes ago, PhilipChonacky said:

It looks like my issue was I hadn't refreshed the assets folder in my IDE (eclipse) after making changes to the JSON files - it works now. 

 

One of the many reasons I chose a different IDE...

Edited by V0idWa1k3r
Posted
5 minutes ago, V0idWa1k3r said:

Instantinate in the registry event.

event.registerAll(new BlockA(), new BlockB(), new Block(Material.IRON).setRegistryName(...), new ...)

 

One of the many reasons I chose a different IDE...

That brings up the challenge of how I would pass the requisite ItemBlocks to the Item registry, or would you recommend I separately instantiate an  identical Block there

 new Item (new ItemBlock (new Block() , new Properties())...

Posted
6 minutes ago, PhilipChonacky said:

 new Item (new ItemBlock (new Block() , new Properties())...

This would not work since new Block() != new Block(). You must pass the same object to the ItemBlock that you have registered, not an identical one.

 

6 minutes ago, PhilipChonacky said:

That brings up the challenge of how I would pass the requisite ItemBlocks to the Item registry

https://mcforge.readthedocs.io/en/1.13.x/concepts/registries/#injecting-registry-values-into-fields

Posted
6 minutes ago, V0idWa1k3r said:

This would not work since new Block() != new Block(). You must pass the same object to the ItemBlock that you have registered, not an identical one.

 

https://mcforge.readthedocs.io/en/1.13.x/concepts/registries/#injecting-registry-values-into-fields

So create a Block Object holder field that matches the registry name of the Block, and then instantiate an ItemBlock of the object in the Item Registry method?

Posted (edited)

Thanks, I think I just learned more about how this modding works in the post 1.9 world than many hours of reading the documentation

[and reading several misleading tutorials]

Edited by PhilipChonacky
Posted

In conclusion, I could have paired all that previous mess down to this:

 

    @Mod.EventBusSubscriber(modid=ChickenMod.MODID, bus=Mod.EventBusSubscriber.Bus.MOD)
    @ObjectHolder(ChickenMod.MODID)
    public static class RegistryEvents {
    	
    	public static final Block test_block=null;
    	public static final Item test_item=null;
    	
        @SubscribeEvent
        public static void onBlocksRegistry(final RegistryEvent.Register<Block> blockRegistryEvent) {
    			blockRegistryEvent.getRegistry().registerAll(
    					new Block(Block.Properties.create(Material.IRON)).setRegistryName(ChickenMod.MODID,"test_block")); 
        }
        
        @SubscribeEvent
        public static void onItemsRegistry(final RegistryEvent.Register<Item> itemRegistryEvent) {
        	itemRegistryEvent.getRegistry().registerAll(
        			(Item)new ItemBlock(test_block,new Item.Properties().group(ITEMTAB)).setRegistryName(test_block.getRegistryName()),
        			new Item(new Item.Properties().group(ITEMTAB)).setRegistryName(ChickenMod.MODID,"test_item")
        			);
        }
        
    }
    

I may make some changes to scale up [and possibly find a better IDE]

 

/P [aka mush4brains]

 

Posted

You can see an example of registering ItemBlocks automatically here, but this comes with the overhead of iterating the entire blocks registry.

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • The game crashed whilst unexpected error Error: net.minecraftforge.fml.ModLoadingException: Advanced Mining Dimension (mining_dimension) encountered an error during the done event phase
    • Here is the end of the log. it was way too big to put in pastebin, but I started from when I was online and everything was fine. Error should be in here: https://pastebin.com/Sdhdq593
    • Update: I stand corrected as I was able to dig up a relevant log from my earlier testing which highlights the overall issue but does not explain how to solve it. See, Diagnostic Logs for pack.mcmeta not found: https://pastebin.com/LXS8Rtna
    • Which mod was this? What are all the mods that were in use? It will help if enough information to replicate the problem is available.
    • I have been attempting to create a supplementary resource pack with Patchouli in order to add back the guidebook for Better End but unfortunately in every prototype I have made pack.mcmeta and my resource pack are not recognized. I have tested both zipped and unzipped and either way curseforge does not recognize my resource pack as existing. For testing I stripped my pack down to just the pack.mcmeta file and two empty folders labelled data and assets and I know the data folder is not the problem as firstly my first attempts just had an assets folder following Patchouli instructions and data came later in my flailing attempts to make anything in my pack work. The mcmeta file is not recognized whether or not I use this:  { "pack": { "pack_format": 15, "description": "A replacement for the BetterEnd Guide Book." } "language": { "en_US": { "name": "English", "region": "United States" } } } ,or this:  { "pack": { "pack_format": 15, "description": "A replacement for the BetterEnd Guide Book." } } I have made sure to only use lowercase and the pack folder is named better-end-guide. Is this some magic nonsense from me doing this manually instead of using an IDE or similar tool? Could it be because my files are by default in UTF-8 even though ANSI gives the same results? Is there a specific community secret tool I am supposed to use for zipping or specific settings? I am pulling my hair in distress. Unfortunately as there are no errors involved I lack logs to offer, if that disqualifies this thread please do not be harsh and instead if you can then please direct me to a forum with different rules and sufficiently respectful but knowledgeable as to be of assistance. Most of my experience with the programming community has been poor and so naturally I find myself wary.
  • Topics

×
×
  • Create New...

Important Information

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