Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.gloriarpg.handler;
- import java.util.EnumSet;
- import net.gloriarpg.GloriaRPG;
- import net.gloriarpg.item.IAccessory;
- import net.minecraft.client.Minecraft;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.item.Item;
- import net.minecraft.item.ItemStack;
- import net.minecraft.nbt.NBTTagCompound;
- import net.minecraft.nbt.NBTTagList;
- import cpw.mods.fml.common.ITickHandler;
- import cpw.mods.fml.common.TickType;
- public class PlayerTickHandler implements ITickHandler
- {
- private ItemStack[] currentSlots = new ItemStack[7];
- private ItemStack[] lastSlots = new ItemStack[7];
- private final EnumSet<TickType> ticksToGet;
- public PlayerTickHandler(EnumSet<TickType> ticksToGet)
- {
- this.ticksToGet = ticksToGet;
- }
- @Override
- public void tickStart(EnumSet<TickType> type, Object... tickData)
- {
- playerTick((EntityPlayer) tickData[0]);
- }
- @Override
- public void tickEnd(EnumSet<TickType> type, Object... tickData)
- {
- }
- @Override
- public EnumSet<TickType> ticks()
- {
- return ticksToGet;
- }
- @Override
- public String getLabel()
- {
- return "N/A";
- }
- public void playerTick(EntityPlayer player)
- {
- NBTTagCompound playerNBT = player.getEntityData();
- if(Minecraft.getMinecraft().currentScreen != null)
- {
- AccessoriesKeyHandler.pressed = false;
- }
- if(AccessoriesKeyHandler.pressed)
- {
- player.openGui(GloriaRPG.instance, 2, player.worldObj, (int) player.posX, (int) player.posY, (int) player.posZ);
- AccessoriesKeyHandler.pressed = false;
- }
- if(playerNBT != null)
- {
- NBTTagList nbtTag = playerNBT.getTagList("Accessories");
- for(int i = 0;i < nbtTag.tagCount();i++)
- {
- NBTTagCompound nbt = (NBTTagCompound)nbtTag.tagAt(i);
- byte slot = nbt.getByte("Slot");
- if(slot >= 0 && slot < 7);
- {
- ItemStack itemStack = ItemStack.loadItemStackFromNBT(nbt);
- Item item = itemStack.getItem();
- this.currentSlots[i] = itemStack;
- if(item instanceof IAccessory)
- {
- IAccessory accessory = (IAccessory)item;
- accessory.tick(player);
- }
- }
- }
- }
- for(int i = 0;i < 7;i++)
- {
- GloriaRPG.print("HELLO?");
- if(this.lastSlots[i] != this.currentSlots[i])
- {
- GloriaRPG.print("YOOOO");
- if(this.currentSlots[i] != null && this.currentSlots[i].getItem() instanceof IAccessory)
- {
- IAccessory accessory = (IAccessory)this.currentSlots[i].getItem();
- accessory.equipped(player);
- }
- if(this.lastSlots[i] != null && this.lastSlots[i].getItem() instanceof IAccessory)
- {
- IAccessory accessory = (IAccessory)this.lastSlots[i].getItem();
- accessory.unequipped(player);
- }
- }
- }
- this.lastSlots = this.currentSlots;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement