Skip to content

Commit

Permalink
合并项目分享。
Browse files Browse the repository at this point in the history
 也许需要重新整理codeshare区域。
  • Loading branch information
M1hono authored Oct 27, 2024
2 parents f655109 + 0ce449a commit 6a31a0a
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
60 changes: 60 additions & 0 deletions docs/zh/modpack/kubejs/1.20.1/codeshare/InvertedBonemeal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# 反转骨粉

::: v-info
手持反转骨粉右键具有“minecraft:crops”标签的方块,获取age,并将方块替换为age = age - 1的作物方块

触发概率可调,默认80%(0.8)

物品注册代码及物品贴图请自行实现。

粒子效果方法和声音方法的参数请参阅[Wiki /particle指令](https://zh.minecraft.wiki/w/%E5%91%BD%E4%BB%A4/particle)[Wiki /playsound](https://zh.minecraft.wiki/w/%E5%91%BD%E4%BB%A4/playsound),并结合ProbeJS食用。
:::

```js
BlockEvents.rightClicked(event => {

// 解构
const { block, item, player, hand } = event // 解构

// 如果方块不是作物,退出
if (!block.hasTag('minecraft:crops')) return

// 退化概率
const degenerateChance = 0.8

// 如果右键物品是反转骨粉
if (item.id == 'halosense:inverted_bone_meal') {

// 获取方块位置(坐标)
const blockPos = block.pos
// 获取作物生长阶段(字符串)
const ageString = block.properties.get('age')
// 字符串转数字
let age = parseInt(ageString)

// 消耗一个物品
item.count --
// 手部挥动
player.swing(hand, true)
// 播放粒子效果
block.level.spawnParticles('minecraft:angry_villager', false, blockPos.x + 0.5, blockPos.y - 0.5, blockPos.z + 0.5, 0.25, 0.1, 0.25, 10, 0)
// 播放声音
block.level.playSound(null, blockPos, 'minecraft:item.bone_meal.use', 'players')

// 随机数
if (Math.random() < degenerateChance) {

// 如果生长阶段为0,则破坏作物方块
if (age == 0) {
block.level.destroyBlock(blockPos, true)
}
else { // 否则作物方块生长阶段-1
age --
const newAgeString = age.toString()
block.set(block.id, {'age': newAgeString})
}
}

}
})
```
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 @@ -320,6 +320,9 @@ root:
- title: 死亡扣除生命上限
path: /
file: LifeValue
- title: 反向骨粉
path: /
file: InvertedBonemeal
prev: false
next: false
---

0 comments on commit 6a31a0a

Please sign in to comment.