Advertisement
Guest User

Untitled

a guest
Aug 29th, 2015
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.69 KB | None | 0 0
  1. /**
  2.  * This class can be referred to as your AuroniumCrystal
  3.  */
  4. public class ItemFirst extends ItemModded {
  5.  
  6.     public ItemFirst(String unlocalizedName) {
  7.         super(unlocalizedName);
  8.     }
  9.  
  10.     @Override
  11.     public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) {
  12.         if (player.inventory.hasItem(ModdedItems.second)) {
  13.             ItemStack itemStacks[] = player.inventory.mainInventory;
  14.             ItemStack secondItem = null;
  15.             for (ItemStack stack : itemStacks) {
  16.                 if (stack != null && stack.getItem() == ModdedItems.second) {
  17.                     if (secondItem != null)
  18.                         break;
  19.  
  20.                     secondItem = stack;
  21.                 }
  22.             }
  23.             if (secondItem != null) {
  24.                 if (!secondItem.hasTagCompound())
  25.                     secondItem.setTagCompound(new NBTTagCompound());
  26.                 if (secondItem.getTagCompound().getTag("someTag") == null)
  27.                     secondItem.setTagInfo("someTag", new NBTTagInt(0));
  28.                 else {
  29.                     int amount = secondItem.getTagCompound().getInteger("someTag");
  30.                     secondItem.getTagCompound().setInteger("someTag", ++amount); // In the previous example I made a minor mistake here
  31.                 }
  32.             }
  33.         }
  34.         return super.onItemRightClick(itemStack, world, player);
  35.     }
  36. }
  37.  
  38. /**
  39.  * And this class will represent the AuroniumHolder
  40.  */
  41. public class ItemSecond extends ItemModded {
  42.  
  43.     public ItemSecond(String unlocalizedName) {
  44.         super(unlocalizedName);
  45.     }
  46.  
  47.     @Override
  48.     public void addInformation(ItemStack itemStack, EntityPlayer player, List toolTip, boolean flag) {
  49.         if (!itemStack.hasTagCompound()
  50.                 || (itemStack.getTagCompound() != null && !itemStack.getTagCompound().hasKey("someTag")))
  51.             return;
  52.  
  53.         toolTip.add(String.format("Value: %d", itemStack.getTagCompound().getInteger("someTag")));
  54.     }
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement