-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExperienceCraftingPlayerProperties
More file actions
79 lines (70 loc) · 2.64 KB
/
ExperienceCraftingPlayerProperties
File metadata and controls
79 lines (70 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package io.github.anon10w1z.expcrafting;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraftforge.common.IExtendedEntityProperties;
/**
* The extended player properties of Experience Crafting
*/
public class ExperienceCraftingPlayerProperties implements IExtendedEntityProperties {
/**
* The name of the properties
*/
public static final String PROPERTIES_NAME = "EXPERIENCE_CRAFTING_PROPERTIES";
/**
* The player these properties are attached to
*/
public EntityPlayer player;
/**
* The max experience level the player has attained
*/
public int maxExperienceLevel = 0;
/**
* Saves the max experience level to NBT
* @param nbtTagCompound The NBT tag compound to save the max experience level to
*/
@Override
public void saveNBTData(NBTTagCompound nbtTagCompound) {
nbtTagCompound.setInteger("HighestXpLevel", this.maxExperienceLevel);
}
/**
* Loads the max experience level from NBT
* @param nbtTagCompound The NBT tag compound to load the max experience level from
*/
@Override
public void loadNBTData(NBTTagCompound nbtTagCompound) {
this.maxExperienceLevel = nbtTagCompound.getInteger("HighestXpLevel");
}
@Override
public void init(Entity entity, World world) {
//do nothing
}
/**
* Updates the max experience level for the given player
* @param player The player to update the max experience for
*/
public static void updateMaxExperienceLevel(EntityPlayer player) {
setMaxExperienceLevel(player, Math.max(player.experienceLevel, getMaxExperienceLevel(player)));
}
/**
* Sets the given max experience level for the given player
* @param player The player to set the max experience level for
* @param maxExperienceLevel The max experience level to set the player's to
*/
public static void setMaxExperienceLevel(EntityPlayer player, int maxExperienceLevel) {
((ExperienceCraftingPlayerProperties) player.getExtendedProperties(PROPERTIES_NAME)).maxExperienceLevel = maxExperienceLevel;
}
/**
* Gets the max experience level for the given player
* @param player The player to get the max experience level of
* @return The max experience level of the given player
*/
public static int getMaxExperienceLevel(EntityPlayer player) {
if (player == null)
return 0;
if (player.getExtendedProperties("EXPERIENCE_CRAFTING_PROPERTIES") == null)
player.registerExtendedProperties("EXPERIENCE_CRAFTING_PROPERTIES", new ExperienceCraftingPlayerProperties());
return ((ExperienceCraftingPlayerProperties) player.getExtendedProperties(PROPERTIES_NAME)).maxExperienceLevel;
}
}