Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package terramagna.utils;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.nbt.NBTTagCompound;
- import net.minecraft.world.*;
- import net.minecraftforge.event.ForgeSubscribe;
- import net.minecraftforge.event.entity.EntityJoinWorldEvent;
- public class PlayerStatsUtil extends WorldSavedData
- {
- public PlayerStatsUtil(String par1Str){super(par1Str);}
- public static NBTTagCompound theNBT;
- @ForgeSubscribe
- public void onEntityJoinWorld(EntityJoinWorldEvent event)
- {
- if (event.entity instanceof EntityPlayer)
- {
- World world = event.world;
- NBTTagCompound nbt = world.getWorldInfo().getPlayerNBTTagCompound();
- theNBT = nbt;
- theNBT.getInteger("gold");
- }
- }
- public static void editGold(int amount, int mode)
- {
- //MODE 0 = SET | MODE 1 = ADD | MODE 2 = REMOVE
- int currentAmount = theNBT.getInteger("gold");
- if(mode == 0)
- {
- theNBT.setInteger("gold", amount);
- }
- if(mode == 1)
- {
- theNBT.setInteger("gold", (currentAmount + amount));
- }
- if(mode == 2)
- {
- theNBT.setInteger("gold", (currentAmount - amount));
- }
- }
- public static int getGold()
- {
- return theNBT.getInteger("gold");
- }
- @Override
- public void readFromNBT(NBTTagCompound nbttagcompound){}
- @Override
- public void writeToNBT(NBTTagCompound nbttagcompound){}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement