luan Posted December 31, 2013 Posted December 31, 2013 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... Quote
Draco18s Posted January 1, 2014 Posted January 1, 2014 registerIcons is run once when the game loads, you're in the wrong function. Quote 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.
larsgerrits Posted January 1, 2014 Posted January 1, 2014 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. Quote 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/
luan Posted January 1, 2014 Author Posted January 1, 2014 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. Quote
larsgerrits Posted January 1, 2014 Posted January 1, 2014 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; } } Quote 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/
luan Posted January 1, 2014 Author Posted January 1, 2014 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. Quote
CJLetsGame Posted January 1, 2014 Posted January 1, 2014 worldObj.markBlockForRenderUpdate(x,y,z); Quote
luan Posted January 2, 2014 Author Posted January 2, 2014 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? Quote
CJLetsGame Posted January 2, 2014 Posted January 2, 2014 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 } } } Quote
Recommended Posts
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.