Advertisement
Guest User

Untitled

a guest
Nov 7th, 2015
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.05 KB | None | 0 0
  1. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  3. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  4. //ITEM CODE:
  5. public class enderPack extends Item
  6. {    
  7.     public static List<backpackTile> backpackList = new ArrayList<backpackTile>();
  8.      //private backpackTile enderPackData = new backpackTile();//Using only one, any player could access the tileData
  9.    
  10.     @Override//Clears the item coords
  11.     public ItemStack onItemRightClick(ItemStack stack, World worldIn, EntityPlayer playerIn)
  12.     {
  13.         //if(backpackList.)
  14.         if(playerIn.isSneaking())
  15.         {
  16.             //This next part should loop until it finds a players data.
  17.             if(backpackList.isEmpty())
  18.             {
  19.                 backpackList.add(new backpackTile(playerIn));
  20.                 //backpackList.get(backpackList.size()-1).setChestID(playerIn.playerLocation.getX());//setChestID here
  21.                 System.out.println("\nNo backpacks existed, adding first.");
  22.             }
  23.             for (int i = backpackList.size()-1; i >= 0; i--)
  24.             {
  25.                 if(backpackList.get(i) != null)
  26.                 {
  27.                     if (backpackList.get(i).getPlayerData().getName().equals(playerIn.getName()))
  28.                     {
  29.                         backpackTile enderPackInventory = backpackList.get(i);
  30.                         BlockPos pos = new BlockPos(1,1,1);
  31.                         TileEntity tileentity = worldIn.getTileEntity(pos );
  32.    
  33.                         enderPackInventory.setChestTileEntity((TileEntityEnderChest)tileentity);
  34.                         playerIn.displayGUIChest(enderPackInventory);
  35.                         System.out.println("\nFound entry with EXACT match to player: " + playerIn.getName() + " VS: "+ backpackList.get(i).getPlayerData().getName());
  36.                     }
  37.                     else
  38.                     {
  39.                         System.out.println("\nFound entry with no match to player: " + playerIn.getName() + " VS: "+ backpackList.get(i).getPlayerData().getName());
  40.                     }
  41.                 }
  42.             }                
  43.         }
  44.         return stack;
  45.     }
  46. }
  47.  
  48. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  49. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  50. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  51. //EnderPouchTileData
  52. public class enderPouchTile extends InventoryBasic
  53. {  
  54.     private TileEntityEnderChest associatedChest;
  55.     private static final String __OBFID = "CL_00001759";
  56.     private EntityPlayer playerData;
  57.    
  58.     public enderPouchTile(EntityPlayer playerIn)
  59.     {
  60.         super("Ender Pack", false, 27);
  61.         Random rand = new Random();
  62.         playerData = playerIn;
  63.         System.out.println("\nPlayerIN: " + playerData.getName());
  64.     }
  65.  
  66.     public void setChestTileEntity(TileEntityEnderChest chestTileEntity)
  67.     {
  68.         this.associatedChest = chestTileEntity;
  69.     }
  70.  
  71.     public void loadInventoryFromNBT(NBTTagList tagList)
  72.     {
  73.         int i;
  74.  
  75.         for (i = 0; i < this.getSizeInventory(); ++i)
  76.         {
  77.             this.setInventorySlotContents(i, (ItemStack)null);
  78.         }
  79.  
  80.         for (i = 0; i < tagList.tagCount(); ++i)
  81.         {
  82.             NBTTagCompound nbttagcompound = tagList.getCompoundTagAt(i);
  83.             int j = nbttagcompound.getByte("Slot") & 255;
  84.  
  85.             if (j >= 0 && j < this.getSizeInventory())
  86.             {
  87.                 this.setInventorySlotContents(j, ItemStack.loadItemStackFromNBT(nbttagcompound));
  88.             }
  89.         }
  90.     }
  91.  
  92.     public NBTTagList saveInventoryToNBT()
  93.     {
  94.         NBTTagList nbttaglist = new NBTTagList();
  95.  
  96.         for (int i = 0; i < this.getSizeInventory(); ++i)
  97.         {
  98.             ItemStack itemstack = this.getStackInSlot(i);
  99.  
  100.             if (itemstack != null)
  101.             {
  102.                 NBTTagCompound nbttagcompound = new NBTTagCompound();
  103.                 nbttagcompound.setByte("Slot", (byte)i);
  104.                 itemstack.writeToNBT(nbttagcompound);
  105.                 nbttaglist.appendTag(nbttagcompound);
  106.             }
  107.         }
  108.  
  109.         return nbttaglist;
  110.     }
  111.  
  112.     /**
  113.      * Do not make give this method the name canInteractWith because it clashes with Container
  114.      */
  115.     public boolean isUseableByPlayer(EntityPlayer player)
  116.     {
  117.         return this.associatedChest != null && !this.associatedChest.func_145971_a(player) ? false : super.isUseableByPlayer(player);
  118.     }
  119.  
  120.     public void openInventory(EntityPlayer player)
  121.     {
  122.         if (this.associatedChest != null)
  123.         {
  124.             this.associatedChest.func_145969_a();
  125.         }
  126.  
  127.         super.openInventory(player);
  128.     }
  129.  
  130.     public void closeInventory(EntityPlayer player)
  131.     {
  132.         if (this.associatedChest != null)
  133.         {
  134.             this.associatedChest.func_145970_b();
  135.         }
  136.  
  137.         super.closeInventory(player);
  138.         this.associatedChest = null;
  139.     }
  140.    
  141.     public EntityPlayer getPlayerData()
  142.     {
  143.         return playerData;
  144.     }
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement