-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from xiaoliziawa/main
new code block
- Loading branch information
Showing
3 changed files
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
docs/zh/modpack/kubejs/1.20.1/codeshare/CraftingTableGUI.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
}) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters