Skip to content
On this page
Common

KattonVillagerTradeModificationApi

top.katton.api.modcommon/src/main/kotlin/top/katton/api/mod/KattonVillagerTradeModificationApi.kt
Configuration for a single trade to be appended to an existing [TradeSet] via [addVillagerTrade].

VillagerTradeAdditionConfig

VillagerTradeAdditionConfigCommonClass
kotlin
class VillagerTradeAdditionConfig internal constructor( val tradeSet: ResourceKey<TradeSet>, )

Configuration for a single trade to be appended to an existing [TradeSet] via [addVillagerTrade].

Fields map directly to the public VillagerTrade(TradeCost wants, Optional<TradeCost> additionalWants, ItemStackTemplate gives, int maxUses, int xp, float priceMultiplier, ...) constructor on MC 26.1.2 — every value here is plain enough to keep stable across patch releases.

VillagerTradeAdditionConfig.costItemId

VillagerTradeAdditionConfig.costItemIdCommonProperty
kotlin
var costItemId: Identifier?

Item the merchant wants from the player.

VillagerTradeAdditionConfig.costBItemId

VillagerTradeAdditionConfig.costBItemIdCommonProperty
kotlin
var costBItemId: Identifier?

Optional secondary cost.

VillagerTradeAdditionConfig.resultItemId

VillagerTradeAdditionConfig.resultItemIdCommonProperty
kotlin
var resultItemId: Identifier?

Item the merchant gives back.

VillagerTradeAdditionConfig.maxUses

VillagerTradeAdditionConfig.maxUsesCommonProperty
kotlin
var maxUses: Int

Maximum trade uses (vanilla farmer level 1 emerald-bread = 16).

VillagerTradeAdditionConfig.xp

VillagerTradeAdditionConfig.xpCommonProperty
kotlin
var xp: Int

Villager XP awarded per trade.

VillagerTradeAdditionConfig.priceMultiplier

VillagerTradeAdditionConfig.priceMultiplierCommonProperty
kotlin
var priceMultiplier: Float

Vanilla price multiplier (0.05 default; matches farmer baselines).

addVillagerTrade

addVillagerTradeCommonFunction
kotlin
@ApiStatus.Experimental
@ApiStatus.Experimental fun addVillagerTrade(tradeSetKey: String, configure: VillagerTradeAdditionConfig.() -> Unit): Boolean

Appends a new trade entry to an existing villager / wandering trader [TradeSet].

tradeSetKey is a registry id from minecraft:trade_set, e.g. "minecraft:farmer/level_1" or "minecraft:wandering_trader/buying".

The mutation is staged through [VillagerTradeManager] and flushed during the standard reload cycle (after script execution, on the server thread). Calling this outside /katton reload is safe — the change is not visible until the server applies pending datapack mutations.

Returns false and logs a warning when:

  • the server is offline,
  • the trade-set id cannot be parsed,
  • the configuration is missing required fields (cost / result).

addVillagerTrade

addVillagerTradeCommonFunction
kotlin
@ApiStatus.Experimental
@ApiStatus.Experimental fun addVillagerTrade(tradeSetId: Identifier, configure: VillagerTradeAdditionConfig.() -> Unit): Boolean

Identifier overload of [addVillagerTrade].