Advertisement
Disconsented

Untitled

Apr 15th, 2014
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.31 KB | None | 0 0
  1.    
  2.  
  3.     package tutorial.generic;
  4.      
  5.     import net.minecraft.entity.Entity;
  6.     import net.minecraft.entity.player.EntityPlayer;
  7.     import net.minecraft.entity.player.EntityPlayerMP;
  8.     import net.minecraft.nbt.NBTTagCompound;
  9.     import net.minecraft.util.IChatComponent;
  10.     import net.minecraft.world.World;
  11.     import net.minecraftforge.common.IExtendedEntityProperties;
  12.      
  13.     public final class PlayerInformation implements IExtendedEntityProperties {
  14.             private int currentXP;
  15.             public final static String EXT_PROP_NAME = "PlayerInformation";
  16.             private final EntityPlayer player;
  17.            
  18.             public static final PlayerInformation get(EntityPlayer player) {
  19.                     return (PlayerInformation) player.getExtendedProperties(EXT_PROP_NAME);
  20.             }
  21.            
  22.            
  23.             public PlayerInformation(EntityPlayer player) {
  24.                     NBTTagCompound entityTempTag = player.getEntityData();
  25.                     NBTTagCompound persistTag = entityTempTag.getCompoundTag(player.PERSISTED_NBT_TAG);
  26.                     this.player = player;
  27.             }
  28.            
  29.             public static final void register(EntityPlayer player) {
  30.                     player.registerExtendedProperties(PlayerInformation.EXT_PROP_NAME, new PlayerInformation(player));
  31.             }
  32.      
  33.             @Override //Updates anything that needs to be updated each tick
  34.             public void init(Entity entity, World world) {        
  35.             }
  36.      
  37.         @Override
  38.         public void saveNBTData(NBTTagCompound compound) {
  39.             compound.setInteger("currentXP", currentXP);
  40.             //System.out.println("NBT Saved");
  41.             //System.out.println(compound);
  42.            
  43.         }
  44.      
  45.             @Override
  46.             public final void loadNBTData(NBTTagCompound compound) {               
  47.                     System.out.println("NBT LOADED");
  48.                     this.currentXP = compound.getInteger("currentXP");    
  49.             }
  50.      
  51.         public void addXP(int ammount){
  52.             this.currentXP += ammount;
  53.         }
  54.         public void setXP(int ammount){
  55.             this.currentXP = ammount;
  56.         }      
  57.        
  58.         public int getXP(){
  59.             return this.currentXP;
  60.         }
  61.      
  62.      
  63.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement