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

The following are Jave code examples for showing how to use addExperience() 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: pnc-repressurized   File: TileEntityAerialInterface.java   View Source Code Vote up 6 votes
@Override
public int fill(FluidStack resource, boolean doFill) {
    if (resource != null && canFill(resource.getFluid())) {
        EntityPlayer player = getPlayer();
        if (player != null) {
            int liquidToXP = PneumaticCraftAPIHandler.getInstance().liquidXPs.get(resource.getFluid());
            int xpPoints = resource.amount / liquidToXP;
            if (doFill) {
                player.addExperience(xpPoints);
                curXpFluid = resource.getFluid();
            }
            return xpPoints * liquidToXP;
        }
    }
    return 0;
}
 
Example 2
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 3
Project: JustJunk   File: ItemTincan.java   View Source Code Vote up 5 votes
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn){
    if (!playerIn.world.isRemote) {
        playerIn.inventory.addItemStackToInventory(new ItemStack(ModItems.emptytincan, 1));
        playerIn.addExperience(1);
        playerIn.getHeldItem(handIn).shrink(1);
        ItemStack random_item = new ItemStack(loot_table[(int) (Math.random() * loot_table.length)], 1);
        playerIn.inventory.addItemStackToInventory(random_item);
    }
    return super.onItemRightClick(worldIn, playerIn, handIn);
}
 
Example 4
Project: JustJunk   File: ItemToothbrush.java   View Source Code Vote up 5 votes
@Override
public EnumActionResult onItemUse(EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand handIn, EnumFacing facing, float hitX, float hitY, float hitZ){
    playerIn.inventory.addItemStackToInventory(new ItemStack(ModItems.brokentoothbrush,1));
    playerIn.addExperience(1);
    playerIn.getHeldItem(handIn).shrink(1);
    return super.onItemUse(playerIn, worldIn, pos, handIn, facing, hitX, hitY, hitZ);
}
 
Example 5
Project: DecompiledMinecraft   File: EntityXPOrb.java   View Source Code Vote up 5 votes
/**
 * Called by a player entity when they collide with an entity
 */
public void onCollideWithPlayer(EntityPlayer entityIn)
{
    if (!this.worldObj.isRemote)
    {
        if (this.delayBeforeCanPickup == 0 && entityIn.xpCooldown == 0)
        {
            entityIn.xpCooldown = 2;
            this.worldObj.playSoundAtEntity(entityIn, "random.orb", 0.1F, 0.5F * ((this.rand.nextFloat() - this.rand.nextFloat()) * 0.7F + 1.8F));
            entityIn.onItemPickup(this, 1);
            entityIn.addExperience(this.xpValue);
            this.setDead();
        }
    }
}
 
Example 6
Project: DecompiledMinecraft   File: EntityXPOrb.java   View Source Code Vote up 5 votes
/**
 * Called by a player entity when they collide with an entity
 */
public void onCollideWithPlayer(EntityPlayer entityIn)
{
    if (!this.worldObj.isRemote)
    {
        if (this.delayBeforeCanPickup == 0 && entityIn.xpCooldown == 0)
        {
            entityIn.xpCooldown = 2;
            this.worldObj.playSoundAtEntity(entityIn, "random.orb", 0.1F, 0.5F * ((this.rand.nextFloat() - this.rand.nextFloat()) * 0.7F + 1.8F));
            entityIn.onItemPickup(this, 1);
            entityIn.addExperience(this.xpValue);
            this.setDead();
        }
    }
}
 
Example 7
Project: BaseClient   File: EntityXPOrb.java   View Source Code Vote up 5 votes
/**
 * Called by a player entity when they collide with an entity
 */
public void onCollideWithPlayer(EntityPlayer entityIn)
{
    if (!this.worldObj.isRemote)
    {
        if (this.delayBeforeCanPickup == 0 && entityIn.xpCooldown == 0)
        {
            entityIn.xpCooldown = 2;
            this.worldObj.playSoundAtEntity(entityIn, "random.orb", 0.1F, 0.5F * ((this.rand.nextFloat() - this.rand.nextFloat()) * 0.7F + 1.8F));
            entityIn.onItemPickup(this, 1);
            entityIn.addExperience(this.xpValue);
            this.setDead();
        }
    }
}
 
Example 8
Project: BaseClient   File: EntityXPOrb.java   View Source Code Vote up 5 votes
/**
 * Called by a player entity when they collide with an entity
 */
public void onCollideWithPlayer(EntityPlayer entityIn)
{
    if (!this.worldObj.isRemote)
    {
        if (this.delayBeforeCanPickup == 0 && entityIn.xpCooldown == 0)
        {
            entityIn.xpCooldown = 2;
            this.worldObj.playSoundAtEntity(entityIn, "random.orb", 0.1F, 0.5F * ((this.rand.nextFloat() - this.rand.nextFloat()) * 0.7F + 1.8F));
            entityIn.onItemPickup(this, 1);
            entityIn.addExperience(this.xpValue);
            this.setDead();
        }
    }
}
 
Example 9
Project: Backmemed   File: EntityXPOrb.java   View Source Code Vote up 5 votes
/**
 * Called by a player entity when they collide with an entity
 */
public void onCollideWithPlayer(EntityPlayer entityIn)
{
    if (!this.world.isRemote)
    {
        if (this.delayBeforeCanPickup == 0 && entityIn.xpCooldown == 0)
        {
            entityIn.xpCooldown = 2;
            entityIn.onItemPickup(this, 1);
            ItemStack itemstack = EnchantmentHelper.getEnchantedItem(Enchantments.MENDING, entityIn);

            if (!itemstack.func_190926_b() && itemstack.isItemDamaged())
            {
                int i = Math.min(this.xpToDurability(this.xpValue), itemstack.getItemDamage());
                this.xpValue -= this.durabilityToXp(i);
                itemstack.setItemDamage(itemstack.getItemDamage() - i);
            }

            if (this.xpValue > 0)
            {
                entityIn.addExperience(this.xpValue);
            }

            this.setDead();
        }
    }
}
 
Example 10
Project: CustomWorldGen   File: EntityXPOrb.java   View Source Code Vote up 5 votes
/**
 * Called by a player entity when they collide with an entity
 */
public void onCollideWithPlayer(EntityPlayer entityIn)
{
    if (!this.worldObj.isRemote)
    {
        if (this.delayBeforeCanPickup == 0 && entityIn.xpCooldown == 0)
        {
            if (net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.entity.player.PlayerPickupXpEvent(entityIn, this))) return;
            entityIn.xpCooldown = 2;
            this.worldObj.playSound((EntityPlayer)null, entityIn.posX, entityIn.posY, entityIn.posZ, SoundEvents.ENTITY_EXPERIENCE_ORB_TOUCH, SoundCategory.PLAYERS, 0.1F, 0.5F * ((this.rand.nextFloat() - this.rand.nextFloat()) * 0.7F + 1.8F));
            entityIn.onItemPickup(this, 1);
            ItemStack itemstack = EnchantmentHelper.getEnchantedItem(Enchantments.MENDING, entityIn);

            if (itemstack != null && itemstack.isItemDamaged())
            {
                int i = Math.min(this.xpToDurability(this.xpValue), itemstack.getItemDamage());
                this.xpValue -= this.durabilityToXp(i);
                itemstack.setItemDamage(itemstack.getItemDamage() - i);
            }

            if (this.xpValue > 0)
            {
                entityIn.addExperience(this.xpValue);
            }

            this.setDead();
        }
    }
}
 
Example 11
Project: mc-XPBox   File: BlockXPBox.java   View Source Code Vote up 4 votes
public static void updateXP(EntityPlayer player, int op, int xp) {
   int exp;
   XPCapability cap = player.getCapability(XPBox.XP_CAPABILITY, null);

   switch (op) {
   case MessageOp.WITHDRAW:
      if (xp > cap.value)
         xp = cap.value;
      if (0 == xp)
         break;
      player.addExperience(xp);
      cap.value -= xp;
      break;
   case MessageOp.DEPOSIT:
      exp = getTotalXP(player);
      if (xp > exp)
         break;
      if (xp + cap.value > GuiXPBox.MAX)
         xp = GuiXPBox.MAX - cap.value;
      if (0 == xp)
         break;
      player.experience = 0;
      player.experienceLevel = 0;
      player.experienceTotal = 0;
      player.addExperience(exp - xp);
      cap.value += xp;
      break;
   case MessageOp.SETLEVEL:
      exp = getTotalXP(player);
      if (exp + cap.value < exp)
         exp = Integer.MAX_VALUE;
      else
         exp += cap.value;
      if (0 == exp)
         break;
      player.experience = 0;
      player.experienceLevel = 0;
      player.experienceTotal = 0;
      for (int lv = 0; lv < xp; ++lv) {
         int t = xpBarCap(lv);
         if (exp >= t) {
            exp -= t;
            player.addExperience(t);
         } else {
            player.addExperience(exp);
            exp = 0;
            break;
         }
      }
      if (exp > GuiXPBox.MAX)
         exp = GuiXPBox.MAX;
      cap.value = exp;
      break;
   }
   sendXPMessage(player);
}
 
Example 12
Project: DecompiledMinecraft   File: CommandXP.java   View Source Code Vote up 4 votes
/**
 * Callback when the command is invoked
 */
public void processCommand(ICommandSender sender, String[] args) throws CommandException
{
    if (args.length <= 0)
    {
        throw new WrongUsageException("commands.xp.usage", new Object[0]);
    }
    else
    {
        String s = args[0];
        boolean flag = s.endsWith("l") || s.endsWith("L");

        if (flag && s.length() > 1)
        {
            s = s.substring(0, s.length() - 1);
        }

        int i = parseInt(s);
        boolean flag1 = i < 0;

        if (flag1)
        {
            i *= -1;
        }

        EntityPlayer entityplayer = args.length > 1 ? getPlayer(sender, args[1]) : getCommandSenderAsPlayer(sender);

        if (flag)
        {
            sender.setCommandStat(CommandResultStats.Type.QUERY_RESULT, entityplayer.experienceLevel);

            if (flag1)
            {
                entityplayer.addExperienceLevel(-i);
                notifyOperators(sender, this, "commands.xp.success.negative.levels", new Object[] {Integer.valueOf(i), entityplayer.getName()});
            }
            else
            {
                entityplayer.addExperienceLevel(i);
                notifyOperators(sender, this, "commands.xp.success.levels", new Object[] {Integer.valueOf(i), entityplayer.getName()});
            }
        }
        else
        {
            sender.setCommandStat(CommandResultStats.Type.QUERY_RESULT, entityplayer.experienceTotal);

            if (flag1)
            {
                throw new CommandException("commands.xp.failure.widthdrawXp", new Object[0]);
            }

            entityplayer.addExperience(i);
            notifyOperators(sender, this, "commands.xp.success", new Object[] {Integer.valueOf(i), entityplayer.getName()});
        }
    }
}
 
Example 13
Project: DecompiledMinecraft   File: CommandXP.java   View Source Code Vote up 4 votes
/**
 * Callback when the command is invoked
 */
public void processCommand(ICommandSender sender, String[] args) throws CommandException
{
    if (args.length <= 0)
    {
        throw new WrongUsageException("commands.xp.usage", new Object[0]);
    }
    else
    {
        String s = args[0];
        boolean flag = s.endsWith("l") || s.endsWith("L");

        if (flag && s.length() > 1)
        {
            s = s.substring(0, s.length() - 1);
        }

        int i = parseInt(s);
        boolean flag1 = i < 0;

        if (flag1)
        {
            i *= -1;
        }

        EntityPlayer entityplayer = args.length > 1 ? getPlayer(sender, args[1]) : getCommandSenderAsPlayer(sender);

        if (flag)
        {
            sender.setCommandStat(CommandResultStats.Type.QUERY_RESULT, entityplayer.experienceLevel);

            if (flag1)
            {
                entityplayer.addExperienceLevel(-i);
                notifyOperators(sender, this, "commands.xp.success.negative.levels", new Object[] {Integer.valueOf(i), entityplayer.getName()});
            }
            else
            {
                entityplayer.addExperienceLevel(i);
                notifyOperators(sender, this, "commands.xp.success.levels", new Object[] {Integer.valueOf(i), entityplayer.getName()});
            }
        }
        else
        {
            sender.setCommandStat(CommandResultStats.Type.QUERY_RESULT, entityplayer.experienceTotal);

            if (flag1)
            {
                throw new CommandException("commands.xp.failure.widthdrawXp", new Object[0]);
            }

            entityplayer.addExperience(i);
            notifyOperators(sender, this, "commands.xp.success", new Object[] {Integer.valueOf(i), entityplayer.getName()});
        }
    }
}
 
Example 14
Project: BaseClient   File: CommandXP.java   View Source Code Vote up 4 votes
/**
 * Callback when the command is invoked
 */
public void processCommand(ICommandSender sender, String[] args) throws CommandException
{
    if (args.length <= 0)
    {
        throw new WrongUsageException("commands.xp.usage", new Object[0]);
    }
    else
    {
        String s = args[0];
        boolean flag = s.endsWith("l") || s.endsWith("L");

        if (flag && s.length() > 1)
        {
            s = s.substring(0, s.length() - 1);
        }

        int i = parseInt(s);
        boolean flag1 = i < 0;

        if (flag1)
        {
            i *= -1;
        }

        EntityPlayer entityplayer = args.length > 1 ? getPlayer(sender, args[1]) : getCommandSenderAsPlayer(sender);

        if (flag)
        {
            sender.setCommandStat(CommandResultStats.Type.QUERY_RESULT, entityplayer.experienceLevel);

            if (flag1)
            {
                entityplayer.addExperienceLevel(-i);
                notifyOperators(sender, this, "commands.xp.success.negative.levels", new Object[] {Integer.valueOf(i), entityplayer.getName()});
            }
            else
            {
                entityplayer.addExperienceLevel(i);
                notifyOperators(sender, this, "commands.xp.success.levels", new Object[] {Integer.valueOf(i), entityplayer.getName()});
            }
        }
        else
        {
            sender.setCommandStat(CommandResultStats.Type.QUERY_RESULT, entityplayer.experienceTotal);

            if (flag1)
            {
                throw new CommandException("commands.xp.failure.widthdrawXp", new Object[0]);
            }

            entityplayer.addExperience(i);
            notifyOperators(sender, this, "commands.xp.success", new Object[] {Integer.valueOf(i), entityplayer.getName()});
        }
    }
}
 
Example 15
Project: BaseClient   File: CommandXP.java   View Source Code Vote up 4 votes
/**
 * Callback when the command is invoked
 */
public void processCommand(ICommandSender sender, String[] args) throws CommandException
{
    if (args.length <= 0)
    {
        throw new WrongUsageException("commands.xp.usage", new Object[0]);
    }
    else
    {
        String s = args[0];
        boolean flag = s.endsWith("l") || s.endsWith("L");

        if (flag && s.length() > 1)
        {
            s = s.substring(0, s.length() - 1);
        }

        int i = parseInt(s);
        boolean flag1 = i < 0;

        if (flag1)
        {
            i *= -1;
        }

        EntityPlayer entityplayer = args.length > 1 ? getPlayer(sender, args[1]) : getCommandSenderAsPlayer(sender);

        if (flag)
        {
            sender.setCommandStat(CommandResultStats.Type.QUERY_RESULT, entityplayer.experienceLevel);

            if (flag1)
            {
                entityplayer.addExperienceLevel(-i);
                notifyOperators(sender, this, "commands.xp.success.negative.levels", new Object[] {Integer.valueOf(i), entityplayer.getName()});
            }
            else
            {
                entityplayer.addExperienceLevel(i);
                notifyOperators(sender, this, "commands.xp.success.levels", new Object[] {Integer.valueOf(i), entityplayer.getName()});
            }
        }
        else
        {
            sender.setCommandStat(CommandResultStats.Type.QUERY_RESULT, entityplayer.experienceTotal);

            if (flag1)
            {
                throw new CommandException("commands.xp.failure.widthdrawXp", new Object[0]);
            }

            entityplayer.addExperience(i);
            notifyOperators(sender, this, "commands.xp.success", new Object[] {Integer.valueOf(i), entityplayer.getName()});
        }
    }
}
 
Example 16
Project: Backmemed   File: CommandXP.java   View Source Code Vote up 4 votes
/**
 * Callback for when the command is executed
 */
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
{
    if (args.length <= 0)
    {
        throw new WrongUsageException("commands.xp.usage", new Object[0]);
    }
    else
    {
        String s = args[0];
        boolean flag = s.endsWith("l") || s.endsWith("L");

        if (flag && s.length() > 1)
        {
            s = s.substring(0, s.length() - 1);
        }

        int i = parseInt(s);
        boolean flag1 = i < 0;

        if (flag1)
        {
            i *= -1;
        }

        EntityPlayer entityplayer = args.length > 1 ? getPlayer(server, sender, args[1]) : getCommandSenderAsPlayer(sender);

        if (flag)
        {
            sender.setCommandStat(CommandResultStats.Type.QUERY_RESULT, entityplayer.experienceLevel);

            if (flag1)
            {
                entityplayer.addExperienceLevel(-i);
                notifyCommandListener(sender, this, "commands.xp.success.negative.levels", new Object[] {Integer.valueOf(i), entityplayer.getName()});
            }
            else
            {
                entityplayer.addExperienceLevel(i);
                notifyCommandListener(sender, this, "commands.xp.success.levels", new Object[] {Integer.valueOf(i), entityplayer.getName()});
            }
        }
        else
        {
            sender.setCommandStat(CommandResultStats.Type.QUERY_RESULT, entityplayer.experienceTotal);

            if (flag1)
            {
                throw new CommandException("commands.xp.failure.widthdrawXp", new Object[0]);
            }

            entityplayer.addExperience(i);
            notifyCommandListener(sender, this, "commands.xp.success", new Object[] {Integer.valueOf(i), entityplayer.getName()});
        }
    }
}
 
Example 17
Project: Mods   File: TF2Util.java   View Source Code Vote up 4 votes
public static void setExperiencePoints(EntityPlayer player, int amount) {
	player.experienceLevel = 0;
	player.experience = 0;
	player.addExperience(amount);
}
 
Example 18
Project: CustomWorldGen   File: CommandXP.java   View Source Code Vote up 4 votes
/**
 * Callback for when the command is executed
 */
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
{
    if (args.length <= 0)
    {
        throw new WrongUsageException("commands.xp.usage", new Object[0]);
    }
    else
    {
        String s = args[0];
        boolean flag = s.endsWith("l") || s.endsWith("L");

        if (flag && s.length() > 1)
        {
            s = s.substring(0, s.length() - 1);
        }

        int i = parseInt(s);
        boolean flag1 = i < 0;

        if (flag1)
        {
            i *= -1;
        }

        EntityPlayer entityplayer = args.length > 1 ? getPlayer(server, sender, args[1]) : getCommandSenderAsPlayer(sender);

        if (flag)
        {
            sender.setCommandStat(CommandResultStats.Type.QUERY_RESULT, entityplayer.experienceLevel);

            if (flag1)
            {
                entityplayer.addExperienceLevel(-i);
                notifyCommandListener(sender, this, "commands.xp.success.negative.levels", new Object[] {Integer.valueOf(i), entityplayer.getName()});
            }
            else
            {
                entityplayer.addExperienceLevel(i);
                notifyCommandListener(sender, this, "commands.xp.success.levels", new Object[] {Integer.valueOf(i), entityplayer.getName()});
            }
        }
        else
        {
            sender.setCommandStat(CommandResultStats.Type.QUERY_RESULT, entityplayer.experienceTotal);

            if (flag1)
            {
                throw new CommandException("commands.xp.failure.widthdrawXp", new Object[0]);
            }

            entityplayer.addExperience(i);
            notifyCommandListener(sender, this, "commands.xp.success", new Object[] {Integer.valueOf(i), entityplayer.getName()});
        }
    }
}