Пример #1
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();
                    }
                }
            }
        }