Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.bbw2.moneyMod.holders;
- import com.bbw2.moneyMod.blocks.TEBank;
- import com.bbw2.moneyMod.reference.NBTTags;
- import com.bbw2.moneyMod.utility.LogHelper;
- import cpw.mods.fml.common.FMLCommonHandler;
- import net.minecraft.client.Minecraft;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.nbt.NBTTagCompound;
- import net.minecraft.server.MinecraftServer;
- import net.minecraft.world.World;
- import java.util.UUID;
- /**
- * Created on 9/30/2015.
- */
- public class BankAccount {
- private TEBank bank;
- private EntityPlayer player;
- private UUID id;
- private float credit;
- public BankAccount(TEBank bank, EntityPlayer player){this(bank, player, 0F);}
- public BankAccount(TEBank bank, UUID id){this(bank, id, 0F);}
- public BankAccount(TEBank bank, EntityPlayer player, float credit){
- this.bank = bank;
- this.player = player;
- this.id = player.getGameProfile().getId();
- this.credit = credit;
- }
- public BankAccount(TEBank bank, UUID id, float credit){
- this.bank = bank;
- this.id = id;
- this.credit = credit;
- }
- public EntityPlayer getPlayer() {
- if (player == null) {
- player = Minecraft.getMinecraft().theWorld.func_152378_a(id);
- if (player==null){}
- }
- return player;
- }
- public TEBank getBank() {return bank;}
- public UUID getId() {return id;}
- public float getCredit() {return credit;}
- public void addCredit(float amount){this.credit += amount;}
- public void removeCredit(float amount){this.credit -= amount;}
- public static NBTTagCompound toNBT(BankAccount account, boolean forCard){
- NBTTagCompound tag = new NBTTagCompound();
- NBTTagCompound ownerTag = new NBTTagCompound();
- UUID id = account.id;
- TEBank bank = account.bank;
- long ownerIDLeast = id.getLeastSignificantBits();
- long ownerIDMost = id.getMostSignificantBits();
- ownerTag.setLong(NBTTags.Card.UUID_LEAST_TAG,ownerIDLeast);
- ownerTag.setLong(NBTTags.Card.UUID_MOST_TAG, ownerIDMost);
- tag.setTag(NBTTags.Card.UUID_OWNER_TAG, ownerTag);
- tag.setIntArray(NBTTags.Bank.COORDS, new int[]{
- bank.xCoord,bank.yCoord,bank.zCoord
- });
- if (!forCard)tag.setFloat(NBTTags.Bank.CREDIT,account.credit);
- return tag;
- }
- public static BankAccount fromNBT(World world, NBTTagCompound tag, TEBank bank){
- //TEBank bank;
- float credit;
- boolean forCard = false;
- LogHelper.info("Bank");
- if (bank == null) {
- int[] XYZ = tag.getIntArray(NBTTags.Bank.COORDS);
- if (world==null){
- if (FMLCommonHandler.instance().getEffectiveSide().isClient()){
- world = Minecraft.getMinecraft().theWorld;
- } else if (FMLCommonHandler.instance().getEffectiveSide().isServer()){
- world = MinecraftServer.getServer().worldServerForDimension(0);
- }
- }
- if (world !=null) bank = (TEBank) world.getTileEntity(XYZ[0],XYZ[1],XYZ[2]);
- forCard = true;
- }
- long ownerIDLeast, ownerIDMost;
- NBTTagCompound ownerTag = tag.getCompoundTag(NBTTags.Card.UUID_OWNER_TAG);
- ownerIDLeast = ownerTag.getLong(NBTTags.Card.UUID_LEAST_TAG);
- ownerIDMost = ownerTag.getLong(NBTTags.Card.UUID_MOST_TAG);
- UUID id = new UUID(ownerIDMost,ownerIDLeast);
- if (bank!=null) {
- BankAccount account = bank.getAccount(id);
- if (account != null) {
- return account;
- }
- }
- if (forCard){
- return new BankAccount(bank,id);
- } else {
- credit = tag.getFloat(NBTTags.Bank.CREDIT);
- return new BankAccount(bank,id,credit);
- }
- }
- public static BankAccount getAccountFromBank(UUID id, int x, int y, int z){
- return getAccountFromBank(id,(TEBank) Minecraft.getMinecraft().theWorld.getTileEntity(x,y,z));
- }
- public static BankAccount getAccountFromBank(UUID id, TEBank bank) {
- return bank.getAccount(id);
- }
- public static BankAccount fromNBT(NBTTagCompound tag, TEBank bank) {
- return fromNBT(null,tag,bank);
- }
- }
Add Comment
Please, Sign In to add comment