Skip to content

Commit

Permalink
feat: support 1.21.x stable
Browse files Browse the repository at this point in the history
  • Loading branch information
Lete114 committed Jun 21, 2024
1 parent 91fd007 commit f69f9d5
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 44 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ To download, you need to go to the GitHub repository [releases](https://github.c

> required enable Beta API
Players with OP (operator-level permissions) can modify the probability (50%) using the `/scriptevent serendipity:prob 50` command, which defaults to 1%. (If you are a modpack author, you may need this command)
The probability of finding the treasure is 1%

## Debugger

Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"lint:fix": "eslint --fix src && prettier --check --write src"
},
"devDependencies": {
"@minecraft/server": "1.7.0-beta.1.20.40-stable",
"@minecraft/server": "1.11.0",
"@rollup/plugin-node-resolve": "^15.1.0",
"@rollup/plugin-typescript": "^11.1.2",
"@types/fs-extra": "^11.0.1",
Expand All @@ -34,6 +34,7 @@
"typescript": "^5.0.2"
},
"dependencies": {
"@mcbe-mods/utils": "^0.1.1"
"@mcbe-mods/utils": "^0.1.1",
"@minecraft/vanilla-data": "^1.21.0"
}
}
28 changes: 14 additions & 14 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/behavior_pack/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@
"description": "pack.description",
"name": "pack.name",
"uuid": "404c04d4-32f3-47d9-bd04-0172b1dc0301",
"version": [1, 0, 2],
"min_engine_version": [1, 20, 40]
"version": [1, 0, 3],
"min_engine_version": [1, 21, 0]
},
"modules": [
{
"description": "JavaScript module code",
"language": "javascript",
"type": "script",
"uuid": "9e376b78-7a64-418a-b2fa-4cee29949758",
"version": [1, 0, 2],
"version": [1, 0, 3],
"entry": "scripts/main.js"
}
],
"dependencies": [
{
"module_name": "@minecraft/server",
"version": "1.7.0-beta"
"version": "1.11.0"
}
],
"metadata": {
Expand Down
26 changes: 5 additions & 21 deletions src/behavior_pack/scripts/main.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,13 @@
import { world, system, Player, ItemStack, ItemTypes } from '@minecraft/server'
import { world, ItemStack } from '@minecraft/server'
import { MinecraftItemTypes } from '@minecraft/vanilla-data'
import { getRandomProbability } from '@mcbe-mods/utils'

const itemTypes = ItemTypes.getAll().map((item) => item.id)
const PROB = 'prob'

world.afterEvents.worldInitialize.subscribe(() => {
if (world.getDynamicProperty(PROB)) return
world.setDynamicProperty(PROB, 1)
})

system.afterEvents.scriptEventReceive.subscribe((e) => {
const { id, message } = e
const prob = +message
if (isNaN(prob)) return

const player = e.sourceEntity as Player
if (id === 'serendipity:prob' && player?.isOp()) {
world.setDynamicProperty(PROB, prob)
}
})
const itemTypes = Object.values(MinecraftItemTypes)
const PROBABILITY = 1

world.afterEvents.playerBreakBlock.subscribe(async (e) => {
const { dimension, block, player } = e
const prob = (world.getDynamicProperty(PROB) as number) || 1
const is = getRandomProbability(prob)
const is = getRandomProbability(PROBABILITY)
if (!is) return

player.playSound('random.orb', { pitch: 0.5, volume: 0.5 })
Expand Down
2 changes: 1 addition & 1 deletion src/behavior_pack/texts/en_US.lang
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pack.name=Serendipity v1.0.2
pack.name=Serendipity v1.0.3
pack.description=When you break a block, there is a 1/100 chance to randomly drop an item from the game.
2 changes: 1 addition & 1 deletion src/behavior_pack/texts/zh_CN.lang
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pack.name=意外发现 v1.0.2
pack.name=意外发现 v1.0.3
pack.description=打碎方块时,有 1/100 的几率随机掉落游戏中的物品。

0 comments on commit f69f9d5

Please sign in to comment.