# Smithing/Smelting Interface (MakeX)

## 🔨 Smithing & Smelting Production System

![Smithing Interface](https://runescape.wiki/images/Smithing_interface.png?b6bfc)

### 🚀 Quick Access

The smithing and smelting frameworks are accessed through the skilling property on any BwuScript or SuspendableScript:

```kotlin
class MyScript : SuspendableScript() {
    override suspend fun onLoop() {
        // Access smithing DSL
        val smithing = this.skilling.productionOf<SmithingProduction> {
            input("Iron bar")
            output("Iron sword")
            modifier(SmithingBaseModifier.BASE)
        }
        
        // Access smelting DSL
        val smelting = this.skilling.productionOf<SmeltingProduction> {
            input("Iron ore")
            output("Iron bar")
        }
    }
}
```

### 📚 Available Methods

The framework provides specialized methods for metalworking:

* `productionOf<SmithingProduction>(builder)` - Smithing DSL configuration
* `productionOf<SmeltingProduction>(builder)` - Smelting DSL configuration

### 🎨 DSL Pattern (Recommended)

<details>

<summary>🔨 Smithing Production</summary>

#### Basic Smithing Configuration

```kotlin
val smithing = this.skilling.productionOf<SmithingProduction> {
    input("Iron bar")           // Input material (bar)
    output("Iron sword")        // Output item
    modifier(SmithingBaseModifier.BASE)  // Enhancement level
}
```

#### Smithing Base Modifiers

The smithing system supports different enhancement levels:

```kotlin
enum class SmithingBaseModifier(val display: String, val componentID: Int) {
    BASE("base", 149),          // Standard item
    PLUS_1("+ 1", 161),         // +1 enhancement
    PLUS_2("+ 2", 159),         // +2 enhancement
    PLUS_3("+ 3", 157),         // +3 enhancement
    PLUS_4("+ 4", 155),         // +4 enhancement
    PLUS_5("+ 5", 153),         // +5 enhancement
    BURIAL("burial", 151)       // Burial variant
}
```

#### Smithing Examples

```kotlin
// Basic iron sword
val ironSword = this.skilling.productionOf<SmithingProduction> {
    input("Iron bar")
    output("Iron sword")
    modifier(SmithingBaseModifier.BASE)
}

// Enhanced steel dagger
val steelDagger = this.skilling.productionOf<SmithingProduction> {
    input("Steel bar")
    output("Steel dagger")
    modifier(SmithingBaseModifier.PLUS_3)
}

// Burial armor
val burialPlatebody = this.skilling.productionOf<SmithingProduction> {
    input("Rune bar")
    output("Rune platebody")
    modifier(SmithingBaseModifier.BURIAL)
}
```

#### Smithing Production Results

```kotlin
smithing.produceItem(
    onProgress = { result, current, total, rate, xp ->
        when (result.result) {
            ProductionResult.CREATION_IN_PROGRESS -> {
                println("Smithing: $current/$total items")
            }
            ProductionResult.Smithing.INPUT_NOT_FOUND -> {
                println("Cannot find input bar")
            }
            ProductionResult.Smithing.OUTPUT_NOT_FOUND -> {
                println("Cannot find output item")
            }
            ProductionResult.Smithing.SELECTING_BASE_MODIFIER -> {
                println("Selecting enhancement level")
            }
            ProductionResult.Smithing.SELECTING_BASE_MODIFIER_NOT_SUPPORTED -> {
                println("Enhancement not supported for this item")
            }
            ProductionResult.MISSING_REQUIREMENTS -> {
                println("Missing materials or level requirements")
            }
        }
    },
    onFinished = { totalXp ->
        println("Smithing complete! Total XP: $totalXp")
    }
)
```

</details>

<details>

<summary>🔥 Smelting Production</summary>

#### Basic Smelting Configuration

```kotlin
val smelting = this.skilling.productionOf<SmeltingProduction> {
    input("Iron ore")    // Input ore
    output("Iron bar")   // Output bar
}
```

#### Smelting Examples

```kotlin
// Basic iron smelting
val ironSmelting = this.skilling.productionOf<SmeltingProduction> {
    input("Iron ore")
    output("Iron bar")
}

// Gold smelting
val goldSmelting = this.skilling.productionOf<SmeltingProduction> {
    input("Gold ore")
    output("Gold bar")
}

// Mithril smelting
val mithrilSmelting = this.skilling.productionOf<SmeltingProduction> {
    input("Mithril ore")
    output("Mithril bar")
}
```

#### Smelting Production Results

```kotlin
smelting.produceItem(
    onProgress = { result, current, total, rate, xp ->
        
    },
    onFinished = { totalXp ->
        println("Smelting complete! Total XP: $totalXp")
    }
)
```

</details>

### 🔧 Builder Pattern

For more complex configurations, you can use the builder pattern directly:

```kotlin
// Smithing Builder
val smithingBuilder = SmithingProduction()
    .input("Steel bar")
    .output("Steel sword")
    .modifier(SmithingBaseModifier.PLUS_2)
    .build(this)

// Smelting Builder
val smeltingBuilder = SmeltingProduction()
    .input("Adamant ore")
    .output("Adamant bar")
    .build(this)
```

### 📊 Production Results

The framework provides detailed result information through specialized ProductionResult classes:

#### Smithing Results

* `ProductionResult.Smithing.INPUT_NOT_FOUND` - Input bar not found
* `ProductionResult.Smithing.OUTPUT_NOT_FOUND` - Output item not found
* `ProductionResult.Smithing.SELECTING_BASE_MODIFIER` - Selecting enhancement level
* `ProductionResult.Smithing.SELECTING_BASE_MODIFIER_NOT_SUPPORTED` - Enhancement not supported

#### Common Results

* `ProductionResult.CREATION_IN_PROGRESS` - Production in progress
* `ProductionResult.INTERFACE_ERROR` - Interface interaction error
* `ProductionResult.MISSING_REQUIREMENTS` - Missing materials or level requirements

### 🎯 Production Methods

#### Core Production Method

```kotlin
fun produceItem(
    onFinished: (Double) -> Unit = { _ -> },
    onProgress: (ProductionMessage<ProductionResult>, Int, Int, Int, Double) -> Unit = { _, _, _, _, _ -> }
)
```

#### Capability Check

```kotlin
fun canProduce(): Boolean
```

#### Common Issues

* **"Cannot find input bar/ore"** - Check item names and inventory
* **"Enhancement not supported"** - Some items don't support all enhancement levels
* **"Missing requirements"** - Verify materials and skill levels
* **Interface errors** - Ensure the correct interface is open

#### Debug Tips

```kotlin
// Enable detailed logging
smithing.produceItem(
    onProgress = { message, current, total, rate, xp ->
        println("DEBUG: ${message.message} - Progress: $current/$total")
    }
)
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://kxapi.gitbook.io/kxapi/skilling/smithing-smelting-interface-makex.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
