Jump to content

[1.6.4] How to change an item texture according to the player's armor?


Recommended Posts

Posted

I'd like to change the texture of an item (and of a block too, actually) if the player is wearing some special goggles. But in the registerIcons method I can't seem to access any of the player's current state. I think the easiest way would be to add two animation frames, but not actually add an animation (in the .mcmeta file), like the clock or compass. Then, change the frame according to the scenario, but I'm not sure how to do that... Is it possible somehow?

 

I know qCraft has something in this manner but it is not open-source, I'm afraid. I tried to look at the actual clock code from vanilla, but there isn't a registerIcons method there - it must work via some sort of black magic or something. Thaumcraft (Goggles of Revealing) and TinkersMechworks (Spool of Wire) both have items that change the way you see the world, but not the actual texture of items, which should be much simpler. I tried, even though, to look at the TM's code, but still couldn't figure it out.

 

I am pretty new, this is the first mod I am trying to make, so I might be just ignoring something very obvious... But I just can't find any way to do it...

Posted

registerIcons is run once when the game loads, you're in the wrong function.

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.

Posted

Use a tickhandler and check for the player that is wearing the goggles, and then change your block textures based on the player which is wearing the goggles.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Posted

Ok, so I looked up on these TickHandlers, they sound quite promising. I added this to my server proxy register method:

TickRegistry.registerTickHandler(new ITickHandler() {
    		
    		private void onPlayerTick(EntityPlayer player) {
    			if (player.getCurrentItemOrArmor(4) != null && player.getCurrentItemOrArmor(4).getItem().itemID == CItems._my_goggles_) {
			System.out.println("is on");
    				CItems._my_item_.changeTextures(true);
    			} else {
    				CItems._my_item_.changeTextures(false);
    			}
    		}

	@Override
	public void tickStart(EnumSet<TickType> type, Object... tickData) {
		if (type.equals(EnumSet.of(TickType.PLAYER))) {
			onPlayerTick((EntityPlayer) tickData[0]);
		}
	}

	@Override
	public void tickEnd(EnumSet<TickType> type, Object... tickData) { }

	@Override
	public EnumSet<TickType> ticks() {
		return EnumSet.of(TickType.PLAYER, TickType.SERVER);
	}

	@Override
	public String getLabel() {
		return null;
	}
    		
    	}, Side.SERVER);

 

The checking works, it keeps printing "is on", and only when I'm wearing the goggles. But I have no idea on how to implement the changeTexture(boolean) method I declared in the class CItem (my inheritance of Item).

Or what to do inside that 'if', if it is something else, that would allow me to change the frame of the icon I want to draw. I can use two separate icons too, if that is easier, but I can't just call registerIcons again and assign a new icon, as I don't have access to the instance of IconRegister to pass as a parameter.

Posted

In your registerIcons method you can register 2 different icons at once. Just create a new icon like this:

public Icon iconOn;
public Icon iconOff;

and your registerIcons method should look like this:

public void registerIcons(IconRegister iconRegister)
{
    this.iconOn = iconRegister.registerIcon("your_mod_id:your_on_texture");
    this.iconOff = iconRegister.registerIcon("your_mod_id:your_off_texture");
}

In your item class you can use this code:

public void changeTexture(boolean your_boolean)
{
    if(your_boolean)
    {
        this.itemIcon = this.iconOn;
    }
    else
    {
        this.itemIcon = this.iconOff;
    }
}

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Posted

Thanks very much, larsgerrits! It works like a charm for the items. I think I finally understand these concepts. One more problem, though. I did the same thing with the blocks, and they work just fine while in rendering in inventory, or dropped on the floor, or, whatever, item form - but it seems that the blocks already placed (block form) won't change immediately; I did some testing, and it seems that they will all change together only when one of the blocks receives a block update, or when a previously hidden block becomes visible. The ones on the screen from the start, even if you look away and look back, won't change the texture until them, even if the ones in the inventory are already different. There seem to be some sort of buffer or cache for the block's texture, in order to make rendering faster, I guess. Is there a way to clear this buffer? I couldn't find any reference to it in the block class. I could iterate through the world until I found an instance of the block, and then sen an update to it, but that seems way too slow (and ugly) to me, and I'm not even sure it'd work, anyway.

Posted

But I'm supposed to just iterate through the current chunck and search for a block of the correct type to update? Is that really the correct way of doing this? Like get player's x and y and just go from (x - 16, y - 16) to (x + 16, y + 16), z from 0 to 255? Wouldn't that take too long every time I changed armor? Can't I call a method on the Block class, to set a flag or something so that when the next block of that type gets rendered, it updates the texture?

Posted

Actually y is the height, not z.

 

Plus you could do this, and no it wont be slow.

 

int Range = 20;
for (int x = -Range; x < Range; x++)
{
for (int y = -Range; y < Range; y++)
{
for (int z = -Range; z < Range; z++)
{
//Code Here
}
}
}

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.