? Player Carpet Extension (PlayerCarpetEx)
一款强大的 Minecraft Carpet Mod 扩展模组,赋予服务器管理员完全控制玩家物品栏的权限。

? 概述
Player Carpet Extension 是一款基于 Fabric 的服务端模组,它通过先进的玩家物品栏管理工具扩展了 Carpet Mod 的功能。本模组专为服务器管理员、SMP 运营者和地图制作者设计,提供了两个核心功能,彻底改变了你与服务器中玩家物品栏交互的方式。

这个模组能做什么?
本模组为你的 Minecraft 服务器添加了两大系统:
-
远程物品栏查看与管理 — 以完整的 GUI 界面打开任何玩家的物品栏,并支持双向同步。你在查看器中进行的任何更改都会立即应用到目标玩家的物品栏中,反之亦然。你还可以使用命令在任何玩家的物品栏槽位中给予、移除、交换、设置、计数、整理和丢弃物品。
-
自动切换快捷栏系统 — 当选中的快捷栏槽位耗尽时,系统会自动为玩家补充快捷栏。系统会从下一个可用的快捷栏槽位中提取物品;如果整个快捷栏都为空,则从主物品栏中提取。当所有物品都耗尽时,主物品栏将被锁定,以防止在提供新物品之前进行外部修改。
✨ 功能特性
? 物品栏 GUI 查看器
在游戏客户端中直接打开任何玩家物品栏的可视化表示。查看器显示一个 54 格(9×6)的容器,其布局经过精心编排,与玩家实际物品栏的结构相匹配。
GUI 布局结构:
容器视图使用装饰性玻璃板划分为清晰标记的区域:
| 行 |
槽位 |
内容 |
描述 |
| 第 0 行 |
0–8 |
副手 + 护甲 + 玻璃 |
槽位 0 = 副手,槽位 2 = 头盔,槽位 3 = 胸甲,槽位 4 = 护腿,槽位 5 = 靴子。蓝色玻璃板填充装饰位置(槽位 1, 6, 7, 8)。 |
| 第 1 行 |
9–17 |
快捷栏 |
玩家的快捷栏槽位 1 至 9,按顺序显示。 |
| 第 2 行 |
18–26 |
分隔符 |
灰色玻璃板在快捷栏/护甲区域与主物品栏之间创建视觉分隔。 |
| 第 3 行 |
27–35 |
主物品栏(第一行) |
主物品栏槽位 9–17。 |
| 第 4 行 |
36–44 |
主物品栏(第二行) |
主物品栏槽位 18–26。 |
| 第 5 行 |
45–53 |
主物品栏(第三行) |
主物品栏槽位 27–35。 |
双向同步:
- 查看器物品栏每 10 刻(0.5 秒)同步一次到目标玩家的物品栏,确保即使目标玩家移动物品,你也能始终看到最新状态。
- 当你在查看器中修改物品(拿起、放置、交换)时,这些更改会立即推送到目标玩家的物品栏。
syncing 标志用于防止初始化和修改期间的无限递归同步循环。
- 玻璃板分隔符在初始化期间强制执行,并在同步过程中保持不变。
? 自动切换快捷栏
自动切换系统持续监控玩家选中的快捷栏槽位,并在该槽位变空时自动为其补充。这非常适合自动化农场、PvP 服务器或任何需要持续物品供应的场景。

自动切换逻辑工作原理:
- 快捷栏检查 — 当选中的快捷栏槽位为空时,系统扫描剩余的快捷栏槽位(环绕搜索),寻找最近的可用物品。如果找到,会将该物品移动到选中槽位并通知玩家。
- 从物品栏提取 — 如果整个快捷栏都为空,系统会在主物品栏(槽位 9–35)中搜索任何物品,并将其拉到当前选中的快捷栏槽位。
- 物品栏锁定 — 当快捷栏和主物品栏的所有槽位完全为空时,系统锁定主物品栏。在锁定期间,外部尝试向主物品栏添加物品(来自发射器、漏斗或其他机制)的行为将被阻止。只能向快捷栏添加物品。
- 自动解锁 — 如果在锁定的物品栏中检测到物品,锁定将自动解除,恢复正常操作。
? 安装指南
依赖项
| 依赖项 |
最低版本 |
用途 |
| Minecraft |
1.20.4 |
目标游戏版本 |
| Fabric Loader |
0.15.0+ |
模组加载器 |
| Fabric API |
1.20.4 最新版 |
API 框架 |
| Carpet Mod |
1.4.128+ |
必需的父级模组 |
| Java |
17+ |
运行环境 |
步骤
- 安装 Fabric Loader — 下载并安装适用于 Minecraft 1.20.4 的 Fabric Loader。
- 安装 Fabric API — 下载适用于 Minecraft 1.20.4 的 Fabric API 并将其放入你的
mods/ 文件夹中。
- 安装 Carpet Mod — 下载 Carpet Mod 版本 1.4.128 或更高版本,并将其放入你的
mods/ 文件夹中。
- 安装 PlayerCarpetEx — 下载
PlayerCarpetEx-1.3.0.jar 文件并将其放入服务器的 mods/ 文件夹中。
- 重启服务器 — 重启 Minecraft 服务器以加载所有模组。
验证安装
服务器启动后,你应该看到以下日志消息:
[PlayerCarpetEx] Player Carpet Extension initialized!
[PlayerCarpetEx] Player Carpet Extension: game started.
[PlayerCarpetEx] Player Carpet Extension: server loaded.
你也可以运行 /version 或查看 Carpet Mod 的规则列表 —— PlayerCarpetEx 会作为已注册的 Carpet Extension 出现,版本号为 1.3.0。
?️ 命令
所有命令都需要 权限等级 2(操作员状态)。基础命令是 /playerex。
注意: 在以下所有命令中,将 <player> 替换为实际的玩家名称。
物品栏管理
/playerex <玩家> inventory(或 /playerex <玩家> inventory view)
打开一个可视化的 GUI 查看器,显示目标玩家的完整物品栏(包括副手、盔甲栏、快捷栏和主物品栏)。该 GUI 使用 9×6 的容器布局,并以玻璃板作为分隔符,以实现清晰的分类。
/playerex Steve inventory
/playerex <玩家> inventory list
直接在聊天栏中输出目标玩家物品栏内容的详细文本列表。按快捷栏和主物品栏区域组织,显示每个槽位索引、物品名称和数量。
/playerex Steve inventory list
示例输出:
[CarpetEx] 库存信息:Steve
[CarpetEx] --- 快捷栏(槽位 0-8) ---
[CarpetEx] [0] 钻石剑 x1
[CarpetEx] [1] 空
[CarpetEx] [2] 金苹果 x16
[CarpetEx] --- 主背包(槽位 9-35) ---
[CarpetEx] [9] 橡木木板 x64
[CarpetEx] [10] 圆石 x32
/playerex <玩家> inventory info <槽位>
显示特定物品栏槽位的详细信息,包括物品名称、当前数量以及最大堆叠大小。
/playerex <玩家> inventory give <槽位> <物品> [数量]
将指定物品放入目标玩家的背包中,位置为给定的槽位编号。如果未指定数量,则默认为 1。数量范围可在 1 到 64 之间。
/playerex Steve inventory give 0 minecraft:diamond_sword 1
/playerex Steve inventory give 9 minecraft:golden_apple 64
/playerex <玩家> inventory remove <槽位> [数量]
从目标玩家的指定槽位中移除物品。如果指定的数量大于或等于当前堆叠的大小,则清空该槽位。默认移除 1 个物品。
/playerex Steve inventory remove 9 32
/playerex Steve inventory remove 0
/playerex <玩家> inventory clear
完全清空目标玩家的整个物品栏(快捷栏、主物品栏、护甲栏和副手)。请谨慎使用。
/playerex Steve inventory clear
/playerex <玩家> inventory swap <槽位1> <槽位2>
替换目标玩家物品栏中两个格子内的内容。两个格子的编号都必须在 0 到 40 之间(40 号格子 = 副手)。
/playerex Steve inventory swap 0 9
/playerex Steve inventory swap 36 37
/playerex <玩家> inventory set <格子> <物品> [数量]
将特定槽位的内容设置为指定的物品和数量,替换掉之前存在的任何内容。类似于 give 命令,但会覆盖现有的堆叠。
/playerex Steve inventory set 0 minecraft:netherite_sword 1
/playerex <玩家> inventory count <物品>
统计目标玩家背包中所有槽位里指定物品的总数量。用于快速检查资源数量。
/playerex Steve inventory count minecraft:diamond
示例输出:
[CarpetEx] 47x 钻石
/playerex <玩家> inventory compact
将目标玩家物品栏中所有可堆叠的物品合并,把部分堆叠的组整合为完整堆叠。通过合并同类物品来释放物品栏空间。
/playerex Steve inventory compact
/playerex <玩家> inventory drop <槽位>
将指定槽位的物品掉落在目标玩家附近的地上。该物品会从背包中被物理抛出到世界中。
/playerex Steve inventory drop 36
自动切换系统
/playerex <玩家> use switch
切换目标玩家的自动切换快捷栏系统的开关。首次启用时,系统将开始监控并自动填充玩家当前选中的快捷栏槽位。
/playerex Steve use switch
/playerex <玩家> use switch true
显式启用目标玩家的自动切换功能。
/playerex Steve use switch true
/playerex <玩家> use switch false
显式禁用目标玩家的自动切换。如果库存锁定处于激活状态,此操作也会解除该锁定。
/playerex Steve use switch false
槽位参考指南
| 槽位范围 |
描述 |
| 0–8 |
快捷栏(从左到右) |
| 9–35 |
主背包 |
| 36 |
靴子 |
| 37 |
护腿 |
| 38 |
胸甲 |
| 39 |
头盔 |
| 40 |
副手 |
? 技术细节
架构
该模组采用清晰、模块化的架构,由四个主要部分组成:
1. 命令模块 (commands/)
PlayerInventoryCommand.java — 处理所有背包管理命令及 GUI 查看器系统。包含槽位映射逻辑、玻璃面板初始化以及双向同步引擎。
PlayerUseSwitchCommand.java — 处理自动切换开关命令及状态管理。
2. 处理器模块 (handler/)
SwitchHandler.java — 核心自动切换引擎。在每个服务器刻运行,检查选中的快捷栏槽位并执行物品轮换、背包抽取及锁定管理。
3. Mixin 模块 (mixin/)
PlayerInventoryMixin.java — 挂钩到 PlayerInventory.setStack()、PlayerInventory.addStack() 和 PlayerInventory.markDirty(),以拦截库存修改并在自动切换处于活动状态且库存耗尽时强制执行锁定。
ServerPlayerEntityMixin.java — 挂钩到 ServerPlayerEntity.closeHandledScreen(),以检测玩家何时关闭库存查看器 GUI,从而触发从查看器到目标的最终同步。
4. 核心模块
PlayerCarpetExtension.java — 实现 ModInitializer 和 CarpetExtension 的主模组入口点。初始化所有系统并注册 Carpet 设置管理器。
同步系统
双向同步系统是模组中最关键的部分之一。它确保查看者(viewer)和目标玩家始终看到一致的物品栏状态。
查看 → 目标同步:
- 当查看者在 GUI 中修改任何物品时触发(通过
SimpleInventory.markDirty() 重写)。
- 遍历所有 54 个查看槽位,检查
VIEW_TO_TARGET 映射数组,并将非玻璃材质的物品复制到对应的目标物品栏槽位。
syncing 标志可防止导致无限循环的重入调用。
目标 → 查看同步:
- 每 10 个服务端刻(0.5 秒)通过
ServerTickEvents.END_SERVER_TICK 触发。
- 遍历所有 41 个目标物品栏槽位,检查
TARGET_TO_VIEW 反向映射数组,并将物品复制到对应的查看槽位。
- 仅在查看者未处于初始化阶段时运行。
初始化保护:
- 当 GUI 首次打开时,
syncing 和 initializing 标志均设置为 true。
- 这可以防止在初始填充查看物品栏期间产生任何副作用。
- 在所有物品和玻璃板放置完成后,清除
initializing 标志。
- 在初始化块完成后,清除
syncing 标志。
槽位映射
槽位映射系统使用两个查找数组,在 54 槽位的查看容器与 41 槽位的 Minecraft 玩家物品栏之间进行转换:
VIEW_TO_TARGET[54] — 将每个查看容器槽位(0–53)映射到相应的目标物品栏槽位(玻璃/未使用则为 -1)。
TARGET_TO_VIEW[41] — 从目标物品栏槽位到查看容器槽位的反向映射(未映射则为 -1)。
这种双向映射实现了两个方向上的高效同步。
?️ 画廊
| 图片 |
描述 |
 |
模组横幅艺术图 |
 |
GUI 布局示意图,展示有组织的物品栏视图 |
 |
功能概览插图 |
 |
自动切换快捷栏机制示意图 |
 |
游戏内物品栏查看器截图 |
? 兼容性
| 模组 |
兼容 |
备注 |
| Carpet Mod 1.4.128+ |
✅ 是 |
必需依赖项 |
| Fabric API |
✅ 是 |
必需依赖项 |
| Lithium |
✅ 是 |
完全兼容 |
| Sodium |
✅ 是 |
仅客户端,无冲突 |
| Indium |
✅ 是 |
仅客户端,无冲突 |
| ModMenu |
✅ 是 |
将显示在模组列表中 |
? 更新日志
v1.3.0 — 物品栏 GUI 重构
- 彻底重写了基于可视化 GUI 容器的物品栏查看系统
- 添加了基于 54 槽位(9×6)的
GenericContainerScreenHandler 查看器
- 实现了查看者与目标之间的双向同步(每 10 个刻一次)
- 添加了玻璃板分隔符:盔甲行使用蓝色染色玻璃,快捷栏/物品栏分隔线使用灰色染色玻璃
- 添加了
syncing 和 initializing 标志,以防止初始化期间的重入同步
- 添加了正确的
VIEW_TO_TARGET 和 TARGET_TO_VIEW 槽位映射数组
- 新增物品栏子命令:
give、remove、clear、swap、set、count、compact、drop
- 添加了对
ServerPlayerEntity.closeHandledScreen() 的 Mixin,以检测 GUI 关闭事件
- 添加了对
PlayerInventory 的 Mixin,以支持自动切换物品栏锁定
v1.2.0 — 自动切换系统
- 添加了带有快捷栏旋转、物品栏抽取和物品栏锁定的自动切换快捷栏填充系统
- 添加了用于拦截
setStack、addStack 和 markDirty 的 PlayerInventoryMixin
- 添加了使用
ConcurrentHashMap 进行逐玩家状态管理的 SwitchHandler
v1.1.0 — 初始物品栏命令
- 添加了
/playerex <player> inventory list 和 /playerex <player> inventory info <slot>
- 修复了打开物品栏视图时物品消失的 bug
- 改进了使用 Brigadier 参数类型的命令结构
v1.0.0 — 首次发布
- 基本的
/playerex 命令结构
- 初始物品栏查看命令(基于文本)
- Carpet Mod 扩展注册
? 许可证
本模组根据 MIT 许可证 发布。您可以自由在任何项目中使用、修改和分发此模组,前提是包含原始许可证通知。
MIT License
Copyright (c) 2026 PlayerCarpetEx
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
? 链接
由 ❤️ 为 Minecraft 服务器管理社区制作。
? Player Carpet Extension (PlayerCarpetEx)
A powerful Carpet Mod extension for Minecraft that gives server operators full control over player inventories.

? Overview
Player Carpet Extension is a server-side Fabric mod that extends the capabilities of Carpet Mod with advanced player inventory management tools. Designed for server administrators, SMP operators, and mapmakers, this mod provides two core features that revolutionize how you interact with player inventories on your server.

What does this mod do?
This mod adds two major systems to your Minecraft server:
-
Remote Inventory Viewing & Management — Open any player's inventory as a full GUI screen, with bidirectional synchronization. Any changes you make in the viewer are instantly applied to the target player's inventory, and vice versa. You can also use commands to give, remove, swap, set, count, compact, and drop items in any player's inventory slots.
-
Auto-Switch Hotbar System — Automatically refills a player's hotbar when the selected slot runs out. The system pulls items from the next available hotbar slot, and if the entire hotbar is empty, it pulls from the main inventory. When everything is depleted, the main inventory locks to prevent external modifications until new items are provided.
✨ Features
? Inventory GUI Viewer
Open a visual representation of any player's inventory directly in your game client. The viewer displays a 54-slot (9×6) container with a carefully organized layout that mirrors the player's actual inventory structure.
GUI Layout Structure:
The container view is divided into clearly marked sections using decorative glass panes:
| Row |
Slots |
Content |
Description |
| Row 0 |
0–8 |
Offhand + Armor + Glass |
Slot 0 = Offhand, Slot 2 = Helmet, Slot 3 = Chestplate, Slot 4 = Leggings, Slot 5 = Boots. Blue glass panes fill the decorative positions (slots 1, 6, 7, 8). |
| Row 1 |
9–17 |
Hotbar |
The player's hotbar slots 1 through 9, displayed in order. |
| Row 2 |
18–26 |
Separator |
Gray glass panes create a visual separation between the hotbar/armor area and the main inventory. |
| Row 3 |
27–35 |
Main Inventory (first row) |
Main inventory slots 9–17. |
| Row 4 |
36–44 |
Main Inventory (second row) |
Main inventory slots 18–26. |
| Row 5 |
45–53 |
Main Inventory (third row) |
Main inventory slots 27–35. |
Bidirectional Synchronization:
- The viewer inventory syncs to the target player's inventory every 10 ticks (0.5 seconds), ensuring you always see the latest state even if the target player moves items around.
- When you modify items in the viewer (pick up, place, swap), those changes are immediately pushed to the target player's inventory.
- A
syncing flag prevents infinite re-entrant sync loops during initialization and modification.
- Glass pane separators are enforced during initialization and preserved across syncs.
? Auto-Switch Hotbar
The auto-switch system continuously monitors a player's selected hotbar slot and automatically refills it when it becomes empty. This is perfect for scenarios like automated farms, PvP servers, or any situation where players need continuous item supply.

How the auto-switch logic works:
- Hotbar Check — When the selected hotbar slot is empty, the system scans the remaining hotbar slots (wrapping around) for the nearest available item. If found, it moves that item to the selected slot and notifies the player.
- Inventory Pull — If the entire hotbar is empty, the system searches the main inventory (slots 9–35) for any item and pulls it to the currently selected hotbar slot.
- Inventory Lock — When all hotbar AND main inventory slots are completely empty, the system locks the main inventory. While locked, external attempts to add items to the main inventory (from dispensers, hoppers, or other mechanisms) are blocked. Items can only be added to the hotbar.
- Auto-Unlock — If items are somehow detected in the locked inventory, the lock automatically releases and normal operation resumes.
? Installation
Requirements
| Dependency |
Minimum Version |
Purpose |
| Minecraft |
1.20.4 |
Target game version |
| Fabric Loader |
0.15.0+ |
Mod loader |
| Fabric API |
Latest for 1.20.4 |
API framework |
| Carpet Mod |
1.4.128+ |
Required parent mod |
| Java |
17+ |
Runtime environment |
Steps
- Install Fabric Loader — Download and install Fabric Loader for Minecraft 1.20.4.
- Install Fabric API — Download the Fabric API for Minecraft 1.20.4 and place it in your
mods/ folder.
- Install Carpet Mod — Download Carpet Mod version 1.4.128 or newer and place it in your
mods/ folder.
- Install PlayerCarpetEx — Download the
PlayerCarpetEx-1.3.0.jar file and place it in your server's mods/ folder.
- Restart Server — Restart your Minecraft server to load all mods.
Verifying Installation
Once the server starts, you should see the following log messages:
[PlayerCarpetEx] Player Carpet Extension initialized!
[PlayerCarpetEx] Player Carpet Extension: game started.
[PlayerCarpetEx] Player Carpet Extension: server loaded.
You can also run /version or check the Carpet Mod rules list — PlayerCarpetEx will appear as a registered Carpet Extension with version 1.3.0.
?️ Commands
All commands require permission level 2 (operator status). The base command is /playerex.
Note: Replace <player> with the actual player name in all commands below.
Inventory Management
/playerex <player> inventory (or /playerex <player> inventory view)
Opens a visual GUI viewer displaying the target player's complete inventory (offhand, armor, hotbar, and main inventory). The GUI uses a 9×6 container with glass pane separators for clear organization.
/playerex Steve inventory
/playerex <player> inventory list
Prints a detailed text listing of the target player's inventory contents directly in chat. Shows each slot index, item name, and count, organized by hotbar and main inventory sections.
/playerex Steve inventory list
Example output:
[CarpetEx] Inventory of: Steve
[CarpetEx] --- Hotbar (Slots 0-8) ---
[CarpetEx] [0] Diamond Sword x1
[CarpetEx] [1] empty
[CarpetEx] [2] Golden Apple x16
[CarpetEx] --- Main Inventory (Slots 9-35) ---
[CarpetEx] [9] Oak Planks x64
[CarpetEx] [10] Cobblestone x32
/playerex <player> inventory info <slot>
Displays detailed information about a specific inventory slot, including the item name, current count, and maximum stack size.
/playerex Steve inventory info 5
/playerex <player> inventory give <slot> <item> [count]
Places a specified item into the target player's inventory at the given slot number. If no count is specified, defaults to 1. The count can range from 1 to 64.
/playerex Steve inventory give 0 minecraft:diamond_sword 1
/playerex Steve inventory give 9 minecraft:golden_apple 64
/playerex <player> inventory remove <slot> [count]
Removes items from the target player's inventory at the specified slot. If the count matches or exceeds the current stack size, the slot is cleared entirely. Defaults to removing 1 item.
/playerex Steve inventory remove 9 32
/playerex Steve inventory remove 0
/playerex <player> inventory clear
Completely clears the target player's entire inventory (hotbar, main inventory, armor, and offhand). Use with caution.
/playerex Steve inventory clear
/playerex <player> inventory swap <slot1> <slot2>
Swaps the contents of two inventory slots in the target player's inventory. Both slot numbers must be between 0 and 40 (slot 40 = offhand).
/playerex Steve inventory swap 0 9
/playerex Steve inventory swap 36 37
/playerex <player> inventory set <slot> <item> [count]
Sets the contents of a specific slot to the specified item and count, replacing whatever was there before. Similar to give but overwrites the existing stack.
/playerex Steve inventory set 0 minecraft:netherite_sword 1
/playerex <player> inventory count <item>
Counts the total number of a specific item across all slots in the target player's inventory. Useful for quickly checking resource amounts.
/playerex Steve inventory count minecraft:diamond
Example output:
[CarpetEx] 47x Diamond
/playerex <player> inventory compact
Consolidates all stackable items in the target player's inventory by merging partial stacks into complete ones. This frees up inventory space by combining items of the same type.
/playerex Steve inventory compact
/playerex <player> inventory drop <slot>
Drops the item from the specified slot on the ground near the target player. The item is physically ejected from the inventory into the world.
/playerex Steve inventory drop 36
Auto-Switch System
/playerex <player> use switch
Toggles the auto-switch hotbar system for the target player on or off. When first enabled, the system will begin monitoring and refilling the player's selected hotbar slot automatically.
/playerex Steve use switch
/playerex <player> use switch true
Explicitly enables auto-switch for the target player.
/playerex Steve use switch true
/playerex <player> use switch false
Explicitly disables auto-switch for the target player. This also releases the inventory lock if it was active.
/playerex Steve use switch false
Slot Reference Guide
| Slot Range |
Description |
| 0–8 |
Hotbar (left to right) |
| 9–35 |
Main Inventory |
| 36 |
Boots |
| 37 |
Leggings |
| 38 |
Chestplate |
| 39 |
Helmet |
| 40 |
Offhand |
? Technical Details
Architecture
The mod is built with a clean, modular architecture consisting of four main components:
1. Commands Module (commands/)
PlayerInventoryCommand.java — Handles all inventory management commands and the GUI viewer system. Contains the slot mapping logic, glass pane initialization, and bidirectional synchronization engine.
PlayerUseSwitchCommand.java — Handles the auto-switch toggle command and state management.
2. Handler Module (handler/)
SwitchHandler.java — The core auto-switch engine. Runs every server tick, checking the selected hotbar slot and performing item rotation, inventory pulling, and lock management.
3. Mixin Module (mixin/)
PlayerInventoryMixin.java — Hooks into PlayerInventory.setStack(), PlayerInventory.addStack(), and PlayerInventory.markDirty() to intercept inventory modifications and enforce the lock when auto-switch is active with a depleted inventory.
ServerPlayerEntityMixin.java — Hooks into ServerPlayerEntity.closeHandledScreen() to detect when a player closes the inventory viewer GUI, triggering a final sync from viewer to target.
4. Core Module
PlayerCarpetExtension.java — The main mod entry point implementing ModInitializer and CarpetExtension. Initializes all systems and registers the Carpet settings manager.
Synchronization System
The bidirectional sync system is one of the most critical parts of the mod. It ensures that both the viewing operator and the target player see a consistent inventory state at all times.
View → Target Sync:
- Triggered when the viewer modifies any item in the GUI (via the
SimpleInventory.markDirty() override).
- Iterates through all 54 view slots, checks the
VIEW_TO_TARGET mapping array, and copies non-glass items to the corresponding target inventory slots.
- The
syncing flag prevents re-entrant calls that could cause infinite loops.
Target → View Sync:
- Triggered every 10 server ticks (0.5 seconds) via
ServerTickEvents.END_SERVER_TICK.
- Iterates through all 41 target inventory slots, checks the
TARGET_TO_VIEW reverse mapping array, and copies items to the corresponding view slots.
- Only runs when the viewer is not in the initializing phase.
Initialization Guards:
- When the GUI first opens, both
syncing and initializing flags are set to true.
- This prevents any side effects during the initial population of the view inventory.
- The
initializing flag is cleared after all items and glass panes are placed.
- The
syncing flag is cleared after the initialization block completes.
Slot Mapping
The slot mapping system translates between the 54-slot view container and the 41-slot Minecraft player inventory using two lookup arrays:
VIEW_TO_TARGET[54] — Maps each view container slot (0–53) to the corresponding target inventory slot (-1 for glass/unused).
TARGET_TO_VIEW[41] — Reverse mapping from target inventory slots to view container slots (-1 for unmapped).
This bidirectional mapping enables efficient synchronization in both directions.
?️ Gallery
| Image |
Description |
 |
Mod banner artwork |
 |
GUI layout diagram showing the organized inventory view |
 |
Feature overview illustration |
 |
Auto-switch hotbar mechanic diagram |
 |
In-game inventory viewer screenshot |
? Compatibility
| Mod |
Compatible |
Notes |
| Carpet Mod 1.4.128+ |
✅ Yes |
Required dependency |
| Fabric API |
✅ Yes |
Required dependency |
| Lithium |
✅ Yes |
Fully compatible |
| Sodium |
✅ Yes |
Client-side only, no conflicts |
| Indium |
✅ Yes |
Client-side only, no conflicts |
| ModMenu |
✅ Yes |
Will appear in the mod list |
? Changelog
v1.3.0 — Inventory GUI Overhaul
- Complete rewrite of the inventory viewing system with a visual GUI container
- Added 54-slot (9×6)
GenericContainerScreenHandler based viewer
- Implemented bidirectional synchronization between viewer and target (every 10 ticks)
- Added glass pane separators: blue stained glass for the armor row, gray stained glass for the hotbar/inventory divider
- Added
syncing and initializing flags to prevent re-entrant sync during initialization
- Added proper
VIEW_TO_TARGET and TARGET_TO_VIEW slot mapping arrays
- New inventory subcommands:
give, remove, clear, swap, set, count, compact, drop
- Added Mixin for
ServerPlayerEntity.closeHandledScreen() to detect GUI close events
- Added Mixin for
PlayerInventory to support auto-switch inventory locking
v1.2.0 — Auto-Switch System
- Added auto-switch hotbar refill system with hotbar rotation, inventory pull, and inventory locking
- Added
PlayerInventoryMixin for setStack, addStack, and markDirty interception
- Added
SwitchHandler with per-player state management using ConcurrentHashMap
v1.1.0 — Initial Inventory Commands
- Added
/playerex <player> inventory list and /playerex <player> inventory info <slot>
- Fixed item disappearing bug when opening inventory view
- Improved command structure with Brigadier argument types
v1.0.0 — First Release
- Basic
/playerex command structure
- Initial inventory view command (text-based)
- Carpet Mod extension registration
? License
This mod is released under the MIT License. You are free to use, modify, and distribute this mod in any project, provided that the original license notice is included.
MIT License
Copyright (c) 2026 PlayerCarpetEx
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
? Links
Made with ❤️ for the Minecraft server administration community.
评论 0
登录后参与评分
还没有评论,来抢沙发吧