Jump to content

Recommended Posts

Posted

I'm currently trying to make an item with a subtype and they don't have textures on them.

 

Here is my code:

Item Code

public class ItemPDA extends Item {
public ItemPDA () {
	maxStackSize = 1;
	setHasSubtypes(true);
	setMaxDamage(0);
}

@Override
public String getUnlocalizedName(ItemStack stack) {
	return super.getUnlocalizedName(stack) + "_" + stack.getMetadata();
}

@SideOnly(Side.CLIENT)
@Override
public void getSubItems(Item itemIn, CreativeTabs tab, List<ItemStack> subItems) {
	for (int i = 0; i < 1; i++) {
		subItems.add(new ItemStack(itemIn, 1, i));
	}
}
}

 

public class TFCItems {
public static Item pda;

public static void init () {
	pda = new ItemPDA().setUnlocalizedName("pda").setCreativeTab(tab);
}

public static void register () {
	registerItem(pda);
}

public static void registerItem (Item item) {
	GameRegistry.register(item.setRegistryName(item.getUnlocalizedName().substring(5)));
}

public static void registerRenders () {
	Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(pda, 0, new ModelResourceLocation(Refrence.MODID + ":pda_0", "inventory"));
	Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(pda, 1, new ModelResourceLocation(Refrence.MODID + ":pda_1", "inventory"));
}
}

 

In the console it shows that the model pda.json isn't found but when I do make it, it doesn't use the texture defined by the model file.

 

How would I go about fixing this?

Posted

First instead of using the modelMesher you should use ModelLoader.setCustomModelResourceLocation(...) And post your model JSONs

 

Here is the json models

 

pda.json

{
    "parent": "item/generated",
    "textures": {
        "layer0": "tfc:items/pda_0"
    }
}

 

pda_0.json

{
    "parent": "item/generated",
    "textures": {
        "layer0": "tfc:items/pda_0"
    }
}

 

pda_1.json

{
    "parent": "item/generated",
    "textures": {
        "layer0": "tfc:items/pda_1"
    }
}

 

I also changed the code:

public static void registerRenders () {
	ModelLoader.setCustomModelResourceLocation(pda, 0, new ModelResourceLocation(Refrence.MODID + ":pda_0", "inventory"));
	ModelLoader.setCustomModelResourceLocation(pda, 1, new ModelResourceLocation(Refrence.MODID + ":pda_1", "inventory"));
}

 

still no textures

Posted

ModelLoader

methods must be called in preInit. Does your code do this?

 

Post the FML log, it should say exactly what went wrong.

 

 

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

  • 1 month later...
Posted

I have the same problem and I think I've done everything this thread suggests. I am trying to register a simple bow that should have one subtype with a different texture. I believe I can just register a new item with a new class, but I would rather do it the right way.

 

Registration in CommonProxy:

SimpleItem simpleItem = new SimpleItem();
simpleItem.setUnlocalizedName("simple_item_0");
simpleItem.setRegistryName("simple_item_0");
GameRegistry.register(simpleItem);

 

Registering model locations in ClientProxy:

ModelLoader.setCustomModelResourceLocation(ModItems.SIMPLE_ITEM, 0, new ModelResourceLocation("simple_item_0"));
ModelLoader.setCustomModelResourceLocation(ModItems.SIMPLE_ITEM, 1, new ModelResourceLocation("simple_item_1));

 

In SimpleItem class:

@Override
public String getUnlocalizedName(ItemStack stack) 
{
    return stack.getMetadata() == 0 ? "simple_item_0" : simple_item_1;
}

@SideOnly(Side.CLIENT)
public void getSubItems(Item itemIn, CreativeTabs tab, List<ItemStack> subItems)
{
    subItems.add(new ItemStack(this, 1, 1));
}

 

I've got two json files with names "simple_item_0" and "simple_item_1". The problem is that no matter what I change in the second json file (the subtype one) the item is always loaded with the texture set in the first json file. I've setup a recipe that is suppose to craft the subtype, but all I get is the original texture with the damage indicator over it in my inventory.

 

The real class I have is not called like this and I've got things set a lot different, but this is an extrapolated version that should be sufficient for demonstrating my problem. And yes, setHasSubtypes(true) is set in the separate item constructor. It's late now and I am a bit tired so that's why I am definitely missing something, just can't figure out what it is. What's the correct way to do this step by step? Thank you in advance, this has been driving me insane for the last 3 hours.

I still haven't published a mod because I can never get that in-dev version just right to warrant a public release. And yes, after two years of mod development I am still learning to speak Java.

 

Follow me on GitHub: https://github.com/yooksi

Contact me on Twitter: https://twitter.com/yooksi

Read my Minecraft blog: https://yooksidoesminecraft.blogspot.de/

Posted
ModelResourceLocation("simple_item_0")

 

I think you should have passed the registry name, not a static string.

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Posted

I believe so, yes.

 

You can also use Blockstate variants if you want to, rather than multiple separate json files.

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

ModelResourceLocation("simple_item_0")

 

I think you should have passed the registry name, not a static string.

This is what I usually do, this was just a quickly written example. However, isn't it okay to use a string like that if you know the registry name for a fact? Java passes things by value, right? So there shouldn't be any problems from a technical perspective.

 

I believe so, yes.

 

You can also use Blockstate variants if you want to, rather than multiple separate json files.

What exactly are Blockstate variants and how would I go about learning more about them?

I still haven't published a mod because I can never get that in-dev version just right to warrant a public release. And yes, after two years of mod development I am still learning to speak Java.

 

Follow me on GitHub: https://github.com/yooksi

Contact me on Twitter: https://twitter.com/yooksi

Read my Minecraft blog: https://yooksidoesminecraft.blogspot.de/

Posted

What exactly are Blockstate variants and how would I go about learning more about them?

 

This will let you understand the broad strokes, but honestly little about making it work:

http://mcforge.readthedocs.io/en/latest/blockstates/forgeBlockstates/

 

This is very nuts and bolts, but won't explain the broad strokes as to why it's doing what it's doing:

https://github.com/Draco18s/ReasonableRealism/blob/master/src/main/java/com/draco18s/hardlib/client/ClientEasyRegistry.java

 

(super methods there call the setRegistryName and GameRegistry.register methods)

My code there was put together very much with the help of Choonster, so help yourself.  I've been adding to it as I find something new that I want to do that isn't supported by the class yet (e.g. I it won't currently support a block, with variants, and a custom item that only needs to be one variant--say, a bed--as I haven't encountered the need yet).

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

I've tried to create more simple items and subtype them in a separate project and I've managed to make it work. Thank you everyone who contributed to this thread, it made it a lot easier.

 

To help everyone else I've created a dedicated branch in my tutorial project for anyone who wants to learn how to do this. You can see the content of the branch here.

 

Don't worry about additional changes that might come in the future, this link should always display the up-to-date content of the branch.

I still haven't published a mod because I can never get that in-dev version just right to warrant a public release. And yes, after two years of mod development I am still learning to speak Java.

 

Follow me on GitHub: https://github.com/yooksi

Contact me on Twitter: https://twitter.com/yooksi

Read my Minecraft blog: https://yooksidoesminecraft.blogspot.de/

Posted

...isn't it okay to use a string like that if you know the registry name for a fact?

 

No.

 

Registry name acquires a "modid:" prefix during its setting. Your bare string is missing that critical piece.

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Posted

...isn't it okay to use a string like that if you know the registry name for a fact?

 

No.

 

Registry name acquires a "modid:" prefix during its setting. Your bare string is missing that critical piece.

 

My apologies, I did not see that I didn't include a prefix in there. Is it okay to use it if we include it, a string like this "modid:simple_item"?

I still haven't published a mod because I can never get that in-dev version just right to warrant a public release. And yes, after two years of mod development I am still learning to speak Java.

 

Follow me on GitHub: https://github.com/yooksi

Contact me on Twitter: https://twitter.com/yooksi

Read my Minecraft blog: https://yooksidoesminecraft.blogspot.de/

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.