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

The following are Jave code examples for showing how to use removeExperienceLevel() 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.
Example 1
Project: BaseClient   File: ContainerEnchantment.java   Source Code and License Vote up 4 votes
/**
 * Handles the given Button-click on the server, currently only used by enchanting. Name is for legacy.
 */
public boolean enchantItem(EntityPlayer playerIn, int id)
{
    ItemStack itemstack = this.tableInventory.getStackInSlot(0);
    ItemStack itemstack1 = this.tableInventory.getStackInSlot(1);
    int i = id + 1;

    if ((itemstack1 == null || itemstack1.stackSize < i) && !playerIn.capabilities.isCreativeMode)
    {
        return false;
    }
    else if (this.enchantLevels[id] > 0 && itemstack != null && (playerIn.experienceLevel >= i && playerIn.experienceLevel >= this.enchantLevels[id] || playerIn.capabilities.isCreativeMode))
    {
        if (!this.worldPointer.isRemote)
        {
            List<EnchantmentData> list = this.func_178148_a(itemstack, id, this.enchantLevels[id]);
            boolean flag = itemstack.getItem() == Items.book;

            if (list != null)
            {
                playerIn.removeExperienceLevel(i);

                if (flag)
                {
                    itemstack.setItem(Items.enchanted_book);
                }

                for (int j = 0; j < list.size(); ++j)
                {
                    EnchantmentData enchantmentdata = (EnchantmentData)list.get(j);

                    if (flag)
                    {
                        Items.enchanted_book.addEnchantment(itemstack, enchantmentdata);
                    }
                    else
                    {
                        itemstack.addEnchantment(enchantmentdata.enchantmentobj, enchantmentdata.enchantmentLevel);
                    }
                }

                if (!playerIn.capabilities.isCreativeMode)
                {
                    itemstack1.stackSize -= i;

                    if (itemstack1.stackSize <= 0)
                    {
                        this.tableInventory.setInventorySlotContents(1, (ItemStack)null);
                    }
                }

                playerIn.triggerAchievement(StatList.field_181739_W);
                this.tableInventory.markDirty();
                this.xpSeed = playerIn.getXPSeed();
                this.onCraftMatrixChanged(this.tableInventory);
            }
        }

        return true;
    }
    else
    {
        return false;
    }
}
 
Example 2
Project: BaseClient   File: ContainerEnchantment.java   Source Code and License Vote up 4 votes
/**
 * Handles the given Button-click on the server, currently only used by enchanting. Name is for legacy.
 */
public boolean enchantItem(EntityPlayer playerIn, int id)
{
    ItemStack itemstack = this.tableInventory.getStackInSlot(0);
    ItemStack itemstack1 = this.tableInventory.getStackInSlot(1);
    int i = id + 1;

    if ((itemstack1 == null || itemstack1.stackSize < i) && !playerIn.capabilities.isCreativeMode)
    {
        return false;
    }
    else if (this.enchantLevels[id] > 0 && itemstack != null && (playerIn.experienceLevel >= i && playerIn.experienceLevel >= this.enchantLevels[id] || playerIn.capabilities.isCreativeMode))
    {
        if (!this.worldPointer.isRemote)
        {
            List<EnchantmentData> list = this.func_178148_a(itemstack, id, this.enchantLevels[id]);
            boolean flag = itemstack.getItem() == Items.book;

            if (list != null)
            {
                playerIn.removeExperienceLevel(i);

                if (flag)
                {
                    itemstack.setItem(Items.enchanted_book);
                }

                for (int j = 0; j < list.size(); ++j)
                {
                    EnchantmentData enchantmentdata = (EnchantmentData)list.get(j);

                    if (flag)
                    {
                        Items.enchanted_book.addEnchantment(itemstack, enchantmentdata);
                    }
                    else
                    {
                        itemstack.addEnchantment(enchantmentdata.enchantmentobj, enchantmentdata.enchantmentLevel);
                    }
                }

                if (!playerIn.capabilities.isCreativeMode)
                {
                    itemstack1.stackSize -= i;

                    if (itemstack1.stackSize <= 0)
                    {
                        this.tableInventory.setInventorySlotContents(1, (ItemStack)null);
                    }
                }

                playerIn.triggerAchievement(StatList.field_181739_W);
                this.tableInventory.markDirty();
                this.xpSeed = playerIn.getXPSeed();
                this.onCraftMatrixChanged(this.tableInventory);
            }
        }

        return true;
    }
    else
    {
        return false;
    }
}
 
Example 3
Project: CustomWorldGen   File: ContainerEnchantment.java   Source Code and License Vote up 4 votes
/**
 * Handles the given Button-click on the server, currently only used by enchanting. Name is for legacy.
 */
public boolean enchantItem(EntityPlayer playerIn, int id)
{
    ItemStack itemstack = this.tableInventory.getStackInSlot(0);
    ItemStack itemstack1 = this.tableInventory.getStackInSlot(1);
    int i = id + 1;

    if ((itemstack1 == null || itemstack1.stackSize < i) && !playerIn.capabilities.isCreativeMode)
    {
        return false;
    }
    else if (this.enchantLevels[id] > 0 && itemstack != null && (playerIn.experienceLevel >= i && playerIn.experienceLevel >= this.enchantLevels[id] || playerIn.capabilities.isCreativeMode))
    {
        if (!this.worldPointer.isRemote)
        {
            List<EnchantmentData> list = this.getEnchantmentList(itemstack, id, this.enchantLevels[id]);
            boolean flag = itemstack.getItem() == Items.BOOK;

            if (list != null)
            {
                playerIn.removeExperienceLevel(i);

                if (flag)
                {
                    itemstack.setItem(Items.ENCHANTED_BOOK);
                }

                for (int j = 0; j < list.size(); ++j)
                {
                    EnchantmentData enchantmentdata = (EnchantmentData)list.get(j);

                    if (flag)
                    {
                        Items.ENCHANTED_BOOK.addEnchantment(itemstack, enchantmentdata);
                    }
                    else
                    {
                        itemstack.addEnchantment(enchantmentdata.enchantmentobj, enchantmentdata.enchantmentLevel);
                    }
                }

                if (!playerIn.capabilities.isCreativeMode)
                {
                    itemstack1.stackSize -= i;

                    if (itemstack1.stackSize <= 0)
                    {
                        this.tableInventory.setInventorySlotContents(1, (ItemStack)null);
                    }
                }

                playerIn.addStat(StatList.ITEM_ENCHANTED);
                this.tableInventory.markDirty();
                this.xpSeed = playerIn.getXPSeed();
                this.onCraftMatrixChanged(this.tableInventory);
                this.worldPointer.playSound((EntityPlayer)null, this.position, SoundEvents.BLOCK_ENCHANTMENT_TABLE_USE, SoundCategory.BLOCKS, 1.0F, this.worldPointer.rand.nextFloat() * 0.1F + 0.9F);
            }
        }

        return true;
    }
    else
    {
        return false;
    }
}