Jump to content

[1.7.10] Saving Item Mode


Rohzek

Recommended Posts

Hello. I am trying to come up with a way to have an item that supports mode changing.

 

While the mode changing itself is fine, I want a way to save what mode it was in the last time the player used it. I tried sticking it in an NBTTagCompound which.. there doesn't seem to be a way to save in the standard Item based class so it only saves until Minecraft is restarted. I see some kind of saving method by passing that compound into itemStack.TagCompound(); but am unsure how to use that exactly. Outside of specific functions I don't seem to have access to the ItemStack... Would storing it there and pulling it out on load with the onUpdate function work? I assume all overridden functions get the same ItemStack passed into it? Or is there a better way of doing this or somewhere else to store my NBT Compound? (I original thought of trying to store this value in damage values?)

 

My class as it is now: http://pastebin.com/jdbjFiwF

Developing the Spiral Power Mod .

こんにちは!お元気ですか?

Link to comment
Share on other sites

Hello. I am trying to come up with a way to have an item that supports mode changing.

 

While the mode changing itself is fine, I want a way to save what mode it was in the last time the player used it. I tried sticking it in an NBTTagCompound which.. there doesn't seem to be a way to save in the standard Item based class so it only saves until Minecraft is restarted. I see some kind of saving method by passing that compound into itemStack.TagCompound(); but am unsure how to use that exactly. Outside of specific functions I don't seem to have access to the ItemStack... Would storing it there and pulling it out on load with the onUpdate function work? I assume all overridden functions get the same ItemStack passed into it? Or is there a better way of doing this or somewhere else to store my NBT Compound? (I original thought of trying to store this value in damage values?)

 

My class as it is now: http://pastebin.com/jdbjFiwF

 

Item

s are singletons, only one instance of the class exists for each type. If you want to store data for individual items, you need to use the

NBTTagCompound

of the

ItemStack

that you receive as an argument of various

Item

methods. If you don't have an

ItemStack

argument, you don't have access to the data.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

That's what I thought. Shame there isn't anywhere else.

So I've gotten something working by doing exactly what I mentioned in my first post: passing the NBT Compound to the ItemStack and checking for it in onUpdate which seems to start running well before visuals load in so it effectively does exactly what I need (setting textures on load). I can't help but feel though tying this into the onUpdate function seems a little much checking the boolean for loading every frame for the rest of time you hold the item... But I don't guess it would slow anything down. Is there a major downside to this?

 

 

 

// onUpdate seems to run while the game is loading to start simulating the world.. Thus the change happens before the player can see the item
@Override
public void onUpdate(ItemStack itemStack, World world, Entity entity, int x, boolean a)
{
	if(!hasLoaded)
	{
		retrieveMode(itemStack);
		hasLoaded = true;
	}

}

// We need to this every time we change the mode.
private void saveMode(ItemStack itemStack)
{
	dataStore.setInteger("changeNum", changeNum);
	itemStack.setTagCompound(dataStore);
}

// Gets the number out of our NBTCompound
private void retrieveMode(ItemStack itemStack)
{
	dataStore = itemStack.getTagCompound();
	changeNum = dataStore.getInteger("changeNum");
}

 

 

 

If this isn't a horrible atrocity I'll toss in a null check to make sure it doesn't try to load before there's data there and call it done?

If this is seriously bad I guess I'll have to try to set it to damage states which I imagine get saved with the item.

Developing the Spiral Power Mod .

こんにちは!お元気ですか?

Link to comment
Share on other sites

That won't work. Only one instance of the class exists, so any fields are shared between all stacks of that item type.

 

You need to store all data in the NBT, read from and write to the stack's tag compound directly rather than storing data in fields.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

This.... is true. And infact the way the class is currently set up it... it just changes all guns in the world at the same time... I... think I have to base the mode off damage states to make it work anyway... Yeah.. Thanks for pointing me in the right direction. :)

Developing the Spiral Power Mod .

こんにちは!お元気ですか?

Link to comment
Share on other sites

Apologies for a double post, but I'm not sure anyone would have checked if I just edited the last one, but I wonder.. assuming I found a way to keep the mode change out of the class and only passed it between functions in the ItemStack NBT... Is there any way I could use the number from the ItemStack NBT to change the texture drawn on a specific ItemStack? While damage states would solve my problem this time... I'm thinking if I had something like a pick that I wanted to change texture on right click and didn't have the damage states available.. How would that be done?

Developing the Spiral Power Mod .

こんにちは!お元気ですか?

Link to comment
Share on other sites

Metadata, it gets passed as a parameter to the getIIcon method(assuming you are in 1.7.10). You can control the metadata value anywhere you have access to the ItemStack (onItemRightClick) and in you getIIcon method you would return a different thing based on the metaData. You might have to override a lot of other methods like damaging an item, so that damage values are held in NBT instead of metadata.

Current Project: Armerger 

Planned mods: Light Drafter  | Ore Swords

Looking for help getting a mod off the ground? Coding  | Textures

Link to comment
Share on other sites

That is absolutely right. With the loss of item IDs (and the fact that the Item.class docs mention placing blocks with the item) it went invisible and it slipped my mind but.. Thing's like wool and dye are the same item with different textures based on metadata aren't they? That would work beautifully for not only my current issue but any further items with a similar idea. Thank you so much

Developing the Spiral Power Mod .

こんにちは!お元気ですか?

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Baba  Serege [[+27-73 590 8989]] has experience of 27 years in helping and guiding many people from all over the world. His psychic abilities may help you answer and resolve many unanswered questions. He specialize in helping women and men from all walks of life.. 1) – Bring back lost lover. even if lost for a long time. 2) – My lover is abusing alcohol, partying and cheating on me I urgently need help” 3) – Divorce or court issues. 4) – Is your love falling apart? 5) – Do you want your love to grow stronger? 6) – Is your partner losing interest in you? 7) – Do you want to catch your partner cheating on you? – We help to keep your partner faithful and loyal to you. 9) – We recover love and happiness when relationship breaks down. 10) – Making your partner loves you alone. 11) – We create loyalty and everlasting love between couples. 12) – Get a divorce settlement quickly from your ex-partner. 13) – We create everlasting love between couples. 14) – We help you look for the best suitable partner. 15) – We bring back lost lover even if lost for a long time. 16) – We strengthen bonds in all love relationship and marriages 17) – Are you an herbalist who wants to get more powers? 18) – Buy a house or car of your dream. 19) – Unfinished jobs by other doctors come to me. 20) – I help those seeking employment. 21) – Pensioners free treatment. 22) – Win business tenders and contracts. 23) – Do you need to recover your lost property? 24) – Promotion at work and better pay. 25) – Do you want to be protected from bad spirits and nightmares? 26) – Financial problems. 27) – Why you can’t keep money or lovers? 28) – Why you have a lot of enemies? 29) – Why you are fired regularly on jobs? 30) – Speed up money claim spell, delayed payments, pension and accident funds 31) – I help students pass their exams/interviews. 33) – Removal of bad luck and debts. 34) – Are struggling to sleep because of a spiritual wife or husband. 35- ) Recover stolen property
    • OLXTOTO adalah situs bandar togel online resmi terbesar dan terpercaya di Indonesia. Bergabunglah dengan OLXTOTO dan nikmati pengalaman bermain togel yang aman dan terjamin. Koleksi toto 4D dan togel toto terlengkap di OLXTOTO membuat para member memiliki pilihan taruhan yang lebih banyak. Sebagai situs togel terpercaya, OLXTOTO menjaga keamanan dan kenyamanan para membernya dengan sistem keamanan terbaik dan enkripsi data. Transaksi yang cepat, aman, dan terpercaya merupakan jaminan dari OLXTOTO. Nikmati layanan situs toto terbaik dari OLXTOTO dengan tampilan yang user-friendly dan mudah digunakan. Layanan pelanggan tersedia 24/7 untuk membantu para member. Bergabunglah dengan OLXTOTO sekarang untuk merasakan pengalaman bermain togel yang menyenangkan dan menguntungkan.
    • Baba  Serege [[+27-73 590 8989]] has experience of 27 years in helping and guiding many people from all over the world. His psychic abilities may help you answer and resolve many unanswered questions. He specialize in helping women and men from all walks of life.. 1) – Bring back lost lover. even if lost for a long time. 2) – My lover is abusing alcohol, partying and cheating on me I urgently need help” 3) – Divorce or court issues. 4) – Is your love falling apart? 5) – Do you want your love to grow stronger? 6) – Is your partner losing interest in you? 7) – Do you want to catch your partner cheating on you? – We help to keep your partner faithful and loyal to you. 9) – We recover love and happiness when relationship breaks down. 10) – Making your partner loves you alone. 11) – We create loyalty and everlasting love between couples. 12) – Get a divorce settlement quickly from your ex-partner. 13) – We create everlasting love between couples. 14) – We help you look for the best suitable partner. 15) – We bring back lost lover even if lost for a long time. 16) – We strengthen bonds in all love relationship and marriages 17) – Are you an herbalist who wants to get more powers? 18) – Buy a house or car of your dream. 19) – Unfinished jobs by other doctors come to me. 20) – I help those seeking employment. 21) – Pensioners free treatment. 22) – Win business tenders and contracts. 23) – Do you need to recover your lost property? 24) – Promotion at work and better pay. 25) – Do you want to be protected from bad spirits and nightmares? 26) – Financial problems. 27) – Why you can’t keep money or lovers? 28) – Why you have a lot of enemies? 29) – Why you are fired regularly on jobs? 30) – Speed up money claim spell, delayed payments, pension and accident funds 31) – I help students pass their exams/interviews. 33) – Removal of bad luck and debts. 34) – Are struggling to sleep because of a spiritual wife or husband. 35- ) Recover stolen property
  • Topics

×
×
  • Create New...

Important Information

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