protected override void DropRareDrop(int par1)
        {
            if (par1 > 0)
            {
                ItemStack itemstack = new ItemStack(Item.SwordGold);
                EnchantmentHelper.Func_48441_a(Rand, itemstack, 5);
                EntityDropItem(itemstack, 0.0F);
            }
            else
            {
                int i = Rand.Next(3);

                if (i == 0)
                {
                    DropItem(Item.IngotGold.ShiftedIndex, 1);
                }
                else if (i == 1)
                {
                    DropItem(Item.SwordGold.ShiftedIndex, 1);
                }
                else if (i == 2)
                {
                    DropItem(Item.HelmetGold.ShiftedIndex, 1);
                }
            }
        }
Example #2
0
        /// <summary>
        /// enchants the item on the table using the specified slot; also deducts XP from player
        /// </summary>
        public override bool EnchantItem(EntityPlayer par1EntityPlayer, int par2)
        {
            ItemStack itemstack = TableInventory.GetStackInSlot(0);

            if (EnchantLevels[par2] > 0 && itemstack != null && (par1EntityPlayer.ExperienceLevel >= EnchantLevels[par2] || par1EntityPlayer.Capabilities.IsCreativeMode))
            {
                if (!WorldPointer.IsRemote)
                {
                    List <EnchantmentData> list = EnchantmentHelper.BuildEnchantmentList(Rand, itemstack, EnchantLevels[par2]);

                    if (list != null)
                    {
                        par1EntityPlayer.RemoveExperience(EnchantLevels[par2]);
                        EnchantmentData enchantmentdata;

                        for (IEnumerator <EnchantmentData> iterator = list.GetEnumerator(); iterator.MoveNext(); itemstack.AddEnchantment(enchantmentdata.Enchantmentobj, enchantmentdata.EnchantmentLevel))
                        {
                            enchantmentdata = iterator.Current;
                        }

                        OnCraftMatrixChanged(TableInventory);
                    }
                }

                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #3
0
        /// <summary>
        /// Damages the item in the ItemStack
        /// </summary>
        public void DamageItem(int par1, EntityLiving par2EntityLiving)
        {
            if (!IsItemStackDamageable())
            {
                return;
            }

            if (par1 > 0 && (par2EntityLiving is EntityPlayer))
            {
                int i = EnchantmentHelper.GetUnbreakingModifier(((EntityPlayer)par2EntityLiving).Inventory);

                if (i > 0 && par2EntityLiving.WorldObj.Rand.Next(i + 1) > 0)
                {
                    return;
                }
            }

            ItemDamage += par1;

            if (ItemDamage > GetMaxDamage())
            {
                par2EntityLiving.RenderBrokenItemStack(this);

                if (par2EntityLiving is EntityPlayer)
                {
                    ((EntityPlayer)par2EntityLiving).AddStat(StatList.ObjectBreakStats[ItemID], 1);
                }

                StackSize--;

                if (StackSize < 0)
                {
                    StackSize = 0;
                }

                ItemDamage = 0;
            }
        }
Example #4
0
        /// <summary>
        /// Callback for when the crafting matrix is changed.
        /// </summary>
        public override void OnCraftMatrixChanged(IInventory par1IInventory)
        {
            if (par1IInventory == TableInventory)
            {
                ItemStack itemstack = par1IInventory.GetStackInSlot(0);

                if (itemstack == null || !itemstack.IsItemEnchantable())
                {
                    for (int i = 0; i < 3; i++)
                    {
                        EnchantLevels[i] = 0;
                    }
                }
                else
                {
                    NameSeed = Rand.Next();

                    if (!WorldPointer.IsRemote)
                    {
                        int j = 0;

                        for (int k = -1; k <= 1; k++)
                        {
                            for (int i1 = -1; i1 <= 1; i1++)
                            {
                                if (k == 0 && i1 == 0 || !WorldPointer.IsAirBlock(PosX + i1, PosY, PosZ + k) || !WorldPointer.IsAirBlock(PosX + i1, PosY + 1, PosZ + k))
                                {
                                    continue;
                                }

                                if (WorldPointer.GetBlockId(PosX + i1 * 2, PosY, PosZ + k * 2) == Block.BookShelf.BlockID)
                                {
                                    j++;
                                }

                                if (WorldPointer.GetBlockId(PosX + i1 * 2, PosY + 1, PosZ + k * 2) == Block.BookShelf.BlockID)
                                {
                                    j++;
                                }

                                if (i1 == 0 || k == 0)
                                {
                                    continue;
                                }

                                if (WorldPointer.GetBlockId(PosX + i1 * 2, PosY, PosZ + k) == Block.BookShelf.BlockID)
                                {
                                    j++;
                                }

                                if (WorldPointer.GetBlockId(PosX + i1 * 2, PosY + 1, PosZ + k) == Block.BookShelf.BlockID)
                                {
                                    j++;
                                }

                                if (WorldPointer.GetBlockId(PosX + i1, PosY, PosZ + k * 2) == Block.BookShelf.BlockID)
                                {
                                    j++;
                                }

                                if (WorldPointer.GetBlockId(PosX + i1, PosY + 1, PosZ + k * 2) == Block.BookShelf.BlockID)
                                {
                                    j++;
                                }
                            }
                        }

                        for (int l = 0; l < 3; l++)
                        {
                            EnchantLevels[l] = EnchantmentHelper.CalcItemStackEnchantability(Rand, l, j, itemstack);
                        }

                        UpdateCraftingResults();
                    }
                }
            }
        }