Jump to content

How can I assign a static int to my item, then read from it later?


Recommended Posts

Posted

Sorry if the title is a little confusing, I wasn't quite sure how to word it :P

 

Basically, what I need to do is assign a static int. Nothing fancy, just a basic number to each of a set of items.. so for example item A is 100, item B is 200 etc.

 

Then, I need to be able to read what these ints are when they're placed into a container, and change the players NBT to add all of those together to a tag. I need to be able to take the values from both item A and item B, and add them together, so effectively adding 300 to the NBT in my example.

 

Can anyone point me in the right direction?

width=463 height=200

http://s13.postimg.org/z9mlly2av/siglogo.png[/img]

My mods (Links coming soon)

Cities | Roads | Remula | SilvaniaMod | MoreStats

Posted

You could store all the values in a map,

public static Map<Item, Integer> itemValue = new HashMap<Item, Integer>();

 

add item/value pair

itemValue.put(theItem, thevalue);

 

get value of an item

if (itemValue.containsKey(theItem)) {
    value = itemValue.get(theItem);
}

 

That would also allow you to use item your mod doesn't add.

 

 

 

If it's only for your own items, you could add it directly to your items class and read from it later.

 

public class ItemValued extends Item
{
    public static itemValue = 200;

......

 

Retrieved later

if (item instanceof ItemValued) {
    value = ((ItemValued)item).itemValue;
}

Posted

If it's only for your own items, you could add it directly to your items class and read from it later.

 

public class ItemValued extends Item
{
    public static itemValue = 200;

......

 

Retrieved later

if (item instanceof ItemValued) {
    value = ((ItemValued)item).itemValue;
}

 

That's all I need, thanks :)

The mod is pretty static. Not something people will have any reason to want to add to later really

 

EDIT: I'm assuming "public static itemValue = 200;" is supposed to be "public static int itemValue = 200;" by the way?

width=463 height=200

http://s13.postimg.org/z9mlly2av/siglogo.png[/img]

My mods (Links coming soon)

Cities | Roads | Remula | SilvaniaMod | MoreStats

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.