Jump to content

[1.8] More than 1 texture for item [Solved]


xwerswoodx

Recommended Posts

I have two questions;

 

First:

When I create an item named blockchecker, it's texture works well, but when I give model like blockchecker_activated, it isn't work. When I create a new item named blockchecker_activated, it's texture works well and when I give a blockchecker_activated render to blockchecker item it works as well. So I understand this, when I create an item same name with json file, minecraft render item, but when I don't give, it isn't render. So how can I fix this without create casting item, like fishing rod, I found something in ModelBakery.java but it is very long way to do this, is there any way to do this?

 

Secondly:

I have onPlayerTick event. It works fine, but when a player tick I want to upload my blockchecker item I did it, but here it updates all of the blockcheckers in server, doesn't it? So how can I do this for an item which is in player's inventory.

 

	@SubscribeEvent
 public void onPlayerTick(TickEvent.PlayerTickEvent event) {
	EntityPlayer player = event.player;
	InventoryPlayer inventory = player.inventory;

	 if (inventory.hasItem(itemref.blockChecker)) {
		 ((addmeter)itemref.blockChecker).initProps();
	 }
}

 

I did something like this but I am not sure it is work or not;

 

	 for (int x = 0; x < inventory.getSizeInventory(); x++) {
		 if (inventory.getStackInSlot(x).getItem().equals(itemref.blockChecker)) {
			 ((addmeter)inventory.getStackInSlot(x).getItem()).initProps();
		 }
	 }

Link to comment
Share on other sites

Ok I try to explain;

 

When I try to register blockChecker icon, I use that way;

		String name = ref.uid + ":" + (item.getUnlocalizedName().substring(5));
	ModelResourceLocation location = new ModelResourceLocation(name, "inventory");
	Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, location);

 

blockChecker unlocalized name is blockchecker_0 and when I create blockchecker_0.json, texture works in game, but when I try it to blockchecker_1.json, (I also have blockchecker_1.json) texture doesn't work in game.

 

	public void setRender(Item item, int level) {
	if (level < 0) { level = 0; }
	String name = ref.uid + ":" + item.getUnlocalizedName().substring(5).split("_")[0] + "_" + level;
	ModelResourceLocation location = new ModelResourceLocation(name, "inventory");
	String loc = name;
	Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, location);
}

 

This is my setRender void in Item Class, and onPlayerTick event I used that way to setting render;

 

	 public void onPlayerTick(TickEvent.PlayerTickEvent event) {
	EntityPlayer player = event.player;
	InventoryPlayer inventory = player.inventory;

	if (inventory.hasItem(itemref.blockChecker)) {
		 ((addmeter)itemref.blockChecker).initProps();
    }
        }

 

initProps calculate distance between player and block, and settingRender with distance, for example, if he far away blockchecker_0, if he far 8 squire blockchecker_1 if he is in 1 radius return blockchecker_4.

 

@SideOnly(Side.CLIENT)
public void update(Minecraft mc) {

	if (new Date().getTime() <= lastUpdate.longValue() + millisPerUpdate.longValue()) {
		return ;
	}
	lastUpdate = Long.valueOf(new Date().getTime());

	found.clear();
	distanceShortest = -1;

	EntityPlayer player = mc.thePlayer;
	World world = mc.theWorld;

	if ((player == null) || (world == null)) {
		return;
	}

	double cur_x = player.posX;
	double cur_y = player.posY;
	double cur_z = player.posZ;

	int min_x = (int)cur_x - distanceMax - 1;
	int min_y = (int)cur_y - distanceMax;
	int min_z = (int)cur_z - distanceMax;

	int max_x = (int)cur_x + distanceMax;
	int max_y = (int)cur_y + distanceMax;
	int max_z = (int)cur_z + distanceMax + 1;

	for (int z1 = min_z; z1 < max_z; z1++) {
		for (int x1 = min_x; x1 < max_x; x1++) {
			for (int y1 = min_y; y1 < max_y; y1++) {
				BlockPos pos1 = new BlockPos(x1, y1, z1);
				if (world.getBlockState(pos1).getBlock() == this.search) {
					found.add(new int[] { x1, y1, z1 });
				}
			}
		}
	}

	for (int i = 0; i < found.size(); i++) {
		int[] block = (int[])found.get(i);

		double distanceX = block[0] - cur_x;
		double distanceY = block[1] - cur_y + 1.0D;
		double distanceZ = block[2] - cur_z;

		distanceX += (distanceX > 0.0D ? 1.0D : 0.0D);
		distanceZ += (distanceZ > 0.0D ? 1.0D : 0.0D);

		double distance2D = Math.sqrt(Math.pow(distanceX, 2.0D) + Math.pow(distanceZ, 2.0D));
		double distance3D = Math.sqrt(Math.pow(distance2D, 2.0D) + Math.pow(distanceY, 2.0D));

		if ((int)distance3D > distanceMax) {
			found.remove(i);
			i--;
		} else if ((distanceShortest > distance3D) || (distanceShortest == -1)) {
			distanceShortest = (int)distance3D;
			vectorShortest = new int[] { block[0], block[1], block[2] };
		}
	}

    distancePerLevel = distanceMax / 4;
    if (distancePerLevel < 1) {
      distancePerLevel = 1;
    }
    
	if (distanceShortest > -1) {
		int level = (distanceMax - distanceShortest + 1) / distancePerLevel;
		if (distanceMax < 4) {
			level +=4 - distanceMax;
		}
		this.setRender(this, level);;
	} else {
		this.setRender(this, 0);
	}
}

 

But I have an item named blockchecker_0 and texture work when I far away, but when I get closer, and model resource change to blockchecker_1 it doesn't work, on the other hand, when I add for items without creativetabs, as an unlocalizedname blockchecker_1, blockchecker_2, blockchecker_3 and blockchecker_4, all the textures works well. But I have to create a new item for every texture. Or maybe I am doing something wrong somewhere.

 

Also I have a trouble with ticking a specific item. When player get closer to block, this code update all of the blockChecker items in server, I just want to update items which is in player inventory.

 

 

Link to comment
Share on other sites

String name = ref.uid + ":" + (item.getUnlocalizedName().substring(5));
ModelResourceLocation location = new ModelResourceLocation(name, "inventory");

 

You...don't understand how ModelResourceLocation works, do you?

 

The first parameter is the MODID, the second parameter is the filename.  You're adding the item's unlocalized name to the wrong part.  Also,

setTextureName()

and

getTextureName()

are things.  No need to substring the unlocalized name.  I blame Pahmir.

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

String name = ref.uid + ":" + (item.getUnlocalizedName().substring(5));

 

Ah this line is means ref.uid is my modid and (item.getUnlocalizedName().substring(5)) is json file name, for 1.8.0 setTextureName isn't exists anymore, before I can do it with IIcon but now I can't register more than 1 textures for item.

 

For 1.7.10 I can use like this;

private IIcon[] iconIndexes = new IIcon[5];

@SideOnly(Side.CLIENT)
@Override
public void registerIcons(IIconRegister reg) {
	for (int x=0; x < 5; x++) {
		iconIndexes[x] = reg.registerIcon(ref.uid + ":" + (this.getUnlocalizedName().substring(5)) + "_" + x);
	}
	this.itemIcon = iconIndexes[0];
}

 

And use like this;

@SideOnly(Side.CLIENT)
public void update(Minecraft mc) {

	if (new Date().getTime() <= lastUpdate.longValue() + millisPerUpdate.longValue()) {
		return ;
	}
	lastUpdate = Long.valueOf(new Date().getTime());

	found.clear();
	distanceShortest = -1;

	EntityPlayer player = mc.thePlayer;
	World world = mc.theWorld;

	if ((player == null) || (world == null)) {
		return;
	}

	double cur_x = player.posX;
	double cur_y = player.posY;
	double cur_z = player.posZ;

	int min_x = (int)cur_x - distanceMax - 1;
	int min_y = (int)cur_y - distanceMax;
	int min_z = (int)cur_z - distanceMax;

	int max_x = (int)cur_x + distanceMax;
	int max_y = (int)cur_y + distanceMax;
	int max_z = (int)cur_z + distanceMax + 1;

	for (int z1 = min_z; z1 < max_z; z1++) {
		for (int x1 = min_x; x1 < max_x; x1++) {
			for (int y1 = min_y; y1 < max_y; y1++) {
				if (world.getBlock(x1, y1, z1) == this.search) {
					found.add(new int[] { x1, y1, z1 });
				}
			}
		}
	}

	for (int i = 0; i < found.size(); i++) {
		int[] block = (int[])found.get(i);

		double distanceX = block[0] - cur_x;
		double distanceY = block[1] - cur_y + 1.0D;
		double distanceZ = block[2] - cur_z;

		distanceX += (distanceX > 0.0D ? 1.0D : 0.0D);
		distanceZ += (distanceZ > 0.0D ? 1.0D : 0.0D);

		double distance2D = Math.sqrt(Math.pow(distanceX, 2.0D) + Math.pow(distanceZ, 2.0D));
		double distance3D = Math.sqrt(Math.pow(distance2D, 2.0D) + Math.pow(distanceY, 2.0D));

		if ((int)distance3D > distanceMax) {
			found.remove(i);
			i--;
		} else if ((distanceShortest > distance3D) || (distanceShortest == -1)) {
			distanceShortest = (int)distance3D;
			vectorShortest = new int[] { block[0], block[1], block[2] };
		}
	}

    distancePerLevel = distanceMax / 4;
    if (distancePerLevel < 1) {
      distancePerLevel = 1;
    }
    
	if (distanceShortest > -1) {
		int level = (distanceMax - distanceShortest + 1) / distancePerLevel;
		if (distanceMax < 4) {
			level +=4 - distanceMax;
		}
		this.itemIcon = iconIndexes[level];
	} else {
		this.itemIcon = iconIndexes[0];
	}
}

 

So I can't do with modelresourcelocation, because I cant register models without create new item.

Link to comment
Share on other sites

Then don't use item.getUnlocalizedName().substring(5). There is no reason for using that.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Link to comment
Share on other sites

Ok I did what did you say

 

Change my code to:

		ModelResourceLocation location = new ModelResourceLocation(ref.uid, "inventory");
	Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(itemref.ironX, 0, location);

 

texture isn't work.

 

I changed it

 

		ModelResourceLocation location = new ModelResourceLocation(ref.uid + ":ironx", "inventory");
	Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(itemref.ironX, 0, location);

 

Texture works.

 

I changed it to;

		ModelResourceLocation location = new ModelResourceLocation(ref.uid + ":irony", "inventory");
	Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(itemref.ironX, 0, location);

 

Texture doesn't work. (I have ironx.json and irony.json files and both is tested and work)

 

Where did I do mistake? I can't caught it, I remove unlocalizedname.substring(5) and it isn't work. When I type my json file name for "inventory" section, it isn't work. Maybe I don't understand what do you mean, if you can explain it to me with a code I can understand clearly.

Link to comment
Share on other sites

Ah, @Draco18s already said what you have to do. Use Item#setTextureName(String) and Item#getTextureName() instead of item.getUnlocalizedName().substring(5).

And, you should use something like ISmartModel for changing model.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Link to comment
Share on other sites

@Abastro as of 1.8 Item#getTextureName() and Item#setTextureName() don't exist in the item class or anywhere, the only reference to them is in the forge_at.cfg therefore what you are saying doesn't work the only way to set the texture of items in 1.8 that I know of is using the ItemModelMesher and to ask a question to @xwerswoodx have you registered the variant names cause otherwise the items aren't distinguished and the item doesn't know it is looking for multiple textures. To do this Register to the Model Bakery with

ModelBakery.addVariantName(youritem,name)

this needs to be done for every sub-Item that you have. than what you have will work

Did you really need to know?

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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