Advertisement
Guest User

PlayerTickHandler

a guest
Nov 7th, 2013
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.93 KB | None | 0 0
  1. package net.gloriarpg.handler;
  2.  
  3. import java.util.EnumSet;
  4.  
  5. import net.gloriarpg.GloriaRPG;
  6. import net.gloriarpg.item.IAccessory;
  7. import net.minecraft.client.Minecraft;
  8. import net.minecraft.entity.player.EntityPlayer;
  9. import net.minecraft.item.Item;
  10. import net.minecraft.item.ItemStack;
  11. import net.minecraft.nbt.NBTTagCompound;
  12. import net.minecraft.nbt.NBTTagList;
  13. import cpw.mods.fml.common.ITickHandler;
  14. import cpw.mods.fml.common.TickType;
  15.  
  16. public class PlayerTickHandler implements ITickHandler
  17. {
  18.    
  19.     private ItemStack[] currentSlots = new ItemStack[7];
  20.     private ItemStack[] lastSlots = new ItemStack[7];
  21.    
  22.     private final EnumSet<TickType> ticksToGet;
  23.  
  24.     public PlayerTickHandler(EnumSet<TickType> ticksToGet)
  25.     {
  26.  
  27.         this.ticksToGet = ticksToGet;
  28.  
  29.     }
  30.  
  31.     @Override
  32.     public void tickStart(EnumSet<TickType> type, Object... tickData)
  33.     {
  34.  
  35.         playerTick((EntityPlayer) tickData[0]);
  36.  
  37.     }
  38.  
  39.     @Override
  40.     public void tickEnd(EnumSet<TickType> type, Object... tickData)
  41.     {
  42.  
  43.     }
  44.  
  45.     @Override
  46.     public EnumSet<TickType> ticks()
  47.     {
  48.  
  49.         return ticksToGet;
  50.  
  51.     }
  52.  
  53.     @Override
  54.     public String getLabel()
  55.     {
  56.  
  57.         return "N/A";
  58.  
  59.     }
  60.  
  61.     public void playerTick(EntityPlayer player)
  62.     {
  63.        
  64.         NBTTagCompound playerNBT = player.getEntityData();
  65.        
  66.         if(Minecraft.getMinecraft().currentScreen != null)
  67.         {
  68.            
  69.             AccessoriesKeyHandler.pressed = false;
  70.            
  71.         }
  72.        
  73.         if(AccessoriesKeyHandler.pressed)
  74.         {
  75.            
  76.             player.openGui(GloriaRPG.instance, 2, player.worldObj, (int) player.posX, (int) player.posY, (int) player.posZ);
  77.            
  78.             AccessoriesKeyHandler.pressed = false;
  79.  
  80.         }
  81.        
  82.         if(playerNBT != null)
  83.         {
  84.            
  85.             NBTTagList nbtTag = playerNBT.getTagList("Accessories");
  86.            
  87.             for(int i = 0;i < nbtTag.tagCount();i++)
  88.             {
  89.                
  90.                 NBTTagCompound nbt = (NBTTagCompound)nbtTag.tagAt(i);
  91.                
  92.                 byte slot = nbt.getByte("Slot");
  93.                
  94.                 if(slot >= 0 && slot < 7);
  95.                 {
  96.                    
  97.                     ItemStack itemStack = ItemStack.loadItemStackFromNBT(nbt);
  98.                     Item item = itemStack.getItem();
  99.                    
  100.                     this.currentSlots[i] = itemStack;
  101.                    
  102.                     if(item instanceof IAccessory)
  103.                     {
  104.                        
  105.                         IAccessory accessory = (IAccessory)item;
  106.                        
  107.                         accessory.tick(player);
  108.                        
  109.                     }
  110.                    
  111.                 }
  112.                
  113.             }
  114.            
  115.         }
  116.        
  117.         for(int i = 0;i < 7;i++)
  118.         {
  119.            
  120.             GloriaRPG.print("HELLO?");
  121.            
  122.             if(this.lastSlots[i] != this.currentSlots[i])
  123.             {
  124.                
  125.                 GloriaRPG.print("YOOOO");
  126.                
  127.                 if(this.currentSlots[i] != null && this.currentSlots[i].getItem() instanceof IAccessory)
  128.                 {
  129.                    
  130.                     IAccessory accessory = (IAccessory)this.currentSlots[i].getItem();
  131.                    
  132.                     accessory.equipped(player);
  133.                    
  134.                 }
  135.                
  136.                 if(this.lastSlots[i] != null && this.lastSlots[i].getItem() instanceof IAccessory)
  137.                 {
  138.                    
  139.                     IAccessory accessory = (IAccessory)this.lastSlots[i].getItem();
  140.                    
  141.                     accessory.unequipped(player);
  142.                    
  143.                 }
  144.                
  145.             }
  146.            
  147.         }
  148.        
  149.         this.lastSlots = this.currentSlots;
  150.  
  151.     }
  152.    
  153. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement