mrkirby153

Untitled

Nov 26th, 2012
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.09 KB | None | 0 0
  1. package mrkirby153.periodicraft;
  2.  
  3. import net.minecraft.src.EntityItem;
  4. import net.minecraft.src.EntityPlayer;
  5. import net.minecraft.src.ItemStack;
  6. import net.minecraft.src.NBTTagCompound;
  7. import net.minecraft.src.TileEntity;
  8. import net.minecraft.src.World;
  9.  
  10. public class TileEntityPAM extends TileEntity {
  11.  
  12.     private int[] recipieLst = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0};
  13.     private int[] recipieMeta = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0};
  14.  
  15.     /**
  16.      * Begins the process of determining what goes into the block
  17.      * @param player
  18.      * @param world
  19.      */
  20.     public void create(EntityPlayer player, World world){
  21.         System.out.println("Recipie ID:" + recipieLst[0] +" " + recipieLst[1] +" "+ recipieLst[2] +" "+ recipieLst[3] +" "+ recipieLst[4] +" "+ recipieLst[5] +" "+ recipieLst[6] +" "+ recipieLst[7] +" "+ recipieLst[8]);
  22.         System.out.println("Recipie Meta:" + recipieMeta[0] +" " + recipieMeta[1] +" "+ recipieMeta[2] +" "+ recipieMeta[3] +" "+ recipieMeta[4] +" "+ recipieMeta[5] +" "+ recipieMeta[6] +" "+ recipieMeta[7] +" "+ recipieMeta[8]);
  23.         if(player.getHeldItem() != null && player.getHeldItem().getItemDamage() == 0){
  24.             for(int i = 1; i < recipieLst.length; i++){
  25.                 recipieLst[i-1]= recipieLst[i];
  26.             }
  27.             for(int i = 1; i < recipieMeta.length; i++){
  28.                 recipieMeta[i-1]= recipieMeta[i];
  29.             }
  30.  
  31.         //  System.out.println("Recipie ID:" + recipieLst[0] +" "+ recipieLst[2] +" "+ recipieLst[3] +" "+ recipieLst[4] +" "+ recipieLst[5] +" "+ recipieLst[6] +" "+ recipieLst[7] +" "+ recipieLst[8]);
  32.             if(recipieLst[0] == 0){
  33.                 this.compareStack(player, world);
  34.                 player.destroyCurrentEquippedItem();
  35.  
  36.             }
  37.            
  38.  
  39.         }else{
  40.             if(recipieLst[8] == 0){
  41.                 player.addChatMessage("There's nothing stored in this block");
  42.             }else{
  43.                 if(!player.isSneaking() && player.getItemInUse() == null){
  44.                     player.addChatMessage("There's stuff in this block!");
  45.                 }
  46.             }
  47.         }
  48.     }
  49. /**
  50.  * Checks weather the item stack is > 9, then sets all the arrays in the list to the item id. if its greater, spits out items for the player to collect
  51.  * PAM SPECIFIC
  52.  * @param player
  53.  * @param world
  54.  */
  55.     private void compareStack(EntityPlayer player, World world) {
  56.         int stackId = player.getHeldItem().itemID;
  57.         int itemStack = player.getHeldItem().stackSize;
  58.         int metadata = player.getHeldItem().getItemDamage();
  59.         System.out.println(metadata);
  60.         if(itemStack <= recipieLst.length){
  61.             for(int i =  0; i < itemStack; i++){
  62.                     recipieLst[i] = stackId;
  63.                     recipieMeta[i] = metadata;
  64.             }
  65.  
  66.         }else{
  67.             for(int i = 1; i < itemStack - (recipieLst.length - 1); i++)
  68.                 this.dropItemInWorld(world, stackId, metadata);
  69.            
  70.             for(int i = 1; i < recipieLst.length; i++){
  71.                 recipieLst[i] = player.getHeldItem().itemID;
  72.             }
  73.         }
  74.  
  75.     }
  76. /**
  77.  * Drops items into the world.
  78.  * @param world
  79.  * @param itemStack
  80.  * @param metadata
  81.  */
  82.     private void dropItemInWorld(World world, int itemStack, int metadata) {
  83.         EntityItem i = new EntityItem(world, (double)((float)xCoord + 0.01), (double)((float)yCoord + 1), (double)((float)zCoord + 0.01), new ItemStack(itemStack, 1, metadata));
  84.         world.spawnEntityInWorld(i);
  85.  
  86.     }
  87.  
  88.     @Override
  89.     public void writeToNBT(NBTTagCompound nbt) {
  90.         super.writeToNBT(nbt);
  91.         nbt.setIntArray("recipieLst", recipieLst);
  92.         nbt.setIntArray("recipieMeta", recipieMeta);
  93.     }
  94.  
  95.     @Override
  96.     public void readFromNBT(NBTTagCompound nbt) {
  97.         super.readFromNBT(nbt);
  98.         recipieLst = nbt.getIntArray("recipieLst");
  99.         recipieMeta = nbt.getIntArray("recipieMeta");
  100.        
  101.         if(recipieLst.length == 0) recipieLst = new int[9];
  102.         if(recipieMeta.length == 0) recipieMeta = new int[9];
  103.     }
  104.  
  105.     /**
  106.      * Clears the TileEntityPAM's recipie.
  107.      * PAM SPECIFIC
  108.      * @param world
  109.      * @author mrkirby153
  110.      */
  111.     public void clearRecipie(World world) {
  112.         this.dumpInventory(world);
  113.         this.resetValues();
  114.  
  115.     }
  116.  
  117.     private void resetValues() {
  118.         for(int i = 0; i < recipieLst.length; i++){
  119.             recipieLst[i] = 0;
  120.         }
  121.  
  122.     }
  123.  
  124.     private void dumpInventory(World world) {
  125.         for(int i = 0; i < recipieLst.length; i++){
  126.             if(!(recipieLst[i] == 0))
  127.                 this.dropItemInWorld(world, recipieLst[i], recipieMeta[i]);
  128.         }
  129.  
  130.     }
  131. }
Advertisement
Add Comment
Please, Sign In to add comment