Skip to content

Commit

Permalink
Merge pull request #40 from xiaoliziawa/main
Browse files Browse the repository at this point in the history
new code block
  • Loading branch information
M1hono authored Sep 22, 2024
2 parents 108fc8b + ffec11d commit 8a11747
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/auto-imports.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// @ts-nocheck
// noinspection JSUnusedGlobalSymbols
// Generated by unplugin-auto-import

export {}
declare global {

Expand Down
28 changes: 28 additions & 0 deletions docs/zh/modpack/kubejs/1.20.1/codeshare/CraftingTableGUI.md
Original file line number Diff line number Diff line change
@@ -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()
})
```
3 changes: 3 additions & 0 deletions docs/zh/modpack/kubejs/1.20.1/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,9 @@ root:
- title: PainterAPI血条
path: /
file: Painter
- title: 自定义方块打开工作台界面
path: /
file: CraftingTableGUI
# - title: 高级
# path: Advanced
# collapsed: true
Expand Down

0 comments on commit 8a11747

Please sign in to comment.