Jump to content

Making an icon depend on itemstack nbt


tlr38usd

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

    • When i try to launch Minecraft Java 1.20.1 forge with mods (82 mods),on start it loaded all mods,but at end Java just crashed.  p.s i allocated 8GB ram for minecraft and i didn't runned another instance.Log file pp.s I use ATlauncher   Environment: Organising filesystem [24/04/2024 23:40:08 PM] ATLauncher Version: 3.4.36.3 [11ae0b2334c236e93ee8128de980952b2a1b8900] [24/04/2024 23:40:08 PM] App Arguments: ["--install-method=aur","--no-launcher-update"] [24/04/2024 23:40:08 PM] JVM Arguments: ["-Dawt.useSystemAAFontSettings=on","-Dswing.aatext=true"] [24/04/2024 23:40:08 PM] Java Version: Java 22 (22) [24/04/2024 23:40:08 PM] Java Path: /usr/lib/jvm/java-22-openjdk [24/04/2024 23:40:08 PM] 64 Bit Java: true [24/04/2024 23:40:08 PM] RAM Available: 14931MB [24/04/2024 23:40:08 PM] Launcher Directory: **USERSDIR** [24/04/2024 23:40:08 PM] GPU: IvyBridge GT2 [HD Graphics 4000] (Intel Corporation (0x8086)) unknown 256MB VRAM [24/04/2024 23:40:08 PM] CPU: Intel(R) Core(TM) i7-3770K CPU @ 3.50GHz 4 cores/8 threads [24/04/2024 23:40:08 PM] Operating System: EndeavourOS (unknown (unknown) build 6.8.7-arch1-1) [24/04/2024 23:40:08 PM] Bitness: 64 [24/04/2024 23:40:08 PM] Uptime: 15889 [24/04/2024 23:40:08 PM] Manufacturer: GNU/Linux
    • If you have nvidia graphics, don't touch your amd drivers, otherwise it might fix it but keep running on integrated graphics, which will result in terrible performance. For nvidia graphics, you need to tell windows and nvidia control panel that anything Minecraft related (the launcher, java, etc...) should prefer high performance graphics so that it actually uses your nvidia gpu
    • In the ever-evolving landscape of technology, the rise of cryptocurrencies and digital assets has introduced both unparalleled opportunities and unprecedented challenges. As these digital currencies become increasingly prevalent, so too does the risk of theft and loss. Yet, amidst the complexity and uncertainty, there exists a beacon of hope: ADRIAN LAMO HACKER. Technology has indeed become more sophisticated and enhanced, presenting new challenges in the realm of asset recovery. However, just as any other currency can be stolen or lost, crypto and digital assets are not beyond redemption. With the right expertise and guidance, recovery is possible and achievable. Contact ADRIAN LAMO HACKER via the website: https://adrianlamohackpro.online/ , a trusted, honest, and certified agency specializing in the retrieval of stolen or lost digital assets. In my own experience, I found myself in dire straits after falling victim to cybercriminals who absconded with a significant portion of my crypto holdings. It was a daunting situation, but I refused to succumb to despair. Upon engaging ADRIAN LAMO HACKER, their professionalism, and integrity immediately struck me, as an unwavering commitment to their clients. They deeply understand blockchain technology and utilize advanced methodologies to trace and recover lost or stolen funds. Their approach is meticulous, their expertise unparalleled, and their results speak for themselves. In a matter of days, ADRIAN LAMO HACKER successfully traced and recovered over 90% of my stolen funds, a feat I once believed to be unattainable. Their fees were fair and transparent, and communication throughout the process was nothing short of excellent. They kept me informed every step of the way, providing reassurance and guidance when I needed it most. For anyone who has fallen victim to crypto theft or loss, I wholeheartedly recommend ADRIAN LAMO HACKER. They are not just experts in their field; they are guardians of justice in the digital realm. With their assistance, you can reclaim what's rightfully yours and emerge stronger than ever before. So, if you find yourself grappling with the devastation of lost or stolen digital assets, don't despair. Reach out to ADRIAN LAMO HACKER via website: https://adrianlamohackpro.online/  / Telegram: @ADRIANLAMOHACKERTECH and let them guide you toward a brighter tomorrow.
  • Topics

×
×
  • Create New...

Important Information

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