Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package terramagna.helpers;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.nbt.NBTTagCompound;
- import net.minecraft.world.WorldSavedData;
- import net.minecraftforge.event.ForgeSubscribe;
- import net.minecraftforge.event.entity.EntityJoinWorldEvent;
- public class PlayerStatsHelper extends WorldSavedData
- {
- private static int experience;
- public PlayerStatsHelper(String par1Str)
- {
- super(par1Str);
- }
- @ForgeSubscribe
- public void onEntityJoinWorld(EntityJoinWorldEvent event)
- {
- if (!event.entity.worldObj.isRemote && event.entity instanceof EntityPlayer)
- {
- EntityPlayer player = (EntityPlayer) event.entity;
- NBTTagCompound nbt = player.getEntityData().getCompoundTag("PlayerPersisted");
- nbt.getInteger("Experience");
- if(nbt.getInteger("Experience") == 0)
- {
- nbt.setInteger("Experience", 0);
- }
- this.experience = nbt.getInteger("Experience");
- }
- }
- @Override
- public void readFromNBT(NBTTagCompound nbttagcompound) {
- // TODO Auto-generated method stub
- }
- @Override
- public void writeToNBT(NBTTagCompound nbttagcompound) {
- // TODO Auto-generated method stub
- }
- public static int getExperience()
- {
- return experience;
- }
- public static void addExperience(int amount)
- {
- experience = experience + amount;
- }
- public static void removeExperience(int amount)
- {
- experience = experience - amount;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment