blob: f1655c0eadc3a683b553b89cf58f656170e0c15c (
plain)
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
|
package darkknight.jewelrycraft.util;
import darkknight.jewelrycraft.events.ScreenHandler;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
/**
* Code taken from OpenBlocks
*/
public class PlayerUtils
{
/**
* Returns the NBTTag of the player
*
* @param player the player
* @param modName the mod name
* @return appropriate NBTTag
*/
public static NBTTagCompound getModPlayerPersistTag(EntityPlayer player, String modName)
{
if (player.worldObj.isRemote && ScreenHandler.tagCache != null) return ScreenHandler.tagCache;
NBTTagCompound tag = player.getEntityData();
NBTTagCompound persistTag = null;
if (tag.hasKey(EntityPlayer.PERSISTED_NBT_TAG)) persistTag = tag.getCompoundTag(EntityPlayer.PERSISTED_NBT_TAG);
else{
persistTag = new NBTTagCompound();
tag.setTag(EntityPlayer.PERSISTED_NBT_TAG, persistTag);
}
NBTTagCompound modTag = null;
if (persistTag.hasKey(modName)) modTag = persistTag.getCompoundTag(modName);
else{
modTag = new NBTTagCompound();
persistTag.setTag(modName, modTag);
}
return modTag;
}
}
|