diff --git a/docs/auto-imports.d.ts b/docs/auto-imports.d.ts index 1d89ee8c..174bc1af 100644 --- a/docs/auto-imports.d.ts +++ b/docs/auto-imports.d.ts @@ -3,6 +3,7 @@ // @ts-nocheck // noinspection JSUnusedGlobalSymbols // Generated by unplugin-auto-import + export {} declare global { diff --git a/docs/zh/modpack/kubejs/1.20.1/codeshare/CraftingTableGUI.md b/docs/zh/modpack/kubejs/1.20.1/codeshare/CraftingTableGUI.md new file mode 100644 index 00000000..49b4ff8d --- /dev/null +++ b/docs/zh/modpack/kubejs/1.20.1/codeshare/CraftingTableGUI.md @@ -0,0 +1,28 @@ +# 自定义方块打开工作台界面 +::: v-info +通过加载原版Java类来进行方块右键打开工作台GUI的功能 +::: + +```js +let $SimpleMenuProvider = Java.loadClass('net.minecraft.world.SimpleMenuProvider') +let $CraftingMenu = Java.loadClass('net.minecraft.world.inventory.CraftingMenu') +let $Optional = Java.loadClass(`java.util.Optional`) + +// 下方以草方块作为一个示例代码,具体需求可以自行更改 +BlockEvents.rightClicked('grass_block', (event) => { + const { player, level, block } = event + + if (level.clientSide) return + + player.openMenu( + new $SimpleMenuProvider((i, inv, p) => { + return new $CraftingMenu(i, inv, (func) => { + func.apply(level, block.pos) + return $Optional.empty() + }) + }, '工作台') + ) + + player.swing() +}) +``` \ No newline at end of file diff --git a/docs/zh/modpack/kubejs/1.20.1/index.md b/docs/zh/modpack/kubejs/1.20.1/index.md index a17f89d8..00054ce0 100644 --- a/docs/zh/modpack/kubejs/1.20.1/index.md +++ b/docs/zh/modpack/kubejs/1.20.1/index.md @@ -325,6 +325,9 @@ root: - title: PainterAPI血条 path: / file: Painter + - title: 自定义方块打开工作台界面 + path: / + file: CraftingTableGUI # - title: 高级 # path: Advanced # collapsed: true