Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

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


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 post
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 post
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 post
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 post
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 post
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 post
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 post
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

If I sound like a jerk it's because I'm tired

Link to post
Share on other sites
Guest
This topic is now closed to further replies.


  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • so I have done nothing wrong by the coding itself, it's just the understanding of mojang
    • I've noticed that forge for 1.16.5 no longer accepts version specific mod folders, has the format been changed from the version number to something else, is this a bug, or has this feature been removed? 
    • setBlockAndUpdate uses flag 3, but I've tried 1, 2, and 4 with no success. Is there any documentation on what these flags do? I found this thread but since I'm using the mojang mappings I don't think I have the same javadocs.   
    • Ok i can't make it work. It gives me this error "java.lang.RuntimeException: Attempted to load class net/minecraft/client/renderer/tileentity/ItemStackTileEntityRenderer for invalid dist DEDICATED_SERVER" I try to move the chestRenderer() methods to a separate class but it keeps to give me this error. I don't know how to separate the Supplier<Callable<ItemStackTileEntityRenderer>> renderMethod parameter to the server registration. I tryied to make a class for only the items, removing it from the Blocks class:   public class Items { public static final DeferredRegister<Item> ITEMS; private static final RegistryObject<Item> MINI_CHEST; private static final RegistryObject<Item> SMELTING_CHEST; private static final RegistryObject<Item> INVISIBLE_CHEST; private static final RegistryObject<Item> TRAP_CHEST; private static final RegistryObject<Item> PITFALL_CHEST; private static final RegistryObject<Item> DRILL_CHEST; private static final RegistryObject<Item> TELEPORT_CHEST; private static final RegistryObject<Item> LOOT_CHEST; private static final RegistryObject<Item> MONSTER_CHEST; private static final RegistryObject<Item> POCKET_DIMENSION_CHEST; private static final RegistryObject<Item> COLOSSAL_CHEST; static { ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, TenChest.MODID); MINI_CHEST = register("mini_chest", Blocks.MINI_CHEST, ItemBlockRenderer::baseChestRenderer); SMELTING_CHEST = register("smelting_chest", Blocks.SMELTING_CHEST, ItemBlockRenderer::smeltingChestRenderer); INVISIBLE_CHEST = register("invisible_chest", Blocks.INVISIBLE_CHEST, ItemBlockRenderer::baseChestRenderer); TRAP_CHEST = register("trap_chest", Blocks.TRAP_CHEST, ItemBlockRenderer::baseChestRenderer); PITFALL_CHEST = register("pitfall_chest", Blocks.PITFALL_CHEST, ItemBlockRenderer::baseChestRenderer); DRILL_CHEST = register("drill_chest", Blocks.DRILL_CHEST, ItemBlockRenderer::baseChestRenderer); TELEPORT_CHEST = register("teleport_chest", Blocks.TELEPORT_CHEST, ItemBlockRenderer::teleportChestRenderer); LOOT_CHEST = register("loot_chest", Blocks.LOOT_CHEST, ItemBlockRenderer::lootChestRenderer); MONSTER_CHEST = register("monster_chest", Blocks.MONSTER_CHEST, ItemBlockRenderer::baseChestRenderer); POCKET_DIMENSION_CHEST = register("pocket_dimension_chest", Blocks.POCKET_DIMENSION_CHEST, ItemBlockRenderer::pocketDimensionChestRenderer); COLOSSAL_CHEST = register("colossal_chest", Blocks.COLOSSAL_CHEST, ItemBlockRenderer::baseChestRenderer); } private static <T extends Item> RegistryObject<T> register(String name, RegistryObject<Block> block, Supplier<Callable<ItemStackTileEntityRenderer>> renderMethod) { return register(name, block, (item) -> item(block, renderMethod)); } private static <T extends Item> RegistryObject<T> register(String name, RegistryObject<Block> ret, Function<RegistryObject<Block>, Supplier<? extends Item>> itemCreator) { return ITEMS.register(name, (Supplier) itemCreator.apply(ret)); } private static Supplier<BlockItem> item(RegistryObject<? extends Block> block, Supplier<Callable<ItemStackTileEntityRenderer>> renderMethod) { return () -> { BlockItem blockItem = new BlockItem(block.get(), (new Item.Properties().tab(TenChest.MOD_GROUP).setISTER(renderMethod))); return blockItem; }; } } But the items are not registered, and i don't know why. It gives to me this:   [16:06:18] [Render thread/INFO] [ne.mi.re.GameData/REGISTRIES]: Injecting existing registry data into this CLIENT instance [16:06:18] [Render thread/INFO] [ne.mi.re.ForgeRegistry/REGISTRIES]: Registry Item: Found a missing id from the world tenchest:colossal_chest [16:06:18] [Render thread/INFO] [ne.mi.re.ForgeRegistry/REGISTRIES]: Registry Item: Found a missing id from the world tenchest:colossal_chest_part [16:06:18] [Render thread/INFO] [ne.mi.re.ForgeRegistry/REGISTRIES]: Registry Item: Found a missing id from the world tenchest:drill_chest [16:06:18] [Render thread/INFO] [ne.mi.re.ForgeRegistry/REGISTRIES]: Registry Item: Found a missing id from the world tenchest:invisible_chest [16:06:18] [Render thread/INFO] [ne.mi.re.ForgeRegistry/REGISTRIES]: Registry Item: Found a missing id from the world tenchest:loot_chest [16:06:18] [Render thread/INFO] [ne.mi.re.ForgeRegistry/REGISTRIES]: Registry Item: Found a missing id from the world tenchest:mini_chest [16:06:18] [Render thread/INFO] [ne.mi.re.ForgeRegistry/REGISTRIES]: Registry Item: Found a missing id from the world tenchest:monster_chest [16:06:18] [Render thread/INFO] [ne.mi.re.ForgeRegistry/REGISTRIES]: Registry Item: Found a missing id from the world tenchest:pitfall_chest [16:06:18] [Render thread/INFO] [ne.mi.re.ForgeRegistry/REGISTRIES]: Registry Item: Found a missing id from the world tenchest:pocket_dimension_chest [16:06:18] [Render thread/INFO] [ne.mi.re.ForgeRegistry/REGISTRIES]: Registry Item: Found a missing id from the world tenchest:smelting_chest [16:06:18] [Render thread/INFO] [ne.mi.re.ForgeRegistry/REGISTRIES]: Registry Item: Found a missing id from the world tenchest:teleport_chest [16:06:18] [Render thread/INFO] [ne.mi.re.ForgeRegistry/REGISTRIES]: Registry Item: Found a missing id from the world tenchest:trap_chest [16:06:18] [Render thread/DEBUG] [ne.mi.re.GameData/REGISTRIES]: There are 12 mappings missing - attempting a mod remap [16:06:18] [Render thread/ERROR] [ne.mi.re.GameData/REGISTRIES]: Unidentified mapping from registry minecraft:item tenchest:colossal_chest: 987 tenchest:colossal_chest_part: 986 tenchest:drill_chest: 981 tenchest:invisible_chest: 978 tenchest:loot_chest: 983 tenchest:mini_chest: 976 tenchest:monster_chest: 984 tenchest:pitfall_chest: 980 tenchest:pocket_dimension_chest: 985 tenchest:smelting_chest: 977 tenchest:teleport_chest: 982 tenchest:trap_chest: 979  
    • I've tried to play my old world with mods, but Minecraft just crashes after the mods loading screen. The Minecraft version is 1.12.2 and the Forge version is the latest one, 14.23.5.2855   I've already reinstalled forge, deleted the mods and using the previous version (which I used originally and worked) and even using different versions of Java, so I don't know what else to do   The debug.log file is this: https://pastebin.com/vwLHWvFE . The error is in the line 332, I hope it helps.   Thanks in advance
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.