Java Code Examples for net.minecraft.entity.player.EntityPlayer.xpBarCap()

The following are Jave code examples for showing how to use xpBarCap() of the net.minecraft.entity.player.EntityPlayer class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: GlobalXP   File: EventHandler.java   View Source Code Vote up 6 votes
@SubscribeEvent
public void onRightClickBlock(RightClickBlock event)
{
	if(!(event.getWorld().getBlockState(event.getPos()).getBlock() instanceof XPBlock) || event.getHand() != EnumHand.MAIN_HAND)
		return;

	if(!event.getWorld().isRemote)
	{
		if(event.getEntityPlayer().isSneaking()) //sneaking = add all player XP to the block
		{
			((TileEntityXPBlock)event.getWorld().getTileEntity(event.getPos())).addXP(event.getEntityPlayer().experienceTotal);
			event.getEntityPlayer().addExperienceLevel(-event.getEntityPlayer().experienceLevel - 1); // set player XP to 0
		}
		else //not sneaking = remove exactly enough XP from the block to get player to the next level
		{
			TileEntityXPBlock te = ((TileEntityXPBlock)event.getWorld().getTileEntity(event.getPos()));
			EntityPlayer player = event.getEntityPlayer();
			int neededXP = player.xpBarCap() - (int)player.experience;
			int availableXP = te.removeXP(neededXP);
			
			player.addExperience(availableXP);
		}
	}
}
 
Example 2
Project: pnc-repressurized   File: TileEntityAerialInterface.java   View Source Code Vote up 5 votes
/**
 * This method is copied from OpenMods' OpenModsLib
 * https://github.com/OpenMods/OpenModsLib/blob/master/src/main/java/openmods/utils/EnchantmentUtils.java
 *
 * @param player
 * @return
 */

private void addPlayerXP(EntityPlayer player, int amount) {
    int experience = getPlayerXP(player) + amount;
    player.experienceTotal = experience;
    player.experienceLevel = getLevelForExperience(experience);
    int expForLevel = getExperienceForLevel(player.experienceLevel);
    player.experience = (float) (experience - expForLevel) / (float) player.xpBarCap();
}
 
Example 3
Project: Mods   File: TF2Util.java   View Source Code Vote up 5 votes
public static int getExperiencePoints(EntityPlayer player) {
	int playerLevel = player.experienceLevel;
	player.experienceLevel = 0;
	int totalExp = 0;
	for (int i = 0; i < playerLevel; i++) {
		player.experienceLevel = i;
		totalExp += player.xpBarCap();
	}
	player.experienceLevel = playerLevel;
	totalExp += Math.round(player.experience * player.xpBarCap());
	return totalExp;
}
 
Example 4
Project: pnc-repressurized   File: TileEntityAerialInterface.java   View Source Code Vote up 2 votes
/**
 * This method is copied from OpenMods' OpenModsLib
 * https://github.com/OpenMods/OpenModsLib/blob/master/src/main/java/openmods/utils/EnchantmentUtils.java
 *
 * @param player
 * @return
 */
private int getPlayerXP(EntityPlayer player) {
    return (int) (getExperienceForLevel(player.experienceLevel) + player.experience * player.xpBarCap());
}