Arctic_Wolfy

BankAccount from NBT

Oct 2nd, 2015
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.95 KB | None | 0 0
  1. public static BankAccount fromNBT(NBTTagCompound tag, TEBank bank){
  2.         //TEBank bank;
  3.         EntityPlayer player = null;
  4.         float credit;
  5.  
  6.         boolean forCard = false;
  7.  
  8.         if (bank == null) {
  9.             int[] XYZ = tag.getIntArray(NBTTags.Bank.COORDS);
  10.             if (XYZ == null) {
  11.                 LogHelper.warn("Bank Coord is null.");
  12.             }
  13.             assert XYZ != null;
  14.             Minecraft mc = Minecraft.getMinecraft();
  15.             WorldClient world = mc.theWorld;
  16.             TileEntity te = world.getTileEntity(XYZ[0], XYZ[1], XYZ[2]);
  17.  
  18.             bank = (TEBank) te;
  19.  
  20.             forCard = true;
  21.         }
  22.  
  23.         long ownerIDLeast, ownerIDMost;
  24.  
  25.         NBTTagCompound ownerTag = tag.getCompoundTag(NBTTags.Card.UUID_OWNER_TAG);
  26.  
  27.         ownerIDLeast = ownerTag.getLong(NBTTags.Card.UUID_LEAST_TAG);
  28.         ownerIDMost = ownerTag.getLong(NBTTags.Card.UUID_MOST_TAG);
  29.  
  30.         UUID id = new UUID(ownerIDMost,ownerIDLeast);
  31.  
  32.         BankAccount account = bank.getAccount(id);
  33.  
  34.         if (account!=null){
  35.             return account;
  36.         }
  37.  
  38.         if (Minecraft.getMinecraft().theWorld!=null)
  39.             player = Minecraft.getMinecraft().theWorld.func_152378_a(id);
  40.  
  41.         if (player == null){
  42.             LogHelper.warn("Player with UUID (" + id + ") not found.");
  43.         }// else LogHelper.info("Player with UUID (" + id + ") found.");
  44.  
  45.         if (forCard){
  46.             if (bank!=null)return bank.getAccount(player); //Compiler says this is always true.
  47.             else if (player!=null)return new BankAccount(null,player);
  48.             else return new BankAccount(null,id);
  49.         } else {
  50.             credit = tag.getFloat(NBTTags.Bank.CREDIT);
  51.             if (player!=null) return new BankAccount(bank, player, credit);
  52.             else{
  53.                 LogHelper.warn("Will find player later.");
  54.                 return new BankAccount(bank,id,credit);
  55.             }
  56.         }
  57.     }
Add Comment
Please, Sign In to add comment