SHOW:
|
|
- or go back to the newest paste.
| 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 | - | compound.getCompoundTag("PERSISTED_NBT_TAG");
|
| 37 | + | |
| 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 | compound.getTag(EXT_PROP_NAME); | |
| 49 | System.out.println(this.currentXP); | |
| 50 | if (this.currentXP != 0) | |
| 51 | {
| |
| 52 | this.currentXP = compound.getInteger("currentXP");
| |
| 53 | } | |
| 54 | else | |
| 55 | {
| |
| 56 | System.out.println("From loadNBTData:"+currentXP);
| |
| 57 | } | |
| 58 | ||
| 59 | } | |
| 60 | ||
| 61 | public void addXP(int ammount){
| |
| 62 | this.currentXP += ammount; | |
| 63 | } | |
| 64 | ||
| 65 | public int getXP(){
| |
| 66 | return this.currentXP; | |
| 67 | } | |
| 68 | ||
| 69 | ||
| 70 | } |