Jump to content

Recommended Posts

Posted

I have an itemstack that needs to have different textures depending on nbt data, for example, an item with an nbt value of "wood" would have a "item_wood" texture while an itemstack with nbt value of "fire" would have a "item_fire" texture. I would also like this to be modular so I don't want to make a bunch of icons in the iconRegister method. What would be the best way to do this?

Posted

Well you have to register the icons at some point. So you have to make "a bunch of icons" anyway. :P

The only thing you can tweak is how to organize them.

I would use a HashMap holding custom objects as keys and Icons as values.

Those custom objects would hold the nbt data (or equivalent data) and override equals and hash methods to be compared.

You may want to organize the textures locations too.

Posted

Yeah, you're going to have to register them anyway.

 

Here's what I did:

 

public void registerIcons(IconRegister iconReg)
    {
        //can't loop this as there are different amounts of each set
        itemIcon = iconReg.registerIcon("artifacts:artifact1");
        icons.put("artifact1",itemIcon);
        icons.put("amulet1",iconReg.registerIcon("artifacts:amulet1"));
        icons.put("amulet2",iconReg.registerIcon("artifacts:amulet2"));
        icons.put("amulet3",iconReg.registerIcon("artifacts:amulet3"));
        icons.put("amulet4",iconReg.registerIcon("artifacts:amulet4"));
        icons.put("dagger1",iconReg.registerIcon("artifacts:dagger1"));
        icons.put("dagger2",iconReg.registerIcon("artifacts:dagger2"));
        icons.put("dagger3",iconReg.registerIcon("artifacts:dagger3"));
        icons.put("dagger4",iconReg.registerIcon("artifacts:dagger4"));
        icons.put("figurine1",iconReg.registerIcon("artifacts:figurine1"));
        icons.put("figurine2",iconReg.registerIcon("artifacts:figurine2"));
        icons.put("ring1",iconReg.registerIcon("artifacts:ring1"));
        icons.put("ring2",iconReg.registerIcon("artifacts:ring2"));
        icons.put("ring3",iconReg.registerIcon("artifacts:ring3"));
        icons.put("ring4",iconReg.registerIcon("artifacts:ring4"));
        icons.put("ring5",iconReg.registerIcon("artifacts:ring5"));
        icons.put("ring6",iconReg.registerIcon("artifacts:ring6"));
        icons.put("ring7",iconReg.registerIcon("artifacts:ring7"));
        icons.put("staff1",iconReg.registerIcon("artifacts:staff1"));
        icons.put("staff2",iconReg.registerIcon("artifacts:staff2"));
        icons.put("staff3",iconReg.registerIcon("artifacts:staff3"));
        icons.put("staff4",iconReg.registerIcon("artifacts:staff4"));
        icons.put("sword1",iconReg.registerIcon("artifacts:sword1"));
        icons.put("sword2",iconReg.registerIcon("artifacts:sword2"));
        icons.put("sword3",iconReg.registerIcon("artifacts:sword3"));
        icons.put("trinket1",iconReg.registerIcon("artifacts:trinket1"));
        icons.put("trinket2",iconReg.registerIcon("artifacts:trinket2"));
        icons.put("trinket3",iconReg.registerIcon("artifacts:trinket3"));
        icons.put("trinket4",iconReg.registerIcon("artifacts:trinket4"));
        icons.put("trinket5",iconReg.registerIcon("artifacts:trinket5"));
        icons.put("trinket6",iconReg.registerIcon("artifacts:trinket6"));
        icons.put("trinket7",iconReg.registerIcon("artifacts:trinket7"));
        icons.put("wand1",iconReg.registerIcon("artifacts:wand1"));
        icons.put("wand2",iconReg.registerIcon("artifacts:wand2"));
        icons.put("wand3",iconReg.registerIcon("artifacts:wand3"));
        icons.put("wand4",iconReg.registerIcon("artifacts:wand4"));
        icons.put("wand5",iconReg.registerIcon("artifacts:wand5"));
        icons.put("boots1",iconReg.registerIcon("artifacts:boots1"));
        icons.put("chestplate1",iconReg.registerIcon("artifacts:chestplate1"));
        icons.put("helm1",iconReg.registerIcon("artifacts:helm1"));
        icons.put("leggings1",iconReg.registerIcon("artifacts:leggings1"));
    }

public Icon getIcon(ItemStack stack, int pass)
    {
	Icon i = itemIcon;
	if(pass == 0) {
		if(stack.stackTagCompound == null) {
			return itemIcon;
		}
		i = (Icon) icons.get(stack.stackTagCompound.getString("icon").toLowerCase());
		if(i == null) {
			i = itemIcon;
		}
	}
	return i;
    }

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 would like to add mod support though so the icon amounts will be dynamic. Is there a way to dynamically create / delete icons at any given time? Also could I'm using a custom renderer, would there be a way to make it work with that?

Posted

I would like to add mod support though so the icon amounts will be dynamic. Is there a way to dynamically create / delete icons at any given time? Also could I'm using a custom renderer, would there be a way to make it work with that?

 

You don't need to add and delete icons at "any time."  You're either going to register icons at startup or you're not.

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

Well they'd be registered dynamically at startup. I'd check what mods were in the mods folder then add (maybe delete wasn't the best word) all the icons it needs. I'd rather not make a new icon for all the mods I plan to support.

 

I actually have an idea, it's a little tough to explain though =P

Posted

Is there a way to register them dynamically at startup?

 

Yes.

 

(I don't have the details behind how you would want to configure it, etc., so I cannot be more helpful).

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

Is there a way to access the register icons class that's not in an item or a block? Theoretically my idea could work in an item/block but it's not the optimal solution.

 

In theory.  Unfortunately, that would probably be a base class edit.

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

My guess is that you saved a reference to the icon registerer, and used it later.  Bit of a workaround, but I'd have thought that it would have stopped stitching textures by then (i.e. newly added icons would be "ignored").

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

Here's the setup, I'm making weapons of all different tiers, gold, iron, diamond etc. and I wanted to have mod support so other people could add there own weapon types, copper, bronze, tin etc. These weapons are textured weird, they use overlays & colors. I was getting complaints from resource packers that the textures limited their options when texturing my mod. As a resource pack user myself I didn't want to upset them. So what I did is each weapon material has it's own instance WeaponMaterial.stone, WeaponMaterial.iron etc. In each one of those instances I stored a list of possible icons and in the render file I had it check whether these icons existed in the current resource pack. If it returned true it would get the correct icon from the list and display it.

 

To you this may seem like an obvious solution, but to me, a relatively new modder, this was a ground breaking discovery.

 

If you want to see the code and laugh at me for it, here's the github link =P

https://github.com/TuxCraft/TuxWeapons

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.