Jump to content

[1.7.2]Get icon file name on server


maxanier

Recommended Posts

Hello

 

I'm currently working on a server mod which beside others allows you to show your players inventory on an Android device. To show the items in the app, I want to use icons from a texturepack.

The problem is, how to get the item's icon? My current approach is to send the the icons file name as it is in a texturepack (e.g. apple.png or book_enchanted.png) to the app, which can take the image from its own texturepack.

My question is how can I get the item's icon's file name? The class Item has a protected method getIconString(), which I could access with the dirty method of creating a new wrapperclass in the net.minecraft.item package, but, at least at server side, it only returns MISSING_ICON_ITEM_37_flower instead of flower_dandelion.png.

Do you have any idea how I could get the appropriate file name?

 

Thank you in advance.

maxanier

Minecraft Second Screen Mod: Use your mobile as a second screen for Minecraft and see your inventory, redstone stati, the chat and much more on it.

link

Vampirism: Become a vampire in Minecraft

link

Link to comment
Share on other sites

Ok thanks for the advice, I will try using that.

But this will probably not solve the problem that the iconString is empty on the server.

Anyone an idea?

Minecraft Second Screen Mod: Use your mobile as a second screen for Minecraft and see your inventory, redstone stati, the chat and much more on it.

link

Vampirism: Become a vampire in Minecraft

link

Link to comment
Share on other sites

I tried using reflection, but the field is just null on the server :(

 

Now I tried another way, since Items and Blocks have a method registerIcon or registerBlockIcon where they set their Icon in an IIconRegister, which then returns a IIcon. This method is not called on the server, so I simply call these methods with a fakeIconRegister, which returns the icon_file_String to me. That actually works, but now the aver block on which I call this method shows up with an undefined purple/black texture on the client (http://www.directupload.net/file/d/3547/w7qil68o_png.htm). This is probably caused by the FakeIIconRegister which return null as an IIcon and the client synchronizing it with the server (why ever).

The I changed the FakeRegister to return a new IIcon (a TextureAtlasSprite with the iconString as parameter in fact) instead of null, now the blocks and items show up as orange blinking blocks (http://www.directupload.net/file/d/3547/guo3k6hl_png.htm).

 

Any idea how to avoid this?

 

Thanks in advance!

 

Edit: I now abort the method registerIcon by throwing a null pointer. Almost everythings exept for any wooden stuff works now

 

Here my getIconString method:

private String getTextureString(Item i){
	FakeIconRegister register=new FakeIconRegister();
	try {
			try {
				ItemBlock ib=(ItemBlock)i;
				ib.field_150939_a.registerBlockIcons(register);
			} catch (java.lang.ClassCastException e) {

				i.registerIcons(register);
			}
		} catch (NullPointerException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	return register.getTextureString();
}

 

And my FakeIconRegister:

private class FakeIconRegister implements IIconRegister{

			String texture;
	@Override
	public IIcon registerIcon(String var1) {
		texture=var1;

		//Should throw a nullpointer
		String n=null;
		n.charAt(1);

		return createTextureAtlasSprite(texture);

	}
	public String getTextureString(){
		return texture;
	}

	private IIcon createTextureAtlasSprite(String s){
		try {
			Class<?> c = TextureAtlasSprite.class;
			java.lang.reflect.Constructor constr=c.getDeclaredConstructor(String.class);
			constr.setAccessible(true);
			return (IIcon)constr.newInstance(s);
		} catch (NoSuchMethodException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SecurityException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

}

 

 

 

Minecraft Second Screen Mod: Use your mobile as a second screen for Minecraft and see your inventory, redstone stati, the chat and much more on it.

link

Vampirism: Become a vampire in Minecraft

link

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

    • 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.