ItemMarket — 游戏内物品买卖市场(Fabric)
EN
ItemMarket 添加了一个简单、快速的游戏内市场图形用户界面(GUI),玩家可以使用内置的按世界保存的金币余额来购买和出售物品。价格完全可以通过简单的 JSON 文件进行配置,并且该模组提供了一个小型的 Java/Fabric API,允许其他模组读取/写入玩家余额并监听市场交易。
制作人员: 由 TNTStudios 开发 —— 网站:TNTStudios.space —— 社交媒体:@TNTStudiosn
功能特性
EN
- ✅ 客户端 GUI 市场(默认按 M 键打开)
- ✅ 每次购买 1 件物品(服务器权威验证)
- ✅ 出售库存中的 1 件或全部某类物品
- ✅ 内置经济系统,按世界存储(PersistentState)
- ✅ 通过 JSON 配置价格(每个价格一个文件,内部包含物品列表)
- ✅ 加入时同步客户端价格
- ✅ 公共 API (
ItemMarketAPI) 用于获取/增加/减少金币
- ✅ 交易成功时的回调事件 (
MarketTransactionCallback)
依赖要求
EN
- Minecraft: 基于 Fabric 的环境(客户端 + 服务端)
- Fabric Loader + Fabric API
- 需在服务端和客户端均安装(因为市场是一个与服务器通信的客户端 GUI)
如果仅在服务端安装,玩家将无法看到 GUI/快捷键,也无法使用市场。
安装方法
EN
- 为你的 Minecraft 版本安装 Fabric Loader 和 Fabric API。
- 将 ItemMarket
.jar 放入:
- 启动一次游戏/服务器以生成配置文件文件夹。
使用方法(玩家)
EN
- 加入世界/服务器。
- 按 M 键打开市场。
- 你可以在 选项 → 控制 中重新绑定按键(搜索 “ItemMarket”)。
- 选择:
- 购买(绿色)—— 使用你的金币购买物品
- 出售(金色)—— 出售你库存中的物品
- 滚动物品列表并点击某个物品:
- 购买: 确认购买 1 件
- 出售: 选择 出售 1 件 或 出售全部
- 你的余额显示在屏幕右上角。
当你购买时会发生什么?
EN
- 服务器检查该物品配置的购买价格。
- 如果你的金币足够,扣除金币并给予你 1 件 物品。
当你出售时会发生什么?
EN
- 服务器检查该物品配置的出售价格。
- 如果你有该物品:
- 出售 1 件: 移除 1 件物品,增加金币
- 出售全部: 移除所有该物品的堆叠,根据总数量增加金币
经济系统(金币如何保存)
EN
- 余额使用
PersistentState 存储在服务端,按世界隔离。
- 数据键名:
itemmarket_economy
- 每位玩家的 UUID 对应一个 Long 类型的金钱值。
- 新玩家初始拥有 0 枚金币,除非有其他模组(或自定义代码)通过 API 添加金币。
价格配置(JSON)
ItemMarket 从以下位置读取价格:
config/ItemMarket/compra/
config/ItemMarket/venta/
EN
compra/ = 购买价格(玩家支付金币以获得物品)
venta/ = 出售价格(玩家出售物品获得金币)
文件命名规则
EN
每个 .json 文件名必须是一个数字,该数字即为价格。
示例:
config/ItemMarket/compra/100.json → 购买价格 = 100 金币
config/ItemMarket/venta/25.json → 出售价格 = 25 金币
如果文件名不是纯数字,将被跳过。
重要提示:价格 0 作为文件名是有效的(0.json),但在游戏中不起作用,因为交易要求 price > 0。请使用 1+。
JSON 格式
EN
每个文件都是一个物品 ID(字符串)的 JSON 数组:
[
"minecraft:diamond",
"minecraft:emerald",
"minecraft:iron_ingot"
]
购买配置示例
EN
创建:
config/ItemMarket/compra/250.json
[
"minecraft:diamond",
"minecraft:netherite_ingot"
]
结果:
- 购买 钻石 花费 250
- 购买 下界合金锭 花费 250
出售配置示例
EN
创建:
config/ItemMarket/venta/50.json
[
"minecraft:iron_ingot",
"minecraft:gold_ingot"
]
结果:
- 出售 铁锭 每件获得 50
- 出售 金锭 每件获得 50
如果一个物品出现在多个文件中怎么办?
EN
每个物品在内存中只能有一个价格(映射关系会因物品而覆盖)。如果你将相同的物品放入多个价格文件中,最后加载的文件将生效——文件顺序可能取决于操作系统,因此不要依赖它。请确保每个文件夹内的列表唯一。
如果物品 ID 错误或模组缺失怎么办?
EN
- 无效 ID 会被跳过,并记录日志消息。
- 注册表中找不到的物品(通常是“缺少模组”)会被跳过。
我需要重启才能应用更改吗?
EN
是的。价格在启动时由 MarketConfig.init() 加载。目前还没有内置的热重载命令,所以你应该:
- 重启服务器,或者
- 重启客户端并重新加入(加入时会同步价格)
开发者 API(Java/Fabric API)
ItemMarket 提供了面向其他 Fabric 模组的 Java API。
EN
这不是 HTTP/REST API。你需要通过将 ItemMarket 添加为依赖项并调用其类来“连接”。
API:读取/写入余额
类:com.TNTStudios.itemmarket.api.ItemMarketAPI
方法:
getBalance(ServerPlayerEntity player) -> long
addBalance(ServerPlayerEntity player, long amount) -> long
removeBalance(ServerPlayerEntity player, long amount) -> boolean
EN(示例:玩家在加入时获得金币)
import com.TNTStudios.itemmarket.api.ItemMarketAPI;
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
public class MyMod {
public static void init() {
ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> {
var player = handler.getPlayer();
// 首次加入时给予 100 金币(简单示例)
ItemMarketAPI.addBalance(player, 100);
});
}
}
备注(EN)
addBalance() 和 removeBalance() 如果玩家打开了市场界面,还会通过打开/更新市场屏幕来触发 UI 同步(通过 MarketNetwork.openMarketForPlayer)。
- 当玩家资金不足时,
removeBalance() 返回 false。
事件:交易回调
接口:com.TNTStudios.itemmarket.api.MarketTransactionCallback
仅在交易 成功 时调用。
签名:
void onTransaction(ServerPlayerEntity player, Item item, int count, long totalPrice, boolean isBuy);
EN(示例:记录每笔交易)
import com.TNTStudios.itemmarket.api.MarketTransactionCallback;
public class MyMod {
public static void init() {
MarketTransactionCallback.EVENT.register((player, item, count, totalPrice, isBuy) -> {
String type = isBuy ? "BUY" : "SELL";
System.out.println("[MyMod] " + player.getName().getString() +
" " + type + " " + count + "x " + item.getName().getString() +
" for " + totalPrice + " coins");
});
}
}
网络与安全(内部工作原理)
EN
- 玩家加入时,服务器发送:
- 所有 BUY 价格
- 所有 SELL 价格
到客户端(价格缓存)。
- 当玩家按下 M 键时,客户端请求打开市场。
- 服务器响应玩家的当前 余额,然后客户端打开 GUI。
- 当玩家点击物品时:
- 客户端发送交易请求(
buy/sell、物品 ID、sellAll 标志)
- 服务器验证所有内容(价格、余额、库存)
- 服务器应用更改并更新客户端 GUI
EN
服务器具有权威性,因此客户端无法通过数据包“伪造”价格或余额。
故障排除
EN
市场打不开(按 M 无反应)
- 确保模组已安装在 客户端
- 检查按键冲突并在控制设置中重新绑定
- 确保已安装 Fabric API
物品显示但无法购买/出售
- 检查 JSON 文件名是否为数字(例如
100.json)
- 确保物品 ID 正确
- 确保价格为 >= 1
部分物品缺失
- 该物品所属的模组可能未安装在服务器上
- 模组在 ID 缺失时会记录 “Item not found”
致谢与链接
EN
- 由 TNTStudios 开发
- 网站:TNTStudios.space
- 社交媒体:@TNTStudiosn
ItemMarket — Minecraft 内购/售物品的市场 (Fabric)
ES
ItemMarket 添加了一个简单快捷的游戏内 GUI 市场,让玩家可以使用保存在世界中的金币余额 购买 和 出售 物品。价格通过非常容易配置的 JSON 文件进行设置,并且模组包含一个 Java/Fabric API,供其他模组读取/写入余额并监听交易。
Créditos: 由 TNTStudios 开发 — 网站:TNTStudios.space — 社交媒体:@TNTStudiosn
特性
ES
- ✅ 客户端 GUI 市场(默认按 M 打开)
- ✅ 每次交易购买 1 个物品(服务器端验证)
- ✅ 出售 1 个或背包中的 全部 某类物品
- ✅ 内置经济系统,按世界保存(PersistentState)
- ✅ 通过 JSON 配置价格(文件 = 价格,列表 = 物品)
- ✅ 加入时同步价格
- ✅ 公共 API (
ItemMarketAPI) 用于查询/增加/减少金币
- ✅ 交易成功时的事件 (
MarketTransactionCallback)
要求
ES
- Minecraft: 基于 Fabric 的环境(客户端 + 服务器)
- Fabric Loader + Fabric API
- 必须在 服务器和客户端 上安装(因为 GUI 在客户端,并与服务器通信)
如果仅安装在服务器上,玩家将没有 GUI/按键,也无法使用市场。
安装
ES
- 为你的 Minecraft 版本安装 Fabric Loader 和 Fabric API。
- 将 ItemMarket 的
.jar 文件放入:
- 启动游戏/服务器一次以创建配置文件夹。
如何使用(玩家)
ES
- 进入世界/服务器。
- 按 M 打开市场。
- 你可以在 选项 → 控制 中更改按键(搜索 “ItemMarket”)。
- 选择:
- 购买(绿色)— 使用你的金币购买
- 出售(金色)— 出售背包中的物品
- 滚动列表并点击一个物品:
- 购买: 确认以购买 1 个
- 出售: 选择 出售 1 或 出售全部
- 你的余额显示在右上角。
购买时会发生什么?
ES
- 服务器检查配置的 购买价格。
- 如果你有足够的金币,扣除余额并给予你 1 个物品。
出售时会发生什么?
ES
- 服务器检查配置的 出售价格。
- 如果你有该物品:
- 出售 1: 移除 1 个并增加金币
- 出售全部: 移除该物品的所有堆叠并按总数量增加金币
经济系统(金币如何保存)
ES
- 余额使用
PersistentState 保存在 服务器 上,按世界存储。
- 保存键名:
itemmarket_economy
- 金钱作为 Long 类型按玩家 UUID 保存。
- 新玩家默认拥有 0 金币,除非其他模组(或你的代码)通过 API 为其添加金币。
价格配置(JSON)
ItemMarket 从以下位置读取价格:
config/ItemMarket/compra/
config/ItemMarket/venta/
ES
compra/ = 购买 价格(支付金币以获得物品)
venta/ = 出售 价格(出售时获得金币)
文件名规则
ES
每个 .json 必须命名为一个 数字,该数字即为 价格。
示例:
config/ItemMarket/compra/100.json → 购买价格 = 100 金币
config/ItemMarket/venta/25.json → 出售价格 = 25 金币
如果名称不完全为数字,则会被忽略。
Importante: 0.json existe, pero no funcionará en juego porque las transacciones requieren price > 0. Usa 1+.
Formato del JSON
ES
Cada archivo es un arreglo JSON de IDs de ítems (strings):
[
"minecraft:diamond",
"minecraft:emerald",
"minecraft:iron_ingot"
]
Ejemplo de compra
ES
Crear:
config/ItemMarket/compra/250.json
[
"minecraft:diamond",
"minecraft:netherite_ingot"
]
Resultado:
- Comprar diamond cuesta 250
- Comprar netherite_ingot cuesta 250
Ejemplo de venta
ES
Crear:
config/ItemMarket/venta/50.json
[
"minecraft:iron_ingot",
"minecraft:gold_ingot"
]
Resultado:
- Vender iron_ingot da 50 por ítem
- Vender gold_ingot da 50 por ítem
¿Qué pasa si un ítem está en varios archivos?
ES
Cada ítem solo puede tener un precio en memoria (los mapas sobreescriben por ítem). Si repites un ítem en varios archivos, “gana” el último que se cargue — el orden puede variar por sistema operativo. Mejor no repetir ítems.
¿Y si el ID está mal o falta un mod?
ES
- IDs inválidos se ignoran (con mensaje en logs).
- Ítems que no existen en el registro (normalmente “falta el mod”) se ignoran.
¿Debo reiniciar para aplicar cambios?
ES
Sí. Los precios se cargan al iniciar con MarketConfig.init(). No hay recarga en vivo por comando (todavía), así que:
- Reinicia el servidor, o
- Reinicia el cliente y vuelve a entrar (la sincronización ocurre al entrar)
API para Desarrolladores (Java/Fabric)
ItemMarket incluye una API Java para otros mods Fabric.
ES
Esto no es una API HTTP/REST. Te “conectas” agregando ItemMarket como dependencia y llamando sus clases.
API: Leer/Escribir balance
Clase: com.TNTStudios.itemmarket.api.ItemMarketAPI
Métodos:
getBalance(ServerPlayerEntity player) -> long
addBalance(ServerPlayerEntity player, long amount) -> long
removeBalance(ServerPlayerEntity player, long amount) -> boolean
ES (Ejemplo: dar monedas al entrar)
import com.TNTStudios.itemmarket.api.ItemMarketAPI;
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
public class MiMod {
public static void init() {
ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> {
var player = handler.getPlayer();
ItemMarketAPI.addBalance(player, 100);
});
}
}
Notas (ES)
addBalance() y removeBalance() también sincronizan la UI abriendo/actualizando la pantalla del mercado cuando corresponde.
removeBalance() devuelve false si no hay fondos suficientes.
Evento: Callback de transacción
Interfaz: com.TNTStudios.itemmarket.api.MarketTransactionCallback
Se llama solo si la transacción fue exitosa.
Firma:
void onTransaction(ServerPlayerEntity player, Item item, int count, long totalPrice, boolean isBuy);
ES (Ejemplo: registrar transacciones en consola)
import com.TNTStudios.itemmarket.api.MarketTransactionCallback;
public class MiMod {
public static void init() {
MarketTransactionCallback.EVENT.register((player, item, count, totalPrice, isBuy) -> {
String tipo = isBuy ? "COMPRA" : "VENTA";
System.out.println("[MiMod] " + player.getName().getString() +
" " + tipo + " " + count + "x " + item.getName().getString() +
" por " + totalPrice + " monedas");
});
}
}
Red & Seguridad (Cómo funciona por dentro)
ES
- Al entrar, el servidor envía al cliente:
- precios de COMPRA
- precios de VENTA
(cache de precios).
- Al presionar M, el cliente solicita abrir el mercado.
- El servidor responde con el balance, y el cliente abre la GUI.
- Al hacer clic:
- el cliente envía la solicitud (
comprar/vender, id del ítem, sellAll)
- el servidor valida (precio, balance, inventario)
- aplica cambios y actualiza la GUI
ES
El servidor manda, así que el cliente no puede falsificar precios o balances.
Solución de problemas
ES
No abre el mercado (M no hace nada)
- Asegúrate que el mod esté instalado en el cliente
- Revisa conflictos de tecla y cámbiala en Controles
- Verifica que Fabric API esté instalado
Se ven ítems pero no deja comprar/vender
- Revisa que los nombres de JSON sean numéricos (ej.
100.json)
- Revisa IDs correctos
- Asegúrate que el precio sea >= 1
Faltan algunos ítems
- Puede faltar el mod del ítem en el servidor
- El mod imprime “Item no encontrado” en logs cuando falta un ID
Créditos & Links
ES
- Desarrollado por TNTStudios
- Sitio web: TNTStudios.space
- Redes: @TNTStudiosn
ItemMarket — In‑Game Item Buy/Sell Market (Fabric)
EN
ItemMarket adds a simple, fast in‑game market GUI where players can buy and sell items using a built‑in coin balance saved per-world. Prices are fully configurable via easy JSON files, and the mod exposes a small Java/Fabric API so other mods can read/write player balances and listen to market transactions.
Credits: Developed by TNTStudios — Website: TNTStudios.space — Socials: @TNTStudiosn
Features
EN
- ✅ Client GUI market (open with M by default)
- ✅ Buy 1 item at a time (server-authoritative)
- ✅ Sell 1 or all of an item in your inventory
- ✅ Built-in economy stored per world (PersistentState)
- ✅ Price configuration via JSON (per-price file, item list inside)
- ✅ Client price sync on join
- ✅ Public API (
ItemMarketAPI) to get/add/remove coins
- ✅ Event callback (
MarketTransactionCallback) when a transaction succeeds
Requirements
EN
- Minecraft: Fabric-based environment (client + server)
- Fabric Loader + Fabric API
- Installed on both server and client (because the market is a client GUI that talks to the server)
If you only install it on the server, players won’t have the GUI/keybind and won’t be able to use the market.
Installation
EN
- Install Fabric Loader and Fabric API for your Minecraft version.
- Drop the ItemMarket
.jar into:
- Client:
mods/
- Server:
mods/
- Launch the game/server once to generate the config folders.
How to Use (Players)
EN
- Join the world/server.
- Press M to open the market.
- You can rebind the key in Options → Controls (search for “ItemMarket”).
- Choose:
- Buy (green) — buy items using your coins
- Sell (gold) — sell items from your inventory
- Scroll the item list and click an item:
- Buy: confirm to purchase 1
- Sell: choose Sell 1 or Sell All
- Your balance is shown at the top-right of the screen.
What happens when you buy?
EN
- The server checks the configured buy price for that item.
- If you have enough coins, it subtracts coins and gives you 1 item.
What happens when you sell?
EN
- The server checks the configured sell price for that item.
- If you have the item:
- Sell 1: removes 1 item, adds coins
- Sell All: removes all stacks of that item, adds coins for total quantity
Economy System (How coins are saved)
EN
- Balances are stored on the server using
PersistentState, per world.
- Data key:
itemmarket_economy
- Money is stored as a Long per player UUID.
- New players start with 0 coins unless another mod (or your custom code) adds coins via the API.
Price Configuration (JSON)
ItemMarket reads prices from:
config/ItemMarket/compra/
config/ItemMarket/venta/
EN
compra/ = BUY prices (player pays coins to get items)
venta/ = SELL prices (player receives coins to sell items)
File naming rule
EN
Each .json filename must be a number, and that number is the price.
Examples:
config/ItemMarket/compra/100.json → buy price = 100 coins
config/ItemMarket/venta/25.json → sell price = 25 coins
If the filename is not purely numeric, it will be skipped.
Important: price 0 is valid as a filename (0.json) but will not work in-game because transactions require price > 0. Use 1+.
JSON format
EN
Each file is a JSON array of item IDs (strings):
[
"minecraft:diamond",
"minecraft:emerald",
"minecraft:iron_ingot"
]
Buy configuration example
EN
Create:
config/ItemMarket/compra/250.json
[
"minecraft:diamond",
"minecraft:netherite_ingot"
]
Result:
- Buying a diamond costs 250
- Buying a netherite_ingot costs 250
Sell configuration example
EN
Create:
config/ItemMarket/venta/50.json
[
"minecraft:iron_ingot",
"minecraft:gold_ingot"
]
Result:
- Selling iron_ingot gives 50 per item
- Selling gold_ingot gives 50 per item
What if an item appears in multiple files?
EN
Each item can only have one price in memory (maps overwrite by item). If you put the same item in multiple price files, whichever file is loaded last will win — file ordering may depend on the OS, so don’t rely on it. Keep your lists unique per folder.
What if an item ID is wrong or the mod is missing?
EN
- Invalid IDs are skipped with a log message.
- Items not found in the registry (usually “missing mod”) are skipped.
Do I need to restart to apply changes?
EN
Yes. Prices are loaded at startup by MarketConfig.init(). There is no built-in live reload command yet, so you should:
- Restart the server, or
- Restart the client & rejoin (price sync occurs on join)
Developer API (Java/Fabric API)
ItemMarket provides a Java API intended for other Fabric mods.
EN
This is not an HTTP/REST API. You “connect” by adding ItemMarket as a dependency and calling its classes.
API: Read/Write balance
Class: com.TNTStudios.itemmarket.api.ItemMarketAPI
Methods:
getBalance(ServerPlayerEntity player) -> long
addBalance(ServerPlayerEntity player, long amount) -> long
removeBalance(ServerPlayerEntity player, long amount) -> boolean
EN (Example: Give coins on player join)
import com.TNTStudios.itemmarket.api.ItemMarketAPI;
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
public class MyMod {
public static void init() {
ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> {
var player = handler.getPlayer();
// Give 100 coins on first join (simple example)
ItemMarketAPI.addBalance(player, 100);
});
}
}
Notes (EN)
addBalance() and removeBalance() will also trigger a UI sync by opening/updating the market screen if the player has it open (via MarketNetwork.openMarketForPlayer).
removeBalance() returns false when the player doesn’t have enough funds.
Event: Transaction callback
Interface: com.TNTStudios.itemmarket.api.MarketTransactionCallback
Called only when a transaction succeeds.
Signature:
void onTransaction(ServerPlayerEntity player, Item item, int count, long totalPrice, boolean isBuy);
EN (Example: Log every transaction)
import com.TNTStudios.itemmarket.api.MarketTransactionCallback;
public class MyMod {
public static void init() {
MarketTransactionCallback.EVENT.register((player, item, count, totalPrice, isBuy) -> {
String type = isBuy ? "BUY" : "SELL";
System.out.println("[MyMod] " + player.getName().getString() +
" " + type + " " + count + "x " + item.getName().getString() +
" for " + totalPrice + " coins");
});
}
}
Networking & Security (How it works internally)
EN
- On player join, the server sends:
- all BUY prices
- all SELL prices
to the client (price cache).
- When the player presses M, the client requests the market to open.
- The server responds with the player’s current balance, and the client opens the GUI.
- When the player clicks an item:
- the client sends a transaction request (
buy/sell, item id, sellAll flag)
- the server validates everything (price, balance, inventory)
- the server applies changes and then updates the client GUI
EN
The server is authoritative, so clients cannot “fake” prices or balances via packets.
Troubleshooting
EN
Market doesn’t open (pressing M does nothing)
- Make sure the mod is installed on the client
- Check keybind conflicts and rebind in Controls
- Ensure Fabric API is installed
Items show but can’t buy/sell
- Check your JSON file names are numeric (e.g.
100.json)
- Ensure the item IDs are correct
- Ensure price is >= 1
Some items missing
- The item’s mod may not be installed on the server
- The mod logs “Item not found” when an ID is missing
Credits & Links
EN
- Developed by TNTStudios
- Website: TNTStudios.space
- Socials: @TNTStudiosn
ItemMarket — Mercado In‑Game para Comprar/Vender Ítems (Fabric)
ES
ItemMarket agrega un mercado simple y rápido con GUI dentro del juego para que los jugadores puedan comprar y vender ítems usando un balance de monedas guardado por mundo. Los precios se configuran con archivos JSON muy fáciles, y el mod incluye una API Java/Fabric para que otros mods puedan leer/escribir balances y escuchar transacciones.
Créditos: Desarrollado por TNTStudios — Sitio web: TNTStudios.space — Redes: @TNTStudiosn
Características
ES
- ✅ Mercado con GUI en el cliente (abrir con M por defecto)
- ✅ Comprar 1 ítem por transacción (validación en servidor)
- ✅ Vender 1 o todo de un ítem del inventario
- ✅ Economía integrada guardada por mundo (PersistentState)
- ✅ Configuración de precios por JSON (archivo = precio, lista de ítems dentro)
- ✅ Sincronización de precios al entrar
- ✅ API pública (
ItemMarketAPI) para consultar/sumar/restar monedas
- ✅ Evento (
MarketTransactionCallback) cuando una transacción es exitosa
Requisitos
ES
- Minecraft: entorno basado en Fabric (cliente + servidor)
- Fabric Loader + Fabric API
- Instalado en servidor y cliente (porque la GUI está en el cliente y se comunica con el servidor)
Si lo instalas solo en el servidor, los jugadores no tendrán la GUI/tecla y no podrán usar el mercado.
Instalación
ES
- Instala Fabric Loader y Fabric API para tu versión de Minecraft.
- Coloca el
.jar de ItemMarket en:
- Cliente:
mods/
- Servidor:
mods/
- Inicia el juego/servidor una vez para que se creen las carpetas de configuración.
Cómo usarlo (Jugadores)
ES
- Entra al mundo/servidor.
- Presiona M para abrir el mercado.
- Puedes cambiar la tecla en Opciones → Controles (busca “ItemMarket”).
- Elige:
- Comprar (verde) — compras usando tus monedas
- Vender (dorado) — vendes ítems del inventario
- Desplázate por la lista y haz clic en un ítem:
- Comprar: confirmar para comprar 1
- Vender: elegir Vender 1 o Vender todo
- Tu balance aparece arriba a la derecha.
¿Qué pasa al comprar?
ES
- El servidor revisa el precio de compra configurado.
- Si tienes monedas suficientes, descuenta y te entrega 1 ítem.
¿Qué pasa al vender?
ES
- El servidor revisa el precio de venta configurado.
- Si tienes el ítem:
- Vender 1: quita 1 y suma monedas
- Vender todo: quita todas las stacks de ese ítem y suma monedas por la cantidad total
Economía (Cómo se guardan las monedas)
ES
- Los balances se guardan en el servidor usando
PersistentState, por mundo.
- Clave de guardado:
itemmarket_economy
- El dinero se guarda como Long por UUID del jugador.
- Los jugadores nuevos empiezan con 0 monedas a menos que otro mod (o tu código) les agregue monedas con la API.
Configuración de Precios (JSON)
ItemMarket lee precios desde:
config/ItemMarket/compra/
config/ItemMarket/venta/
ES
compra/ = precios de COMPRA (pagas monedas para obtener ítems)
venta/ = precios de VENTA (recibes monedas al vender)
Regla de nombres de archivo
ES
Cada .json debe llamarse con un número, y ese número es el precio.
Ejemplos:
config/ItemMarket/compra/100.json → precio de compra = 100 monedas
config/ItemMarket/venta/25.json → precio de venta = 25 monedas
Si el nombre no es 100% numérico, se ignora.
Importante: 0.json existe, pero no funcionará en juego porque las transacciones requieren price > 0. Usa 1+.
Formato del JSON
ES
Cada archivo es un arreglo JSON de IDs de ítems (strings):
[
"minecraft:diamond",
"minecraft:emerald",
"minecraft:iron_ingot"
]
Ejemplo de compra
ES
Crear:
config/ItemMarket/compra/250.json
[
"minecraft:diamond",
"minecraft:netherite_ingot"
]
Resultado:
- Comprar diamond cuesta 250
- Comprar netherite_ingot cuesta 250
Ejemplo de venta
ES
Crear:
config/ItemMarket/venta/50.json
[
"minecraft:iron_ingot",
"minecraft:gold_ingot"
]
Resultado:
- Vender iron_ingot da 50 por ítem
- Vender gold_ingot da 50 por ítem
¿Qué pasa si un ítem está en varios archivos?
ES
Cada ítem solo puede tener un precio en memoria (los mapas sobreescriben por ítem). Si repites un ítem en varios archivos, “gana” el último que se cargue — el orden puede variar por sistema operativo. Mejor no repetir ítems.
¿Y si el ID está mal o falta un mod?
ES
- IDs inválidos se ignoran (con mensaje en logs).
- Ítems que no existen en el registro (normalmente “falta el mod”) se ignoran.
¿Debo reiniciar para aplicar cambios?
ES
Sí. Los precios se cargan al iniciar con MarketConfig.init(). No hay recarga en vivo por comando (todavía), así que:
- Reinicia el servidor, o
- Reinicia el cliente y vuelve a entrar (la sincronización ocurre al entrar)
API para Desarrolladores (Java/Fabric)
ItemMarket incluye una API Java para otros mods Fabric.
ES
Esto no es una API HTTP/REST. Te “conectas” agregando ItemMarket como dependencia y llamando sus clases.
API: Leer/Escribir balance
Clase: com.TNTStudios.itemmarket.api.ItemMarketAPI
Métodos:
getBalance(ServerPlayerEntity player) -> long
addBalance(ServerPlayerEntity player, long amount) -> long
removeBalance(ServerPlayerEntity player, long amount) -> boolean
ES (Ejemplo: dar monedas al entrar)
import com.TNTStudios.itemmarket.api.ItemMarketAPI;
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
public class MiMod {
public static void init() {
ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> {
var player = handler.getPlayer();
ItemMarketAPI.addBalance(player, 100);
});
}
}
Notas (ES)
addBalance() y removeBalance() también sincronizan la UI abriendo/actualizando la pantalla del mercado cuando corresponde.
removeBalance() devuelve false si no hay fondos suficientes.
Evento: Callback de transacción
Interfaz: com.TNTStudios.itemmarket.api.MarketTransactionCallback
Se llama solo si la transacción fue exitosa.
Firma:
void onTransaction(ServerPlayerEntity player, Item item, int count, long totalPrice, boolean isBuy);
ES (Ejemplo: registrar transacciones en consola)
import com.TNTStudios.itemmarket.api.MarketTransactionCallback;
public class MiMod {
public static void init() {
MarketTransactionCallback.EVENT.register((player, item, count, totalPrice, isBuy) -> {
String tipo = isBuy ? "COMPRA" : "VENTA";
System.out.println("[MiMod] " + player.getName().getString() +
" " + tipo + " " + count + "x " + item.getName().getString() +
" por " + totalPrice + " monedas");
});
}
}
Red & Seguridad (Cómo funciona por dentro)
ES
- Al entrar, el servidor envía al cliente:
- precios de COMPRA
- precios de VENTA
(cache de precios).
- Al presionar M, el cliente solicita abrir el mercado.
- El servidor responde con el balance, y el cliente abre la GUI.
- Al hacer clic:
- el cliente envía la solicitud (
comprar/vender, id del ítem, sellAll)
- el servidor valida (precio, balance, inventario)
- aplica cambios y actualiza la GUI
ES
El servidor manda, así que el cliente no puede falsificar precios o balances.
Solución de problemas
ES
No abre el mercado (M no hace nada)
- Asegúrate que el mod esté instalado en el cliente
- Revisa conflictos de tecla y cámbiala en Controles
- Verifica que Fabric API esté instalado
Se ven ítems pero no deja comprar/vender
- Revisa que los nombres de JSON sean numéricos (ej.
100.json)
- Revisa IDs correctos
- Asegúrate que el precio sea >= 1
Faltan algunos ítems
- Puede faltar el mod del ítem en el servidor
- El mod imprime “Item no encontrado” en logs cuando falta un ID
Créditos & Links
ES
- Desarrollado por TNTStudios
- Sitio web: TNTStudios.space
- Redes: @TNTStudiosn
评论 0
登录后参与评分
还没有评论,来抢沙发吧