Jump to content

Recommended Posts

Posted

I had previously asked this question on StackOverflow, but have received no response and still have not figured out how to set more than one item's texture in my mod for Forge 1.12 (1.12.2-14.23.3.2669). The below text is copied from StackOverflow. I know I can set the models for the item's, but after setting the first item's model, no matter what I try to do to set a future item's model, it just changes the first item's model only, even when I am not trying to set the first item's model again.

 

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 

I am trying to set the model to my second block in a utility mod I am making. I managed to successfully make the first block, Fast Cobble, but trying to tie the resource file to the second block, Clock, just changes the resource of Fast Cobble and does not set clock at all. Ironically, this bug only effects the item model and not when the block is placed on the ground. The world texture works just fine, so I know it is not an issue with the .json files.

The below is my creation of the itemblocks FastCobble and Clock.

public Item FastCobble() {
    FastCobbleItem = new ItemBlock(RegisterBlocks.FastCobble).setRegistryName(RegisterBlocks.FastCobble.getRegistryName());
    ModelResourceLocation FastCobbleResource = new ModelResourceLocation(SenorsStuff.MODID + ":fast_cobble", "inventory");
    ModelLoader.setCustomModelResourceLocation(FastCobbleItem, 0, FastCobbleResource);
    System.out.println("RN: " + RegisterBlocks.FastCobble.getRegistryName());
    System.out.println("FC: " + FastCobbleResource.toString());

    System.out.println("Register Item: " + FastCobbleItem.getUnlocalizedName().toString());
    return FastCobbleItem;
}

public Item Clock() {
    ClockItem = new ItemBlock(RegisterBlocks.Clock).setRegistryName(RegisterBlocks.Clock.getRegistryName());
    ModelResourceLocation ClockResource = new ModelResourceLocation(SenorsStuff.MODID + ":clock", "inventory"); //Changes FastCobble, but Not Clock
    ModelLoader.setCustomModelResourceLocation(ClockItem, 0, ClockResource);

    System.out.println("RN: " + RegisterBlocks.Clock.getRegistryName());
    System.out.println("CR: " + ClockResource.toString());

    System.out.println("Register Item: " + ClockItem.getUnlocalizedName().toString());
    return ClockItem;
}

The items are registered with the line event.getRegistry().registerAll(FastCobbleItem, ClockItem);

The terminal output for my printlines are...

[08:11:28] [main/INFO]: [com.senorcontento.stuff.RegisterItems:FastCobble:28]: RN: senorsstuff:fast_cobble
[08:11:28] [main/INFO]: [com.senorcontento.stuff.RegisterItems:FastCobble:29]: FC: senorsstuff:fast_cobble#inventory
[08:11:28] [main/INFO]: [com.senorcontento.stuff.RegisterItems:FastCobble:31]: Register Item: tile.stonebrick
[08:11:28] [main/INFO]: [com.senorcontento.stuff.RegisterItems:Clock:40]: RN: senorsstuff:clock
[08:11:28] [main/INFO]: [com.senorcontento.stuff.RegisterItems:Clock:41]: CR: senorsstuff:clock#inventory
[08:11:28] [main/INFO]: [com.senorcontento.stuff.RegisterItems:Clock:43]: Register Item: tile.senorsstuff:clock

The "Register Item:" for FastCobble is tile.stonebrick because I set the unlocalized name of the block to be the same as vanilla cobblestone so it can look like vanilla cobblestone (I am working on a message below the name to differentiate between FastCobble and vanilla cobble as not everyone will have pressed F3 + H like I did).

 

Lastly, my JSON files follow the format of

Blockstate File: assets.senorsstuff.blockstates.clock

{
  "variants": {
    "normal": { "model": "senorsstuff:clock"},
    "inventory": { "model": "senorsstuff:clock"}
  }
}

Block File: assets.senorsstuff.models.block.clock

{
  "parent": "block/cube_all",
  "textures": {
    "all": "minecraft:blocks/dirt"
  }
}

Item File: assets.senorsstuff.models.item.clock

{
  "parent": "senorsstuff:clock",
}

As for the block file, I have my own texture for the clock, but the issue still happens even when setting the vanilla dirt texture. FastCobble's resources follow the same format, except that clock becomes fast_cobble. (E.g. as in senorsstuff:clock to senorsstuff:fast_cobble). Fast Cobble uses minecraft:blocks/cobblestone when I don't try setting the clock's item resource.

The blocks use the correct resources when put on the ground in the world, and commenting out the code below will allow FastCobble to use the correct resources in the inventory, but setting the below code changes the texture of FastCobble to whatever I set Clock's texture to be and clock just has the default black and purple resource texture.

ModelResourceLocation ClockResource = new ModelResourceLocation(SenorsStuff.MODID + ":clock", "inventory"); //Changes FastCobble, but Not Clock
ModelLoader.setCustomModelResourceLocation(ClockItem, 0, ClockResource);

If this is the wrong place for this type of question, I would be more than happy to move this question, but having already looked at Gaming's Tour Page, I don't think they take programming questions, so I put the question here.

I decided to push the whole repo to a new branch for this question incase it is more complicated than I thought and you need more information.

Edit:

So, I decided to create the block FastStone to test to see if the Resource Loading Issue was caused by trying to load a modded resource file, it wasn't. FastStone is the exact same code as FastCobble, except that it points to Smoothstone instead of Cobblestone.

In this, I decided to test to see if the bug was caused by ModelResourceLocation or by ModelLoader. I had tested this by allowing the ModelResourceLocations to create the resources, but would load another item's resource instead (e.g. Loading FastCobble or FastStone on the Clock or FastStone). I also tried it by disabling the ModelResourceLocations that were not being set (same thing of Loading FastCobble Resource over Clock Item). This still produced the same bug, but would cause whatever resource to be set to be the one that FastStone or Clock loaded. This bug would happen regardless of whether the item was registered into the game or not. The way to prevent a resource from overwriting another is to disable ModelLoader for that item not registered.

I also moved the items to be local to their function, incase that had something to do with it. No. It didn't. The below code is what I mean by localizing it. Notice Item FastCobbleItem. I also changed the old code of SenorsStuff.MODID + ":fast_cobble" to grab the registry name directly from the block by using RegisterBlocks.FastCobble.getRegistryName(). This did nothing to solve the issue.

public Item FastCobble() {
  Item FastCobbleItem = new ItemBlock(RegisterBlocks.FastCobble).setRegistryName(RegisterBlocks.FastCobble.getRegistryName());
  ModelResourceLocation FastCobbleResource = new ModelResourceLocation(RegisterBlocks.FastCobble.getRegistryName(), "inventory");
  ModelLoader.setCustomModelResourceLocation(FastCobbleItem, 0, FastCobbleResource);
  ...
}

All in all, I know the bug has something to do with ModelLoader (and it is getting called in pre-init), but I still cannot understand why. I could try messing around with what items I set and also try objectifying the ModelLoader (as in ML ml = new ML();). If that changes anything, I will update accordingly.

You cannot set .setCustomModelResourceLocation objectively, it has to be static. Also, setting different items does not affect which item is set after you have set the first item's resource. The first item will set correctly, no matter if it is FastCobble, FastStone, or Clock. After that, only the item you set first will be updated with a new resource, regardless of which item you try to set.

Posted
1 hour ago, SenorContento said:

new ModelResourceLocation(SenorsStuff.MODID + ":fast_cobble", "inventory")

Don't do that. Do this:

new ModelResourceLocation(FastCobbleItem.getRegistryName().toString(),"inventory")

 

Problematic Code #1

Not visible in your code, but worth checking: #7, #10

 

As to your actual problem: I can't actually find your problem in your post.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted (edited)

Sorry for the late reply. I just moved into an apartment yesterday. I feel I should mention this so it doesn't seem like I forgot about this thread.

 

I had already changed the ModelResourceLocation to the getRegistryName() one prior to my first post. Given that, I feel it would be best to post my updated RegisterItems.java to help clearly show what my code looks like.

 

RegisterItems.java

package com.senorcontento.stuff;

import com.senorcontento.stuff.items.Scythe;

import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.event.RegistryEvent;

public class RegisterItems {	
	public void register(RegistryEvent.Register<Item> event) {
		//event.getRegistry().registerAll(scythe);//, item2, ...);
		System.out.println("Registered Item Count");
		
		Item FastCobbleItem = FastCobble();
		Item FastStoneItem = FastStone();
		Item ClockItem = Clock();
		
		/*event.getRegistry().register(FastCobbleItem);
		event.getRegistry().register(FastStoneItem);
		event.getRegistry().register(ClockItem);*/
		
		event.getRegistry().registerAll(FastCobbleItem, FastStoneItem, ClockItem);
	}
	
	public Item FastCobble() {
		Item FastCobbleItem = new ItemBlock(RegisterBlocks.FastCobble).setRegistryName(RegisterBlocks.FastCobble.getRegistryName());
		ModelResourceLocation FastCobbleResource = new ModelResourceLocation(RegisterBlocks.FastCobble.getRegistryName(), "inventory");
		ModelLoader.setCustomModelResourceLocation(FastCobbleItem, 0, FastCobbleResource);
		//ModelLoader.registerItemVariants(FastCobbleItem, FastCobbleResource);
		
		System.out.println("Registry Name: " + RegisterBlocks.FastCobble.getRegistryName().toString());
		System.out.println("Resource Name: " + FastCobbleResource.toString());
		System.out.println("Unlocalized Name: " + FastCobbleItem.getUnlocalizedName().toString());
		
		return FastCobbleItem;
	}
	
	public Item FastStone() {
		Item FastStoneItem = new ItemBlock(RegisterBlocks.FastStone).setRegistryName(RegisterBlocks.FastStone.getRegistryName());
		ModelResourceLocation FastStoneResource = new ModelResourceLocation(RegisterBlocks.FastStone.getRegistryName(), "inventory");
		ModelLoader.setCustomModelResourceLocation(FastStoneItem, 0, FastStoneResource);
		//ModelLoader.registerItemVariants(FastStoneItem, FastStoneResource);
		
		System.out.println("Registry Name: " + RegisterBlocks.FastStone.getRegistryName().toString());
		System.out.println("Resource Name: " + FastStoneResource.toString());
		System.out.println("Unlocalized Name: " + FastStoneItem.getUnlocalizedName().toString());
		
		return FastStoneItem;
	}
	
	public Item Clock() {
		Item ClockItem = new ItemBlock(RegisterBlocks.Clock).setRegistryName(RegisterBlocks.Clock.getRegistryName());
		ModelResourceLocation ClockResource = new ModelResourceLocation(RegisterBlocks.Clock.getRegistryName(), "inventory"); //Changes FastCobble, but Not Clock
		ModelLoader.setCustomModelResourceLocation(ClockItem, 0, ClockResource);
		//ModelLoader.registerItemVariants(ClockItem, ClockResource);
		
		System.out.println("Registry Name: " + RegisterBlocks.Clock.getRegistryName().toString());
		System.out.println("Resource Name: " + ClockResource.toString());
		System.out.println("Unlocalized Name: " + ClockItem.getUnlocalizedName().toString());
		
		return ClockItem;
	}
	
	/*public Item Scythe() {
		Scythe scythe = new Scythe();
		
		return scythe;
	}*/
}

 

As for my main class with the @Mod stuff. It is called SenorsStuff.java

 

package com.senorcontento.stuff;

import net.minecraft.init.Blocks;
import net.minecraft.item.Item; // For the abstract concept of Item!!!
import net.minecraft.item.ItemBlock;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraftforge.client.event.ModelRegistryEvent;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.model.Models;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

@Mod.EventBusSubscriber
@Mod(modid = SenorsStuff.MODID, name = SenorsStuff.NAME, version = SenorsStuff.VERSION, useMetadata = true)
public class SenorsStuff
{
	public static final String MODID = "senorsstuff";
	public static final String NAME = "SenorContento's Stuff";
	public static final String VERSION = "1.0";
	public static SenorsStuffCreativeTab tab;
	
	@EventHandler
	public void init(FMLInitializationEvent event)
	{
		System.out.println("Initializing " + SenorsStuff.NAME);
		System.out.println(Blocks.DIRT.getLocalizedName() + ": " + Blocks.DIRT.getUnlocalizedName());
		
		tab = new SenorsStuffCreativeTab(CreativeTabs.getNextID()); //Initializes The Tab for Creative Mode
		addBlocksAndItemsToTabs(); // Needs To Be Called After Creation Of All Tabs
	}

	@EventHandler
	public void preInit(FMLPreInitializationEvent event) {
		System.out.println("Pre-Initializing " + SenorsStuff.NAME);
		
		MinecraftForge.EVENT_BUS.register(new SenorsStuff());
	}

	@EventHandler
	public void postInit(FMLPostInitializationEvent event) {
		System.out.println("Post-Initializing " + SenorsStuff.NAME);
	}
	
	//Putting Registration of Items/Blocks in their own classes for Readability.
	@SubscribeEvent
	public void registerBlocks(RegistryEvent.Register<Block> event) {
		RegisterBlocks registerBlock = new RegisterBlocks();
		registerBlock.register(event);
	}

	/*@SubscribeEvent
	public void registerItems(RegistryEvent.NewRegistry event) {
		RegisterItems registerItem = new RegisterItems();
		registerItem.register(event);
	}*/
	
	@SubscribeEvent
	public void registerItems(RegistryEvent.Register<Item> event) {
		RegisterItems registerItem = new RegisterItems();
		registerItem.register(event);
      
      		//This is what calls RegisterItems.java (For MinecraftForge.net)
	}
	
	/*@SubscribeEvent
	public void registerModels(RegistryEvent.Register<Models> event) {
		Item FastCobbleItem = new ItemBlock(RegisterBlocks.FastCobble).setRegistryName(RegisterBlocks.FastCobble.getRegistryName());
		ModelResourceLocation FastCobbleResource = new ModelResourceLocation(RegisterBlocks.FastCobble.getRegistryName(), "inventory");
		ModelLoader.setCustomModelResourceLocation(FastCobbleItem, 0, FastCobbleResource);
		
		Item FastStoneItem = new ItemBlock(RegisterBlocks.FastStone).setRegistryName(RegisterBlocks.FastStone.getRegistryName());
		ModelResourceLocation FastStoneResource = new ModelResourceLocation(RegisterBlocks.FastStone.getRegistryName(), "inventory");
		ModelLoader.setCustomModelResourceLocation(FastStoneItem, 0, FastStoneResource);
		
		Item ClockItem = new ItemBlock(RegisterBlocks.Clock).setRegistryName(RegisterBlocks.Clock.getRegistryName());
		ModelResourceLocation ClockResource = new ModelResourceLocation(RegisterBlocks.Clock.getRegistryName(), "inventory");
		ModelLoader.setCustomModelResourceLocation(ClockItem, 0, ClockResource);
	}*/
	
	public void addBlocksAndItemsToTabs() {
		addBlocksToTabs();
		addItemsToTabs();
	}
	
	public void addBlocksToTabs() {
		AddBlocksToTab addTab = new AddBlocksToTab();
		addTab.addToTab(tab); // Can include multiple tabs here.
	}
	
	public void addItemsToTabs() {
		AddItemsToTab addTab = new AddItemsToTab();
		addTab.addToTab(tab); // Can include multiple tabs here.
	}
}

 

The below quote is part of the output from the mod. It still has the same model loading issues even with the code in this post.

 

Quote

[14:06:26] [main/INFO]: [com.senorcontento.stuff.RegisterItems:register:14]: Registered Item Count

[14:06:26] [main/INFO]: [com.senorcontento.stuff.RegisterItems:FastCobble:33]: Registry Name: senorsstuff:fast_cobble

[14:06:26] [main/INFO]: [com.senorcontento.stuff.RegisterItems:FastCobble:34]: Resource Name: senorsstuff:fast_cobble#inventory

[14:06:26] [main/INFO]: [com.senorcontento.stuff.RegisterItems:FastCobble:35]: Unlocalized Name: tile.stonebrick

[14:06:26] [main/INFO]: [com.senorcontento.stuff.RegisterItems:FastStone:46]: Registry Name: senorsstuff:fast_stone

[14:06:26] [main/INFO]: [com.senorcontento.stuff.RegisterItems:FastStone:47]: Resource Name: senorsstuff:fast_stone#inventory

[14:06:26] [main/INFO]: [com.senorcontento.stuff.RegisterItems:FastStone:48]: Unlocalized Name: tile.stone.stone

[14:06:26] [main/INFO]: [com.senorcontento.stuff.RegisterItems:Clock:59]: Registry Name: senorsstuff:clock

[14:06:26] [main/INFO]: [com.senorcontento.stuff.RegisterItems:Clock:60]: Resource Name: senorsstuff:clock#inventory

[14:06:26] [main/INFO]: [com.senorcontento.stuff.RegisterItems:Clock:61]: Unlocalized Name: tile.senorsstuff:clock

 

After re-reading the below quote, I realized that you don't know what I am having trouble doing, so I am fixing that.

 

Quote

As to your actual problem: I can't actually find your problem in your post.

 

When loading the mod into the world, I have 3 blocks. They are FastCobble, FastStone, and Clock. FastCobble and FastStone exist solely for testing block and item creation, but otherwise they can be mined like vanilla dirt. Clock is a utility block I am working on. When I specify the data for the blocks, I am able to set the name of the block in the inventory, the texture of the block in the world, and even the block hardness (so it mines like dirt). I cannot set the item texture properly though. This does not crash the game, nor does it throw any errors.

 

When attempting to set the texture for the itemblock, I can only set the texture for the first item created. After that, any attempt to set the textures of future items only sets the texture of the first item (even when I don't touch the first item anymore). It doesn't matter which item I set first, nor does it matter if the texture is vanilla or custom.

 

I have tried registering the item before moving onto the next one through use of code such as 

event.getRegistry().register(FastStoneItem);

 

I can set the texture correctly on the first time, just never any future times. I suspect that I am registering the models in the wrong event and that I should be registering them sooner/later than I am. I have tried registering through events such as

RegistryEvent.Register<Models>

and

RegistryEvent.NewRegistry

 

I seem to lose my ability to set models on those two events. On the other hand, I decided to look at other author's code again and seeing Plethora's Helper.java, I can see that Plethora uses ModelRegistryEvent. Trying to replicate that code is producing zero models for me. I will have to experiment further and post any updates on a new post instead of continually editing this one. If you know why this might be the case, I would be more than happy to hear why. Thanks!

Edited by SenorContento
To help clarify what my problem is

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



×
×
  • Create New...

Important Information

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