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



×
×
  • Create New...

Important Information

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