Arctic_Wolfy

ItemCard

Oct 2nd, 2015
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.08 KB | None | 0 0
  1. package com.bbw2.moneyMod.items;
  2.  
  3. import com.bbw2.moneyMod.MoneyMod;
  4. import com.bbw2.moneyMod.handler.MyPacket;
  5. import com.bbw2.moneyMod.holders.BankAccount;
  6. import com.bbw2.moneyMod.reference.NBTTags;
  7. import com.bbw2.moneyMod.utility.LogHelper;
  8. import cpw.mods.fml.client.config.GuiConfigEntries;
  9. import cpw.mods.fml.common.registry.EntityRegistry;
  10. import net.minecraft.client.Minecraft;
  11. import net.minecraft.entity.Entity;
  12. import net.minecraft.entity.player.EntityPlayer;
  13. import net.minecraft.item.ItemStack;
  14. import net.minecraft.nbt.NBTTagCompound;
  15. import net.minecraft.nbt.NBTTagString;
  16. import net.minecraft.network.Packet;
  17. import net.minecraft.util.ChatComponentStyle;
  18. import net.minecraft.util.EnumChatFormatting;
  19. import net.minecraft.world.World;
  20.  
  21. import java.util.ArrayDeque;
  22. import java.util.ArrayList;
  23. import java.util.List;
  24. import java.util.UUID;
  25.  
  26. /**
  27.  * Created on 9/30/2015.
  28.  */
  29. public class ItemCard extends ItemMT {
  30.  
  31.     public ItemCard(){
  32.         super();
  33.         this.setUnlocalizedName("creditCard");
  34.     }
  35.  
  36.     @Override
  37.     public void onUpdate(ItemStack stack, World world, Entity entity, int p_77663_4_, boolean p_77663_5_) {
  38.         /*NBTTagCompound tag = stack.stackTagCompound;
  39.         if (tag == null) tag = new NBTTagCompound();
  40.         NBTTagCompound ownerTag = tag.getCompoundTag("ownerID");
  41.         long ownerIDLeast = ownerTag.getLong("UUID_least");
  42.         long ownerIDMost = ownerTag.getLong("UUID_most");
  43.  
  44.         if (ownerIDLeast == 0L || ownerIDMost == 0L){
  45.             if (entity instanceof EntityPlayer){
  46.                 UUID id = entity.getPersistentID();
  47.                 ownerIDLeast = id.getLeastSignificantBits();
  48.                 ownerIDMost = id.getMostSignificantBits();
  49.                 ownerTag.setLong("UUID_least",ownerIDLeast);
  50.                 ownerTag.setLong("UUID_most", ownerIDMost);
  51.                 tag.setTag("ownerID", ownerTag);
  52.  
  53.                 stack.stackTagCompound = tag;
  54.             }
  55.         }*/
  56.  
  57.  
  58.     }
  59.  
  60.     @Override
  61.     public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean p_77624_4_) {
  62.         NBTTagCompound tag = stack.stackTagCompound;
  63.         if (tag != null) {
  64.             if (tag.hasKey(NBTTags.Card.ACCOUNTS_TAG)) {
  65.                 NBTTagCompound accountTag = tag.getCompoundTag(NBTTags.Card.ACCOUNTS_TAG);
  66.                                 BankAccount account = BankAccount.fromNBT(accountTag, null);
  67.                 if (account!=null) {
  68.                     if (account.getPlayer() != null) list.add("Owner: " + ((account.getPlayer()==player) ? EnumChatFormatting.GREEN : EnumChatFormatting.DARK_RED) + account.getPlayer().getDisplayName());
  69.                     else list.add("Owner: " + EnumChatFormatting.DARK_RED + account.getId());
  70.                     if (account.getBank()!=null) list.add("Bank: " + EnumChatFormatting.GREEN + account.getBank().getName());
  71.                     else list.add("Bank: " + EnumChatFormatting.DARK_RED + "Bankrupt");
  72.                     list.add(String.format("Credit: %s\u20a9%.3f",
  73.                             ((account.getCredit() > 0) ? EnumChatFormatting.GREEN :
  74.                                     ((account.getCredit() < 0) ? EnumChatFormatting.DARK_RED :
  75.                                             EnumChatFormatting.YELLOW)),
  76.                             account.getCredit()));
  77.                 } else {
  78.                     LogHelper.warn("Account not found.");
  79.  
  80.                     NBTTagCompound ownerTag = accountTag.getCompoundTag(NBTTags.Card.UUID_OWNER_TAG);
  81.  
  82.                     long ownerIDLeast = ownerTag.getLong(NBTTags.Card.UUID_LEAST_TAG);
  83.                     long ownerIDMost = ownerTag.getLong(NBTTags.Card.UUID_MOST_TAG);
  84.  
  85.                     UUID id = new UUID(ownerIDMost, ownerIDLeast);
  86.  
  87.                     list.add("Owner: " + EnumChatFormatting.DARK_RED + id);
  88.                 }
  89.             }
  90.             list.add(tag.toString());
  91.         }
  92.     }
  93.  
  94.     private String[] tagToViewable(NBTTagCompound tag){
  95.         String tagString = tag.toString();
  96.  
  97.         char[] charArray = tagString.toCharArray();
  98.  
  99.         String line = "";
  100.  
  101.         ArrayList<String> lines = new ArrayList<String>();
  102.  
  103.         for (int i = 0; i < charArray.length; i++) {
  104.             char current = charArray[i];
  105.             line += current;
  106.             if ("{,}".indexOf(current) > 0){
  107.                 lines.add(line);
  108.                 line = "";
  109.             }
  110.         }
  111.  
  112.         return null;
  113.     }
  114.  
  115.     @Override
  116.     public String getItemStackDisplayName(ItemStack stack) {
  117.         NBTTagCompound tag = stack.stackTagCompound;
  118.         if (tag != null){
  119.             if (tag.hasKey(NBTTags.Card.ACCOUNTS_TAG)){
  120.                 NBTTagCompound accountTag = tag.getCompoundTag(NBTTags.Card.ACCOUNTS_TAG);
  121.                 BankAccount account = BankAccount.fromNBT(accountTag,null);
  122.                 if (account!=null&&account.getBank()!=null) {
  123.                     return account.getBank().getName() + " " + super.getItemStackDisplayName(stack);
  124.                 }
  125.             }
  126.         }
  127.  
  128.         return super.getItemStackDisplayName(stack);
  129.     }
  130. }
Advertisement
Add Comment
Please, Sign In to add comment