Описание
# Trade Everything
> **Built for [Dungeon Train](https://modrinth.com/mod/dungeon-train) — works anywhere.**
> Trade Everything was created as a companion to the [Dungeon Train](https://modrinth.com/mod/dungeon-train) mod, where an endless procedurally-generated train needs an economy to match. But it has **no dependency on Dungeon Train** — drop it into any modpack or vanilla-plus world and every villager instantly becomes a universal merchant.
---
## What it does
Every villager (and wandering trader) gains one extra trade at the **top** of its trade list: a **Trade Anything** slot.
Put **any item in the world** into it, and the villager offers you a fair exchange for goods it actually wants — coal, wheat, paper, iron, emeralds, whatever that villager buys. No more hoarding chests full of junk you can't sell. That stack of cobblestone, that half-broken enchanted pickaxe, that pile of rotten flesh — it all has a price now.
Prices aren't arbitrary. Every item is valued by what it's genuinely **worth**:
- **Rarity** sets a baseline (common items ≈ 16 to the emerald).
- **Crafting & smithing recipes** are solved recursively — a diamond pickaxe is worth its diamonds and sticks; a netherite sword is worth the diamond sword plus the ingot and template that upgraded it.
- **Durability** matters — a nearly-broken tool is worth a fraction of a pristine one, scaling smoothly back up to full value.
- **Enchantments** add real value — each level roughly doubles the premium, so a Sharpness V book is worth far more than a Sharpness I.
High-value items pay out in **emeralds**, and truly premium items (enchanted netherite, god-roll gear) pay in **emerald blocks**.
---
## How to use it
1. **Right-click any villager** to open its trades.
2. The top row is the **Trade Anything** slot — it shows a chest labelled *"Trade Anything"* until you use it.
3. **Drop any item** into the left payment slot. The offer instantly rewrites itself to show exactly how many of that item the villager wants and what it'll pay.
4. **Take the trade** like any normal villager trade.
That's it. No commands, no config required, no crafting anything. It just works the moment the mod is installed.
### Spending emerald blocks
If you're carrying emerald blocks and buy something priced in emeralds, the mod **automatically breaks exactly enough blocks** to cover the cost and hands back the change in emeralds — so your block-stack currency spends seamlessly on any villager trade.
### Selling gear back
Villagers will **buy back their own stock** at a small margin below what they sell it for, so you can return that armor you didn't need. Discounts (from curing a zombie villager or Hero of the Village) never turn this into an exploit — the buy-back always tracks the live price.
---
## Capabilities & design
- **Works on villagers and wandering traders** (wandering traders configurable).
- **Exact-item matching** — enchanted, damaged, named, or trimmed items are each valued and matched precisely as their own distinct good.
- **No profession XP, no restocking side effects** — the Trade Anything slot never levels the villager or interferes with its normal trades. Its offers are never saved to the villager, so nothing bloats your world file.
- **Fair, exploit-resistant economy** — villagers won't buy emeralds or the commodities they already purchase (those belong to their real trades), and payout rates carry a merchant margin so you can't spin trades in a circle for free profit.
- **Fully server-side** — install it on a dedicated server and every connected vanilla client gets the feature automatically. In singleplayer the integrated server covers it. (Listed as *client: unsupported / server: required* — that's why: clients need nothing.)
- **Multiloader** — Fabric, Forge, and NeoForge, Minecraft 1.21.1.
## Configuration
A config file is written on first launch at `config/tradeeverything.json`. Everything is tunable:
| Setting | What it controls |
|---|---|
| `rarity_values_sixteenths` | Base value per rarity tier (in 1/16-emerald units) |
| `item_overrides_sixteenths` | Per-item value overrides (by item id) |
| `result_multiplier` | Payout rate — the villager's margin (default 0.75) |
| `max_cost_count` / `max_result_count` | Trade size caps |
| `derive_values_from_recipes` | Toggle recipe/smithing-based valuation |
| `enchantment_value_per_level_sixteenths` | How much each enchantment level is worth |
| `allow_undervalued_trades` | Whether near-worthless items can still be sold |
| `enable_wandering_trader` | Give wandering traders the slot too |
Values are in **sixteenths of an emerald**: `16` = one emerald, `1` = one-sixteenth (so 16 of that item buys one emerald's worth).
## For mod developers
Trade Everything exposes a small Java API (`games.brennan.tradeeverything.api.TradeEverythingApi`) so other mods can plug into the economy without a Trade Everything update:
- **`registerValueProvider`** — supply custom values for your own items (Dungeon Train uses this to price its narrative books).
- **`setItemOverride`** — override any item's value at runtime.
- **`registerBuyItemSelector`** — control what a given villager pays out.
- **`getValueSixteenths`** / **`config()`** / **`reload()`** — read and refresh the current valuation.
---
## Compatibility
- **Minecraft:** 1.21.1
- **Loaders:** Fabric · Forge · NeoForge
- **Dungeon Train:** designed alongside it, deeper synergy when both are installed, but entirely optional.
- Third-party mods that listen for villager trade events will see the synthetic trades — this is intentional and harmless.
## License
PolyForm Shield 1.0.0 — see the [licence](https://polyformproject.org/licenses/shield/1.0.0/).
*Source & issues: [github.com/bh679/tradeeverything-mc](https://github.com/bh679/tradeeverything-mc)*