├── .gitignore ├── filters └── move-manifest.py ├── docs ├── blocks │ ├── before-on-player-place │ │ ├── cancel.md │ │ ├── double-slab.md │ │ ├── sugar-cane.md │ │ ├── stairs.md │ │ └── turn-into.md │ ├── on-player-destroy │ │ ├── regenerate.md │ │ ├── double-slab.md │ │ ├── melt.md │ │ ├── drop-experience.md │ │ └── spawn-item.md │ ├── on-random-tick │ │ ├── grow.md │ │ ├── plant-growth.md │ │ ├── sugar-cane.md │ │ ├── melt.md │ │ └── effect.md │ ├── on-player-interact │ │ ├── candle.md │ │ ├── turn-into-entity.md │ │ └── turn-into.md │ ├── on-tick │ │ ├── torch-particles.md │ │ └── candle-particles.md │ ├── on-step-on │ │ ├── bounce.md │ │ └── effect.md │ ├── on-place │ │ └── turn-into.md │ ├── on-entity-fall-on │ │ └── bounce.md │ └── on-step-off │ │ └── effect.md └── items │ ├── on-consume │ ├── teleport.md │ ├── run-command.md │ └── food-effect.md │ ├── on-use-on │ ├── item-fire-charge.md │ ├── item-wax.md │ ├── run-command.md │ ├── item-dye.md │ ├── item-glass-bottle.md │ └── item-bucket.md │ ├── on-before-durability-damage │ ├── prevent-damage-durability.md │ ├── modify-durability-damage.md │ ├── run-command.md │ └── modify-durability-damage-conditional.md │ ├── on-mine-block │ ├── digger.md │ ├── run-command.md │ └── digger-conditional.md │ ├── on-use │ ├── item-goat-horn.md │ └── run-command.md │ ├── on-hit-entity │ ├── run-command.md │ ├── summon-particle.md │ └── summon-entity.md │ └── on-complete-use │ └── run-command.md ├── stable ├── package.json ├── tsup.config.ts ├── scripts │ ├── utils │ │ ├── math.ts │ │ ├── shared_parameters.ts │ │ └── helper.ts │ ├── blocks │ │ ├── sugar_cane.ts │ │ ├── registry │ │ │ ├── on_place.ts │ │ │ ├── on_entity_fall_on.ts │ │ │ ├── on_step_off.ts │ │ │ ├── before_on_player_place.ts │ │ │ ├── on_step_on.ts │ │ │ ├── on_tick.ts │ │ │ └── on_player_break.ts │ │ └── double_slab.ts │ ├── item │ │ ├── registry │ │ │ ├── on_complete_use.ts │ │ │ ├── on_use.ts │ │ │ ├── on_mine_block.ts │ │ │ ├── on_consume.ts │ │ │ ├── on_hit_entity.ts │ │ │ └── on_before_durability_damage.ts │ │ ├── item_bucket.ts │ │ └── teleport.ts │ └── main.ts └── tsconfig.json ├── rc ├── tsup.config.ts ├── package.json ├── scripts │ ├── utils │ │ ├── math.ts │ │ ├── shared_parameters.ts │ │ └── helper.ts │ ├── blocks │ │ ├── sugar_cane.ts │ │ ├── registry │ │ │ ├── on_place.ts │ │ │ ├── on_entity_fall_on.ts │ │ │ ├── on_step_off.ts │ │ │ ├── before_on_player_place.ts │ │ │ ├── on_step_on.ts │ │ │ ├── on_tick.ts │ │ │ └── on_player_break.ts │ │ └── double_slab.ts │ ├── item │ │ ├── registry │ │ │ ├── on_complete_use.ts │ │ │ ├── on_use.ts │ │ │ ├── on_mine_block.ts │ │ │ ├── on_consume.ts │ │ │ ├── on_hit_entity.ts │ │ │ └── on_before_durability_damage.ts │ │ ├── item_bucket.ts │ │ ├── teleport.ts │ │ └── item_wax.ts │ └── main.ts └── tsconfig.json ├── experimental ├── tsup.config.ts ├── package.json ├── scripts │ ├── utils │ │ ├── math.ts │ │ ├── shared_parameters.ts │ │ └── helper.ts │ ├── blocks │ │ ├── sugar_cane.ts │ │ ├── registry │ │ │ ├── on_place.ts │ │ │ ├── on_entity_fall_on.ts │ │ │ ├── on_step_off.ts │ │ │ ├── before_on_player_place.ts │ │ │ ├── on_step_on.ts │ │ │ ├── on_tick.ts │ │ │ └── on_player_break.ts │ │ └── double_slab.ts │ ├── item │ │ ├── registry │ │ │ ├── on_complete_use.ts │ │ │ ├── on_use.ts │ │ │ ├── on_mine_block.ts │ │ │ ├── on_consume.ts │ │ │ ├── on_hit_entity.ts │ │ │ └── on_before_durability_damage.ts │ │ ├── item_bucket.ts │ │ └── teleport.ts │ └── main.ts └── tsconfig.json ├── packs └── data │ ├── stable.json │ ├── rc.json │ └── experimental.json ├── package.json ├── config.json └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | /.regolith 3 | /**/node_modules 4 | /packs/* 5 | !/packs/data 6 | dist -------------------------------------------------------------------------------- /filters/move-manifest.py: -------------------------------------------------------------------------------- 1 | import shutil 2 | import sys 3 | 4 | if __name__ == "__main__": 5 | if len(sys.argv)-1 < 1: 6 | print("Too few arguments") 7 | exit(1) 8 | 9 | shutil.copyfile(f'data/{sys.argv[1]}.json', "BP/manifest.json") -------------------------------------------------------------------------------- /docs/blocks/before-on-player-place/cancel.md: -------------------------------------------------------------------------------- 1 | # adk_lib:before_on_player_place_cancel 2 | 3 | ## What does it do? 4 | 5 | This component cancels the placement of the block. 6 | 7 | ## How to use 8 | 9 | Add `"adk_lib:before_on_player_place_cancel": {}` to your block json file. 10 | -------------------------------------------------------------------------------- /docs/items/on-consume/teleport.md: -------------------------------------------------------------------------------- 1 | # adk_lib:on_consume_teleport 2 | 3 | ## What does it do? 4 | 5 | This component enables the chorus fruit teleportation functionality 6 | 7 | ## How to use 8 | 9 | Add `adk_lib:on_consume_teleport` to the `minecraft:custom_components` array in your item json file. 10 | -------------------------------------------------------------------------------- /docs/items/on-use-on/item-fire-charge.md: -------------------------------------------------------------------------------- 1 | # adk_lib:on_use_on_fire 2 | 3 | ## What does it do? 4 | 5 | This component enables the fire charge or flint and steel functionality 6 | 7 | ## How to use 8 | 9 | Add `adk_lib:on_use_on_fire` to the `minecraft:custom_components` array in your item json file. 10 | -------------------------------------------------------------------------------- /docs/blocks/before-on-player-place/double-slab.md: -------------------------------------------------------------------------------- 1 | # adk_lib:before_on_player_place_double_slab 2 | 3 | ## What does it do? 4 | 5 | This component allows the slab block to turn into a double block. 6 | 7 | ## How to use 8 | 9 | Add `"adk_lib:before_on_player_place_double_slab": {}` to your block json file. 10 | -------------------------------------------------------------------------------- /docs/items/on-use-on/item-wax.md: -------------------------------------------------------------------------------- 1 | # adk_lib:on_use_on_wax 2 | 3 | ## What does it do? 4 | 5 | This component enables the waxing functionality. It allows items to wax signs and copper blocks. 6 | 7 | ## How to use 8 | 9 | Add `adk_lib:on_use_on_wax` to the `minecraft:custom_components` array in your item json file. 10 | -------------------------------------------------------------------------------- /docs/blocks/on-player-destroy/regenerate.md: -------------------------------------------------------------------------------- 1 | # adk_lib:on_player_destroy_regenerate 2 | 3 | ## What does it do? 4 | 5 | This component will make the block regenerate when destroyed. This component has no customization. 6 | 7 | ## How to use 8 | 9 | Add `"adk_lib:on_player_destroy_regenerate": {}` to your block json file. 10 | -------------------------------------------------------------------------------- /docs/blocks/before-on-player-place/sugar-cane.md: -------------------------------------------------------------------------------- 1 | # adk_lib:before_on_player_place_sugar_cane 2 | 3 | ## What does it do? 4 | 5 | This component checks for the same condition a vanilla sugar cane requires to be placed. 6 | 7 | ## How to use 8 | 9 | Add `"adk_lib:before_on_player_place_sugar_cane": {}` to your block json file. 10 | -------------------------------------------------------------------------------- /docs/blocks/on-random-tick/grow.md: -------------------------------------------------------------------------------- 1 | # adk_lib:on_random_tick_grow 2 | 3 | ## What does it do? 4 | 5 | This component will make the block grow in a random direction. This component has no customization. 6 | 7 | ## How to use 8 | 9 | Add `adk_lib:on_random_tick_grow` to the `minecraft:custom_components` array in your item json file. 10 | -------------------------------------------------------------------------------- /docs/blocks/on-player-interact/candle.md: -------------------------------------------------------------------------------- 1 | # adk_lib:on_player_interact_candle 2 | 3 | ## What does it do? 4 | 5 | This component is used for determining the shape of the block that uses the `adk::BlockCandle` class. This component has no customization. 6 | 7 | ## How to use 8 | 9 | Add `"adk_lib:on_player_interact_candle": {}` to your block json file. 10 | -------------------------------------------------------------------------------- /docs/blocks/on-tick/torch-particles.md: -------------------------------------------------------------------------------- 1 | # adk_lib:on_tick_torch_particles 2 | 3 | ## What does it do? 4 | 5 | This component will spawn flame particles for the `adk::BlockTorch` class. This component has no customization. 6 | 7 | ## How to use 8 | 9 | Add `adk_lib:on_tick_torch_particles` to the `minecraft:custom_components` array in your item json file. 10 | -------------------------------------------------------------------------------- /docs/blocks/before-on-player-place/stairs.md: -------------------------------------------------------------------------------- 1 | # adk_lib:before_on_player_place_stairs 2 | 3 | ## What does it do? 4 | 5 | This component is used for determining the shape of the block that uses the `adk::BlockStairs` class. This component has no customization. 6 | 7 | ## How to use 8 | 9 | Add `"adk_lib:before_on_player_place_stairs": {}` to your block json file. 10 | -------------------------------------------------------------------------------- /docs/blocks/on-tick/candle-particles.md: -------------------------------------------------------------------------------- 1 | # adk_lib:on_tick_candle_particles 2 | 3 | ## What does it do? 4 | 5 | This component will spawn flame particles for the `adk::BlockCandleAbstract` class. This component has no customization. 6 | 7 | ## How to use 8 | 9 | Add `adk_lib:on_tick_candle_particles` to the `minecraft:custom_components` array in your item json file. 10 | -------------------------------------------------------------------------------- /docs/items/on-before-durability-damage/prevent-damage-durability.md: -------------------------------------------------------------------------------- 1 | # adk_lib:before_durability_damage_prevent_damage_durability 2 | 3 | # **RC** 4 | 5 | ## What does it do? 6 | 7 | This component prevents the item from taking any durability damage 8 | 9 | ## How to use 10 | 11 | Add `adk_lib:before_durability_damage_prevent_damage_durability` to the `minecraft:custom_components` array in your item json file. 12 | -------------------------------------------------------------------------------- /stable/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "author": "SmokeyStack", 3 | "dependencies": { 4 | "@minecraft/server": "2.0.0", 5 | "adk-scripts-server": "2.0.0" 6 | }, 7 | "description": "", 8 | "keywords": [], 9 | "license": "GPL-3.0-only", 10 | "main": "index.js", 11 | "name": "adk-lib-stable", 12 | "scripts": { 13 | "compile": "tsup" 14 | }, 15 | "version": "1.0.0" 16 | } -------------------------------------------------------------------------------- /docs/blocks/on-player-destroy/double-slab.md: -------------------------------------------------------------------------------- 1 | # adk_lib:on_player_destroy_double_slab 2 | 3 | ## What does it do? 4 | 5 | This component will spawn the destroyed slab as an item form if the tool has the silk touch enchantment. This is to workaround the fact that silk touch ignores the `minecraft:loot` component. 6 | 7 | ## How to use 8 | 9 | Add `"adk_lib:on_player_destroy_double_slab": {}` to your block json file. 10 | -------------------------------------------------------------------------------- /docs/blocks/on-random-tick/plant-growth.md: -------------------------------------------------------------------------------- 1 | # adk_lib:on_random_tick_plant_growth 2 | 3 | ## What does it do? 4 | 5 | This component will make the block advance their age similar to vanilla crops. This component requires you to have the block state, `adk_lib:age`, which is an int property. 6 | 7 | ## How to use 8 | 9 | Add `adk_lib:on_random_tick_plant_growth` to the `minecraft:custom_components` array in your item json file. 10 | -------------------------------------------------------------------------------- /docs/blocks/on-random-tick/sugar-cane.md: -------------------------------------------------------------------------------- 1 | # adk_lib:on_random_tick_sugar_cane 2 | 3 | ## What does it do? 4 | 5 | This component will make the block advance their age similar to vanilla sugar cane. This component requires you to have the block state, `{namespace}:age`, which is an int property. 6 | 7 | ## How to use 8 | 9 | Add `adk_lib:on_random_tick_sugar_cane` to the `minecraft:custom_components` array in your item json file. 10 | -------------------------------------------------------------------------------- /rc/tsup.config.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'tsup'; 2 | 3 | export default defineConfig({ 4 | entry: ['scripts/main.ts'], 5 | bundle: true, 6 | minify: false, 7 | sourcemap: false, 8 | format: ['esm'], 9 | outDir: '../packs/BP/scripts', 10 | external: ['@minecraft/server'], 11 | noExternal: ['adk-scripts-server'], 12 | outExtension({}) { 13 | return { 14 | js: `.js` 15 | }; 16 | } 17 | }); 18 | -------------------------------------------------------------------------------- /stable/tsup.config.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'tsup'; 2 | 3 | export default defineConfig({ 4 | entry: ['scripts/main.ts'], 5 | bundle: true, 6 | minify: true, 7 | sourcemap: false, 8 | format: ['esm'], 9 | outDir: '../packs/BP/scripts', 10 | external: ['@minecraft/server'], 11 | noExternal: ['adk-scripts-server'], 12 | outExtension({}) { 13 | return { 14 | js: `.js` 15 | }; 16 | } 17 | }); 18 | -------------------------------------------------------------------------------- /experimental/tsup.config.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'tsup'; 2 | 3 | export default defineConfig({ 4 | entry: ['scripts/main.ts'], 5 | bundle: true, 6 | minify: false, 7 | sourcemap: false, 8 | format: ['esm'], 9 | outDir: '../packs/BP/scripts', 10 | external: ['@minecraft/server'], 11 | noExternal: ['adk-scripts-server'], 12 | outExtension({}) { 13 | return { 14 | js: `.js` 15 | }; 16 | } 17 | }); 18 | -------------------------------------------------------------------------------- /docs/blocks/on-step-on/bounce.md: -------------------------------------------------------------------------------- 1 | # adk_lib:on_step_on_bounce 2 | 3 | ## What does it do? 4 | 5 | This component will make the entity that steps on this block to bounce. 6 | 7 | ## How to use 8 | 9 | Add `"adk_lib:on_step_on_bounce": {}` to your block json file. 10 | 11 | ### Parameters 12 | 13 | - `"force"`: The amount of force to apply. Default value is `1.0`. 14 | 15 | ### Example 16 | 17 | ```json 18 | "adk_lib:on_step_on_bounce": { 19 | "force": 0.8 20 | } 21 | ``` -------------------------------------------------------------------------------- /docs/blocks/on-place/turn-into.md: -------------------------------------------------------------------------------- 1 | # adk_lib:on_place_turn_into 2 | 3 | ## What does it do? 4 | 5 | This component allows the block to turn into another block when it is placed. 6 | 7 | ## How to use 8 | 9 | Add `"adk_lib:on_place_turn_into": {}` to your block json file. 10 | 11 | ### Parameters 12 | 13 | - `"block"`: Identifier of the block to turn into 14 | 15 | ### Example 16 | 17 | ```json 18 | "adk_lib:on_place_turn_into": { 19 | "block": "minecraft:bedrock" 20 | } 21 | ``` 22 | -------------------------------------------------------------------------------- /docs/blocks/on-random-tick/melt.md: -------------------------------------------------------------------------------- 1 | # adk_lib:on_random_tick_melt 2 | 3 | ## What does it do? 4 | 5 | This component will turn your block into the melted state when a player destroys the block. 6 | 7 | ## How to use 8 | 9 | Add `"adk_lib:on_random_tick_melt": {}` to your block json file. 10 | 11 | ### Parameters 12 | 13 | - `"melted_state"`: The melted state 14 | 15 | ### Example 16 | 17 | ```json 18 | "adk_lib:on_random_tick_melt": { 19 | "melted_state": "minecraft:water" 20 | } 21 | ``` 22 | -------------------------------------------------------------------------------- /docs/blocks/on-entity-fall-on/bounce.md: -------------------------------------------------------------------------------- 1 | # adk_lib:on_entity_fall_on_bounce 2 | 3 | ## What does it do? 4 | 5 | This component will make the entity that falls on this block to bounce. 6 | 7 | ## How to use 8 | 9 | Add `"adk_lib:on_entity_fall_on_bounce": {}` to your block json file. 10 | 11 | ### Parameters 12 | 13 | - `"force"`: The amount of force to apply. Default value is `1.0`. 14 | 15 | ### Example 16 | 17 | ```json 18 | "adk_lib:on_entity_fall_on_bounce": { 19 | "force": 0.8 20 | } 21 | ``` -------------------------------------------------------------------------------- /rc/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "author": "SmokeyStack", 3 | "dependencies": { 4 | "@minecraft/server": "2.1.0-rc.1.21.100-preview.23", 5 | "adk-scripts-server": "^2.1.0-rc.1" 6 | }, 7 | "description": "", 8 | "devDependencies": { 9 | "tsup": "^8.3.5" 10 | }, 11 | "keywords": [], 12 | "license": "GPL-3.0-only", 13 | "main": "index.js", 14 | "name": "adk-lib-rc", 15 | "scripts": { 16 | "compile": "tsup" 17 | }, 18 | "version": "1.0.0" 19 | } -------------------------------------------------------------------------------- /docs/blocks/on-player-destroy/melt.md: -------------------------------------------------------------------------------- 1 | # adk_lib:on_player_destroy_melt 2 | 3 | ## What does it do? 4 | 5 | This component will turn your block into the melted state when a player destroys the block. 6 | 7 | ## How to use 8 | 9 | Add `"adk_lib:on_player_destroy_melt": {}` to your block json file. 10 | 11 | ### Parameters 12 | 13 | - `"melted_state"`: The melted state 14 | 15 | ### Example 16 | 17 | ```json 18 | "adk_lib:on_player_destroy_melt": { 19 | "melted_state": "minecraft:water" 20 | } 21 | ``` 22 | -------------------------------------------------------------------------------- /experimental/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "author": "SmokeyStack", 3 | "dependencies": { 4 | "@minecraft/server": "2.2.0-beta.1.21.100-preview.23", 5 | "adk-scripts-server": "^2.2.0-beta.1" 6 | }, 7 | "description": "", 8 | "devDependencies": { 9 | "tsup": "^8.3.5" 10 | }, 11 | "keywords": [], 12 | "license": "GPL-3.0-only", 13 | "main": "index.js", 14 | "name": "adk-lib-experimental", 15 | "scripts": { 16 | "compile": "tsup" 17 | }, 18 | "version": "1.0.0" 19 | } -------------------------------------------------------------------------------- /docs/blocks/on-player-destroy/drop-experience.md: -------------------------------------------------------------------------------- 1 | # adk_lib:on_player_destroy_drop_experience 2 | 3 | ## What does it do? 4 | 5 | This component will spawn experience orbs when a player destroys the block. 6 | 7 | ## How to use 8 | 9 | Add `"adk_lib:on_player_destroy_drop_experience": {}` to your block json file. 10 | 11 | ### Parameters 12 | 13 | - `"experience_reward"`: Amount of xp to drop 14 | 15 | ### Example 16 | 17 | ```json 18 | "adk_lib:on_player_destroy_drop_experience": { 19 | "experience_reward": 10 20 | } 21 | ``` 22 | -------------------------------------------------------------------------------- /docs/blocks/before-on-player-place/turn-into.md: -------------------------------------------------------------------------------- 1 | # adk_lib:before_on_player_place_turn_into 2 | 3 | ## What does it do? 4 | 5 | This component allows the block to turn into another block before the player places it. 6 | 7 | ## How to use 8 | 9 | Add `"adk_lib:before_on_player_place_turn_into": {}` to your block json file. 10 | 11 | ### Parameters 12 | 13 | - `"block"`: Identifier of the block to turn into 14 | 15 | ### Example 16 | 17 | ```json 18 | "adk_lib:before_on_player_place_turn_into": { 19 | "block": "minecraft:bedrock" 20 | } 21 | ``` 22 | -------------------------------------------------------------------------------- /rc/scripts/utils/math.ts: -------------------------------------------------------------------------------- 1 | import { Vector3 } from '@minecraft/server'; 2 | 3 | export function vectorOfCenter(vector: Vector3): Vector3 { 4 | return { x: vector.x + 0.5, y: vector.y + 0.5, z: vector.z + 0.5 }; 5 | } 6 | 7 | export function nextDouble(min: number, max: number): number { 8 | if (min >= max) return min; 9 | 10 | return Math.random() * (max - min) + min; 11 | } 12 | 13 | export function getRandomVelocity(): Vector3 { 14 | return { 15 | x: nextDouble(-0.5, 0.5), 16 | y: nextDouble(-0.5, 0.5), 17 | z: nextDouble(-0.5, 0.5) 18 | }; 19 | } 20 | -------------------------------------------------------------------------------- /stable/scripts/utils/math.ts: -------------------------------------------------------------------------------- 1 | import { Vector3 } from '@minecraft/server'; 2 | 3 | export function vectorOfCenter(vector: Vector3): Vector3 { 4 | return { x: vector.x + 0.5, y: vector.y + 0.5, z: vector.z + 0.5 }; 5 | } 6 | 7 | export function nextDouble(min: number, max: number): number { 8 | if (min >= max) return min; 9 | 10 | return Math.random() * (max - min) + min; 11 | } 12 | 13 | export function getRandomVelocity(): Vector3 { 14 | return { 15 | x: nextDouble(-0.5, 0.5), 16 | y: nextDouble(-0.5, 0.5), 17 | z: nextDouble(-0.5, 0.5) 18 | }; 19 | } 20 | -------------------------------------------------------------------------------- /experimental/scripts/utils/math.ts: -------------------------------------------------------------------------------- 1 | import { Vector3 } from '@minecraft/server'; 2 | 3 | export function vectorOfCenter(vector: Vector3): Vector3 { 4 | return { x: vector.x + 0.5, y: vector.y + 0.5, z: vector.z + 0.5 }; 5 | } 6 | 7 | export function nextDouble(min: number, max: number): number { 8 | if (min >= max) return min; 9 | 10 | return Math.random() * (max - min) + min; 11 | } 12 | 13 | export function getRandomVelocity(): Vector3 { 14 | return { 15 | x: nextDouble(-0.5, 0.5), 16 | y: nextDouble(-0.5, 0.5), 17 | z: nextDouble(-0.5, 0.5) 18 | }; 19 | } 20 | -------------------------------------------------------------------------------- /docs/blocks/on-player-destroy/spawn-item.md: -------------------------------------------------------------------------------- 1 | # adk_lib:on_player_destroy_spawn_item 2 | 3 | ## What does it do? 4 | 5 | This component will spawn an item when a player destroys the block. 6 | 7 | ## How to use 8 | 9 | Add `"adk_lib:on_player_destroy_spawn_item": {}` to your block json file. Since custom components do not have parameter support yet, this component utilizes block tags. 10 | 11 | ### Parameters 12 | 13 | - `"items"`: Identifier(s) of the item to spawn 14 | 15 | ### Example 16 | 17 | ```json 18 | "adk_lib:on_player_destroy_spawn_item": { 19 | "items": ["minecraft:bedrock"] 20 | } 21 | ``` 22 | -------------------------------------------------------------------------------- /docs/items/on-mine-block/digger.md: -------------------------------------------------------------------------------- 1 | # adk_lib:on_mine_block_digger 2 | 3 | ## What does it do? 4 | 5 | This component modifies the durability damage when you mine a block. 6 | 7 | ## How to use 8 | 9 | Add `adk_lib:on_mine_block_digger` to the `minecraft:custom_components` array in your item json file. Since custom components do not have parameter support yet, this component utilizes item tags. 10 | 11 | To indicate what command your item should should, add the following tag: `adk_lib:digger_[amount]` 12 | 13 | ### Example 14 | 15 | ```json 16 | "minecraft:tags": { 17 | "tags": [ 18 | "adk_lib:digger_75" 19 | ] 20 | } 21 | ``` 22 | -------------------------------------------------------------------------------- /docs/items/on-use/item-goat-horn.md: -------------------------------------------------------------------------------- 1 | # adk_lib:on_use_goat_horn 2 | 3 | ## What does it do? 4 | 5 | This component enables the goat horn functionality. It allows items to play a sound. 6 | 7 | ## How to use 8 | 9 | Add `adk_lib:on_use_goat_horn` to the `minecraft:custom_components` array in your item json file. Since custom components do not have parameter support yet, this component utilizes item tags. 10 | 11 | To indicate what instrument your item should play, add the following tag: `adk_lib:instrument_[identifier of the sound]` 12 | 13 | ### Example 14 | 15 | ```json 16 | "minecraft:tags": { 17 | "tags": [ 18 | "adk_lib:instrument_horn.call.5" 19 | ] 20 | } 21 | ``` 22 | -------------------------------------------------------------------------------- /docs/items/on-use/run-command.md: -------------------------------------------------------------------------------- 1 | # adk_lib:on_use_run_command 2 | 3 | # **RC** 4 | 5 | ## What does it do? 6 | 7 | This component allows the item to run a command when used. 8 | 9 | ## How to use 10 | 11 | Add `adk_lib:on_use_run_command` to the `minecraft:custom_components` array in your item json file. Since custom components do not have parameter support yet, this component utilizes item tags. 12 | 13 | To indicate what command your item should should, add the following tag: `adk_lib:on_use_[command]` 14 | 15 | ### Example 16 | 17 | ```json 18 | "minecraft:tags": { 19 | "tags": [ 20 | "adk_lib:on_use_tp ~~10~", 21 | "adk_lib:on_use_say hi" 22 | ] 23 | } 24 | ``` 25 | -------------------------------------------------------------------------------- /docs/items/on-use-on/run-command.md: -------------------------------------------------------------------------------- 1 | # adk_lib:on_use_on_run_command 2 | 3 | # **RC** 4 | 5 | ## What does it do? 6 | 7 | This component allows the item to run a command when used. 8 | 9 | ## How to use 10 | 11 | Add `adk_lib:on_use_on_run_command` to the `minecraft:custom_components` array in your item json file. Since custom components do not have parameter support yet, this component utilizes item tags. 12 | 13 | To indicate what command your item should should, add the following tag: `adk_lib:on_use_on_[command]` 14 | 15 | ### Example 16 | 17 | ```json 18 | "minecraft:tags": { 19 | "tags": [ 20 | "adk_lib:on_use_on_tp ~~10~", 21 | "adk_lib:on_use_on_say hi" 22 | ] 23 | } 24 | ``` 25 | -------------------------------------------------------------------------------- /docs/items/on-consume/run-command.md: -------------------------------------------------------------------------------- 1 | # adk_lib:on_consume_run_command 2 | 3 | # **RC** 4 | 5 | ## What does it do? 6 | 7 | This component allows the item to run a command when used. 8 | 9 | ## How to use 10 | 11 | Add `adk_lib:on_consume_run_command` to the `minecraft:custom_components` array in your item json file. Since custom components do not have parameter support yet, this component utilizes item tags. 12 | 13 | To indicate what command your item should should, add the following tag: `adk_lib:on_consume_[command]` 14 | 15 | ### Example 16 | 17 | ```json 18 | "minecraft:tags": { 19 | "tags": [ 20 | "adk_lib:on_consume_tp ~~10~", 21 | "adk_lib:on_consume_say hi" 22 | ] 23 | } 24 | ``` 25 | -------------------------------------------------------------------------------- /docs/items/on-hit-entity/run-command.md: -------------------------------------------------------------------------------- 1 | # adk_lib:on_mine_block_run_command 2 | 3 | # **RC** 4 | 5 | ## What does it do? 6 | 7 | This component allows the item to run a command when used. 8 | 9 | ## How to use 10 | 11 | Add `adk_lib:on_mine_block_run_command` to the `minecraft:custom_components` array in your item json file. Since custom components do not have parameter support yet, this component utilizes item tags. 12 | 13 | To indicate what command your item should should, add the following tag: `adk_lib:on_mine_block_[command]` 14 | 15 | ### Example 16 | 17 | ```json 18 | "minecraft:tags": { 19 | "tags": [ 20 | "adk_lib:on_mine_block_tp ~~10~", 21 | "adk_lib:on_mine_block_say hi" 22 | ] 23 | } 24 | ``` 25 | -------------------------------------------------------------------------------- /docs/items/on-mine-block/run-command.md: -------------------------------------------------------------------------------- 1 | # adk_lib:on_hit_entity_run_command 2 | 3 | # **RC** 4 | 5 | ## What does it do? 6 | 7 | This component allows the item to run a command when used. 8 | 9 | ## How to use 10 | 11 | Add `adk_lib:on_hit_entity_run_command` to the `minecraft:custom_components` array in your item json file. Since custom components do not have parameter support yet, this component utilizes item tags. 12 | 13 | To indicate what command your item should should, add the following tag: `adk_lib:on_hit_entity_[command]` 14 | 15 | ### Example 16 | 17 | ```json 18 | "minecraft:tags": { 19 | "tags": [ 20 | "adk_lib:on_hit_entity_tp ~~10~", 21 | "adk_lib:on_hit_entity_say hi" 22 | ] 23 | } 24 | ``` 25 | -------------------------------------------------------------------------------- /rc/scripts/utils/shared_parameters.ts: -------------------------------------------------------------------------------- 1 | type ParameterEffect = { 2 | effect: string; 3 | duration: number; 4 | radius: number; 5 | amplifier?: number; 6 | show_particles?: boolean; 7 | entity_type?: string[]; 8 | }[]; 9 | 10 | type ParameterMelt = { 11 | melted_state: string; 12 | }; 13 | 14 | type ParameterBounceForce = { 15 | force?: number; 16 | }; 17 | 18 | type ParameterRunCommand = { 19 | command: string[]; 20 | }; 21 | 22 | type ParameterLiquidPickup = { 23 | liquid_to_pickup?: string[]; 24 | transform_to: string; 25 | }[]; 26 | 27 | export { 28 | ParameterEffect, 29 | ParameterMelt, 30 | ParameterBounceForce, 31 | ParameterRunCommand, 32 | ParameterLiquidPickup 33 | }; 34 | -------------------------------------------------------------------------------- /docs/items/on-complete-use/run-command.md: -------------------------------------------------------------------------------- 1 | # adk_lib:on_complete_use_run_command 2 | 3 | # **RC** 4 | 5 | ## What does it do? 6 | 7 | This component allows the item to run a command when used. 8 | 9 | ## How to use 10 | 11 | Add `adk_lib:on_complete_use_run_command` to the `minecraft:custom_components` array in your item json file. Since custom components do not have parameter support yet, this component utilizes item tags. 12 | 13 | To indicate what command your item should should, add the following tag: `adk_lib:on_complete_use_[command]` 14 | 15 | ### Example 16 | 17 | ```json 18 | "minecraft:tags": { 19 | "tags": [ 20 | "adk_lib:on_complete_use_tp ~~10~", 21 | "adk_lib:on_complete_use_say hi" 22 | ] 23 | } 24 | ``` 25 | -------------------------------------------------------------------------------- /stable/scripts/utils/shared_parameters.ts: -------------------------------------------------------------------------------- 1 | type ParameterEffect = { 2 | effect: string; 3 | duration: number; 4 | radius: number; 5 | amplifier?: number; 6 | show_particles?: boolean; 7 | entity_type?: string[]; 8 | }[]; 9 | 10 | type ParameterMelt = { 11 | melted_state: string; 12 | }; 13 | 14 | type ParameterBounceForce = { 15 | force?: number; 16 | }; 17 | 18 | type ParameterRunCommand = { 19 | command: string[]; 20 | }; 21 | 22 | type ParameterLiquidPickup = { 23 | liquid_to_pickup?: string[]; 24 | transform_to: string; 25 | }[]; 26 | 27 | export { 28 | ParameterEffect, 29 | ParameterMelt, 30 | ParameterBounceForce, 31 | ParameterRunCommand, 32 | ParameterLiquidPickup 33 | }; 34 | -------------------------------------------------------------------------------- /experimental/scripts/utils/shared_parameters.ts: -------------------------------------------------------------------------------- 1 | type ParameterEffect = { 2 | effect: string; 3 | duration: number; 4 | radius: number; 5 | amplifier?: number; 6 | show_particles?: boolean; 7 | entity_type?: string[]; 8 | }[]; 9 | 10 | type ParameterMelt = { 11 | melted_state: string; 12 | }; 13 | 14 | type ParameterBounceForce = { 15 | force?: number; 16 | }; 17 | 18 | type ParameterRunCommand = { 19 | command: string[]; 20 | }; 21 | 22 | type ParameterLiquidPickup = { 23 | liquid_to_pickup?: string[]; 24 | transform_to: string; 25 | }[]; 26 | 27 | export { 28 | ParameterEffect, 29 | ParameterMelt, 30 | ParameterBounceForce, 31 | ParameterRunCommand, 32 | ParameterLiquidPickup 33 | }; 34 | -------------------------------------------------------------------------------- /docs/items/on-before-durability-damage/modify-durability-damage.md: -------------------------------------------------------------------------------- 1 | # adk_lib:before_durability_damage_modify_durability_damage 2 | 3 | # **RC** 4 | 5 | ## What does it do? 6 | 7 | This component modifies the durability damage when you hit an entity. 8 | 9 | ## How to use 10 | 11 | Add `adk_lib:before_durability_damage_modify_durability_damage` to the `minecraft:custom_components` array in your item json file. Since custom components do not have parameter support yet, this component utilizes item tags. 12 | 13 | To indicate what command your item should should, add the following tag: `adk_lib:modify_durability_damage_[amount]` 14 | 15 | ### Example 16 | 17 | ```json 18 | "minecraft:tags": { 19 | "tags": [ 20 | "adk_lib:modify_durability_damage_75" 21 | ] 22 | } 23 | ``` 24 | -------------------------------------------------------------------------------- /docs/items/on-hit-entity/summon-particle.md: -------------------------------------------------------------------------------- 1 | # adk_lib:on_hit_entity_summon_particle 2 | 3 | # **RC** 4 | 5 | ## What does it do? 6 | 7 | This component allows the item to spawn an entity at the position of the entity that this item hit. 8 | 9 | ## How to use 10 | 11 | Add `adk_lib:on_hit_entity_summon_particle` to the `minecraft:custom_components` array in your item json file. Since custom components do not have parameter support yet, this component utilizes item tags. 12 | 13 | To indicate what command your item should should, add the following tag: `adk_lib:on_hit_summon_particle_[particle id]` 14 | 15 | ### Example 16 | 17 | ```json 18 | "minecraft:tags": { 19 | "tags": [ 20 | "adk_lib:on_hit_summon_particle_minecraft:crop_growth_area_emitter" 21 | ] 22 | } 23 | ``` 24 | -------------------------------------------------------------------------------- /docs/items/on-before-durability-damage/run-command.md: -------------------------------------------------------------------------------- 1 | # adk_lib:before_durability_damage_run_command 2 | 3 | # **RC** 4 | 5 | ## What does it do? 6 | 7 | This component allows the item to run a command when used. 8 | 9 | ## How to use 10 | 11 | Add `adk_lib:before_durability_damage_run_command` to the `minecraft:custom_components` array in your item json file. Since custom components do not have parameter support yet, this component utilizes item tags. 12 | 13 | To indicate what command your item should should, add the following tag: `adk_lib:before_durability_damage_[command]` 14 | 15 | ### Example 16 | 17 | ```json 18 | "minecraft:tags": { 19 | "tags": [ 20 | "adk_lib:before_durability_damage_tp ~~10~", 21 | "adk_lib:before_durability_damage_say hi" 22 | ] 23 | } 24 | ``` 25 | -------------------------------------------------------------------------------- /docs/items/on-hit-entity/summon-entity.md: -------------------------------------------------------------------------------- 1 | # adk_lib:on_hit_entity_summon_entity 2 | 3 | # **RC** 4 | 5 | ## What does it do? 6 | 7 | This component allows the item to spawn an entity at the position of the entity that this item hit. 8 | 9 | ## How to use 10 | 11 | Add `adk_lib:on_hit_entity_summon_entity` to the `minecraft:custom_components` array in your item json file. Since custom components do not have parameter support yet, this component utilizes item tags. 12 | 13 | To indicate what command your item should should, add the following tag: `adk_lib:on_hit_summon_entity_[entity id]` 14 | 15 | ### Example 16 | 17 | ```json 18 | "minecraft:tags": { 19 | "tags": [ 20 | "adk_lib:on_hit_summon_entity_minecraft:pig", 21 | "adk_lib:on_hit_summon_entity_minecraft:lightning_bolt" 22 | ] 23 | } 24 | ``` 25 | -------------------------------------------------------------------------------- /docs/items/on-mine-block/digger-conditional.md: -------------------------------------------------------------------------------- 1 | # adk_lib:on_mine_block_digger_conditional 2 | 3 | ## What does it do? 4 | 5 | This component modifies the durability damage when you mine a block. Differetnt blocks will do different amount of durability damage. 6 | 7 | ## How to use 8 | 9 | Add `adk_lib:on_mine_block_digger_conditional` to the `minecraft:custom_components` array in your item json file. Since custom components do not have parameter support yet, this component utilizes item tags. 10 | 11 | To indicate what command your item should should, add the following tag: `adk_lib:digger_conditional_block_[block id]_amount_[amount]` 12 | 13 | ### Example 14 | 15 | ```json 16 | "minecraft:tags": { 17 | "tags": [ 18 | "adk_lib:digger_conditional_block_minecraft:stone_amount_5", 19 | "adk_lib:digger_conditional_block_minecraft:dirt_amount_15" 20 | ] 21 | } 22 | ``` 23 | -------------------------------------------------------------------------------- /docs/items/on-use-on/item-dye.md: -------------------------------------------------------------------------------- 1 | # adk_lib:on_use_on_dye 2 | 3 | ## What does it do? 4 | 5 | This component enables the dye functionality. It allows items to dye signs. 6 | 7 | ## How to use 8 | 9 | Add `adk_lib:on_use_on_dye` to the `minecraft:custom_components` array in your item json file. Since custom components do not have parameter support yet, this component utilizes item tags. 10 | 11 | To indicate what dye colour your item is, add the `adk_lib:dye_[colour of the dye]` tag to your item file. 12 | 13 | ### Example 14 | 15 | ```json 16 | "minecraft:tags": { 17 | "tags": [ 18 | "adk_lib:dye_Lime" 19 | ] 20 | } 21 | ``` 22 | 23 | ## Allowed Values 24 | 25 | - Black 26 | - Blue 27 | - Brown 28 | - Cyan 29 | - Gray 30 | - Green 31 | - LightBlue 32 | - Lime 33 | - Magenta 34 | - Orange 35 | - Pink 36 | - Purple 37 | - Red 38 | - Silver 39 | - White 40 | - Yellow 41 | -------------------------------------------------------------------------------- /packs/data/stable.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": [ 3 | { 4 | "module_name": "@minecraft/server", 5 | "version": "2.0.0" 6 | } 7 | ], 8 | "format_version": 2, 9 | "header": { 10 | "description": "Made By SmokeyStack", 11 | "min_engine_version": [ 12 | 1, 13 | 21, 14 | 90 15 | ], 16 | "name": "ADK LIB", 17 | "uuid": "5e2eda3e-6eaf-4068-9076-0a7f0587b8bb", 18 | "version": "1.0.0" 19 | }, 20 | "modules": [ 21 | { 22 | "type": "data", 23 | "uuid": "bb174344-46c7-46a5-87bf-d2535876b70f", 24 | "version": "1.0.0" 25 | }, 26 | { 27 | "entry": "scripts/main.js", 28 | "type": "script", 29 | "uuid": "c57c9003-0630-4432-8275-200ee08e6796", 30 | "version": "1.0.0" 31 | } 32 | ] 33 | } -------------------------------------------------------------------------------- /packs/data/rc.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": [ 3 | { 4 | "module_name": "@minecraft/server", 5 | "version": "2.1.0" 6 | } 7 | ], 8 | "format_version": 2, 9 | "header": { 10 | "description": "Made By SmokeyStack", 11 | "min_engine_version": [ 12 | 1, 13 | 21, 14 | 100 15 | ], 16 | "name": "ADK LIB", 17 | "uuid": "5e2eda3e-6eaf-4068-9076-0a7f0587b8bb", 18 | "version": "1.1.0-rc.1.21.100.23" 19 | }, 20 | "modules": [ 21 | { 22 | "type": "data", 23 | "uuid": "bb174344-46c7-46a5-87bf-d2535876b70f", 24 | "version": "1.1.0-rc.1.21.100.23" 25 | }, 26 | { 27 | "entry": "scripts/main.js", 28 | "type": "script", 29 | "uuid": "c57c9003-0630-4432-8275-200ee08e6796", 30 | "version": "1.1.0-rc.1.21.100.23" 31 | } 32 | ] 33 | } -------------------------------------------------------------------------------- /experimental/scripts/utils/helper.ts: -------------------------------------------------------------------------------- 1 | import { Dimension, Vector3, Block } from '@minecraft/server'; 2 | 3 | /** 4 | * @brief Updates the liquid block since placing a liquid by itself won't make it flow. 5 | * @param dimension The dimension to execute in 6 | * @param location The world location 7 | */ 8 | export function updateLiquidBlock( 9 | dimension: Dimension, 10 | location: Vector3 11 | ): void { 12 | dimension.setBlockType(location, 'minecraft:bedrock'); 13 | dimension.setBlockType(location, 'minecraft:air'); 14 | } 15 | 16 | /** 17 | * @brief Updates the block if it is air. 18 | * @param dimension Dimension to execute in 19 | * @param block Block to check 20 | * @param blockLocation Block location 21 | */ 22 | export function updateIfAir( 23 | dimension: Dimension, 24 | block: Block, 25 | blockLocation: Vector3 26 | ): void { 27 | if (block.typeId == 'minecraft:air') 28 | updateLiquidBlock(dimension, blockLocation); 29 | } 30 | -------------------------------------------------------------------------------- /rc/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "allowUnreachableCode": true, 5 | "allowUnusedLabels": true, 6 | "baseUrl": "./scripts", 7 | "declaration": false, 8 | "emitDecoratorMetadata": true, 9 | "experimentalDecorators": true, 10 | "forceConsistentCasingInFileNames": true, 11 | "listFiles": false, 12 | "module": "ES2020", 13 | "moduleResolution": "Node", 14 | "noEmitHelpers": true, 15 | "noImplicitAny": false, 16 | "noImplicitReturns": false, 17 | "noImplicitUseStrict": false, 18 | "noLib": false, 19 | "outDir": "../packs/BP", 20 | "pretty": true, 21 | "rootDir": ".", 22 | "skipLibCheck": true, 23 | "sourceMap": false, 24 | "strict": true, 25 | "target": "ES2022" 26 | }, 27 | "exclude": ["lib", "dist", "node_modules"], 28 | "include": ["scripts/**/*"] 29 | } 30 | -------------------------------------------------------------------------------- /stable/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "allowUnreachableCode": true, 5 | "allowUnusedLabels": true, 6 | "baseUrl": "./scripts", 7 | "declaration": false, 8 | "emitDecoratorMetadata": true, 9 | "experimentalDecorators": true, 10 | "forceConsistentCasingInFileNames": true, 11 | "listFiles": false, 12 | "module": "ES2020", 13 | "moduleResolution": "Node", 14 | "noEmitHelpers": true, 15 | "noImplicitAny": false, 16 | "noImplicitReturns": false, 17 | "noImplicitUseStrict": false, 18 | "noLib": false, 19 | "outDir": "../packs/BP", 20 | "pretty": true, 21 | "rootDir": ".", 22 | "skipLibCheck": true, 23 | "sourceMap": false, 24 | "strict": false, 25 | "target": "ES2022" 26 | }, 27 | "exclude": ["lib", "dist", "node_modules"], 28 | "include": ["scripts/**/*"] 29 | } 30 | -------------------------------------------------------------------------------- /docs/items/on-use-on/item-glass-bottle.md: -------------------------------------------------------------------------------- 1 | # adk_lib:on_use_on_glass_bottle 2 | 3 | ## What does it do? 4 | 5 | This component enables the glass bottle functionality. It allows items to pickup liquids and turn into a different item. 6 | 7 | ## How to use 8 | 9 | Add `adk_lib:on_use_on_glass_bottle` to the `minecraft:custom_components` array in your item json file. Since custom components do not have parameter support yet, this component utilizes item tags. 10 | 11 | To indicate what liquid your item should pickup, add the following tag: `adk_lib:fluid_[identifier of the liquid]_turn_into_[identifier of the item that this item turns into]` 12 | 13 | ### Example 14 | 15 | ```json 16 | "minecraft:tags": { 17 | "tags": [ 18 | "adk_lib:fluid_minecraft:water_turn_into_minecraft:water_bucket", 19 | "adk_lib:fluid_minecraft:lava_turn_into_minecraft:lava_bucket", 20 | "adk_lib:fluid_minecraft:powder_snow_turn_into_minecraft:powder_snow_bucket" 21 | ] 22 | } 23 | ``` 24 | -------------------------------------------------------------------------------- /experimental/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "allowUnreachableCode": true, 5 | "allowUnusedLabels": true, 6 | "baseUrl": "./scripts", 7 | "declaration": false, 8 | "emitDecoratorMetadata": true, 9 | "experimentalDecorators": true, 10 | "forceConsistentCasingInFileNames": true, 11 | "listFiles": false, 12 | "module": "ES2020", 13 | "moduleResolution": "Node", 14 | "noEmitHelpers": true, 15 | "noImplicitAny": false, 16 | "noImplicitReturns": false, 17 | "noImplicitUseStrict": false, 18 | "noLib": false, 19 | "outDir": "../packs/BP", 20 | "pretty": true, 21 | "rootDir": ".", 22 | "skipLibCheck": true, 23 | "sourceMap": false, 24 | "strict": true, 25 | "target": "ES2022" 26 | }, 27 | "exclude": ["lib", "dist", "node_modules"], 28 | "include": ["scripts/**/*"] 29 | } 30 | -------------------------------------------------------------------------------- /docs/items/on-consume/food-effect.md: -------------------------------------------------------------------------------- 1 | # adk_lib:on_consume_food_effect 2 | 3 | ## What does it do? 4 | 5 | This component enables the item to give a food effect upon consumption. 6 | 7 | ## How to use 8 | 9 | Add `adk_lib:on_consume_food_effect` to the `minecraft:custom_components` array in your item json file. Since custom components do not have parameter support yet, this component utilizes item tags. 10 | 11 | To indicate the effect that your item will give upon consumption, add the `adk_lib:food_[effect name]_[duration in ticks]_[amplifier]_[true or false, this is optional]` tag to your item file. By default, `showParticles` is set to true. 12 | 13 | ### Example 14 | 15 | ```json 16 | "minecraft:tags": { 17 | "tags": [ 18 | "adk_lib:food_absorption_2400_3", 19 | "adk_lib:food_regeneration_600_4", 20 | "adk_lib:food_fire_resistance_6000_0", 21 | "adk_lib:food_resistance_6000_0", 22 | "adk_lib:food_resistance_6000_0_false", 23 | ] 24 | } 25 | ``` 26 | -------------------------------------------------------------------------------- /packs/data/experimental.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": [ 3 | { 4 | "module_name": "@minecraft/server", 5 | "version": "2.2.0-beta" 6 | } 7 | ], 8 | "format_version": 2, 9 | "header": { 10 | "description": "Made By SmokeyStack", 11 | "min_engine_version": [ 12 | 1, 13 | 21, 14 | 100 15 | ], 16 | "name": "ADK LIB", 17 | "uuid": "5e2eda3e-6eaf-4068-9076-0a7f0587b8bb", 18 | "version": "1.2.0-experimental.1.21.100.23" 19 | }, 20 | "modules": [ 21 | { 22 | "type": "data", 23 | "uuid": "bb174344-46c7-46a5-87bf-d2535876b70f", 24 | "version": "1.2.0-experimental.1.21.100.23" 25 | }, 26 | { 27 | "entry": "scripts/main.js", 28 | "type": "script", 29 | "uuid": "c57c9003-0630-4432-8275-200ee08e6796", 30 | "version": "1.2.0-experimental.1.21.100.23" 31 | } 32 | ] 33 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "adk-lib", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "scripts": { 6 | "dev-experimental": "npm run compile --workspace=experimental && regolith run dev-experimental", 7 | "dev-rc": "npm run compile --workspace=rc && regolith run dev-rc", 8 | "dev-stable": "npm run compile --workspace=stable && regolith run dev-stable", 9 | "build-experimental": "npm run compile --workspace=experimental && regolith run build-experimental", 10 | "build-rc": "npm run compile --workspace=rc && regolith run build-rc", 11 | "build-stable": "npm run compile --workspace=stable && regolith run build-stable" 12 | }, 13 | "workspaces": [ 14 | "experimental", 15 | "rc", 16 | "stable" 17 | ], 18 | "keywords": [], 19 | "author": "SmokeyStack", 20 | "license": "GPL-3.0-only", 21 | "description": "", 22 | "devDependencies": { 23 | "tsup": "^8.3.5", 24 | "typescript": "^5.8.2" 25 | } 26 | } -------------------------------------------------------------------------------- /docs/blocks/on-player-interact/turn-into-entity.md: -------------------------------------------------------------------------------- 1 | # adk_lib:on_player_interact_turn_into_entity 2 | 3 | ## What does it do? 4 | 5 | This component allows the block to turn into an entity when interacted with a specific item. 6 | 7 | ## How to use 8 | 9 | Add `"adk_lib:on_player_interact_turn_into_entity": {}` to your block json file. 10 | 11 | ### Parameters 12 | 13 | - Key: Represents the entity it transforms to. 14 | - Value: A list of items (string array) that can trigger the transformation when interacted with. 15 | 16 | ### Example 17 | 18 | ```json 19 | "adk_lib:on_player_interact_turn_into_entity": [ 20 | { 21 | "transform_to": "test", 22 | "transform_from": [ 23 | "test", 24 | { 25 | "tag": "air" 26 | } 27 | ] 28 | }, 29 | { 30 | "transform_to": { 31 | "name": "minecraft:creeper", 32 | "spawn_event": "minecraft:become_charged" 33 | }, 34 | "transform_from": [ 35 | "test" 36 | ] 37 | } 38 | ] 39 | ``` 40 | -------------------------------------------------------------------------------- /docs/items/on-before-durability-damage/modify-durability-damage-conditional.md: -------------------------------------------------------------------------------- 1 | # adk_lib:before_durability_damage_modify_durability_damage_conditional 2 | 3 | # **RC** 4 | 5 | ## What does it do? 6 | 7 | This component modifies the durability damage when you hit specific entities. 8 | 9 | ## How to use 10 | 11 | Add `adk_lib:before_durability_damage_modify_durability_damage_conditional` to the `minecraft:custom_components` array in your item json file. Since custom components do not have parameter support yet, this component utilizes item tags. 12 | 13 | To indicate what command your item should should, add the following tag: `adk_lib:modify_durability_damage_conditional_entity_[entity id]_amount_[amount]` 14 | 15 | ### Example 16 | 17 | ```json 18 | "minecraft:tags": { 19 | "tags": [ 20 | "adk_lib:modify_durability_damage_conditional_entity_minecraft:pig_amount_50", 21 | "adk_lib:modify_durability_damage_conditional_entity_minecraft:cow_amount_25", 22 | "adk_lib:modify_durability_damage_conditional_entity_minecraft:sheep_amount_100" 23 | ] 24 | } 25 | ``` 26 | -------------------------------------------------------------------------------- /docs/blocks/on-player-interact/turn-into.md: -------------------------------------------------------------------------------- 1 | # adk_lib:on_player_interact_turn_into 2 | 3 | ## What does it do? 4 | 5 | This component allows the block to turn into another block when interacted with a specific item. 6 | 7 | ## How to use 8 | 9 | Add `"adk_lib:on_player_interact_turn_into": {}` to your block json file. 10 | 11 | ### Parameters 12 | 13 | - Key: Represents the block it transforms to. 14 | - Value: A list of items (string array) that can trigger the transformation when interacted with. 15 | 16 | ### Example 17 | 18 | ```json 19 | "adk_lib:on_player_interact_turn_into": [ 20 | { 21 | "transform_to": "test", 22 | "transform_from": [ 23 | "test", 24 | { 25 | "tag": "air" 26 | } 27 | ] 28 | }, 29 | { 30 | "transform_to": { 31 | "name": "furnace", 32 | "states": { 33 | "minecraft:cardinal_direction": "east", 34 | "test": 2 35 | } 36 | }, 37 | "transform_from": [ 38 | "test" 39 | ] 40 | } 41 | ] 42 | ``` 43 | -------------------------------------------------------------------------------- /rc/scripts/utils/helper.ts: -------------------------------------------------------------------------------- 1 | import { Dimension, Vector3, Block } from '@minecraft/server'; 2 | 3 | /** 4 | * @brief Updates the liquid block since placing a liquid by itself won't make it flow. 5 | * @param dimension The dimension to execute in 6 | * @param location The world location 7 | */ 8 | export function updateLiquidBlock( 9 | dimension: Dimension, 10 | location: Vector3 11 | ): void { 12 | dimension.setBlockType(location, 'minecraft:bedrock'); 13 | dimension.setBlockType(location, 'minecraft:air'); 14 | } 15 | 16 | /** 17 | * @brief Updates the block if it is air. 18 | * @param dimension Dimension to execute in 19 | * @param block Block to check 20 | * @param blockLocation Block location 21 | */ 22 | export function updateIfAir( 23 | dimension: Dimension, 24 | block: Block, 25 | blockLocation: Vector3 26 | ): void { 27 | if (block.typeId == 'minecraft:air') 28 | updateLiquidBlock(dimension, blockLocation); 29 | } 30 | 31 | export function doesBlockBlockkMovement(block: Block): boolean { 32 | return ( 33 | block.typeId != 'minecraft:cobweb' && 34 | block.typeId != 'minecraft:bamboo_sapling' && 35 | !block.isLiquid && 36 | !block.isAir 37 | ); 38 | } 39 | -------------------------------------------------------------------------------- /stable/scripts/utils/helper.ts: -------------------------------------------------------------------------------- 1 | import { Dimension, Vector3, Block } from '@minecraft/server'; 2 | 3 | /** 4 | * @brief Updates the liquid block since placing a liquid by itself won't make it flow. 5 | * @param dimension The dimension to execute in 6 | * @param location The world location 7 | */ 8 | export function updateLiquidBlock( 9 | dimension: Dimension, 10 | location: Vector3 11 | ): void { 12 | dimension.setBlockType(location, 'minecraft:bedrock'); 13 | dimension.setBlockType(location, 'minecraft:air'); 14 | } 15 | 16 | /** 17 | * @brief Updates the block if it is air. 18 | * @param dimension Dimension to execute in 19 | * @param block Block to check 20 | * @param blockLocation Block location 21 | */ 22 | export function updateIfAir( 23 | dimension: Dimension, 24 | block: Block, 25 | blockLocation: Vector3 26 | ): void { 27 | if (block.typeId == 'minecraft:air') 28 | updateLiquidBlock(dimension, blockLocation); 29 | } 30 | 31 | export function doesBlockBlockkMovement(block: Block): boolean { 32 | return ( 33 | block.typeId != 'minecraft:cobweb' && 34 | block.typeId != 'minecraft:bamboo_sapling' && 35 | !block.isLiquid && 36 | !block.isAir 37 | ); 38 | } 39 | -------------------------------------------------------------------------------- /rc/scripts/blocks/sugar_cane.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Block, 3 | BlockComponentPlayerPlaceBeforeEvent, 4 | BlockPermutation 5 | } from '@minecraft/server'; 6 | import * as adk from 'adk-scripts-server'; 7 | 8 | export function beforeOnPlayerPlaceSugarCane( 9 | data: BlockComponentPlayerPlaceBeforeEvent 10 | ): void { 11 | const block: Block = data.block; 12 | const block_to_place: BlockPermutation = data.permutationToPlace; 13 | const block_to_check: Block | undefined = block.below(); 14 | 15 | if (!block_to_check || block_to_check.typeId === block_to_place.type.id) 16 | return; 17 | if ( 18 | block_to_check.getTags().includes('dirt') || 19 | block_to_check.getTags().includes('sand') 20 | ) { 21 | adk.DirectionType.Horizontal.forEach((direction) => { 22 | const block_2: Block | undefined = block_to_check.offset( 23 | adk.DirectionHelper.toVector3(direction) 24 | ); 25 | 26 | if ( 27 | !block_2 || 28 | block_2.getTags().includes('water') || 29 | block_2.typeId == 'minecraft:frosted_ice' 30 | ) 31 | return; 32 | }); 33 | } 34 | 35 | data.cancel = true; 36 | } 37 | -------------------------------------------------------------------------------- /stable/scripts/blocks/sugar_cane.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Block, 3 | BlockComponentPlayerPlaceBeforeEvent, 4 | BlockPermutation 5 | } from '@minecraft/server'; 6 | import * as adk from 'adk-scripts-server'; 7 | 8 | export function beforeOnPlayerPlaceSugarCane( 9 | data: BlockComponentPlayerPlaceBeforeEvent 10 | ): void { 11 | const block: Block = data.block; 12 | const block_to_place: BlockPermutation = data.permutationToPlace; 13 | const block_to_check: Block | undefined = block.below(); 14 | 15 | if (!block_to_check || block_to_check.typeId === block_to_place.type.id) 16 | return; 17 | if ( 18 | block_to_check.getTags().includes('dirt') || 19 | block_to_check.getTags().includes('sand') 20 | ) { 21 | adk.DirectionType.Horizontal.forEach((direction) => { 22 | const block_2: Block | undefined = block_to_check.offset( 23 | adk.DirectionHelper.toVector3(direction) 24 | ); 25 | 26 | if ( 27 | !block_2 || 28 | block_2.getTags().includes('water') || 29 | block_2.typeId == 'minecraft:frosted_ice' 30 | ) 31 | return; 32 | }); 33 | } 34 | 35 | data.cancel = true; 36 | } 37 | -------------------------------------------------------------------------------- /experimental/scripts/blocks/sugar_cane.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Block, 3 | BlockComponentPlayerPlaceBeforeEvent, 4 | BlockPermutation 5 | } from '@minecraft/server'; 6 | import * as adk from 'adk-scripts-server'; 7 | 8 | export function beforeOnPlayerPlaceSugarCane( 9 | data: BlockComponentPlayerPlaceBeforeEvent 10 | ): void { 11 | const block: Block = data.block; 12 | const block_to_place: BlockPermutation = data.permutationToPlace; 13 | const block_to_check: Block | undefined = block.below(); 14 | 15 | if (!block_to_check || block_to_check.typeId === block_to_place.type.id) 16 | return; 17 | if ( 18 | block_to_check.getTags().includes('dirt') || 19 | block_to_check.getTags().includes('sand') 20 | ) { 21 | adk.DirectionType.Horizontal.forEach((direction) => { 22 | const block_2: Block | undefined = block_to_check.offset( 23 | adk.DirectionHelper.toVector3(direction) 24 | ); 25 | 26 | if ( 27 | !block_2 || 28 | block_2.getTags().includes('water') || 29 | block_2.typeId == 'minecraft:frosted_ice' 30 | ) 31 | return; 32 | }); 33 | } 34 | 35 | data.cancel = true; 36 | } 37 | -------------------------------------------------------------------------------- /rc/scripts/blocks/registry/on_place.ts: -------------------------------------------------------------------------------- 1 | import { 2 | BlockComponentOnPlaceEvent, 3 | BlockCustomComponent, 4 | CustomComponentParameters 5 | } from '@minecraft/server'; 6 | import * as adk from 'adk-scripts-server'; 7 | 8 | abstract class OnPlace implements BlockCustomComponent { 9 | abstract onPlace( 10 | componentData: BlockComponentOnPlaceEvent, 11 | paramData?: CustomComponentParameters 12 | ): void; 13 | } 14 | 15 | class Debug extends OnPlace { 16 | onPlace(componentData: BlockComponentOnPlaceEvent) { 17 | console.log(adk.Debug.logEventData(componentData)); 18 | } 19 | } 20 | 21 | type ParameterTurnInto = { 22 | block: string; 23 | }; 24 | 25 | class TurnInto extends OnPlace { 26 | onPlace( 27 | componentData: BlockComponentOnPlaceEvent, 28 | paramData: CustomComponentParameters 29 | ) { 30 | const param = paramData.params as ParameterTurnInto; 31 | componentData.block.setType(param.block); 32 | } 33 | } 34 | 35 | enum OnPlaceKey { 36 | Debug = 'debug', 37 | TurnInto = 'turn_into' 38 | } 39 | 40 | export const ON_PLACE_REGISTRY: Map = new Map([ 41 | [OnPlaceKey.Debug, new Debug()], 42 | [OnPlaceKey.TurnInto, new TurnInto()] 43 | ]); 44 | -------------------------------------------------------------------------------- /stable/scripts/blocks/registry/on_place.ts: -------------------------------------------------------------------------------- 1 | import { 2 | BlockComponentOnPlaceEvent, 3 | BlockCustomComponent, 4 | CustomComponentParameters 5 | } from '@minecraft/server'; 6 | import * as adk from 'adk-scripts-server'; 7 | 8 | abstract class OnPlace implements BlockCustomComponent { 9 | abstract onPlace( 10 | componentData: BlockComponentOnPlaceEvent, 11 | paramData?: CustomComponentParameters 12 | ): void; 13 | } 14 | 15 | class Debug extends OnPlace { 16 | onPlace(componentData: BlockComponentOnPlaceEvent) { 17 | console.log(adk.Debug.logEventData(componentData)); 18 | } 19 | } 20 | 21 | type ParameterTurnInto = { 22 | block: string; 23 | }; 24 | 25 | class TurnInto extends OnPlace { 26 | onPlace( 27 | componentData: BlockComponentOnPlaceEvent, 28 | paramData: CustomComponentParameters 29 | ) { 30 | const param = paramData.params as ParameterTurnInto; 31 | componentData.block.setType(param.block); 32 | } 33 | } 34 | 35 | enum OnPlaceKey { 36 | Debug = 'debug', 37 | TurnInto = 'turn_into' 38 | } 39 | 40 | export const ON_PLACE_REGISTRY: Map = new Map([ 41 | [OnPlaceKey.Debug, new Debug()], 42 | [OnPlaceKey.TurnInto, new TurnInto()] 43 | ]); 44 | -------------------------------------------------------------------------------- /experimental/scripts/blocks/registry/on_place.ts: -------------------------------------------------------------------------------- 1 | import { 2 | BlockComponentOnPlaceEvent, 3 | BlockCustomComponent, 4 | CustomComponentParameters 5 | } from '@minecraft/server'; 6 | import * as adk from 'adk-scripts-server'; 7 | 8 | abstract class OnPlace implements BlockCustomComponent { 9 | abstract onPlace( 10 | componentData: BlockComponentOnPlaceEvent, 11 | paramData?: CustomComponentParameters 12 | ): void; 13 | } 14 | 15 | class Debug extends OnPlace { 16 | onPlace(componentData: BlockComponentOnPlaceEvent) { 17 | console.log(adk.Debug.logEventData(componentData)); 18 | } 19 | } 20 | 21 | type ParameterTurnInto = { 22 | block: string; 23 | }; 24 | 25 | class TurnInto extends OnPlace { 26 | onPlace( 27 | componentData: BlockComponentOnPlaceEvent, 28 | paramData: CustomComponentParameters 29 | ) { 30 | const param = paramData.params as ParameterTurnInto; 31 | componentData.block.setType(param.block); 32 | } 33 | } 34 | 35 | enum OnPlaceKey { 36 | Debug = 'debug', 37 | TurnInto = 'turn_into' 38 | } 39 | 40 | export const ON_PLACE_REGISTRY: Map = new Map([ 41 | [OnPlaceKey.Debug, new Debug()], 42 | [OnPlaceKey.TurnInto, new TurnInto()] 43 | ]); 44 | -------------------------------------------------------------------------------- /docs/blocks/on-step-on/effect.md: -------------------------------------------------------------------------------- 1 | # adk_lib:on_step_on_effect 2 | 3 | ## What does it do? 4 | 5 | This component will give the entity that steps on the block the specified effect. 6 | 7 | ## How to use 8 | 9 | Add `"adk_lib:on_step_on_effect": {}` to your block json file. 10 | 11 | ### Parameters 12 | 13 | - `"effect"`: Specifies the name of the status effect to be applied 14 | - `"duration"`: Determines how long the effect will last in ticks 15 | - `"radius"`: Defines the area of effect measured in blocks. Entities within this radius from the block will be affected. 16 | - `"amplifier"`: Sets the strength level of the effect. Default is 0 if omitted. 17 | - `"show_particles"`: Indicates whether particles should be visible when the effect is applied. Default is true if omitted. 18 | - `"entity_type"`: A list of entity types that can be affected. If omitted, all entities within the radius will be affected. 19 | 20 | ### Example 21 | 22 | ```json 23 | "adk_lib:on_step_on_effect": [ 24 | { 25 | "effect": "darkness", 26 | "duration": 100, 27 | "radius": 5 28 | }, 29 | { 30 | "effect": "poison", 31 | "duration": 100, 32 | "radius": 1 33 | }, 34 | { 35 | "effect": "levitation", 36 | "duration": 100, 37 | "radius": 10, 38 | "entity_type": [ 39 | "minecraft:pig" 40 | ] 41 | } 42 | ] 43 | ``` 44 | -------------------------------------------------------------------------------- /docs/blocks/on-step-off/effect.md: -------------------------------------------------------------------------------- 1 | # adk_lib:on_step_off_effect 2 | 3 | ## What does it do? 4 | 5 | This component will give the entity that steps off the block the specified effect. 6 | 7 | ## How to use 8 | 9 | Add `"adk_lib:on_step_off_effect": {}` to your block json file. 10 | 11 | ### Parameters 12 | 13 | - `"effect"`: Specifies the name of the status effect to be applied 14 | - `"duration"`: Determines how long the effect will last in ticks 15 | - `"radius"`: Defines the area of effect measured in blocks. Entities within this radius from the block will be affected. 16 | - `"amplifier"`: Sets the strength level of the effect. Default is 0 if omitted. 17 | - `"show_particles"`: Indicates whether particles should be visible when the effect is applied. Default is true if omitted. 18 | - `"entity_type"`: A list of entity types that can be affected. If omitted, all entities within the radius will be affected. 19 | 20 | ### Example 21 | 22 | ```json 23 | "adk_lib:on_step_off_effect": [ 24 | { 25 | "effect": "darkness", 26 | "duration": 100, 27 | "radius": 5 28 | }, 29 | { 30 | "effect": "poison", 31 | "duration": 100, 32 | "radius": 1 33 | }, 34 | { 35 | "effect": "levitation", 36 | "duration": 100, 37 | "radius": 10, 38 | "entity_type": [ 39 | "minecraft:pig" 40 | ] 41 | } 42 | ] 43 | ``` 44 | -------------------------------------------------------------------------------- /docs/blocks/on-random-tick/effect.md: -------------------------------------------------------------------------------- 1 | # adk_lib:on_random_tick_effect 2 | 3 | ## What does it do? 4 | 5 | This component will give the entity that steps off the block the specified effect. 6 | 7 | ## How to use 8 | 9 | Add `"adk_lib:on_random_tick_effect": {}` to your block json file. 10 | 11 | ### Parameters 12 | 13 | - `"effect"`: Specifies the name of the status effect to be applied 14 | - `"duration"`: Determines how long the effect will last in ticks 15 | - `"radius"`: Defines the area of effect measured in blocks. Entities within this radius from the block will be affected. 16 | - `"amplifier"`: Sets the strength level of the effect. Default is 0 if omitted. 17 | - `"show_particles"`: Indicates whether particles should be visible when the effect is applied. Default is true if omitted. 18 | - `"entity_type"`: A list of entity types that can be affected. If omitted, all entities within the radius will be affected. 19 | 20 | ### Example 21 | 22 | ```json 23 | "adk_lib:on_random_tick_effect": [ 24 | { 25 | "effect": "darkness", 26 | "duration": 100, 27 | "radius": 5 28 | }, 29 | { 30 | "effect": "poison", 31 | "duration": 100, 32 | "radius": 1 33 | }, 34 | { 35 | "effect": "levitation", 36 | "duration": 100, 37 | "radius": 10, 38 | "entity_type": [ 39 | "minecraft:pig" 40 | ] 41 | } 42 | ] 43 | ``` 44 | -------------------------------------------------------------------------------- /docs/items/on-use-on/item-bucket.md: -------------------------------------------------------------------------------- 1 | # adk_lib:on_use_on_bucket 2 | 3 | ## What does it do? 4 | 5 | This component enables the bucket functionality. It allows items to pickup or place liquids and turn into a different item. 6 | 7 | ## How to use 8 | 9 | Add `adk_lib:on_use_on_bucket` to the `minecraft:custom_components` array in your item json file. Since custom components do not have parameter support yet, this component utilizes item tags. 10 | 11 | To indicate that your item is an "empty bucket", add the `adk_lib:fluid_empty` tag to your item file. To indicate what liquid your item should pickup, add the following tag: `adk_lib:fluid_[identifier of the liquid]_turn_into_[identifier of the item that this item turns into]` 12 | 13 | ### Example 14 | 15 | ```json 16 | "minecraft:tags": { 17 | "tags": [ 18 | "adk_lib:fluid_empty", 19 | "adk_lib:fluid_minecraft:water_turn_into_minecraft:water_bucket", 20 | "adk_lib:fluid_minecraft:lava_turn_into_minecraft:lava_bucket", 21 | "adk_lib:fluid_minecraft:powder_snow_turn_into_minecraft:powder_snow_bucket" 22 | ] 23 | } 24 | ``` 25 | 26 | To indicate that your item has liquid, add the `adk_lib:fluid_[identifier of the liquid]_[identifier of the item that this item turns into]` 27 | 28 | ### Example 29 | 30 | ```json 31 | "minecraft:tags": { 32 | "tags": [ 33 | "adk_lib:fluid_minecraft:water_minecraft:bucket" 34 | ] 35 | } 36 | ``` 37 | -------------------------------------------------------------------------------- /rc/scripts/item/registry/on_complete_use.ts: -------------------------------------------------------------------------------- 1 | import { 2 | CustomComponentParameters, 3 | ItemComponentCompleteUseEvent, 4 | ItemCustomComponent, 5 | system 6 | } from '@minecraft/server'; 7 | import * as adk from 'adk-scripts-server'; 8 | import { ParameterRunCommand } from 'utils/shared_parameters'; 9 | 10 | abstract class OnCompleteUse implements ItemCustomComponent { 11 | abstract onCompleteUse( 12 | componentData: ItemComponentCompleteUseEvent, 13 | paramData?: CustomComponentParameters 14 | ): void; 15 | } 16 | 17 | class Debug extends OnCompleteUse { 18 | onCompleteUse(componentData: ItemComponentCompleteUseEvent) { 19 | console.log(adk.Debug.logEventData(componentData)); 20 | } 21 | } 22 | 23 | class RunCommand extends OnCompleteUse { 24 | onCompleteUse( 25 | componentData: ItemComponentCompleteUseEvent, 26 | paramData: CustomComponentParameters 27 | ) { 28 | const param = paramData.params as ParameterRunCommand; 29 | system.run(() => { 30 | param.command.forEach((command) => { 31 | componentData.source.runCommand(command); 32 | }); 33 | }); 34 | } 35 | } 36 | 37 | enum OnCompleteUseKey { 38 | Debug = 'debug', 39 | RunCommand = 'run_command' 40 | } 41 | 42 | export const ON_COMPLETE_USE_REGISTRY = new Map([ 43 | [OnCompleteUseKey.Debug, new Debug()], 44 | [OnCompleteUseKey.RunCommand, new RunCommand()] 45 | ]); 46 | -------------------------------------------------------------------------------- /stable/scripts/item/registry/on_complete_use.ts: -------------------------------------------------------------------------------- 1 | import { 2 | CustomComponentParameters, 3 | ItemComponentCompleteUseEvent, 4 | ItemCustomComponent, 5 | system 6 | } from '@minecraft/server'; 7 | import * as adk from 'adk-scripts-server'; 8 | import { ParameterRunCommand } from 'utils/shared_parameters'; 9 | 10 | abstract class OnCompleteUse implements ItemCustomComponent { 11 | abstract onCompleteUse( 12 | componentData: ItemComponentCompleteUseEvent, 13 | paramData?: CustomComponentParameters 14 | ): void; 15 | } 16 | 17 | class Debug extends OnCompleteUse { 18 | onCompleteUse(componentData: ItemComponentCompleteUseEvent) { 19 | console.log(adk.Debug.logEventData(componentData)); 20 | } 21 | } 22 | 23 | class RunCommand extends OnCompleteUse { 24 | onCompleteUse( 25 | componentData: ItemComponentCompleteUseEvent, 26 | paramData: CustomComponentParameters 27 | ) { 28 | const param = paramData.params as ParameterRunCommand; 29 | system.run(() => { 30 | param.command.forEach((command) => { 31 | componentData.source.runCommand(command); 32 | }); 33 | }); 34 | } 35 | } 36 | 37 | enum OnCompleteUseKey { 38 | Debug = 'debug', 39 | RunCommand = 'run_command' 40 | } 41 | 42 | export const ON_COMPLETE_USE_REGISTRY = new Map([ 43 | [OnCompleteUseKey.Debug, new Debug()], 44 | [OnCompleteUseKey.RunCommand, new RunCommand()] 45 | ]); 46 | -------------------------------------------------------------------------------- /experimental/scripts/item/registry/on_complete_use.ts: -------------------------------------------------------------------------------- 1 | import { 2 | CustomComponentParameters, 3 | ItemComponentCompleteUseEvent, 4 | ItemCustomComponent, 5 | system 6 | } from '@minecraft/server'; 7 | import * as adk from 'adk-scripts-server'; 8 | import { ParameterRunCommand } from 'utils/shared_parameters'; 9 | 10 | abstract class OnCompleteUse implements ItemCustomComponent { 11 | abstract onCompleteUse( 12 | componentData: ItemComponentCompleteUseEvent, 13 | paramData?: CustomComponentParameters 14 | ): void; 15 | } 16 | 17 | class Debug extends OnCompleteUse { 18 | onCompleteUse(componentData: ItemComponentCompleteUseEvent) { 19 | console.log(adk.Debug.logEventData(componentData)); 20 | } 21 | } 22 | 23 | class RunCommand extends OnCompleteUse { 24 | onCompleteUse( 25 | componentData: ItemComponentCompleteUseEvent, 26 | paramData: CustomComponentParameters 27 | ) { 28 | const param = paramData.params as ParameterRunCommand; 29 | system.run(() => { 30 | param.command.forEach((command) => { 31 | componentData.source.runCommand(command); 32 | }); 33 | }); 34 | } 35 | } 36 | 37 | enum OnCompleteUseKey { 38 | Debug = 'debug', 39 | RunCommand = 'run_command' 40 | } 41 | 42 | export const ON_COMPLETE_USE_REGISTRY = new Map([ 43 | [OnCompleteUseKey.Debug, new Debug()], 44 | [OnCompleteUseKey.RunCommand, new RunCommand()] 45 | ]); 46 | -------------------------------------------------------------------------------- /rc/scripts/blocks/registry/on_entity_fall_on.ts: -------------------------------------------------------------------------------- 1 | import { 2 | BlockComponentEntityFallOnEvent, 3 | BlockCustomComponent, 4 | CustomComponentParameters, 5 | Entity, 6 | Vector3 7 | } from '@minecraft/server'; 8 | import * as adk from 'adk-scripts-server'; 9 | import { ParameterBounceForce } from 'utils/shared_parameters'; 10 | 11 | abstract class OnEntityFallOn implements BlockCustomComponent { 12 | abstract onEntityFallOn( 13 | componentData: BlockComponentEntityFallOnEvent, 14 | paramData?: CustomComponentParameters 15 | ): void; 16 | } 17 | 18 | class Debug extends OnEntityFallOn { 19 | onEntityFallOn(componentData: BlockComponentEntityFallOnEvent): void { 20 | console.log(adk.Debug.logEventData(componentData)); 21 | } 22 | } 23 | 24 | class Bounce extends OnEntityFallOn { 25 | onEntityFallOn( 26 | componentData: BlockComponentEntityFallOnEvent, 27 | paramData: CustomComponentParameters 28 | ) { 29 | const entity: Entity | undefined = componentData.entity; 30 | 31 | if (!entity) return; 32 | 33 | const velocity: Vector3 = entity.getVelocity(); 34 | if (velocity.y < 0) { 35 | const param = paramData.params as ParameterBounceForce; 36 | const bounce_force = param.force ?? 1; 37 | entity.applyKnockback({ x: 0, z: 0 }, -velocity.y * bounce_force); 38 | } 39 | } 40 | } 41 | 42 | enum OnEntityFallOnKey { 43 | Debug = 'debug', 44 | Bounce = 'bounce' 45 | } 46 | 47 | export const ON_ENTITY_FALL_ON_REGISTRY: Map< 48 | OnEntityFallOnKey, 49 | OnEntityFallOn 50 | > = new Map([ 51 | [OnEntityFallOnKey.Debug, new Debug()], 52 | [OnEntityFallOnKey.Bounce, new Bounce()] 53 | ]); 54 | -------------------------------------------------------------------------------- /stable/scripts/blocks/registry/on_entity_fall_on.ts: -------------------------------------------------------------------------------- 1 | import { 2 | BlockComponentEntityFallOnEvent, 3 | BlockCustomComponent, 4 | CustomComponentParameters, 5 | Entity, 6 | Vector3 7 | } from '@minecraft/server'; 8 | import * as adk from 'adk-scripts-server'; 9 | import { ParameterBounceForce } from 'utils/shared_parameters'; 10 | 11 | abstract class OnEntityFallOn implements BlockCustomComponent { 12 | abstract onEntityFallOn( 13 | componentData: BlockComponentEntityFallOnEvent, 14 | paramData?: CustomComponentParameters 15 | ): void; 16 | } 17 | 18 | class Debug extends OnEntityFallOn { 19 | onEntityFallOn(componentData: BlockComponentEntityFallOnEvent): void { 20 | console.log(adk.Debug.logEventData(componentData)); 21 | } 22 | } 23 | 24 | class Bounce extends OnEntityFallOn { 25 | onEntityFallOn( 26 | componentData: BlockComponentEntityFallOnEvent, 27 | paramData: CustomComponentParameters 28 | ) { 29 | const entity: Entity | undefined = componentData.entity; 30 | 31 | if (!entity) return; 32 | 33 | const velocity: Vector3 = entity.getVelocity(); 34 | if (velocity.y < 0) { 35 | const param = paramData.params as ParameterBounceForce; 36 | const bounce_force = param.force ?? 1; 37 | entity.applyKnockback({ x: 0, z: 0 }, -velocity.y * bounce_force); 38 | } 39 | } 40 | } 41 | 42 | enum OnEntityFallOnKey { 43 | Debug = 'debug', 44 | Bounce = 'bounce' 45 | } 46 | 47 | export const ON_ENTITY_FALL_ON_REGISTRY: Map< 48 | OnEntityFallOnKey, 49 | OnEntityFallOn 50 | > = new Map([ 51 | [OnEntityFallOnKey.Debug, new Debug()], 52 | [OnEntityFallOnKey.Bounce, new Bounce()] 53 | ]); 54 | -------------------------------------------------------------------------------- /experimental/scripts/blocks/registry/on_entity_fall_on.ts: -------------------------------------------------------------------------------- 1 | import { 2 | BlockComponentEntityFallOnEvent, 3 | BlockCustomComponent, 4 | CustomComponentParameters, 5 | Entity, 6 | Vector3 7 | } from '@minecraft/server'; 8 | import * as adk from 'adk-scripts-server'; 9 | import { ParameterBounceForce } from 'utils/shared_parameters'; 10 | 11 | abstract class OnEntityFallOn implements BlockCustomComponent { 12 | abstract onEntityFallOn( 13 | componentData: BlockComponentEntityFallOnEvent, 14 | paramData?: CustomComponentParameters 15 | ): void; 16 | } 17 | 18 | class Debug extends OnEntityFallOn { 19 | onEntityFallOn(componentData: BlockComponentEntityFallOnEvent): void { 20 | console.log(adk.Debug.logEventData(componentData)); 21 | } 22 | } 23 | 24 | class Bounce extends OnEntityFallOn { 25 | onEntityFallOn( 26 | componentData: BlockComponentEntityFallOnEvent, 27 | paramData: CustomComponentParameters 28 | ) { 29 | const entity: Entity | undefined = componentData.entity; 30 | 31 | if (!entity) return; 32 | 33 | const velocity: Vector3 = entity.getVelocity(); 34 | if (velocity.y < 0) { 35 | const param = paramData.params as ParameterBounceForce; 36 | const bounce_force = param.force ?? 1; 37 | entity.applyKnockback({ x: 0, z: 0 }, -velocity.y * bounce_force); 38 | } 39 | } 40 | } 41 | 42 | enum OnEntityFallOnKey { 43 | Debug = 'debug', 44 | Bounce = 'bounce' 45 | } 46 | 47 | export const ON_ENTITY_FALL_ON_REGISTRY: Map< 48 | OnEntityFallOnKey, 49 | OnEntityFallOn 50 | > = new Map([ 51 | [OnEntityFallOnKey.Debug, new Debug()], 52 | [OnEntityFallOnKey.Bounce, new Bounce()] 53 | ]); 54 | -------------------------------------------------------------------------------- /rc/scripts/item/item_bucket.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Block, 3 | Container, 4 | Direction, 5 | EntityInventoryComponent, 6 | EquipmentSlot, 7 | ItemStack, 8 | Player, 9 | Vector3 10 | } from '@minecraft/server'; 11 | import * as adk from 'adk-scripts-server'; 12 | 13 | /** 14 | * Pickup a liquid block and convert it to an item. 15 | * 16 | * @param transform_to The item to transform the liquid into. 17 | * @param block The block that was interacted with. 18 | * @param block_face The face of the block that was interacted with. 19 | * @param player The player who interacted with the block. 20 | * @param item The item stack that was used to interact with the block. 21 | * @param turn_to_air Whether to turn the block into air after pickup. 22 | */ 23 | export function pickupLiquid( 24 | transform_to: string, 25 | block: Block, 26 | block_face: Direction, 27 | player: Player, 28 | item: ItemStack, 29 | turn_to_air: boolean 30 | ): void { 31 | const offset: Vector3 = adk.DirectionHelper.toVector3(block_face); 32 | const block_offset: Block | undefined = block.offset(offset); 33 | if (!block_offset) return; 34 | if (turn_to_air) block_offset.setType('minecraft:air'); 35 | const converted_item: ItemStack = new ItemStack(transform_to); 36 | const inventory: EntityInventoryComponent | undefined = 37 | player.getComponent('inventory'); 38 | if (!inventory) return; 39 | const container: Container = inventory.container; 40 | if (!container) return; 41 | if (container.emptySlotsCount == 0 || item.amount != 1) { 42 | player.dimension.spawnItem(converted_item, player.location); 43 | adk.PlayerHelper.decrementStack(player); 44 | return; 45 | } 46 | 47 | adk.PlayerHelper.setItemToEquippable( 48 | player, 49 | EquipmentSlot.Mainhand, 50 | converted_item 51 | ); 52 | } 53 | -------------------------------------------------------------------------------- /stable/scripts/item/item_bucket.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Block, 3 | Container, 4 | Direction, 5 | EntityInventoryComponent, 6 | EquipmentSlot, 7 | ItemStack, 8 | Player, 9 | Vector3 10 | } from '@minecraft/server'; 11 | import * as adk from 'adk-scripts-server'; 12 | 13 | /** 14 | * Pickup a liquid block and convert it to an item. 15 | * 16 | * @param transform_to The item to transform the liquid into. 17 | * @param block The block that was interacted with. 18 | * @param block_face The face of the block that was interacted with. 19 | * @param player The player who interacted with the block. 20 | * @param item The item stack that was used to interact with the block. 21 | * @param turn_to_air Whether to turn the block into air after pickup. 22 | */ 23 | export function pickupLiquid( 24 | transform_to: string, 25 | block: Block, 26 | block_face: Direction, 27 | player: Player, 28 | item: ItemStack, 29 | turn_to_air: boolean 30 | ): void { 31 | const offset: Vector3 = adk.DirectionHelper.toVector3(block_face); 32 | const block_offset: Block | undefined = block.offset(offset); 33 | if (!block_offset) return; 34 | if (turn_to_air) block_offset.setType('minecraft:air'); 35 | const converted_item: ItemStack = new ItemStack(transform_to); 36 | const inventory: EntityInventoryComponent | undefined = 37 | player.getComponent('inventory'); 38 | if (!inventory) return; 39 | const container: Container = inventory.container; 40 | if (!container) return; 41 | if (container.emptySlotsCount == 0 || item.amount != 1) { 42 | player.dimension.spawnItem(converted_item, player.location); 43 | adk.PlayerHelper.decrementStack(player); 44 | return; 45 | } 46 | 47 | adk.PlayerHelper.setItemToEquippable( 48 | player, 49 | EquipmentSlot.Mainhand, 50 | converted_item 51 | ); 52 | } 53 | -------------------------------------------------------------------------------- /experimental/scripts/item/item_bucket.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Block, 3 | Container, 4 | Direction, 5 | EntityInventoryComponent, 6 | EquipmentSlot, 7 | ItemStack, 8 | Player, 9 | Vector3 10 | } from '@minecraft/server'; 11 | import * as adk from 'adk-scripts-server'; 12 | 13 | /** 14 | * Pickup a liquid block and convert it to an item. 15 | * 16 | * @param transform_to The item to transform the liquid into. 17 | * @param block The block that was interacted with. 18 | * @param block_face The face of the block that was interacted with. 19 | * @param player The player who interacted with the block. 20 | * @param item The item stack that was used to interact with the block. 21 | * @param turn_to_air Whether to turn the block into air after pickup. 22 | */ 23 | export function pickupLiquid( 24 | transform_to: string, 25 | block: Block, 26 | block_face: Direction, 27 | player: Player, 28 | item: ItemStack, 29 | turn_to_air: boolean 30 | ): void { 31 | const offset: Vector3 = adk.DirectionHelper.toVector3(block_face); 32 | const block_offset: Block | undefined = block.offset(offset); 33 | if (!block_offset) return; 34 | if (turn_to_air) block_offset.setType('minecraft:air'); 35 | const converted_item: ItemStack = new ItemStack(transform_to); 36 | const inventory: EntityInventoryComponent | undefined = 37 | player.getComponent('inventory'); 38 | if (!inventory) return; 39 | const container: Container = inventory.container; 40 | if (!container) return; 41 | if (container.emptySlotsCount == 0 || item.amount != 1) { 42 | player.dimension.spawnItem(converted_item, player.location); 43 | adk.PlayerHelper.decrementStack(player); 44 | return; 45 | } 46 | 47 | adk.PlayerHelper.setItemToEquippable( 48 | player, 49 | EquipmentSlot.Mainhand, 50 | converted_item 51 | ); 52 | } 53 | -------------------------------------------------------------------------------- /rc/scripts/item/registry/on_use.ts: -------------------------------------------------------------------------------- 1 | import { 2 | CustomComponentParameters, 3 | ItemComponentUseEvent, 4 | ItemCustomComponent, 5 | ItemStack, 6 | system 7 | } from '@minecraft/server'; 8 | import * as adk from 'adk-scripts-server'; 9 | import { ParameterRunCommand } from 'utils/shared_parameters'; 10 | 11 | abstract class OnUse implements ItemCustomComponent { 12 | abstract onUse( 13 | componentData: ItemComponentUseEvent, 14 | paramData?: CustomComponentParameters 15 | ): void; 16 | } 17 | 18 | class Debug extends OnUse { 19 | onUse(componentData: ItemComponentUseEvent) { 20 | console.log(adk.Debug.logEventData(componentData)); 21 | } 22 | } 23 | 24 | type ParameterGoatHorn = { 25 | instrument: string; 26 | }; 27 | 28 | class GoatHorn extends OnUse { 29 | onUse( 30 | componentData: ItemComponentUseEvent, 31 | paramData: CustomComponentParameters 32 | ) { 33 | const param = paramData.params as ParameterGoatHorn; 34 | componentData.source.playSound(param.instrument, { 35 | volume: 16 36 | }); 37 | const item: ItemStack | undefined = componentData.itemStack; 38 | if (!item) return; 39 | 40 | adk.ComponentItemCooldown.startCooldown(item, componentData.source); 41 | } 42 | } 43 | 44 | class RunCommand extends OnUse { 45 | onUse( 46 | componentData: ItemComponentUseEvent, 47 | paramData: CustomComponentParameters 48 | ) { 49 | const param = paramData.params as ParameterRunCommand; 50 | system.run(() => { 51 | param.command.forEach((command) => { 52 | componentData.source.runCommand(command); 53 | }); 54 | }); 55 | } 56 | } 57 | 58 | enum OnUseKey { 59 | Debug = 'debug', 60 | GoatHorn = 'goat_horn', 61 | RunCommand = 'run_command' 62 | } 63 | 64 | export const ON_USE_REGISTRY = new Map([ 65 | [OnUseKey.Debug, new Debug()], 66 | [OnUseKey.GoatHorn, new GoatHorn()], 67 | [OnUseKey.RunCommand, new RunCommand()] 68 | ]); 69 | -------------------------------------------------------------------------------- /stable/scripts/item/registry/on_use.ts: -------------------------------------------------------------------------------- 1 | import { 2 | CustomComponentParameters, 3 | ItemComponentUseEvent, 4 | ItemCustomComponent, 5 | ItemStack, 6 | system 7 | } from '@minecraft/server'; 8 | import * as adk from 'adk-scripts-server'; 9 | import { ParameterRunCommand } from 'utils/shared_parameters'; 10 | 11 | abstract class OnUse implements ItemCustomComponent { 12 | abstract onUse( 13 | componentData: ItemComponentUseEvent, 14 | paramData?: CustomComponentParameters 15 | ): void; 16 | } 17 | 18 | class Debug extends OnUse { 19 | onUse(componentData: ItemComponentUseEvent) { 20 | console.log(adk.Debug.logEventData(componentData)); 21 | } 22 | } 23 | 24 | type ParameterGoatHorn = { 25 | instrument: string; 26 | }; 27 | 28 | class GoatHorn extends OnUse { 29 | onUse( 30 | componentData: ItemComponentUseEvent, 31 | paramData: CustomComponentParameters 32 | ) { 33 | const param = paramData.params as ParameterGoatHorn; 34 | componentData.source.playSound(param.instrument, { 35 | volume: 16 36 | }); 37 | const item: ItemStack | undefined = componentData.itemStack; 38 | if (!item) return; 39 | 40 | adk.ComponentItemCooldown.startCooldown(item, componentData.source); 41 | } 42 | } 43 | 44 | class RunCommand extends OnUse { 45 | onUse( 46 | componentData: ItemComponentUseEvent, 47 | paramData: CustomComponentParameters 48 | ) { 49 | const param = paramData.params as ParameterRunCommand; 50 | system.run(() => { 51 | param.command.forEach((command) => { 52 | componentData.source.runCommand(command); 53 | }); 54 | }); 55 | } 56 | } 57 | 58 | enum OnUseKey { 59 | Debug = 'debug', 60 | GoatHorn = 'goat_horn', 61 | RunCommand = 'run_command' 62 | } 63 | 64 | export const ON_USE_REGISTRY = new Map([ 65 | [OnUseKey.Debug, new Debug()], 66 | [OnUseKey.GoatHorn, new GoatHorn()], 67 | [OnUseKey.RunCommand, new RunCommand()] 68 | ]); 69 | -------------------------------------------------------------------------------- /experimental/scripts/item/registry/on_use.ts: -------------------------------------------------------------------------------- 1 | import { 2 | CustomComponentParameters, 3 | ItemComponentUseEvent, 4 | ItemCustomComponent, 5 | ItemStack, 6 | system 7 | } from '@minecraft/server'; 8 | import * as adk from 'adk-scripts-server'; 9 | import { ParameterRunCommand } from 'utils/shared_parameters'; 10 | 11 | abstract class OnUse implements ItemCustomComponent { 12 | abstract onUse( 13 | componentData: ItemComponentUseEvent, 14 | paramData?: CustomComponentParameters 15 | ): void; 16 | } 17 | 18 | class Debug extends OnUse { 19 | onUse(componentData: ItemComponentUseEvent) { 20 | console.log(adk.Debug.logEventData(componentData)); 21 | } 22 | } 23 | 24 | type ParameterGoatHorn = { 25 | instrument: string; 26 | }; 27 | 28 | class GoatHorn extends OnUse { 29 | onUse( 30 | componentData: ItemComponentUseEvent, 31 | paramData: CustomComponentParameters 32 | ) { 33 | const param = paramData.params as ParameterGoatHorn; 34 | componentData.source.playSound(param.instrument, { 35 | volume: 16 36 | }); 37 | const item: ItemStack | undefined = componentData.itemStack; 38 | if (!item) return; 39 | 40 | adk.ComponentItemCooldown.startCooldown(item, componentData.source); 41 | } 42 | } 43 | 44 | class RunCommand extends OnUse { 45 | onUse( 46 | componentData: ItemComponentUseEvent, 47 | paramData: CustomComponentParameters 48 | ) { 49 | const param = paramData.params as ParameterRunCommand; 50 | system.run(() => { 51 | param.command.forEach((command) => { 52 | componentData.source.runCommand(command); 53 | }); 54 | }); 55 | } 56 | } 57 | 58 | enum OnUseKey { 59 | Debug = 'debug', 60 | GoatHorn = 'goat_horn', 61 | RunCommand = 'run_command' 62 | } 63 | 64 | export const ON_USE_REGISTRY = new Map([ 65 | [OnUseKey.Debug, new Debug()], 66 | [OnUseKey.GoatHorn, new GoatHorn()], 67 | [OnUseKey.RunCommand, new RunCommand()] 68 | ]); 69 | -------------------------------------------------------------------------------- /config.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://raw.githubusercontent.com/Bedrock-OSS/regolith-schemas/main/config/v1.1.json", 3 | "author": "SmokeyStack", 4 | "name": "adk-lib", 5 | "packs": { 6 | "behaviorPack": "./packs/BP", 7 | "resourcePack": "./packs/RP" 8 | }, 9 | "regolith": { 10 | "dataPath": "./packs/data", 11 | "filterDefinitions": { 12 | "move-manifest": { 13 | "script": "./filters/move-manifest.py", 14 | "runWith": "python" 15 | } 16 | }, 17 | "profiles": { 18 | "dev-experimental": { 19 | "export": { 20 | "readOnly": false, 21 | "target": "preview" 22 | }, 23 | "filters": [ 24 | { 25 | "arguments": [ 26 | "experimental" 27 | ], 28 | "filter": "move-manifest" 29 | } 30 | ] 31 | }, 32 | "dev-rc": { 33 | "export": { 34 | "readOnly": false, 35 | "target": "preview" 36 | }, 37 | "filters": [ 38 | { 39 | "arguments": [ 40 | "rc" 41 | ], 42 | "filter": "move-manifest" 43 | } 44 | ] 45 | }, 46 | "dev-stable": { 47 | "export": { 48 | "readOnly": false, 49 | "target": "development" 50 | }, 51 | "filters": [ 52 | { 53 | "arguments": [ 54 | "stable" 55 | ], 56 | "filter": "move-manifest" 57 | } 58 | ] 59 | }, 60 | "build-experimental": { 61 | "export": { 62 | "readOnly": false, 63 | "target": "local" 64 | }, 65 | "filters": [ 66 | { 67 | "arguments": [ 68 | "experimental" 69 | ], 70 | "filter": "move-manifest" 71 | } 72 | ] 73 | }, 74 | "build-rc": { 75 | "export": { 76 | "readOnly": false, 77 | "target": "local" 78 | }, 79 | "filters": [ 80 | { 81 | "arguments": [ 82 | "rc" 83 | ], 84 | "filter": "move-manifest" 85 | } 86 | ] 87 | }, 88 | "build-stable": { 89 | "export": { 90 | "readOnly": false, 91 | "target": "local" 92 | }, 93 | "filters": [ 94 | { 95 | "arguments": [ 96 | "stable" 97 | ], 98 | "filter": "move-manifest" 99 | } 100 | ] 101 | } 102 | } 103 | } 104 | } -------------------------------------------------------------------------------- /rc/scripts/blocks/registry/on_step_off.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Block, 3 | BlockComponentStepOffEvent, 4 | BlockCustomComponent, 5 | CustomComponentParameters, 6 | Dimension 7 | } from '@minecraft/server'; 8 | import * as adk from 'adk-scripts-server'; 9 | import { ParameterEffect } from 'utils/shared_parameters'; 10 | 11 | abstract class OnStepOff implements BlockCustomComponent { 12 | abstract onStepOff( 13 | componentData: BlockComponentStepOffEvent, 14 | paramData?: CustomComponentParameters 15 | ): void; 16 | } 17 | 18 | class Debug extends OnStepOff { 19 | onStepOff(componentData: BlockComponentStepOffEvent) { 20 | console.log(adk.Debug.logEventData(componentData)); 21 | } 22 | } 23 | 24 | class Effect extends OnStepOff { 25 | onStepOff( 26 | componentData: BlockComponentStepOffEvent, 27 | paramData: CustomComponentParameters 28 | ) { 29 | const param = paramData.params as ParameterEffect; 30 | const dimension: Dimension = adk.Cache.getDimension( 31 | componentData.block.dimension.id 32 | ); 33 | const block: Block = componentData.block; 34 | param.forEach( 35 | ({ 36 | effect, 37 | duration, 38 | radius, 39 | amplifier = 0, 40 | show_particles = true, 41 | entity_type 42 | }) => { 43 | dimension 44 | .getEntities({ 45 | location: block.center(), 46 | maxDistance: radius 47 | }) 48 | .forEach((entity) => { 49 | if ( 50 | !entity_type || 51 | entity_type.includes(entity.typeId) 52 | ) { 53 | entity.addEffect(effect, duration, { 54 | showParticles: show_particles, 55 | amplifier 56 | }); 57 | } 58 | }); 59 | } 60 | ); 61 | } 62 | } 63 | 64 | enum OnStepOffKey { 65 | Debug = 'debug', 66 | Effect = 'effect' 67 | } 68 | 69 | export const ON_STEP_OFF_REGISTRY: Map = new Map([ 70 | [OnStepOffKey.Debug, new Debug()], 71 | [OnStepOffKey.Effect, new Effect()] 72 | ]); 73 | -------------------------------------------------------------------------------- /stable/scripts/blocks/registry/on_step_off.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Block, 3 | BlockComponentStepOffEvent, 4 | BlockCustomComponent, 5 | CustomComponentParameters, 6 | Dimension 7 | } from '@minecraft/server'; 8 | import * as adk from 'adk-scripts-server'; 9 | import { ParameterEffect } from 'utils/shared_parameters'; 10 | 11 | abstract class OnStepOff implements BlockCustomComponent { 12 | abstract onStepOff( 13 | componentData: BlockComponentStepOffEvent, 14 | paramData?: CustomComponentParameters 15 | ): void; 16 | } 17 | 18 | class Debug extends OnStepOff { 19 | onStepOff(componentData: BlockComponentStepOffEvent) { 20 | console.log(adk.Debug.logEventData(componentData)); 21 | } 22 | } 23 | 24 | class Effect extends OnStepOff { 25 | onStepOff( 26 | componentData: BlockComponentStepOffEvent, 27 | paramData: CustomComponentParameters 28 | ) { 29 | const param = paramData.params as ParameterEffect; 30 | const dimension: Dimension = adk.Cache.getDimension( 31 | componentData.block.dimension.id 32 | ); 33 | const block: Block = componentData.block; 34 | param.forEach( 35 | ({ 36 | effect, 37 | duration, 38 | radius, 39 | amplifier = 0, 40 | show_particles = true, 41 | entity_type 42 | }) => { 43 | dimension 44 | .getEntities({ 45 | location: block.center(), 46 | maxDistance: radius 47 | }) 48 | .forEach((entity) => { 49 | if ( 50 | !entity_type || 51 | entity_type.includes(entity.typeId) 52 | ) { 53 | entity.addEffect(effect, duration, { 54 | showParticles: show_particles, 55 | amplifier 56 | }); 57 | } 58 | }); 59 | } 60 | ); 61 | } 62 | } 63 | 64 | enum OnStepOffKey { 65 | Debug = 'debug', 66 | Effect = 'effect' 67 | } 68 | 69 | export const ON_STEP_OFF_REGISTRY: Map = new Map([ 70 | [OnStepOffKey.Debug, new Debug()], 71 | [OnStepOffKey.Effect, new Effect()] 72 | ]); 73 | -------------------------------------------------------------------------------- /experimental/scripts/blocks/registry/on_step_off.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Block, 3 | BlockComponentStepOffEvent, 4 | BlockCustomComponent, 5 | CustomComponentParameters, 6 | Dimension 7 | } from '@minecraft/server'; 8 | import * as adk from 'adk-scripts-server'; 9 | import { ParameterEffect } from 'utils/shared_parameters'; 10 | 11 | abstract class OnStepOff implements BlockCustomComponent { 12 | abstract onStepOff( 13 | componentData: BlockComponentStepOffEvent, 14 | paramData?: CustomComponentParameters 15 | ): void; 16 | } 17 | 18 | class Debug extends OnStepOff { 19 | onStepOff(componentData: BlockComponentStepOffEvent) { 20 | console.log(adk.Debug.logEventData(componentData)); 21 | } 22 | } 23 | 24 | class Effect extends OnStepOff { 25 | onStepOff( 26 | componentData: BlockComponentStepOffEvent, 27 | paramData: CustomComponentParameters 28 | ) { 29 | const param = paramData.params as ParameterEffect; 30 | const dimension: Dimension = adk.Cache.getDimension( 31 | componentData.block.dimension.id 32 | ); 33 | const block: Block = componentData.block; 34 | param.forEach( 35 | ({ 36 | effect, 37 | duration, 38 | radius, 39 | amplifier = 0, 40 | show_particles = true, 41 | entity_type 42 | }) => { 43 | dimension 44 | .getEntities({ 45 | location: block.center(), 46 | maxDistance: radius 47 | }) 48 | .forEach((entity) => { 49 | if ( 50 | !entity_type || 51 | entity_type.includes(entity.typeId) 52 | ) { 53 | entity.addEffect(effect, duration, { 54 | showParticles: show_particles, 55 | amplifier 56 | }); 57 | } 58 | }); 59 | } 60 | ); 61 | } 62 | } 63 | 64 | enum OnStepOffKey { 65 | Debug = 'debug', 66 | Effect = 'effect' 67 | } 68 | 69 | export const ON_STEP_OFF_REGISTRY: Map = new Map([ 70 | [OnStepOffKey.Debug, new Debug()], 71 | [OnStepOffKey.Effect, new Effect()] 72 | ]); 73 | -------------------------------------------------------------------------------- /rc/scripts/item/teleport.ts: -------------------------------------------------------------------------------- 1 | import { Entity, Block, MolangVariableMap } from '@minecraft/server'; 2 | import * as adk from 'adk-scripts-server'; 3 | import { nextDouble } from 'utils/math'; 4 | 5 | export function teleportEntity( 6 | entity: Entity, 7 | location: adk.Vector3Builder, 8 | dimension_height_range: { min: number; max: number } 9 | ): boolean { 10 | while (location.y > dimension_height_range.min) { 11 | const block: Block | undefined = entity.dimension.getBlock(location); 12 | 13 | if (!block) break; 14 | if (block.isLiquid || block.typeId === 'minecraft:air') location.y--; 15 | else break; 16 | } 17 | 18 | const target_block: Block | undefined = entity.dimension.getBlock(location); 19 | if (!target_block) return false; 20 | const target_block_above: Block | undefined = target_block.above(); 21 | if (!target_block_above) return false; 22 | 23 | if ( 24 | target_block.isLiquid || 25 | target_block.typeId === 'minecraft:air' || 26 | !target_block_above.isAir 27 | ) 28 | return false; 29 | 30 | for (let a: number = 0; a < 128; ++a) { 31 | let delta: number = a / 127.0; 32 | let velocity_x: number = (Math.random() - 0.5) * 0.2; 33 | let velocity_y: number = (Math.random() - 0.5) * 0.2; 34 | let velocity_z: number = (Math.random() - 0.5) * 0.2; 35 | let e: number = 36 | adk.MathHelper.lerp(entity.location.x, location.x, delta) + 37 | (nextDouble(0, 1) - 0.5) * 1.0; 38 | let k: number = 39 | adk.MathHelper.lerp(entity.location.y, location.y + 1, delta) + 40 | nextDouble(0, 1) * 2.0; 41 | let l: number = 42 | adk.MathHelper.lerp(entity.location.z, location.z, delta) + 43 | (nextDouble(0, 1) - 0.5) * 1.0; 44 | let molang: MolangVariableMap = new MolangVariableMap(); 45 | molang.setVector3('variable.direction', { 46 | x: velocity_x, 47 | y: velocity_y, 48 | z: velocity_z 49 | }); 50 | molang.setFloat('variable.particle_random_1', Math.random()); 51 | molang.setFloat('variable.particle_random_2', Math.random()); 52 | entity.dimension.spawnParticle( 53 | 'minecraft:portal_directional', 54 | { 55 | x: e, 56 | y: k, 57 | z: l 58 | }, 59 | molang 60 | ); 61 | } 62 | 63 | entity.teleport(location.add(0, 1, 0)); 64 | 65 | return true; 66 | } 67 | -------------------------------------------------------------------------------- /stable/scripts/item/teleport.ts: -------------------------------------------------------------------------------- 1 | import { Entity, Block, MolangVariableMap } from '@minecraft/server'; 2 | import * as adk from 'adk-scripts-server'; 3 | import { nextDouble } from 'utils/math'; 4 | 5 | export function teleportEntity( 6 | entity: Entity, 7 | location: adk.Vector3Builder, 8 | dimension_height_range: { min: number; max: number } 9 | ): boolean { 10 | while (location.y > dimension_height_range.min) { 11 | const block: Block | undefined = entity.dimension.getBlock(location); 12 | 13 | if (!block) break; 14 | if (block.isLiquid || block.typeId === 'minecraft:air') location.y--; 15 | else break; 16 | } 17 | 18 | const target_block: Block | undefined = entity.dimension.getBlock(location); 19 | if (!target_block) return false; 20 | const target_block_above: Block | undefined = target_block.above(); 21 | if (!target_block_above) return false; 22 | 23 | if ( 24 | target_block.isLiquid || 25 | target_block.typeId === 'minecraft:air' || 26 | !target_block_above.isAir 27 | ) 28 | return false; 29 | 30 | for (let a: number = 0; a < 128; ++a) { 31 | let delta: number = a / 127.0; 32 | let velocity_x: number = (Math.random() - 0.5) * 0.2; 33 | let velocity_y: number = (Math.random() - 0.5) * 0.2; 34 | let velocity_z: number = (Math.random() - 0.5) * 0.2; 35 | let e: number = 36 | adk.MathHelper.lerp(entity.location.x, location.x, delta) + 37 | (nextDouble(0, 1) - 0.5) * 1.0; 38 | let k: number = 39 | adk.MathHelper.lerp(entity.location.y, location.y + 1, delta) + 40 | nextDouble(0, 1) * 2.0; 41 | let l: number = 42 | adk.MathHelper.lerp(entity.location.z, location.z, delta) + 43 | (nextDouble(0, 1) - 0.5) * 1.0; 44 | let molang: MolangVariableMap = new MolangVariableMap(); 45 | molang.setVector3('variable.direction', { 46 | x: velocity_x, 47 | y: velocity_y, 48 | z: velocity_z 49 | }); 50 | molang.setFloat('variable.particle_random_1', Math.random()); 51 | molang.setFloat('variable.particle_random_2', Math.random()); 52 | entity.dimension.spawnParticle( 53 | 'minecraft:portal_directional', 54 | { 55 | x: e, 56 | y: k, 57 | z: l 58 | }, 59 | molang 60 | ); 61 | } 62 | 63 | entity.teleport(location.add(0, 1, 0)); 64 | 65 | return true; 66 | } 67 | -------------------------------------------------------------------------------- /experimental/scripts/item/teleport.ts: -------------------------------------------------------------------------------- 1 | import { Entity, Block, MolangVariableMap } from '@minecraft/server'; 2 | import * as adk from 'adk-scripts-server'; 3 | import { nextDouble } from 'utils/math'; 4 | 5 | export function teleportEntity( 6 | entity: Entity, 7 | location: adk.Vector3Builder, 8 | dimension_height_range: { min: number; max: number } 9 | ): boolean { 10 | while (location.y > dimension_height_range.min) { 11 | const block: Block | undefined = entity.dimension.getBlock(location); 12 | 13 | if (!block) break; 14 | if (block.isLiquid || block.typeId === 'minecraft:air') location.y--; 15 | else break; 16 | } 17 | 18 | const target_block: Block | undefined = entity.dimension.getBlock(location); 19 | if (!target_block) return false; 20 | const target_block_above: Block | undefined = target_block.above(); 21 | if (!target_block_above) return false; 22 | 23 | if ( 24 | target_block.isLiquid || 25 | target_block.typeId === 'minecraft:air' || 26 | !target_block_above.isAir 27 | ) 28 | return false; 29 | 30 | for (let a: number = 0; a < 128; ++a) { 31 | let delta: number = a / 127.0; 32 | let velocity_x: number = (Math.random() - 0.5) * 0.2; 33 | let velocity_y: number = (Math.random() - 0.5) * 0.2; 34 | let velocity_z: number = (Math.random() - 0.5) * 0.2; 35 | let e: number = 36 | adk.MathHelper.lerp(entity.location.x, location.x, delta) + 37 | (nextDouble(0, 1) - 0.5) * 1.0; 38 | let k: number = 39 | adk.MathHelper.lerp(entity.location.y, location.y + 1, delta) + 40 | nextDouble(0, 1) * 2.0; 41 | let l: number = 42 | adk.MathHelper.lerp(entity.location.z, location.z, delta) + 43 | (nextDouble(0, 1) - 0.5) * 1.0; 44 | let molang: MolangVariableMap = new MolangVariableMap(); 45 | molang.setVector3('variable.direction', { 46 | x: velocity_x, 47 | y: velocity_y, 48 | z: velocity_z 49 | }); 50 | molang.setFloat('variable.particle_random_1', Math.random()); 51 | molang.setFloat('variable.particle_random_2', Math.random()); 52 | entity.dimension.spawnParticle( 53 | 'minecraft:portal_directional', 54 | { 55 | x: e, 56 | y: k, 57 | z: l 58 | }, 59 | molang 60 | ); 61 | } 62 | 63 | entity.teleport(location.add(0, 1, 0)); 64 | 65 | return true; 66 | } 67 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ADK LIB 2 | 3 | ADK LIB is a library for SmokeyStack's [adk](https://github.com/SmokeyStack/adk) project. This library offers [custom components](https://learn.microsoft.com/en-us/minecraft/creator/documents/customcomponents?view=minecraft-bedrock-stable) that allow reusability across all add-ons. 4 | 5 | This library is a work in progress as custom components are still experimental and emerging in the add-on development space. 6 | 7 | ## Using ADK LIB to play with add-ons 8 | 9 | Download the proper version the add-on requires in the [release](https://github.com/SmokeyStack/adk-lib/releases) page. Once you have it downloaded, import it into Minecraft and you should be good to play your add-on. Make sure to apply the pack in the world you're playing on. 10 | 11 | ## Using ADK LIB to develop add-ons 12 | 13 | To use ADK LIB in your add-on, simply add the following to your behaviour pack's manifest.json in the dependencies section. 14 | 15 | ```json 16 | { 17 | "uuid": "5e2eda3e-6eaf-4068-9076-0a7f0587b8bb", 18 | "version": "0.1.0" 19 | } 20 | ``` 21 | 22 | Download the desired version from the [release](https://github.com/SmokeyStack/adk-lib/releases) page. Once you have it downloaded, import it into Minecraft and you should be good to develop your add-on. Make sure to apply the pack in the world you're developing on. 23 | 24 | ### Using the Components 25 | 26 | To use the custom components, please see the [documentation](/docs) for a list of all registered custom components. 27 | 28 | Once you have chosen the custom component, simply add it to the `minecraft:custom_components` component in your item or block file. 29 | 30 | ```json 31 | { 32 | "minecraft:custom_components": ["adk-lib:on_random_tick_debug"] 33 | } 34 | ``` 35 | 36 | ## Distributing 37 | 38 | Under the [License](LICENSE), you are allowed to distribute this add-on with or without modifications. However, I would much appreciate if instead you direct your users to this [Github Page](https://github.com/SmokeyStack/adk-lib) and ask them to download from the [release](https://github.com/SmokeyStack/adk-lib/releases) page. 39 | 40 | ## Donate 41 | 42 | Help support the development and maintenance of this library. 43 | 44 | [![kofi](https://img.shields.io/badge/kofi-%23F16061.svg?&style=for-the-badge&logo=ko-fi&logoColor=white)](https://ko-fi.com/smokeystack) 45 | 46 | ## Discord 47 | 48 | I have a Discord server where you can ask for help or give suggestions for future components. 49 | 50 | Discord Server: https://discord.com/invite/YF8Jk8JSHh 51 | 52 | ## License 53 | 54 | See [License](LICENSE). 55 | -------------------------------------------------------------------------------- /rc/scripts/item/registry/on_mine_block.ts: -------------------------------------------------------------------------------- 1 | import { 2 | CustomComponentParameters, 3 | EquipmentSlot, 4 | ItemComponentMineBlockEvent, 5 | ItemCustomComponent, 6 | ItemDurabilityComponent, 7 | ItemStack, 8 | Player, 9 | system 10 | } from '@minecraft/server'; 11 | import * as adk from 'adk-scripts-server'; 12 | import { ParameterRunCommand } from 'utils/shared_parameters'; 13 | 14 | abstract class OnMineBlock implements ItemCustomComponent { 15 | abstract onMineBlock( 16 | componentData: ItemComponentMineBlockEvent, 17 | paramData?: CustomComponentParameters 18 | ): void; 19 | } 20 | 21 | class Debug extends OnMineBlock { 22 | onMineBlock(componentData: ItemComponentMineBlockEvent) { 23 | console.log(adk.Debug.logEventData(componentData)); 24 | } 25 | } 26 | 27 | type ParameterDigger = { 28 | damage_amount: number; 29 | block_filter?: string[]; 30 | }[]; 31 | 32 | class Digger extends OnMineBlock { 33 | onMineBlock( 34 | componentData: ItemComponentMineBlockEvent, 35 | paramData: CustomComponentParameters 36 | ) { 37 | const param = paramData.params as ParameterDigger; 38 | for (const entry of param) { 39 | const block_filter: string[] | undefined = entry.block_filter; 40 | const damage: number = entry.damage_amount; 41 | 42 | // Check if player_equipment matches any transform_from 43 | const matches: boolean = (block_filter ?? []).some( 44 | (block: string) => { 45 | return ( 46 | componentData.minedBlockPermutation.type.id === block 47 | ); 48 | } 49 | ); 50 | 51 | // If there's a match, log the corresponding transform_to 52 | if (matches) { 53 | const item = componentData.itemStack; 54 | if (!item) return; 55 | const durability: ItemDurabilityComponent = 56 | adk.ComponentItemDurability.get(item); 57 | durability.damage += damage; 58 | return; // Stop further checks if a match is found 59 | } 60 | } 61 | } 62 | } 63 | 64 | class RunCommand extends OnMineBlock { 65 | onMineBlock( 66 | componentData: ItemComponentMineBlockEvent, 67 | paramData: CustomComponentParameters 68 | ) { 69 | const param = paramData.params as ParameterRunCommand; 70 | system.run(() => { 71 | param.command.forEach((command) => { 72 | componentData.source.runCommand(command); 73 | }); 74 | }); 75 | } 76 | } 77 | 78 | enum OnMineBlockKey { 79 | Debug = 'debug', 80 | Digger = 'digger', 81 | RunCommand = 'run_command' 82 | } 83 | 84 | export const ON_MINE_BLOCK_REGISTRY = new Map([ 85 | [OnMineBlockKey.Debug, new Debug()], 86 | [OnMineBlockKey.Digger, new Digger()], 87 | [OnMineBlockKey.RunCommand, new RunCommand()] 88 | ]); 89 | -------------------------------------------------------------------------------- /stable/scripts/item/registry/on_mine_block.ts: -------------------------------------------------------------------------------- 1 | import { 2 | CustomComponentParameters, 3 | EquipmentSlot, 4 | ItemComponentMineBlockEvent, 5 | ItemCustomComponent, 6 | ItemDurabilityComponent, 7 | ItemStack, 8 | Player, 9 | system 10 | } from '@minecraft/server'; 11 | import * as adk from 'adk-scripts-server'; 12 | import { ParameterRunCommand } from 'utils/shared_parameters'; 13 | 14 | abstract class OnMineBlock implements ItemCustomComponent { 15 | abstract onMineBlock( 16 | componentData: ItemComponentMineBlockEvent, 17 | paramData?: CustomComponentParameters 18 | ): void; 19 | } 20 | 21 | class Debug extends OnMineBlock { 22 | onMineBlock(componentData: ItemComponentMineBlockEvent) { 23 | console.log(adk.Debug.logEventData(componentData)); 24 | } 25 | } 26 | 27 | type ParameterDigger = { 28 | damage_amount: number; 29 | block_filter?: string[]; 30 | }[]; 31 | 32 | class Digger extends OnMineBlock { 33 | onMineBlock( 34 | componentData: ItemComponentMineBlockEvent, 35 | paramData: CustomComponentParameters 36 | ) { 37 | const param = paramData.params as ParameterDigger; 38 | for (const entry of param) { 39 | const block_filter: string[] | undefined = entry.block_filter; 40 | const damage: number = entry.damage_amount; 41 | 42 | // Check if player_equipment matches any transform_from 43 | const matches: boolean = (block_filter ?? []).some( 44 | (block: string) => { 45 | return ( 46 | componentData.minedBlockPermutation.type.id === block 47 | ); 48 | } 49 | ); 50 | 51 | // If there's a match, log the corresponding transform_to 52 | if (matches) { 53 | const item = componentData.itemStack; 54 | if (!item) return; 55 | const durability: ItemDurabilityComponent = 56 | adk.ComponentItemDurability.get(item); 57 | durability.damage += damage; 58 | return; // Stop further checks if a match is found 59 | } 60 | } 61 | } 62 | } 63 | 64 | class RunCommand extends OnMineBlock { 65 | onMineBlock( 66 | componentData: ItemComponentMineBlockEvent, 67 | paramData: CustomComponentParameters 68 | ) { 69 | const param = paramData.params as ParameterRunCommand; 70 | system.run(() => { 71 | param.command.forEach((command) => { 72 | componentData.source.runCommand(command); 73 | }); 74 | }); 75 | } 76 | } 77 | 78 | enum OnMineBlockKey { 79 | Debug = 'debug', 80 | Digger = 'digger', 81 | RunCommand = 'run_command' 82 | } 83 | 84 | export const ON_MINE_BLOCK_REGISTRY = new Map([ 85 | [OnMineBlockKey.Debug, new Debug()], 86 | [OnMineBlockKey.Digger, new Digger()], 87 | [OnMineBlockKey.RunCommand, new RunCommand()] 88 | ]); 89 | -------------------------------------------------------------------------------- /experimental/scripts/item/registry/on_mine_block.ts: -------------------------------------------------------------------------------- 1 | import { 2 | CustomComponentParameters, 3 | EquipmentSlot, 4 | ItemComponentMineBlockEvent, 5 | ItemCustomComponent, 6 | ItemDurabilityComponent, 7 | ItemStack, 8 | Player, 9 | system 10 | } from '@minecraft/server'; 11 | import * as adk from 'adk-scripts-server'; 12 | import { ParameterRunCommand } from 'utils/shared_parameters'; 13 | 14 | abstract class OnMineBlock implements ItemCustomComponent { 15 | abstract onMineBlock( 16 | componentData: ItemComponentMineBlockEvent, 17 | paramData?: CustomComponentParameters 18 | ): void; 19 | } 20 | 21 | class Debug extends OnMineBlock { 22 | onMineBlock(componentData: ItemComponentMineBlockEvent) { 23 | console.log(adk.Debug.logEventData(componentData)); 24 | } 25 | } 26 | 27 | type ParameterDigger = { 28 | damage_amount: number; 29 | block_filter?: string[]; 30 | }[]; 31 | 32 | class Digger extends OnMineBlock { 33 | onMineBlock( 34 | componentData: ItemComponentMineBlockEvent, 35 | paramData: CustomComponentParameters 36 | ) { 37 | const param = paramData.params as ParameterDigger; 38 | for (const entry of param) { 39 | const block_filter: string[] | undefined = entry.block_filter; 40 | const damage: number = entry.damage_amount; 41 | 42 | // Check if player_equipment matches any transform_from 43 | const matches: boolean = (block_filter ?? []).some( 44 | (block: string) => { 45 | return ( 46 | componentData.minedBlockPermutation.type.id === block 47 | ); 48 | } 49 | ); 50 | 51 | // If there's a match, log the corresponding transform_to 52 | if (matches) { 53 | const item = componentData.itemStack; 54 | if (!item) return; 55 | const durability: ItemDurabilityComponent = 56 | adk.ComponentItemDurability.get(item); 57 | durability.damage += damage; 58 | return; // Stop further checks if a match is found 59 | } 60 | } 61 | } 62 | } 63 | 64 | class RunCommand extends OnMineBlock { 65 | onMineBlock( 66 | componentData: ItemComponentMineBlockEvent, 67 | paramData: CustomComponentParameters 68 | ) { 69 | const param = paramData.params as ParameterRunCommand; 70 | system.run(() => { 71 | param.command.forEach((command) => { 72 | componentData.source.runCommand(command); 73 | }); 74 | }); 75 | } 76 | } 77 | 78 | enum OnMineBlockKey { 79 | Debug = 'debug', 80 | Digger = 'digger', 81 | RunCommand = 'run_command' 82 | } 83 | 84 | export const ON_MINE_BLOCK_REGISTRY = new Map([ 85 | [OnMineBlockKey.Debug, new Debug()], 86 | [OnMineBlockKey.Digger, new Digger()], 87 | [OnMineBlockKey.RunCommand, new RunCommand()] 88 | ]); 89 | -------------------------------------------------------------------------------- /rc/scripts/blocks/registry/before_on_player_place.ts: -------------------------------------------------------------------------------- 1 | import { 2 | BlockComponentPlayerPlaceBeforeEvent, 3 | BlockCustomComponent, 4 | BlockPermutation, 5 | CustomComponentParameters 6 | } from '@minecraft/server'; 7 | import { beforeOnPlayerPlaceDoubleSlab } from 'blocks/double_slab'; 8 | import { beforeOnPlayerPlaceSugarCane } from 'blocks/sugar_cane'; 9 | import { beforeOnPlayerPlaceStairs } from 'blocks/stairs'; 10 | import * as adk from 'adk-scripts-server'; 11 | 12 | abstract class BeforeOnPlayerPlace implements BlockCustomComponent { 13 | abstract beforeOnPlayerPlace( 14 | componentData: BlockComponentPlayerPlaceBeforeEvent, 15 | paramData?: CustomComponentParameters 16 | ): void; 17 | } 18 | 19 | class Debug extends BeforeOnPlayerPlace { 20 | beforeOnPlayerPlace(componentData: BlockComponentPlayerPlaceBeforeEvent) { 21 | console.log(adk.Debug.logEventData(componentData)); 22 | } 23 | } 24 | 25 | class Cancel extends BeforeOnPlayerPlace { 26 | beforeOnPlayerPlace(componentData: BlockComponentPlayerPlaceBeforeEvent) { 27 | componentData.cancel = true; 28 | } 29 | } 30 | 31 | type ParameterTurnInto = { 32 | block: string; 33 | }; 34 | 35 | class TurnInto extends BeforeOnPlayerPlace { 36 | beforeOnPlayerPlace( 37 | componentData: BlockComponentPlayerPlaceBeforeEvent, 38 | paramData: CustomComponentParameters 39 | ) { 40 | const param = paramData.params as ParameterTurnInto; 41 | componentData.permutationToPlace = BlockPermutation.resolve( 42 | param.block 43 | ); 44 | } 45 | } 46 | 47 | class DoubleSlab extends BeforeOnPlayerPlace { 48 | beforeOnPlayerPlace( 49 | componentData: BlockComponentPlayerPlaceBeforeEvent 50 | ): void { 51 | beforeOnPlayerPlaceDoubleSlab(componentData); 52 | } 53 | } 54 | 55 | class SugarCane extends BeforeOnPlayerPlace { 56 | beforeOnPlayerPlace( 57 | componentData: BlockComponentPlayerPlaceBeforeEvent 58 | ): void { 59 | beforeOnPlayerPlaceSugarCane(componentData); 60 | } 61 | } 62 | 63 | class Stairs extends BeforeOnPlayerPlace { 64 | beforeOnPlayerPlace( 65 | componentData: BlockComponentPlayerPlaceBeforeEvent 66 | ): void { 67 | beforeOnPlayerPlaceStairs(componentData); 68 | } 69 | } 70 | 71 | enum BeforeOnPlayerPlaceKey { 72 | Debug = 'debug', 73 | Cancel = 'cancel', 74 | TurnInto = 'turn_into', 75 | DoubleSlab = 'double_slab', 76 | SugarCane = 'sugar_cane', 77 | Stairs = 'stairs' 78 | } 79 | 80 | export const BEFORE_ON_PLAYER_PLACE_REGISTRY: Map< 81 | BeforeOnPlayerPlaceKey, 82 | BeforeOnPlayerPlace 83 | > = new Map([ 84 | [BeforeOnPlayerPlaceKey.Debug, new Debug()], 85 | [BeforeOnPlayerPlaceKey.Cancel, new Cancel()], 86 | [BeforeOnPlayerPlaceKey.TurnInto, new TurnInto()], 87 | [BeforeOnPlayerPlaceKey.DoubleSlab, new DoubleSlab()], 88 | [BeforeOnPlayerPlaceKey.SugarCane, new SugarCane()], 89 | [BeforeOnPlayerPlaceKey.Stairs, new Stairs()] 90 | ]); 91 | -------------------------------------------------------------------------------- /stable/scripts/blocks/registry/before_on_player_place.ts: -------------------------------------------------------------------------------- 1 | import { 2 | BlockComponentPlayerPlaceBeforeEvent, 3 | BlockCustomComponent, 4 | BlockPermutation, 5 | CustomComponentParameters 6 | } from '@minecraft/server'; 7 | import { beforeOnPlayerPlaceDoubleSlab } from 'blocks/double_slab'; 8 | import { beforeOnPlayerPlaceSugarCane } from 'blocks/sugar_cane'; 9 | import { beforeOnPlayerPlaceStairs } from 'blocks/stairs'; 10 | import * as adk from 'adk-scripts-server'; 11 | 12 | abstract class BeforeOnPlayerPlace implements BlockCustomComponent { 13 | abstract beforeOnPlayerPlace( 14 | componentData: BlockComponentPlayerPlaceBeforeEvent, 15 | paramData?: CustomComponentParameters 16 | ): void; 17 | } 18 | 19 | class Debug extends BeforeOnPlayerPlace { 20 | beforeOnPlayerPlace(componentData: BlockComponentPlayerPlaceBeforeEvent) { 21 | console.log(adk.Debug.logEventData(componentData)); 22 | } 23 | } 24 | 25 | class Cancel extends BeforeOnPlayerPlace { 26 | beforeOnPlayerPlace(componentData: BlockComponentPlayerPlaceBeforeEvent) { 27 | componentData.cancel = true; 28 | } 29 | } 30 | 31 | type ParameterTurnInto = { 32 | block: string; 33 | }; 34 | 35 | class TurnInto extends BeforeOnPlayerPlace { 36 | beforeOnPlayerPlace( 37 | componentData: BlockComponentPlayerPlaceBeforeEvent, 38 | paramData: CustomComponentParameters 39 | ) { 40 | const param = paramData.params as ParameterTurnInto; 41 | componentData.permutationToPlace = BlockPermutation.resolve( 42 | param.block 43 | ); 44 | } 45 | } 46 | 47 | class DoubleSlab extends BeforeOnPlayerPlace { 48 | beforeOnPlayerPlace( 49 | componentData: BlockComponentPlayerPlaceBeforeEvent 50 | ): void { 51 | beforeOnPlayerPlaceDoubleSlab(componentData); 52 | } 53 | } 54 | 55 | class SugarCane extends BeforeOnPlayerPlace { 56 | beforeOnPlayerPlace( 57 | componentData: BlockComponentPlayerPlaceBeforeEvent 58 | ): void { 59 | beforeOnPlayerPlaceSugarCane(componentData); 60 | } 61 | } 62 | 63 | class Stairs extends BeforeOnPlayerPlace { 64 | beforeOnPlayerPlace( 65 | componentData: BlockComponentPlayerPlaceBeforeEvent 66 | ): void { 67 | beforeOnPlayerPlaceStairs(componentData); 68 | } 69 | } 70 | 71 | enum BeforeOnPlayerPlaceKey { 72 | Debug = 'debug', 73 | Cancel = 'cancel', 74 | TurnInto = 'turn_into', 75 | DoubleSlab = 'double_slab', 76 | SugarCane = 'sugar_cane', 77 | Stairs = 'stairs' 78 | } 79 | 80 | export const BEFORE_ON_PLAYER_PLACE_REGISTRY: Map< 81 | BeforeOnPlayerPlaceKey, 82 | BeforeOnPlayerPlace 83 | > = new Map([ 84 | [BeforeOnPlayerPlaceKey.Debug, new Debug()], 85 | [BeforeOnPlayerPlaceKey.Cancel, new Cancel()], 86 | [BeforeOnPlayerPlaceKey.TurnInto, new TurnInto()], 87 | [BeforeOnPlayerPlaceKey.DoubleSlab, new DoubleSlab()], 88 | [BeforeOnPlayerPlaceKey.SugarCane, new SugarCane()], 89 | [BeforeOnPlayerPlaceKey.Stairs, new Stairs()] 90 | ]); 91 | -------------------------------------------------------------------------------- /experimental/scripts/blocks/registry/before_on_player_place.ts: -------------------------------------------------------------------------------- 1 | import { 2 | BlockComponentPlayerPlaceBeforeEvent, 3 | BlockCustomComponent, 4 | BlockPermutation, 5 | CustomComponentParameters 6 | } from '@minecraft/server'; 7 | import { beforeOnPlayerPlaceDoubleSlab } from 'blocks/double_slab'; 8 | import { beforeOnPlayerPlaceSugarCane } from 'blocks/sugar_cane'; 9 | import { beforeOnPlayerPlaceStairs } from 'blocks/stairs'; 10 | import * as adk from 'adk-scripts-server'; 11 | 12 | abstract class BeforeOnPlayerPlace implements BlockCustomComponent { 13 | abstract beforeOnPlayerPlace( 14 | componentData: BlockComponentPlayerPlaceBeforeEvent, 15 | paramData?: CustomComponentParameters 16 | ): void; 17 | } 18 | 19 | class Debug extends BeforeOnPlayerPlace { 20 | beforeOnPlayerPlace(componentData: BlockComponentPlayerPlaceBeforeEvent) { 21 | console.log(adk.Debug.logEventData(componentData)); 22 | } 23 | } 24 | 25 | class Cancel extends BeforeOnPlayerPlace { 26 | beforeOnPlayerPlace(componentData: BlockComponentPlayerPlaceBeforeEvent) { 27 | componentData.cancel = true; 28 | } 29 | } 30 | 31 | type ParameterTurnInto = { 32 | block: string; 33 | }; 34 | 35 | class TurnInto extends BeforeOnPlayerPlace { 36 | beforeOnPlayerPlace( 37 | componentData: BlockComponentPlayerPlaceBeforeEvent, 38 | paramData: CustomComponentParameters 39 | ) { 40 | const param = paramData.params as ParameterTurnInto; 41 | componentData.permutationToPlace = BlockPermutation.resolve( 42 | param.block 43 | ); 44 | } 45 | } 46 | 47 | class DoubleSlab extends BeforeOnPlayerPlace { 48 | beforeOnPlayerPlace( 49 | componentData: BlockComponentPlayerPlaceBeforeEvent 50 | ): void { 51 | beforeOnPlayerPlaceDoubleSlab(componentData); 52 | } 53 | } 54 | 55 | class SugarCane extends BeforeOnPlayerPlace { 56 | beforeOnPlayerPlace( 57 | componentData: BlockComponentPlayerPlaceBeforeEvent 58 | ): void { 59 | beforeOnPlayerPlaceSugarCane(componentData); 60 | } 61 | } 62 | 63 | class Stairs extends BeforeOnPlayerPlace { 64 | beforeOnPlayerPlace( 65 | componentData: BlockComponentPlayerPlaceBeforeEvent 66 | ): void { 67 | beforeOnPlayerPlaceStairs(componentData); 68 | } 69 | } 70 | 71 | enum BeforeOnPlayerPlaceKey { 72 | Debug = 'debug', 73 | Cancel = 'cancel', 74 | TurnInto = 'turn_into', 75 | DoubleSlab = 'double_slab', 76 | SugarCane = 'sugar_cane', 77 | Stairs = 'stairs' 78 | } 79 | 80 | export const BEFORE_ON_PLAYER_PLACE_REGISTRY: Map< 81 | BeforeOnPlayerPlaceKey, 82 | BeforeOnPlayerPlace 83 | > = new Map([ 84 | [BeforeOnPlayerPlaceKey.Debug, new Debug()], 85 | [BeforeOnPlayerPlaceKey.Cancel, new Cancel()], 86 | [BeforeOnPlayerPlaceKey.TurnInto, new TurnInto()], 87 | [BeforeOnPlayerPlaceKey.DoubleSlab, new DoubleSlab()], 88 | [BeforeOnPlayerPlaceKey.SugarCane, new SugarCane()], 89 | [BeforeOnPlayerPlaceKey.Stairs, new Stairs()] 90 | ]); 91 | -------------------------------------------------------------------------------- /rc/scripts/blocks/double_slab.ts: -------------------------------------------------------------------------------- 1 | import { 2 | BlockComponentPlayerPlaceBeforeEvent, 3 | Block, 4 | Player, 5 | ItemStack, 6 | EquipmentSlot, 7 | Direction, 8 | BlockPermutation, 9 | BlockComponentPlayerBreakEvent, 10 | GameMode 11 | } from '@minecraft/server'; 12 | import type * as minecraftvanilladata from '@minecraft/vanilla-data'; 13 | import * as adk from 'adk-scripts-server'; 14 | 15 | export function beforeOnPlayerPlaceDoubleSlab( 16 | data: BlockComponentPlayerPlaceBeforeEvent 17 | ): void { 18 | const player: Player | undefined = data.player; 19 | if (!player) return; 20 | const player_equipment: ItemStack = adk.PlayerHelper.getItemFromEquippable( 21 | player, 22 | EquipmentSlot.Mainhand 23 | ); 24 | if (!player_equipment) return; 25 | 26 | const block: Block = data.block; 27 | const face: Direction = adk.DirectionHelper.getOpposite(data.face); 28 | const block_to_check: Block | undefined = block.offset( 29 | adk.DirectionHelper.toVector3(face) 30 | ); 31 | 32 | if (!block_to_check) return; 33 | 34 | const namespace: string = block_to_check.typeId.split(':')[0]; 35 | const block_state_double: string = namespace + ':is_double'; 36 | const block_state_half: string = 'minecraft:vertical_half'; 37 | 38 | if ( 39 | block_to_check.permutation.getState( 40 | block_state_double as keyof minecraftvanilladata.BlockStateSuperset 41 | ) 42 | ) 43 | return; 44 | if (block_to_check.typeId !== player_equipment.typeId) return; 45 | if (face === Direction.Up || face === Direction.Down) { 46 | const state = block_to_check.permutation.getState( 47 | block_state_half as keyof minecraftvanilladata.BlockStateSuperset 48 | ); 49 | if ( 50 | (face === Direction.Up && state === 'top') || 51 | (face === Direction.Down && state === 'bottom') 52 | ) { 53 | block_to_check.setPermutation( 54 | BlockPermutation.resolve(block_to_check.typeId, { 55 | [block_state_double]: true 56 | }) 57 | ); 58 | data.cancel = true; 59 | adk.PlayerHelper.decrementStack(player); 60 | } 61 | } 62 | } 63 | 64 | export function onPlayerDestroyDoubleSlab( 65 | data: BlockComponentPlayerBreakEvent 66 | ): void { 67 | const player: Player | undefined = data.player; 68 | if (!player) return; 69 | 70 | const player_equipement: ItemStack = adk.PlayerHelper.getItemFromEquippable( 71 | player, 72 | EquipmentSlot.Mainhand 73 | ); 74 | if (player.getGameMode() == GameMode.Creative) return; 75 | if (player_equipement === undefined) return; 76 | 77 | const has_silk_touch = adk.ComponentItemEnchantable.hasEnchantment( 78 | player_equipement, 79 | 'silk_touch' 80 | ); 81 | 82 | if (!has_silk_touch) return; 83 | 84 | adk.Cache.getDimension(data.dimension.id).spawnItem( 85 | new ItemStack(data.brokenBlockPermutation.type.id), 86 | data.block.location 87 | ); 88 | } 89 | -------------------------------------------------------------------------------- /stable/scripts/blocks/double_slab.ts: -------------------------------------------------------------------------------- 1 | import { 2 | BlockComponentPlayerPlaceBeforeEvent, 3 | Block, 4 | Player, 5 | ItemStack, 6 | EquipmentSlot, 7 | Direction, 8 | BlockPermutation, 9 | BlockComponentPlayerBreakEvent, 10 | GameMode 11 | } from '@minecraft/server'; 12 | import type * as minecraftvanilladata from '@minecraft/vanilla-data'; 13 | import * as adk from 'adk-scripts-server'; 14 | 15 | export function beforeOnPlayerPlaceDoubleSlab( 16 | data: BlockComponentPlayerPlaceBeforeEvent 17 | ): void { 18 | const player: Player | undefined = data.player; 19 | if (!player) return; 20 | const player_equipment: ItemStack = adk.PlayerHelper.getItemFromEquippable( 21 | player, 22 | EquipmentSlot.Mainhand 23 | ); 24 | if (!player_equipment) return; 25 | 26 | const block: Block = data.block; 27 | const face: Direction = adk.DirectionHelper.getOpposite(data.face); 28 | const block_to_check: Block | undefined = block.offset( 29 | adk.DirectionHelper.toVector3(face) 30 | ); 31 | 32 | if (!block_to_check) return; 33 | 34 | const namespace: string = block_to_check.typeId.split(':')[0]; 35 | const block_state_double: string = namespace + ':is_double'; 36 | const block_state_half: string = 'minecraft:vertical_half'; 37 | 38 | if ( 39 | block_to_check.permutation.getState( 40 | block_state_double as keyof minecraftvanilladata.BlockStateSuperset 41 | ) 42 | ) 43 | return; 44 | if (block_to_check.typeId !== player_equipment.typeId) return; 45 | if (face === Direction.Up || face === Direction.Down) { 46 | const state = block_to_check.permutation.getState( 47 | block_state_half as keyof minecraftvanilladata.BlockStateSuperset 48 | ); 49 | if ( 50 | (face === Direction.Up && state === 'top') || 51 | (face === Direction.Down && state === 'bottom') 52 | ) { 53 | block_to_check.setPermutation( 54 | BlockPermutation.resolve(block_to_check.typeId, { 55 | [block_state_double]: true 56 | }) 57 | ); 58 | data.cancel = true; 59 | adk.PlayerHelper.decrementStack(player); 60 | } 61 | } 62 | } 63 | 64 | export function onPlayerDestroyDoubleSlab( 65 | data: BlockComponentPlayerBreakEvent 66 | ): void { 67 | const player: Player | undefined = data.player; 68 | if (!player) return; 69 | 70 | const player_equipement: ItemStack = adk.PlayerHelper.getItemFromEquippable( 71 | player, 72 | EquipmentSlot.Mainhand 73 | ); 74 | if (player.getGameMode() == GameMode.Creative) return; 75 | if (player_equipement === undefined) return; 76 | 77 | const has_silk_touch = adk.ComponentItemEnchantable.hasEnchantment( 78 | player_equipement, 79 | 'silk_touch' 80 | ); 81 | 82 | if (!has_silk_touch) return; 83 | 84 | adk.Cache.getDimension(data.dimension.id).spawnItem( 85 | new ItemStack(data.brokenBlockPermutation.type.id), 86 | data.block.location 87 | ); 88 | } 89 | -------------------------------------------------------------------------------- /experimental/scripts/blocks/double_slab.ts: -------------------------------------------------------------------------------- 1 | import { 2 | BlockComponentPlayerPlaceBeforeEvent, 3 | Block, 4 | Player, 5 | ItemStack, 6 | EquipmentSlot, 7 | Direction, 8 | BlockPermutation, 9 | BlockComponentPlayerBreakEvent, 10 | GameMode 11 | } from '@minecraft/server'; 12 | import type * as minecraftvanilladata from '@minecraft/vanilla-data'; 13 | import * as adk from 'adk-scripts-server'; 14 | 15 | export function beforeOnPlayerPlaceDoubleSlab( 16 | data: BlockComponentPlayerPlaceBeforeEvent 17 | ): void { 18 | const player: Player | undefined = data.player; 19 | if (!player) return; 20 | const player_equipment: ItemStack = adk.PlayerHelper.getItemFromEquippable( 21 | player, 22 | EquipmentSlot.Mainhand 23 | ); 24 | if (!player_equipment) return; 25 | 26 | const block: Block = data.block; 27 | const face: Direction = adk.DirectionHelper.getOpposite(data.face); 28 | const block_to_check: Block | undefined = block.offset( 29 | adk.DirectionHelper.toVector3(face) 30 | ); 31 | 32 | if (!block_to_check) return; 33 | 34 | const namespace: string = block_to_check.typeId.split(':')[0]; 35 | const block_state_double: string = namespace + ':is_double'; 36 | const block_state_half: string = 'minecraft:vertical_half'; 37 | 38 | if ( 39 | block_to_check.permutation.getState( 40 | block_state_double as keyof minecraftvanilladata.BlockStateSuperset 41 | ) 42 | ) 43 | return; 44 | if (block_to_check.typeId !== player_equipment.typeId) return; 45 | if (face === Direction.Up || face === Direction.Down) { 46 | const state = block_to_check.permutation.getState( 47 | block_state_half as keyof minecraftvanilladata.BlockStateSuperset 48 | ); 49 | if ( 50 | (face === Direction.Up && state === 'top') || 51 | (face === Direction.Down && state === 'bottom') 52 | ) { 53 | block_to_check.setPermutation( 54 | BlockPermutation.resolve(block_to_check.typeId, { 55 | [block_state_double]: true 56 | }) 57 | ); 58 | data.cancel = true; 59 | adk.PlayerHelper.decrementStack(player); 60 | } 61 | } 62 | } 63 | 64 | export function onPlayerDestroyDoubleSlab( 65 | data: BlockComponentPlayerBreakEvent 66 | ): void { 67 | const player: Player | undefined = data.player; 68 | if (!player) return; 69 | 70 | const player_equipement: ItemStack = adk.PlayerHelper.getItemFromEquippable( 71 | player, 72 | EquipmentSlot.Mainhand 73 | ); 74 | if (player.getGameMode() == GameMode.Creative) return; 75 | if (player_equipement === undefined) return; 76 | 77 | const has_silk_touch = adk.ComponentItemEnchantable.hasEnchantment( 78 | player_equipement, 79 | 'silk_touch' 80 | ); 81 | 82 | if (!has_silk_touch) return; 83 | 84 | adk.Cache.getDimension(data.dimension.id).spawnItem( 85 | new ItemStack(data.brokenBlockPermutation.type.id), 86 | data.block.location 87 | ); 88 | } 89 | -------------------------------------------------------------------------------- /rc/scripts/blocks/registry/on_step_on.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Block, 3 | BlockComponentStepOnEvent, 4 | BlockCustomComponent, 5 | CustomComponentParameters, 6 | Dimension, 7 | Entity, 8 | Vector3 9 | } from '@minecraft/server'; 10 | import * as adk from 'adk-scripts-server'; 11 | import { ParameterBounceForce, ParameterEffect } from 'utils/shared_parameters'; 12 | 13 | abstract class OnStepOn implements BlockCustomComponent { 14 | abstract onStepOn( 15 | componentData: BlockComponentStepOnEvent, 16 | paramData?: CustomComponentParameters 17 | ): void; 18 | } 19 | 20 | class Debug extends OnStepOn { 21 | onStepOn(componentData: BlockComponentStepOnEvent) { 22 | console.log(adk.Debug.logEventData(componentData)); 23 | } 24 | } 25 | 26 | class Effect extends OnStepOn { 27 | onStepOn( 28 | componentData: BlockComponentStepOnEvent, 29 | paramData: CustomComponentParameters 30 | ) { 31 | const param = paramData.params as ParameterEffect; 32 | const dimension: Dimension = adk.Cache.getDimension( 33 | componentData.block.dimension.id 34 | ); 35 | const block: Block = componentData.block; 36 | param.forEach( 37 | ({ 38 | effect, 39 | duration, 40 | radius, 41 | amplifier = 0, 42 | show_particles = true, 43 | entity_type 44 | }) => { 45 | dimension 46 | .getEntities({ 47 | location: block.center(), 48 | maxDistance: radius 49 | }) 50 | .forEach((entity) => { 51 | if ( 52 | !entity_type || 53 | entity_type.includes(entity.typeId) 54 | ) { 55 | entity.addEffect(effect, duration, { 56 | showParticles: show_particles, 57 | amplifier 58 | }); 59 | } 60 | }); 61 | } 62 | ); 63 | } 64 | } 65 | 66 | class Bounce extends OnStepOn { 67 | onStepOn( 68 | componentData: BlockComponentStepOnEvent, 69 | paramData: CustomComponentParameters 70 | ) { 71 | const entity: Entity | undefined = componentData.entity; 72 | 73 | if (!entity) return; 74 | 75 | const velocity: Vector3 = entity.getVelocity(); 76 | if (velocity.y < 0) { 77 | const param = paramData.params as ParameterBounceForce; 78 | const bounce_force = param.force ?? 1; 79 | entity.applyKnockback({ x: 0, z: 0 }, -velocity.y * bounce_force); 80 | } 81 | } 82 | } 83 | 84 | enum OnStepOnKey { 85 | Debug = 'debug', 86 | Effect = 'effect', 87 | Bounce = 'bounce' 88 | } 89 | 90 | export const ON_STEP_ON_REGISTRY: Map = new Map([ 91 | [OnStepOnKey.Debug, new Debug()], 92 | [OnStepOnKey.Effect, new Effect()], 93 | [OnStepOnKey.Bounce, new Bounce()] 94 | ]); 95 | -------------------------------------------------------------------------------- /stable/scripts/blocks/registry/on_step_on.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Block, 3 | BlockComponentStepOnEvent, 4 | BlockCustomComponent, 5 | CustomComponentParameters, 6 | Dimension, 7 | Entity, 8 | Vector3 9 | } from '@minecraft/server'; 10 | import * as adk from 'adk-scripts-server'; 11 | import { ParameterBounceForce, ParameterEffect } from 'utils/shared_parameters'; 12 | 13 | abstract class OnStepOn implements BlockCustomComponent { 14 | abstract onStepOn( 15 | componentData: BlockComponentStepOnEvent, 16 | paramData?: CustomComponentParameters 17 | ): void; 18 | } 19 | 20 | class Debug extends OnStepOn { 21 | onStepOn(componentData: BlockComponentStepOnEvent) { 22 | console.log(adk.Debug.logEventData(componentData)); 23 | } 24 | } 25 | 26 | class Effect extends OnStepOn { 27 | onStepOn( 28 | componentData: BlockComponentStepOnEvent, 29 | paramData: CustomComponentParameters 30 | ) { 31 | const param = paramData.params as ParameterEffect; 32 | const dimension: Dimension = adk.Cache.getDimension( 33 | componentData.block.dimension.id 34 | ); 35 | const block: Block = componentData.block; 36 | param.forEach( 37 | ({ 38 | effect, 39 | duration, 40 | radius, 41 | amplifier = 0, 42 | show_particles = true, 43 | entity_type 44 | }) => { 45 | dimension 46 | .getEntities({ 47 | location: block.center(), 48 | maxDistance: radius 49 | }) 50 | .forEach((entity) => { 51 | if ( 52 | !entity_type || 53 | entity_type.includes(entity.typeId) 54 | ) { 55 | entity.addEffect(effect, duration, { 56 | showParticles: show_particles, 57 | amplifier 58 | }); 59 | } 60 | }); 61 | } 62 | ); 63 | } 64 | } 65 | 66 | class Bounce extends OnStepOn { 67 | onStepOn( 68 | componentData: BlockComponentStepOnEvent, 69 | paramData: CustomComponentParameters 70 | ) { 71 | const entity: Entity | undefined = componentData.entity; 72 | 73 | if (!entity) return; 74 | 75 | const velocity: Vector3 = entity.getVelocity(); 76 | if (velocity.y < 0) { 77 | const param = paramData.params as ParameterBounceForce; 78 | const bounce_force = param.force ?? 1; 79 | entity.applyKnockback({ x: 0, z: 0 }, -velocity.y * bounce_force); 80 | } 81 | } 82 | } 83 | 84 | enum OnStepOnKey { 85 | Debug = 'debug', 86 | Effect = 'effect', 87 | Bounce = 'bounce' 88 | } 89 | 90 | export const ON_STEP_ON_REGISTRY: Map = new Map([ 91 | [OnStepOnKey.Debug, new Debug()], 92 | [OnStepOnKey.Effect, new Effect()], 93 | [OnStepOnKey.Bounce, new Bounce()] 94 | ]); 95 | -------------------------------------------------------------------------------- /experimental/scripts/blocks/registry/on_step_on.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Block, 3 | BlockComponentStepOnEvent, 4 | BlockCustomComponent, 5 | CustomComponentParameters, 6 | Dimension, 7 | Entity, 8 | Vector3 9 | } from '@minecraft/server'; 10 | import * as adk from 'adk-scripts-server'; 11 | import { ParameterBounceForce, ParameterEffect } from 'utils/shared_parameters'; 12 | 13 | abstract class OnStepOn implements BlockCustomComponent { 14 | abstract onStepOn( 15 | componentData: BlockComponentStepOnEvent, 16 | paramData?: CustomComponentParameters 17 | ): void; 18 | } 19 | 20 | class Debug extends OnStepOn { 21 | onStepOn(componentData: BlockComponentStepOnEvent) { 22 | console.log(adk.Debug.logEventData(componentData)); 23 | } 24 | } 25 | 26 | class Effect extends OnStepOn { 27 | onStepOn( 28 | componentData: BlockComponentStepOnEvent, 29 | paramData: CustomComponentParameters 30 | ) { 31 | const param = paramData.params as ParameterEffect; 32 | const dimension: Dimension = adk.Cache.getDimension( 33 | componentData.block.dimension.id 34 | ); 35 | const block: Block = componentData.block; 36 | param.forEach( 37 | ({ 38 | effect, 39 | duration, 40 | radius, 41 | amplifier = 0, 42 | show_particles = true, 43 | entity_type 44 | }) => { 45 | dimension 46 | .getEntities({ 47 | location: block.center(), 48 | maxDistance: radius 49 | }) 50 | .forEach((entity) => { 51 | if ( 52 | !entity_type || 53 | entity_type.includes(entity.typeId) 54 | ) { 55 | entity.addEffect(effect, duration, { 56 | showParticles: show_particles, 57 | amplifier 58 | }); 59 | } 60 | }); 61 | } 62 | ); 63 | } 64 | } 65 | 66 | class Bounce extends OnStepOn { 67 | onStepOn( 68 | componentData: BlockComponentStepOnEvent, 69 | paramData: CustomComponentParameters 70 | ) { 71 | const entity: Entity | undefined = componentData.entity; 72 | 73 | if (!entity) return; 74 | 75 | const velocity: Vector3 = entity.getVelocity(); 76 | if (velocity.y < 0) { 77 | const param = paramData.params as ParameterBounceForce; 78 | const bounce_force = param.force ?? 1; 79 | entity.applyKnockback({ x: 0, z: 0 }, -velocity.y * bounce_force); 80 | } 81 | } 82 | } 83 | 84 | enum OnStepOnKey { 85 | Debug = 'debug', 86 | Effect = 'effect', 87 | Bounce = 'bounce' 88 | } 89 | 90 | export const ON_STEP_ON_REGISTRY: Map = new Map([ 91 | [OnStepOnKey.Debug, new Debug()], 92 | [OnStepOnKey.Effect, new Effect()], 93 | [OnStepOnKey.Bounce, new Bounce()] 94 | ]); 95 | -------------------------------------------------------------------------------- /rc/scripts/blocks/registry/on_tick.ts: -------------------------------------------------------------------------------- 1 | import { 2 | BlockComponentTickEvent, 3 | BlockCustomComponent, 4 | CustomComponentParameters, 5 | Dimension, 6 | Direction, 7 | Vector3 8 | } from '@minecraft/server'; 9 | import { onTickCandle } from 'blocks/candle'; 10 | import * as adk from 'adk-scripts-server'; 11 | 12 | abstract class OnTick implements BlockCustomComponent { 13 | abstract onTick( 14 | componentData: BlockComponentTickEvent, 15 | paramData?: CustomComponentParameters 16 | ): void; 17 | } 18 | 19 | class Debug extends OnTick { 20 | onTick(componentData: BlockComponentTickEvent) { 21 | console.log(adk.Debug.logEventData(componentData)); 22 | } 23 | } 24 | 25 | class TorchParticles extends OnTick { 26 | onTick(componentData: BlockComponentTickEvent): void { 27 | if (Math.floor(Math.random() * 10) != 0) return; 28 | 29 | let face: string = componentData.block.permutation.getState( 30 | 'minecraft:block_face' 31 | ) as string; 32 | let location: Vector3 = componentData.block.location; 33 | let dimension: Dimension = componentData.block.dimension; 34 | location.x += 0.5; 35 | location.y += 0.7; 36 | location.z += 0.5; 37 | 38 | if (face === 'up') { 39 | dimension.spawnParticle('minecraft:basic_smoke_particle', location); 40 | dimension.spawnParticle('minecraft:basic_flame_particle', location); 41 | } else { 42 | let direction: Direction = 43 | Direction[face.charAt(0).toUpperCase() + face.slice(1)]; 44 | const xzOffset: number = 0.22; 45 | const yOffset: number = 0.27; 46 | 47 | switch (direction) { 48 | case Direction.North: 49 | direction = Direction.South; 50 | break; 51 | case Direction.East: 52 | direction = Direction.West; 53 | break; 54 | case Direction.South: 55 | direction = Direction.North; 56 | break; 57 | case Direction.West: 58 | direction = Direction.East; 59 | break; 60 | default: 61 | break; 62 | } 63 | 64 | dimension.spawnParticle('minecraft:basic_smoke_particle', { 65 | x: 66 | location.x + 67 | xzOffset * adk.DirectionHelper.toVector3(direction).x, 68 | y: location.y + yOffset, 69 | z: 70 | location.z + 71 | xzOffset * adk.DirectionHelper.toVector3(direction).z 72 | }); 73 | dimension.spawnParticle('minecraft:basic_flame_particle', { 74 | x: 75 | location.x + 76 | xzOffset * adk.DirectionHelper.toVector3(direction).x, 77 | y: location.y + yOffset, 78 | z: 79 | location.z + 80 | xzOffset * adk.DirectionHelper.toVector3(direction).z 81 | }); 82 | } 83 | } 84 | } 85 | 86 | class CandleParticles extends OnTick { 87 | onTick(componentData: BlockComponentTickEvent): void { 88 | onTickCandle(componentData); 89 | } 90 | } 91 | 92 | enum OnTickKey { 93 | Debug = 'debug', 94 | TorchParticles = 'torch_particles', 95 | CandleParticles = 'candle_particles' 96 | } 97 | 98 | export const ON_TICK_REGISTRY: Map = new Map([ 99 | [OnTickKey.Debug, new Debug()], 100 | [OnTickKey.TorchParticles, new TorchParticles()], 101 | [OnTickKey.CandleParticles, new CandleParticles()] 102 | ]); 103 | -------------------------------------------------------------------------------- /stable/scripts/blocks/registry/on_tick.ts: -------------------------------------------------------------------------------- 1 | import { 2 | BlockComponentTickEvent, 3 | BlockCustomComponent, 4 | CustomComponentParameters, 5 | Dimension, 6 | Direction, 7 | Vector3 8 | } from '@minecraft/server'; 9 | import { onTickCandle } from 'blocks/candle'; 10 | import * as adk from 'adk-scripts-server'; 11 | 12 | abstract class OnTick implements BlockCustomComponent { 13 | abstract onTick( 14 | componentData: BlockComponentTickEvent, 15 | paramData?: CustomComponentParameters 16 | ): void; 17 | } 18 | 19 | class Debug extends OnTick { 20 | onTick(componentData: BlockComponentTickEvent) { 21 | console.log(adk.Debug.logEventData(componentData)); 22 | } 23 | } 24 | 25 | class TorchParticles extends OnTick { 26 | onTick(componentData: BlockComponentTickEvent): void { 27 | if (Math.floor(Math.random() * 10) != 0) return; 28 | 29 | let face: string = componentData.block.permutation.getState( 30 | 'minecraft:block_face' 31 | ) as string; 32 | let location: Vector3 = componentData.block.location; 33 | let dimension: Dimension = componentData.block.dimension; 34 | location.x += 0.5; 35 | location.y += 0.7; 36 | location.z += 0.5; 37 | 38 | if (face === 'up') { 39 | dimension.spawnParticle('minecraft:basic_smoke_particle', location); 40 | dimension.spawnParticle('minecraft:basic_flame_particle', location); 41 | } else { 42 | let direction: Direction = 43 | Direction[face.charAt(0).toUpperCase() + face.slice(1)]; 44 | const xzOffset: number = 0.22; 45 | const yOffset: number = 0.27; 46 | 47 | switch (direction) { 48 | case Direction.North: 49 | direction = Direction.South; 50 | break; 51 | case Direction.East: 52 | direction = Direction.West; 53 | break; 54 | case Direction.South: 55 | direction = Direction.North; 56 | break; 57 | case Direction.West: 58 | direction = Direction.East; 59 | break; 60 | default: 61 | break; 62 | } 63 | 64 | dimension.spawnParticle('minecraft:basic_smoke_particle', { 65 | x: 66 | location.x + 67 | xzOffset * adk.DirectionHelper.toVector3(direction).x, 68 | y: location.y + yOffset, 69 | z: 70 | location.z + 71 | xzOffset * adk.DirectionHelper.toVector3(direction).z 72 | }); 73 | dimension.spawnParticle('minecraft:basic_flame_particle', { 74 | x: 75 | location.x + 76 | xzOffset * adk.DirectionHelper.toVector3(direction).x, 77 | y: location.y + yOffset, 78 | z: 79 | location.z + 80 | xzOffset * adk.DirectionHelper.toVector3(direction).z 81 | }); 82 | } 83 | } 84 | } 85 | 86 | class CandleParticles extends OnTick { 87 | onTick(componentData: BlockComponentTickEvent): void { 88 | onTickCandle(componentData); 89 | } 90 | } 91 | 92 | enum OnTickKey { 93 | Debug = 'debug', 94 | TorchParticles = 'torch_particles', 95 | CandleParticles = 'candle_particles' 96 | } 97 | 98 | export const ON_TICK_REGISTRY: Map = new Map([ 99 | [OnTickKey.Debug, new Debug()], 100 | [OnTickKey.TorchParticles, new TorchParticles()], 101 | [OnTickKey.CandleParticles, new CandleParticles()] 102 | ]); 103 | -------------------------------------------------------------------------------- /experimental/scripts/blocks/registry/on_tick.ts: -------------------------------------------------------------------------------- 1 | import { 2 | BlockComponentTickEvent, 3 | BlockCustomComponent, 4 | CustomComponentParameters, 5 | Dimension, 6 | Direction, 7 | Vector3 8 | } from '@minecraft/server'; 9 | import { onTickCandle } from 'blocks/candle'; 10 | import * as adk from 'adk-scripts-server'; 11 | 12 | abstract class OnTick implements BlockCustomComponent { 13 | abstract onTick( 14 | componentData: BlockComponentTickEvent, 15 | paramData?: CustomComponentParameters 16 | ): void; 17 | } 18 | 19 | class Debug extends OnTick { 20 | onTick(componentData: BlockComponentTickEvent) { 21 | console.log(adk.Debug.logEventData(componentData)); 22 | } 23 | } 24 | 25 | class TorchParticles extends OnTick { 26 | onTick(componentData: BlockComponentTickEvent): void { 27 | if (Math.floor(Math.random() * 10) != 0) return; 28 | 29 | let face: string = componentData.block.permutation.getState( 30 | 'minecraft:block_face' 31 | ) as string; 32 | let location: Vector3 = componentData.block.location; 33 | let dimension: Dimension = componentData.block.dimension; 34 | location.x += 0.5; 35 | location.y += 0.7; 36 | location.z += 0.5; 37 | 38 | if (face === 'up') { 39 | dimension.spawnParticle('minecraft:basic_smoke_particle', location); 40 | dimension.spawnParticle('minecraft:basic_flame_particle', location); 41 | } else { 42 | let direction: Direction = 43 | Direction[face.charAt(0).toUpperCase() + face.slice(1)]; 44 | const xzOffset: number = 0.22; 45 | const yOffset: number = 0.27; 46 | 47 | switch (direction) { 48 | case Direction.North: 49 | direction = Direction.South; 50 | break; 51 | case Direction.East: 52 | direction = Direction.West; 53 | break; 54 | case Direction.South: 55 | direction = Direction.North; 56 | break; 57 | case Direction.West: 58 | direction = Direction.East; 59 | break; 60 | default: 61 | break; 62 | } 63 | 64 | dimension.spawnParticle('minecraft:basic_smoke_particle', { 65 | x: 66 | location.x + 67 | xzOffset * adk.DirectionHelper.toVector3(direction).x, 68 | y: location.y + yOffset, 69 | z: 70 | location.z + 71 | xzOffset * adk.DirectionHelper.toVector3(direction).z 72 | }); 73 | dimension.spawnParticle('minecraft:basic_flame_particle', { 74 | x: 75 | location.x + 76 | xzOffset * adk.DirectionHelper.toVector3(direction).x, 77 | y: location.y + yOffset, 78 | z: 79 | location.z + 80 | xzOffset * adk.DirectionHelper.toVector3(direction).z 81 | }); 82 | } 83 | } 84 | } 85 | 86 | class CandleParticles extends OnTick { 87 | onTick(componentData: BlockComponentTickEvent): void { 88 | onTickCandle(componentData); 89 | } 90 | } 91 | 92 | enum OnTickKey { 93 | Debug = 'debug', 94 | TorchParticles = 'torch_particles', 95 | CandleParticles = 'candle_particles' 96 | } 97 | 98 | export const ON_TICK_REGISTRY: Map = new Map([ 99 | [OnTickKey.Debug, new Debug()], 100 | [OnTickKey.TorchParticles, new TorchParticles()], 101 | [OnTickKey.CandleParticles, new CandleParticles()] 102 | ]); 103 | -------------------------------------------------------------------------------- /rc/scripts/item/registry/on_consume.ts: -------------------------------------------------------------------------------- 1 | import { 2 | CustomComponentParameters, 3 | ItemComponentConsumeEvent, 4 | ItemCustomComponent, 5 | system, 6 | Vector3 7 | } from '@minecraft/server'; 8 | import { teleportEntity } from '../teleport'; 9 | import * as adk from 'adk-scripts-server'; 10 | import { ParameterEffect, ParameterRunCommand } from 'utils/shared_parameters'; 11 | 12 | abstract class OnConsume implements ItemCustomComponent { 13 | abstract onConsume( 14 | componentData: ItemComponentConsumeEvent, 15 | paramData?: CustomComponentParameters 16 | ): void; 17 | } 18 | 19 | class Debug extends OnConsume { 20 | onConsume(componentData: ItemComponentConsumeEvent): void { 21 | console.log(adk.Debug.logEventData(componentData)); 22 | } 23 | } 24 | 25 | class Teleport extends OnConsume { 26 | onConsume(componentData: ItemComponentConsumeEvent) { 27 | const location: Vector3 = componentData.source.location; 28 | const dimension_height_range = adk.Cache.getDimensionHeightRange( 29 | componentData.source.dimension.id 30 | ); 31 | for (let a = 0; a < 16; ++a) { 32 | const x: number = location.x + (Math.random() - 0.5) * 16.0; 33 | const y: number = adk.MathHelper.clamp( 34 | location.y + (Math.random() * 16 - 8), 35 | dimension_height_range.min, 36 | dimension_height_range.max 37 | ); 38 | const z: number = location.z + (Math.random() - 0.5) * 16.0; 39 | const new_location: adk.Vector3Builder = new adk.Vector3Builder( 40 | x, 41 | y, 42 | z 43 | ); 44 | 45 | if ( 46 | teleportEntity( 47 | componentData.source, 48 | new_location, 49 | dimension_height_range 50 | ) 51 | ) 52 | break; 53 | } 54 | } 55 | } 56 | 57 | class FoodEffect extends OnConsume { 58 | onConsume( 59 | componentData: ItemComponentConsumeEvent, 60 | paramData: CustomComponentParameters 61 | ) { 62 | const param = paramData.params as ParameterEffect; 63 | param.forEach( 64 | ({ 65 | effect, 66 | duration, 67 | amplifier = 0, 68 | show_particles = true, 69 | entity_type 70 | }) => { 71 | if (!entity_type) 72 | componentData.source.addEffect(effect, duration, { 73 | showParticles: show_particles, 74 | amplifier 75 | }); 76 | else { 77 | entity_type.forEach((type) => { 78 | if (componentData.source.typeId === type) 79 | componentData.source.addEffect(effect, duration, { 80 | showParticles: show_particles, 81 | amplifier 82 | }); 83 | }); 84 | } 85 | } 86 | ); 87 | } 88 | } 89 | 90 | class RunCommand extends OnConsume { 91 | onConsume( 92 | componentData: ItemComponentConsumeEvent, 93 | paramData: CustomComponentParameters 94 | ) { 95 | const param = paramData.params as ParameterRunCommand; 96 | system.run(() => { 97 | param.command.forEach((command) => { 98 | componentData.source.runCommand(command); 99 | }); 100 | }); 101 | } 102 | } 103 | 104 | enum OnConsumeKey { 105 | Debug = 'debug', 106 | Teleport = 'teleport', 107 | FoodEffect = 'food_effect', 108 | RunCommand = 'run_command' 109 | } 110 | 111 | export const ON_CONSUME_REGISTRY = new Map([ 112 | [OnConsumeKey.Debug, new Debug()], 113 | [OnConsumeKey.Teleport, new Teleport()], 114 | [OnConsumeKey.FoodEffect, new FoodEffect()], 115 | [OnConsumeKey.RunCommand, new RunCommand()] 116 | ]); 117 | -------------------------------------------------------------------------------- /stable/scripts/item/registry/on_consume.ts: -------------------------------------------------------------------------------- 1 | import { 2 | CustomComponentParameters, 3 | ItemComponentConsumeEvent, 4 | ItemCustomComponent, 5 | system, 6 | Vector3 7 | } from '@minecraft/server'; 8 | import { teleportEntity } from '../teleport'; 9 | import * as adk from 'adk-scripts-server'; 10 | import { ParameterEffect, ParameterRunCommand } from 'utils/shared_parameters'; 11 | 12 | abstract class OnConsume implements ItemCustomComponent { 13 | abstract onConsume( 14 | componentData: ItemComponentConsumeEvent, 15 | paramData?: CustomComponentParameters 16 | ): void; 17 | } 18 | 19 | class Debug extends OnConsume { 20 | onConsume(componentData: ItemComponentConsumeEvent): void { 21 | console.log(adk.Debug.logEventData(componentData)); 22 | } 23 | } 24 | 25 | class Teleport extends OnConsume { 26 | onConsume(componentData: ItemComponentConsumeEvent) { 27 | const location: Vector3 = componentData.source.location; 28 | const dimension_height_range = adk.Cache.getDimensionHeightRange( 29 | componentData.source.dimension.id 30 | ); 31 | for (let a = 0; a < 16; ++a) { 32 | const x: number = location.x + (Math.random() - 0.5) * 16.0; 33 | const y: number = adk.MathHelper.clamp( 34 | location.y + (Math.random() * 16 - 8), 35 | dimension_height_range.min, 36 | dimension_height_range.max 37 | ); 38 | const z: number = location.z + (Math.random() - 0.5) * 16.0; 39 | const new_location: adk.Vector3Builder = new adk.Vector3Builder( 40 | x, 41 | y, 42 | z 43 | ); 44 | 45 | if ( 46 | teleportEntity( 47 | componentData.source, 48 | new_location, 49 | dimension_height_range 50 | ) 51 | ) 52 | break; 53 | } 54 | } 55 | } 56 | 57 | class FoodEffect extends OnConsume { 58 | onConsume( 59 | componentData: ItemComponentConsumeEvent, 60 | paramData: CustomComponentParameters 61 | ) { 62 | const param = paramData.params as ParameterEffect; 63 | param.forEach( 64 | ({ 65 | effect, 66 | duration, 67 | amplifier = 0, 68 | show_particles = true, 69 | entity_type 70 | }) => { 71 | if (!entity_type) 72 | componentData.source.addEffect(effect, duration, { 73 | showParticles: show_particles, 74 | amplifier 75 | }); 76 | else { 77 | entity_type.forEach((type) => { 78 | if (componentData.source.typeId === type) 79 | componentData.source.addEffect(effect, duration, { 80 | showParticles: show_particles, 81 | amplifier 82 | }); 83 | }); 84 | } 85 | } 86 | ); 87 | } 88 | } 89 | 90 | class RunCommand extends OnConsume { 91 | onConsume( 92 | componentData: ItemComponentConsumeEvent, 93 | paramData: CustomComponentParameters 94 | ) { 95 | const param = paramData.params as ParameterRunCommand; 96 | system.run(() => { 97 | param.command.forEach((command) => { 98 | componentData.source.runCommand(command); 99 | }); 100 | }); 101 | } 102 | } 103 | 104 | enum OnConsumeKey { 105 | Debug = 'debug', 106 | Teleport = 'teleport', 107 | FoodEffect = 'food_effect', 108 | RunCommand = 'run_command' 109 | } 110 | 111 | export const ON_CONSUME_REGISTRY = new Map([ 112 | [OnConsumeKey.Debug, new Debug()], 113 | [OnConsumeKey.Teleport, new Teleport()], 114 | [OnConsumeKey.FoodEffect, new FoodEffect()], 115 | [OnConsumeKey.RunCommand, new RunCommand()] 116 | ]); 117 | -------------------------------------------------------------------------------- /experimental/scripts/item/registry/on_consume.ts: -------------------------------------------------------------------------------- 1 | import { 2 | CustomComponentParameters, 3 | ItemComponentConsumeEvent, 4 | ItemCustomComponent, 5 | system, 6 | Vector3 7 | } from '@minecraft/server'; 8 | import { teleportEntity } from '../teleport'; 9 | import * as adk from 'adk-scripts-server'; 10 | import { ParameterEffect, ParameterRunCommand } from 'utils/shared_parameters'; 11 | 12 | abstract class OnConsume implements ItemCustomComponent { 13 | abstract onConsume( 14 | componentData: ItemComponentConsumeEvent, 15 | paramData?: CustomComponentParameters 16 | ): void; 17 | } 18 | 19 | class Debug extends OnConsume { 20 | onConsume(componentData: ItemComponentConsumeEvent): void { 21 | console.log(adk.Debug.logEventData(componentData)); 22 | } 23 | } 24 | 25 | class Teleport extends OnConsume { 26 | onConsume(componentData: ItemComponentConsumeEvent) { 27 | const location: Vector3 = componentData.source.location; 28 | const dimension_height_range = adk.Cache.getDimensionHeightRange( 29 | componentData.source.dimension.id 30 | ); 31 | for (let a = 0; a < 16; ++a) { 32 | const x: number = location.x + (Math.random() - 0.5) * 16.0; 33 | const y: number = adk.MathHelper.clamp( 34 | location.y + (Math.random() * 16 - 8), 35 | dimension_height_range.min, 36 | dimension_height_range.max 37 | ); 38 | const z: number = location.z + (Math.random() - 0.5) * 16.0; 39 | const new_location: adk.Vector3Builder = new adk.Vector3Builder( 40 | x, 41 | y, 42 | z 43 | ); 44 | 45 | if ( 46 | teleportEntity( 47 | componentData.source, 48 | new_location, 49 | dimension_height_range 50 | ) 51 | ) 52 | break; 53 | } 54 | } 55 | } 56 | 57 | class FoodEffect extends OnConsume { 58 | onConsume( 59 | componentData: ItemComponentConsumeEvent, 60 | paramData: CustomComponentParameters 61 | ) { 62 | const param = paramData.params as ParameterEffect; 63 | param.forEach( 64 | ({ 65 | effect, 66 | duration, 67 | amplifier = 0, 68 | show_particles = true, 69 | entity_type 70 | }) => { 71 | if (!entity_type) 72 | componentData.source.addEffect(effect, duration, { 73 | showParticles: show_particles, 74 | amplifier 75 | }); 76 | else { 77 | entity_type.forEach((type) => { 78 | if (componentData.source.typeId === type) 79 | componentData.source.addEffect(effect, duration, { 80 | showParticles: show_particles, 81 | amplifier 82 | }); 83 | }); 84 | } 85 | } 86 | ); 87 | } 88 | } 89 | 90 | class RunCommand extends OnConsume { 91 | onConsume( 92 | componentData: ItemComponentConsumeEvent, 93 | paramData: CustomComponentParameters 94 | ) { 95 | const param = paramData.params as ParameterRunCommand; 96 | system.run(() => { 97 | param.command.forEach((command) => { 98 | componentData.source.runCommand(command); 99 | }); 100 | }); 101 | } 102 | } 103 | 104 | enum OnConsumeKey { 105 | Debug = 'debug', 106 | Teleport = 'teleport', 107 | FoodEffect = 'food_effect', 108 | RunCommand = 'run_command' 109 | } 110 | 111 | export const ON_CONSUME_REGISTRY = new Map([ 112 | [OnConsumeKey.Debug, new Debug()], 113 | [OnConsumeKey.Teleport, new Teleport()], 114 | [OnConsumeKey.FoodEffect, new FoodEffect()], 115 | [OnConsumeKey.RunCommand, new RunCommand()] 116 | ]); 117 | -------------------------------------------------------------------------------- /rc/scripts/main.ts: -------------------------------------------------------------------------------- 1 | import { BEFORE_ON_PLAYER_PLACE_REGISTRY } from './blocks/registry/before_on_player_place'; 2 | import { ON_ENTITY_FALL_ON_REGISTRY } from './blocks/registry/on_entity_fall_on'; 3 | import { ON_PLACE_REGISTRY } from './blocks/registry/on_place'; 4 | import { ON_PLAYER_DESTROY_REGISTRY } from './blocks/registry/on_player_break'; 5 | import { ON_PLAYER_INTERACT_REGISTRY } from './blocks/registry/on_player_interact'; 6 | import { ON_RANDOM_TICK_REGISTRY } from './blocks/registry/on_random_tick'; 7 | import { ON_STEP_OFF_REGISTRY } from './blocks/registry/on_step_off'; 8 | import { ON_STEP_ON_REGISTRY } from './blocks/registry/on_step_on'; 9 | import { ON_TICK_REGISTRY } from './blocks/registry/on_tick'; 10 | import { ON_BEFORE_DURABILITY_DAMAGE_REGISTRY } from './item/registry/on_before_durability_damage'; 11 | import { ON_COMPLETE_USE_REGISTRY } from './item/registry/on_complete_use'; 12 | import { ON_CONSUME_REGISTRY } from './item/registry/on_consume'; 13 | import { ON_HIT_ENTITY_REGISTRY } from './item/registry/on_hit_entity'; 14 | import { ON_MINE_BLOCK_REGISTRY } from './item/registry/on_mine_block'; 15 | import { ON_USE_ON_REGISTRY } from './item/registry/on_use_on'; 16 | import { ON_USE_REGISTRY } from './item/registry/on_use'; 17 | import { SystemHelper } from 'adk-scripts-server'; 18 | 19 | BEFORE_ON_PLAYER_PLACE_REGISTRY.forEach((value, key) => { 20 | SystemHelper.registerCustomComponentBlock( 21 | `adk_lib:before_on_player_place_${key}`, 22 | value 23 | ); 24 | }); 25 | ON_ENTITY_FALL_ON_REGISTRY.forEach((value, key) => { 26 | SystemHelper.registerCustomComponentBlock( 27 | `adk_lib:on_entity_fall_on_${key}`, 28 | value 29 | ); 30 | }); 31 | ON_PLACE_REGISTRY.forEach((value, key) => { 32 | SystemHelper.registerCustomComponentBlock(`adk_lib:on_place_${key}`, value); 33 | }); 34 | ON_PLAYER_DESTROY_REGISTRY.forEach((value, key) => { 35 | SystemHelper.registerCustomComponentBlock( 36 | `adk_lib:on_player_destroy_${key}`, 37 | value 38 | ); 39 | }); 40 | ON_PLAYER_INTERACT_REGISTRY.forEach((value, key) => { 41 | SystemHelper.registerCustomComponentBlock( 42 | `adk_lib:on_player_interact_${key}`, 43 | value 44 | ); 45 | }); 46 | ON_RANDOM_TICK_REGISTRY.forEach((value, key) => { 47 | SystemHelper.registerCustomComponentBlock( 48 | `adk_lib:on_random_tick_${key}`, 49 | value 50 | ); 51 | }); 52 | ON_STEP_OFF_REGISTRY.forEach((value, key) => { 53 | SystemHelper.registerCustomComponentBlock( 54 | `adk_lib:on_step_off_${key}`, 55 | value 56 | ); 57 | }); 58 | ON_STEP_ON_REGISTRY.forEach((value, key) => { 59 | SystemHelper.registerCustomComponentBlock( 60 | `adk_lib:on_step_on_${key}`, 61 | value 62 | ); 63 | }); 64 | ON_TICK_REGISTRY.forEach((value, key) => { 65 | SystemHelper.registerCustomComponentBlock(`adk_lib:on_tick_${key}`, value); 66 | }); 67 | ON_BEFORE_DURABILITY_DAMAGE_REGISTRY.forEach((value, key) => { 68 | SystemHelper.registerCustomComponentItem( 69 | `adk_lib:on_before_durability_damage_${key}`, 70 | value 71 | ); 72 | }); 73 | ON_COMPLETE_USE_REGISTRY.forEach((value, key) => { 74 | SystemHelper.registerCustomComponentItem( 75 | `adk_lib:on_complete_use_${key}`, 76 | value 77 | ); 78 | }); 79 | ON_CONSUME_REGISTRY.forEach((value, key) => { 80 | SystemHelper.registerCustomComponentItem( 81 | `adk_lib:on_consume_${key}`, 82 | value 83 | ); 84 | }); 85 | ON_HIT_ENTITY_REGISTRY.forEach((value, key) => { 86 | SystemHelper.registerCustomComponentItem( 87 | `adk_lib:on_hit_entity_${key}`, 88 | value 89 | ); 90 | }); 91 | ON_MINE_BLOCK_REGISTRY.forEach((value, key) => { 92 | SystemHelper.registerCustomComponentItem( 93 | `adk_lib:on_mine_block_${key}`, 94 | value 95 | ); 96 | }); 97 | ON_USE_ON_REGISTRY.forEach((value, key) => { 98 | SystemHelper.registerCustomComponentItem(`adk_lib:on_use_on_${key}`, value); 99 | }); 100 | ON_USE_REGISTRY.forEach((value, key) => { 101 | SystemHelper.registerCustomComponentItem(`adk_lib:on_use_${key}`, value); 102 | }); 103 | -------------------------------------------------------------------------------- /stable/scripts/main.ts: -------------------------------------------------------------------------------- 1 | import { BEFORE_ON_PLAYER_PLACE_REGISTRY } from './blocks/registry/before_on_player_place'; 2 | import { ON_ENTITY_FALL_ON_REGISTRY } from './blocks/registry/on_entity_fall_on'; 3 | import { ON_PLACE_REGISTRY } from './blocks/registry/on_place'; 4 | import { ON_PLAYER_DESTROY_REGISTRY } from './blocks/registry/on_player_break'; 5 | import { ON_PLAYER_INTERACT_REGISTRY } from './blocks/registry/on_player_interact'; 6 | import { ON_RANDOM_TICK_REGISTRY } from './blocks/registry/on_random_tick'; 7 | import { ON_STEP_OFF_REGISTRY } from './blocks/registry/on_step_off'; 8 | import { ON_STEP_ON_REGISTRY } from './blocks/registry/on_step_on'; 9 | import { ON_TICK_REGISTRY } from './blocks/registry/on_tick'; 10 | import { ON_BEFORE_DURABILITY_DAMAGE_REGISTRY } from './item/registry/on_before_durability_damage'; 11 | import { ON_COMPLETE_USE_REGISTRY } from './item/registry/on_complete_use'; 12 | import { ON_CONSUME_REGISTRY } from './item/registry/on_consume'; 13 | import { ON_HIT_ENTITY_REGISTRY } from './item/registry/on_hit_entity'; 14 | import { ON_MINE_BLOCK_REGISTRY } from './item/registry/on_mine_block'; 15 | import { ON_USE_ON_REGISTRY } from './item/registry/on_use_on'; 16 | import { ON_USE_REGISTRY } from './item/registry/on_use'; 17 | import { SystemHelper } from 'adk-scripts-server'; 18 | 19 | BEFORE_ON_PLAYER_PLACE_REGISTRY.forEach((value, key) => { 20 | SystemHelper.registerCustomComponentBlock( 21 | `adk_lib:before_on_player_place_${key}`, 22 | value 23 | ); 24 | }); 25 | ON_ENTITY_FALL_ON_REGISTRY.forEach((value, key) => { 26 | SystemHelper.registerCustomComponentBlock( 27 | `adk_lib:on_entity_fall_on_${key}`, 28 | value 29 | ); 30 | }); 31 | ON_PLACE_REGISTRY.forEach((value, key) => { 32 | SystemHelper.registerCustomComponentBlock(`adk_lib:on_place_${key}`, value); 33 | }); 34 | ON_PLAYER_DESTROY_REGISTRY.forEach((value, key) => { 35 | SystemHelper.registerCustomComponentBlock( 36 | `adk_lib:on_player_destroy_${key}`, 37 | value 38 | ); 39 | }); 40 | ON_PLAYER_INTERACT_REGISTRY.forEach((value, key) => { 41 | SystemHelper.registerCustomComponentBlock( 42 | `adk_lib:on_player_interact_${key}`, 43 | value 44 | ); 45 | }); 46 | ON_RANDOM_TICK_REGISTRY.forEach((value, key) => { 47 | SystemHelper.registerCustomComponentBlock( 48 | `adk_lib:on_random_tick_${key}`, 49 | value 50 | ); 51 | }); 52 | ON_STEP_OFF_REGISTRY.forEach((value, key) => { 53 | SystemHelper.registerCustomComponentBlock( 54 | `adk_lib:on_step_off_${key}`, 55 | value 56 | ); 57 | }); 58 | ON_STEP_ON_REGISTRY.forEach((value, key) => { 59 | SystemHelper.registerCustomComponentBlock( 60 | `adk_lib:on_step_on_${key}`, 61 | value 62 | ); 63 | }); 64 | ON_TICK_REGISTRY.forEach((value, key) => { 65 | SystemHelper.registerCustomComponentBlock(`adk_lib:on_tick_${key}`, value); 66 | }); 67 | ON_BEFORE_DURABILITY_DAMAGE_REGISTRY.forEach((value, key) => { 68 | SystemHelper.registerCustomComponentItem( 69 | `adk_lib:on_before_durability_damage_${key}`, 70 | value 71 | ); 72 | }); 73 | ON_COMPLETE_USE_REGISTRY.forEach((value, key) => { 74 | SystemHelper.registerCustomComponentItem( 75 | `adk_lib:on_complete_use_${key}`, 76 | value 77 | ); 78 | }); 79 | ON_CONSUME_REGISTRY.forEach((value, key) => { 80 | SystemHelper.registerCustomComponentItem( 81 | `adk_lib:on_consume_${key}`, 82 | value 83 | ); 84 | }); 85 | ON_HIT_ENTITY_REGISTRY.forEach((value, key) => { 86 | SystemHelper.registerCustomComponentItem( 87 | `adk_lib:on_hit_entity_${key}`, 88 | value 89 | ); 90 | }); 91 | ON_MINE_BLOCK_REGISTRY.forEach((value, key) => { 92 | SystemHelper.registerCustomComponentItem( 93 | `adk_lib:on_mine_block_${key}`, 94 | value 95 | ); 96 | }); 97 | ON_USE_ON_REGISTRY.forEach((value, key) => { 98 | SystemHelper.registerCustomComponentItem(`adk_lib:on_use_on_${key}`, value); 99 | }); 100 | ON_USE_REGISTRY.forEach((value, key) => { 101 | SystemHelper.registerCustomComponentItem(`adk_lib:on_use_${key}`, value); 102 | }); 103 | -------------------------------------------------------------------------------- /experimental/scripts/main.ts: -------------------------------------------------------------------------------- 1 | import { BEFORE_ON_PLAYER_PLACE_REGISTRY } from './blocks/registry/before_on_player_place'; 2 | import { ON_ENTITY_FALL_ON_REGISTRY } from './blocks/registry/on_entity_fall_on'; 3 | import { ON_PLACE_REGISTRY } from './blocks/registry/on_place'; 4 | import { ON_PLAYER_DESTROY_REGISTRY } from './blocks/registry/on_player_break'; 5 | import { ON_PLAYER_INTERACT_REGISTRY } from './blocks/registry/on_player_interact'; 6 | import { ON_RANDOM_TICK_REGISTRY } from './blocks/registry/on_random_tick'; 7 | import { ON_STEP_OFF_REGISTRY } from './blocks/registry/on_step_off'; 8 | import { ON_STEP_ON_REGISTRY } from './blocks/registry/on_step_on'; 9 | import { ON_TICK_REGISTRY } from './blocks/registry/on_tick'; 10 | import { ON_BEFORE_DURABILITY_DAMAGE_REGISTRY } from './item/registry/on_before_durability_damage'; 11 | import { ON_COMPLETE_USE_REGISTRY } from './item/registry/on_complete_use'; 12 | import { ON_CONSUME_REGISTRY } from './item/registry/on_consume'; 13 | import { ON_HIT_ENTITY_REGISTRY } from './item/registry/on_hit_entity'; 14 | import { ON_MINE_BLOCK_REGISTRY } from './item/registry/on_mine_block'; 15 | import { ON_USE_ON_REGISTRY } from './item/registry/on_use_on'; 16 | import { ON_USE_REGISTRY } from './item/registry/on_use'; 17 | import { SystemHelper } from 'adk-scripts-server'; 18 | 19 | BEFORE_ON_PLAYER_PLACE_REGISTRY.forEach((value, key) => { 20 | SystemHelper.registerCustomComponentBlock( 21 | `adk_lib:before_on_player_place_${key}`, 22 | value 23 | ); 24 | }); 25 | ON_ENTITY_FALL_ON_REGISTRY.forEach((value, key) => { 26 | SystemHelper.registerCustomComponentBlock( 27 | `adk_lib:on_entity_fall_on_${key}`, 28 | value 29 | ); 30 | }); 31 | ON_PLACE_REGISTRY.forEach((value, key) => { 32 | SystemHelper.registerCustomComponentBlock(`adk_lib:on_place_${key}`, value); 33 | }); 34 | ON_PLAYER_DESTROY_REGISTRY.forEach((value, key) => { 35 | SystemHelper.registerCustomComponentBlock( 36 | `adk_lib:on_player_destroy_${key}`, 37 | value 38 | ); 39 | }); 40 | ON_PLAYER_INTERACT_REGISTRY.forEach((value, key) => { 41 | SystemHelper.registerCustomComponentBlock( 42 | `adk_lib:on_player_interact_${key}`, 43 | value 44 | ); 45 | }); 46 | ON_RANDOM_TICK_REGISTRY.forEach((value, key) => { 47 | SystemHelper.registerCustomComponentBlock( 48 | `adk_lib:on_random_tick_${key}`, 49 | value 50 | ); 51 | }); 52 | ON_STEP_OFF_REGISTRY.forEach((value, key) => { 53 | SystemHelper.registerCustomComponentBlock( 54 | `adk_lib:on_step_off_${key}`, 55 | value 56 | ); 57 | }); 58 | ON_STEP_ON_REGISTRY.forEach((value, key) => { 59 | SystemHelper.registerCustomComponentBlock( 60 | `adk_lib:on_step_on_${key}`, 61 | value 62 | ); 63 | }); 64 | ON_TICK_REGISTRY.forEach((value, key) => { 65 | SystemHelper.registerCustomComponentBlock(`adk_lib:on_tick_${key}`, value); 66 | }); 67 | ON_BEFORE_DURABILITY_DAMAGE_REGISTRY.forEach((value, key) => { 68 | SystemHelper.registerCustomComponentItem( 69 | `adk_lib:on_before_durability_damage_${key}`, 70 | value 71 | ); 72 | }); 73 | ON_COMPLETE_USE_REGISTRY.forEach((value, key) => { 74 | SystemHelper.registerCustomComponentItem( 75 | `adk_lib:on_complete_use_${key}`, 76 | value 77 | ); 78 | }); 79 | ON_CONSUME_REGISTRY.forEach((value, key) => { 80 | SystemHelper.registerCustomComponentItem( 81 | `adk_lib:on_consume_${key}`, 82 | value 83 | ); 84 | }); 85 | ON_HIT_ENTITY_REGISTRY.forEach((value, key) => { 86 | SystemHelper.registerCustomComponentItem( 87 | `adk_lib:on_hit_entity_${key}`, 88 | value 89 | ); 90 | }); 91 | ON_MINE_BLOCK_REGISTRY.forEach((value, key) => { 92 | SystemHelper.registerCustomComponentItem( 93 | `adk_lib:on_mine_block_${key}`, 94 | value 95 | ); 96 | }); 97 | ON_USE_ON_REGISTRY.forEach((value, key) => { 98 | SystemHelper.registerCustomComponentItem(`adk_lib:on_use_on_${key}`, value); 99 | }); 100 | ON_USE_REGISTRY.forEach((value, key) => { 101 | SystemHelper.registerCustomComponentItem(`adk_lib:on_use_${key}`, value); 102 | }); 103 | -------------------------------------------------------------------------------- /rc/scripts/item/registry/on_hit_entity.ts: -------------------------------------------------------------------------------- 1 | import { 2 | CustomComponentParameters, 3 | ItemComponentHitEntityEvent, 4 | ItemCustomComponent, 5 | system 6 | } from '@minecraft/server'; 7 | import * as adk from 'adk-scripts-server'; 8 | import { ParameterRunCommand } from 'utils/shared_parameters'; 9 | 10 | abstract class OnHitEntity implements ItemCustomComponent { 11 | abstract onHitEntity( 12 | componentData: ItemComponentHitEntityEvent, 13 | paramData?: CustomComponentParameters 14 | ): void; 15 | } 16 | 17 | class Debug extends OnHitEntity { 18 | onHitEntity(componentData: ItemComponentHitEntityEvent) { 19 | console.log(adk.Debug.logEventData(componentData)); 20 | } 21 | } 22 | 23 | type ParameterSummonEntity = { 24 | entity: string; 25 | entity_filter?: string[]; 26 | }[]; 27 | 28 | class SummonEntity extends OnHitEntity { 29 | onHitEntity( 30 | componentData: ItemComponentHitEntityEvent, 31 | paramData: CustomComponentParameters 32 | ) { 33 | const param = paramData.params as ParameterSummonEntity; 34 | for (const entry of param) { 35 | const entity_filter: string[] | undefined = entry.entity_filter; 36 | const entity: string = entry.entity; 37 | 38 | // Check if player_equipment matches any transform_from 39 | const matches: boolean = (entity_filter ?? []).some( 40 | (entity: string) => { 41 | return componentData.hitEntity.typeId === entity; 42 | } 43 | ); 44 | 45 | // If there's a match, log the corresponding transform_to 46 | if (matches) { 47 | componentData.hitEntity.dimension.spawnEntity( 48 | entity, 49 | componentData.hitEntity.location 50 | ); 51 | return; // Stop further checks if a match is found 52 | } 53 | } 54 | } 55 | } 56 | 57 | type ParameterSummonParticle = { 58 | particle: string; 59 | entity_filter?: string[]; 60 | }[]; 61 | 62 | class SummonParticle extends OnHitEntity { 63 | onHitEntity( 64 | componentData: ItemComponentHitEntityEvent, 65 | paramData: CustomComponentParameters 66 | ) { 67 | const param = paramData.params as ParameterSummonParticle; 68 | for (const entry of param) { 69 | const entity_filter: string[] | undefined = entry.entity_filter; 70 | const particle: string = entry.particle; 71 | 72 | // Check if player_equipment matches any transform_from 73 | const matches: boolean = (entity_filter ?? []).some( 74 | (entity: string) => { 75 | return componentData.hitEntity.typeId === entity; 76 | } 77 | ); 78 | 79 | // If there's a match, log the corresponding transform_to 80 | if (matches) { 81 | componentData.hitEntity.dimension.spawnParticle( 82 | particle, 83 | componentData.hitEntity.location 84 | ); 85 | return; // Stop further checks if a match is found 86 | } 87 | } 88 | } 89 | } 90 | 91 | class RunCommand extends OnHitEntity { 92 | onHitEntity( 93 | componentData: ItemComponentHitEntityEvent, 94 | paramData: CustomComponentParameters 95 | ) { 96 | const param = paramData.params as ParameterRunCommand; 97 | system.run(() => { 98 | param.command.forEach((command) => { 99 | componentData.attackingEntity.runCommand(command); 100 | }); 101 | }); 102 | } 103 | } 104 | 105 | enum OnHitEntityKey { 106 | Debug = 'debug', 107 | SummonEntity = 'summon_entity', 108 | SummonParticle = 'summon_particle', 109 | RunCommand = 'run_command' 110 | } 111 | 112 | export const ON_HIT_ENTITY_REGISTRY = new Map([ 113 | [OnHitEntityKey.Debug, new Debug()], 114 | [OnHitEntityKey.SummonEntity, new SummonEntity()], 115 | [OnHitEntityKey.SummonParticle, new SummonParticle()], 116 | [OnHitEntityKey.RunCommand, new RunCommand()] 117 | ]); 118 | -------------------------------------------------------------------------------- /stable/scripts/item/registry/on_hit_entity.ts: -------------------------------------------------------------------------------- 1 | import { 2 | CustomComponentParameters, 3 | ItemComponentHitEntityEvent, 4 | ItemCustomComponent, 5 | system 6 | } from '@minecraft/server'; 7 | import * as adk from 'adk-scripts-server'; 8 | import { ParameterRunCommand } from 'utils/shared_parameters'; 9 | 10 | abstract class OnHitEntity implements ItemCustomComponent { 11 | abstract onHitEntity( 12 | componentData: ItemComponentHitEntityEvent, 13 | paramData?: CustomComponentParameters 14 | ): void; 15 | } 16 | 17 | class Debug extends OnHitEntity { 18 | onHitEntity(componentData: ItemComponentHitEntityEvent) { 19 | console.log(adk.Debug.logEventData(componentData)); 20 | } 21 | } 22 | 23 | type ParameterSummonEntity = { 24 | entity: string; 25 | entity_filter?: string[]; 26 | }[]; 27 | 28 | class SummonEntity extends OnHitEntity { 29 | onHitEntity( 30 | componentData: ItemComponentHitEntityEvent, 31 | paramData: CustomComponentParameters 32 | ) { 33 | const param = paramData.params as ParameterSummonEntity; 34 | for (const entry of param) { 35 | const entity_filter: string[] | undefined = entry.entity_filter; 36 | const entity: string = entry.entity; 37 | 38 | // Check if player_equipment matches any transform_from 39 | const matches: boolean = (entity_filter ?? []).some( 40 | (entity: string) => { 41 | return componentData.hitEntity.typeId === entity; 42 | } 43 | ); 44 | 45 | // If there's a match, log the corresponding transform_to 46 | if (matches) { 47 | componentData.hitEntity.dimension.spawnEntity( 48 | entity, 49 | componentData.hitEntity.location 50 | ); 51 | return; // Stop further checks if a match is found 52 | } 53 | } 54 | } 55 | } 56 | 57 | type ParameterSummonParticle = { 58 | particle: string; 59 | entity_filter?: string[]; 60 | }[]; 61 | 62 | class SummonParticle extends OnHitEntity { 63 | onHitEntity( 64 | componentData: ItemComponentHitEntityEvent, 65 | paramData: CustomComponentParameters 66 | ) { 67 | const param = paramData.params as ParameterSummonParticle; 68 | for (const entry of param) { 69 | const entity_filter: string[] | undefined = entry.entity_filter; 70 | const particle: string = entry.particle; 71 | 72 | // Check if player_equipment matches any transform_from 73 | const matches: boolean = (entity_filter ?? []).some( 74 | (entity: string) => { 75 | return componentData.hitEntity.typeId === entity; 76 | } 77 | ); 78 | 79 | // If there's a match, log the corresponding transform_to 80 | if (matches) { 81 | componentData.hitEntity.dimension.spawnParticle( 82 | particle, 83 | componentData.hitEntity.location 84 | ); 85 | return; // Stop further checks if a match is found 86 | } 87 | } 88 | } 89 | } 90 | 91 | class RunCommand extends OnHitEntity { 92 | onHitEntity( 93 | componentData: ItemComponentHitEntityEvent, 94 | paramData: CustomComponentParameters 95 | ) { 96 | const param = paramData.params as ParameterRunCommand; 97 | system.run(() => { 98 | param.command.forEach((command) => { 99 | componentData.attackingEntity.runCommand(command); 100 | }); 101 | }); 102 | } 103 | } 104 | 105 | enum OnHitEntityKey { 106 | Debug = 'debug', 107 | SummonEntity = 'summon_entity', 108 | SummonParticle = 'summon_particle', 109 | RunCommand = 'run_command' 110 | } 111 | 112 | export const ON_HIT_ENTITY_REGISTRY = new Map([ 113 | [OnHitEntityKey.Debug, new Debug()], 114 | [OnHitEntityKey.SummonEntity, new SummonEntity()], 115 | [OnHitEntityKey.SummonParticle, new SummonParticle()], 116 | [OnHitEntityKey.RunCommand, new RunCommand()] 117 | ]); 118 | -------------------------------------------------------------------------------- /experimental/scripts/item/registry/on_hit_entity.ts: -------------------------------------------------------------------------------- 1 | import { 2 | CustomComponentParameters, 3 | ItemComponentHitEntityEvent, 4 | ItemCustomComponent, 5 | system 6 | } from '@minecraft/server'; 7 | import * as adk from 'adk-scripts-server'; 8 | import { ParameterRunCommand } from 'utils/shared_parameters'; 9 | 10 | abstract class OnHitEntity implements ItemCustomComponent { 11 | abstract onHitEntity( 12 | componentData: ItemComponentHitEntityEvent, 13 | paramData?: CustomComponentParameters 14 | ): void; 15 | } 16 | 17 | class Debug extends OnHitEntity { 18 | onHitEntity(componentData: ItemComponentHitEntityEvent) { 19 | console.log(adk.Debug.logEventData(componentData)); 20 | } 21 | } 22 | 23 | type ParameterSummonEntity = { 24 | entity: string; 25 | entity_filter?: string[]; 26 | }[]; 27 | 28 | class SummonEntity extends OnHitEntity { 29 | onHitEntity( 30 | componentData: ItemComponentHitEntityEvent, 31 | paramData: CustomComponentParameters 32 | ) { 33 | const param = paramData.params as ParameterSummonEntity; 34 | for (const entry of param) { 35 | const entity_filter: string[] | undefined = entry.entity_filter; 36 | const entity: string = entry.entity; 37 | 38 | // Check if player_equipment matches any transform_from 39 | const matches: boolean = (entity_filter ?? []).some( 40 | (entity: string) => { 41 | return componentData.hitEntity.typeId === entity; 42 | } 43 | ); 44 | 45 | // If there's a match, log the corresponding transform_to 46 | if (matches) { 47 | componentData.hitEntity.dimension.spawnEntity( 48 | entity, 49 | componentData.hitEntity.location 50 | ); 51 | return; // Stop further checks if a match is found 52 | } 53 | } 54 | } 55 | } 56 | 57 | type ParameterSummonParticle = { 58 | particle: string; 59 | entity_filter?: string[]; 60 | }[]; 61 | 62 | class SummonParticle extends OnHitEntity { 63 | onHitEntity( 64 | componentData: ItemComponentHitEntityEvent, 65 | paramData: CustomComponentParameters 66 | ) { 67 | const param = paramData.params as ParameterSummonParticle; 68 | for (const entry of param) { 69 | const entity_filter: string[] | undefined = entry.entity_filter; 70 | const particle: string = entry.particle; 71 | 72 | // Check if player_equipment matches any transform_from 73 | const matches: boolean = (entity_filter ?? []).some( 74 | (entity: string) => { 75 | return componentData.hitEntity.typeId === entity; 76 | } 77 | ); 78 | 79 | // If there's a match, log the corresponding transform_to 80 | if (matches) { 81 | componentData.hitEntity.dimension.spawnParticle( 82 | particle, 83 | componentData.hitEntity.location 84 | ); 85 | return; // Stop further checks if a match is found 86 | } 87 | } 88 | } 89 | } 90 | 91 | class RunCommand extends OnHitEntity { 92 | onHitEntity( 93 | componentData: ItemComponentHitEntityEvent, 94 | paramData: CustomComponentParameters 95 | ) { 96 | const param = paramData.params as ParameterRunCommand; 97 | system.run(() => { 98 | param.command.forEach((command) => { 99 | componentData.attackingEntity.runCommand(command); 100 | }); 101 | }); 102 | } 103 | } 104 | 105 | enum OnHitEntityKey { 106 | Debug = 'debug', 107 | SummonEntity = 'summon_entity', 108 | SummonParticle = 'summon_particle', 109 | RunCommand = 'run_command' 110 | } 111 | 112 | export const ON_HIT_ENTITY_REGISTRY = new Map([ 113 | [OnHitEntityKey.Debug, new Debug()], 114 | [OnHitEntityKey.SummonEntity, new SummonEntity()], 115 | [OnHitEntityKey.SummonParticle, new SummonParticle()], 116 | [OnHitEntityKey.RunCommand, new RunCommand()] 117 | ]); 118 | -------------------------------------------------------------------------------- /rc/scripts/blocks/registry/on_player_break.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Block, 3 | BlockComponentPlayerBreakEvent, 4 | BlockCustomComponent, 5 | CustomComponentParameters, 6 | GameMode, 7 | ItemStack, 8 | world 9 | } from '@minecraft/server'; 10 | import { onPlayerDestroyDoubleSlab } from '../double_slab'; 11 | import * as adk from 'adk-scripts-server'; 12 | import { ParameterMelt } from 'utils/shared_parameters'; 13 | 14 | abstract class OnPlayerBreak implements BlockCustomComponent { 15 | abstract onPlayerBreak( 16 | componentData: BlockComponentPlayerBreakEvent, 17 | paramData?: CustomComponentParameters 18 | ): void; 19 | } 20 | 21 | class Debug extends OnPlayerBreak { 22 | onPlayerBreak(componentData: BlockComponentPlayerBreakEvent) { 23 | console.log(adk.Debug.logEventData(componentData)); 24 | } 25 | } 26 | 27 | type ParameterSpawnItem = { 28 | items: string[]; 29 | }; 30 | 31 | class SpawnItem extends OnPlayerBreak { 32 | onPlayerBreak( 33 | componentData: BlockComponentPlayerBreakEvent, 34 | paramData: CustomComponentParameters 35 | ) { 36 | if (!componentData.player) return; 37 | 38 | if (componentData.player.getGameMode() == GameMode.Creative) return; 39 | if (!world.gameRules.doTileDrops) return; 40 | const param = paramData.params as ParameterSpawnItem; 41 | 42 | param.items.forEach((item) => { 43 | adk.Cache.getDimension(componentData.dimension.id).spawnItem( 44 | new ItemStack(item), 45 | componentData.block.location 46 | ); 47 | }); 48 | } 49 | } 50 | 51 | class Regenerate extends OnPlayerBreak { 52 | onPlayerBreak(componentData: BlockComponentPlayerBreakEvent) { 53 | componentData.block.setType(componentData.brokenBlockPermutation.type); 54 | } 55 | } 56 | 57 | type ParameterDropExperience = { 58 | experience_reward: number; 59 | }; 60 | 61 | class DropExperience extends OnPlayerBreak { 62 | onPlayerBreak( 63 | componentData: BlockComponentPlayerBreakEvent, 64 | paramData: CustomComponentParameters 65 | ) { 66 | if (!componentData.player) return; 67 | 68 | if (componentData.player.getGameMode() == GameMode.Creative) return; 69 | if (!world.gameRules.doTileDrops) return; 70 | 71 | const param = paramData.params as ParameterDropExperience; 72 | 73 | for (let a = 0; a < param.experience_reward; a++) 74 | adk.Cache.getDimension(componentData.dimension.id).spawnEntity( 75 | 'minecraft:xp_orb', 76 | componentData.block.center() 77 | ); 78 | } 79 | } 80 | 81 | class Melt extends OnPlayerBreak { 82 | onPlayerBreak( 83 | componentData: BlockComponentPlayerBreakEvent, 84 | paramData: CustomComponentParameters 85 | ): void { 86 | const block: Block = componentData.block; 87 | 88 | if (block.dimension.id == 'minecraft:nether') { 89 | block.setType('minecraft:air'); 90 | return; 91 | } 92 | 93 | const block_below: Block | undefined = block.below(); 94 | 95 | if (!block_below) return; 96 | if (adk.BlockHelper.blocksMovement(block_below) || block.isLiquid) { 97 | const param = paramData.params as ParameterMelt; 98 | block.setType(param.melted_state); 99 | return; 100 | } 101 | } 102 | } 103 | 104 | class DoubleSlab extends OnPlayerBreak { 105 | onPlayerBreak(componentData: BlockComponentPlayerBreakEvent): void { 106 | onPlayerDestroyDoubleSlab(componentData); 107 | } 108 | } 109 | 110 | enum OnPlayerDestroyKey { 111 | Debug = 'debug', 112 | SpawnItem = 'spawn_item', 113 | Regenerate = 'regenerate', 114 | DropExperience = 'drop_experience', 115 | Melt = 'melt', 116 | DoubleSlab = 'double_slab' 117 | } 118 | 119 | export const ON_PLAYER_DESTROY_REGISTRY: Map< 120 | OnPlayerDestroyKey, 121 | OnPlayerBreak 122 | > = new Map([ 123 | [OnPlayerDestroyKey.Debug, new Debug()], 124 | [OnPlayerDestroyKey.Regenerate, new Regenerate()], 125 | [OnPlayerDestroyKey.SpawnItem, new SpawnItem()], 126 | [OnPlayerDestroyKey.DropExperience, new DropExperience()], 127 | [OnPlayerDestroyKey.Melt, new Melt()], 128 | [OnPlayerDestroyKey.DoubleSlab, new DoubleSlab()] 129 | ]); 130 | -------------------------------------------------------------------------------- /stable/scripts/blocks/registry/on_player_break.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Block, 3 | BlockComponentPlayerBreakEvent, 4 | BlockCustomComponent, 5 | CustomComponentParameters, 6 | GameMode, 7 | ItemStack, 8 | world 9 | } from '@minecraft/server'; 10 | import { onPlayerDestroyDoubleSlab } from '../double_slab'; 11 | import * as adk from 'adk-scripts-server'; 12 | import { ParameterMelt } from 'utils/shared_parameters'; 13 | 14 | abstract class OnPlayerBreak implements BlockCustomComponent { 15 | abstract onPlayerBreak( 16 | componentData: BlockComponentPlayerBreakEvent, 17 | paramData?: CustomComponentParameters 18 | ): void; 19 | } 20 | 21 | class Debug extends OnPlayerBreak { 22 | onPlayerBreak(componentData: BlockComponentPlayerBreakEvent) { 23 | console.log(adk.Debug.logEventData(componentData)); 24 | } 25 | } 26 | 27 | type ParameterSpawnItem = { 28 | items: string[]; 29 | }; 30 | 31 | class SpawnItem extends OnPlayerBreak { 32 | onPlayerBreak( 33 | componentData: BlockComponentPlayerBreakEvent, 34 | paramData: CustomComponentParameters 35 | ) { 36 | if (!componentData.player) return; 37 | 38 | if (componentData.player.getGameMode() == GameMode.Creative) return; 39 | if (!world.gameRules.doTileDrops) return; 40 | const param = paramData.params as ParameterSpawnItem; 41 | 42 | param.items.forEach((item) => { 43 | adk.Cache.getDimension(componentData.dimension.id).spawnItem( 44 | new ItemStack(item), 45 | componentData.block.location 46 | ); 47 | }); 48 | } 49 | } 50 | 51 | class Regenerate extends OnPlayerBreak { 52 | onPlayerBreak(componentData: BlockComponentPlayerBreakEvent) { 53 | componentData.block.setType(componentData.brokenBlockPermutation.type); 54 | } 55 | } 56 | 57 | type ParameterDropExperience = { 58 | experience_reward: number; 59 | }; 60 | 61 | class DropExperience extends OnPlayerBreak { 62 | onPlayerBreak( 63 | componentData: BlockComponentPlayerBreakEvent, 64 | paramData: CustomComponentParameters 65 | ) { 66 | if (!componentData.player) return; 67 | 68 | if (componentData.player.getGameMode() == GameMode.Creative) return; 69 | if (!world.gameRules.doTileDrops) return; 70 | 71 | const param = paramData.params as ParameterDropExperience; 72 | 73 | for (let a = 0; a < param.experience_reward; a++) 74 | adk.Cache.getDimension(componentData.dimension.id).spawnEntity( 75 | 'minecraft:xp_orb', 76 | componentData.block.center() 77 | ); 78 | } 79 | } 80 | 81 | class Melt extends OnPlayerBreak { 82 | onPlayerBreak( 83 | componentData: BlockComponentPlayerBreakEvent, 84 | paramData: CustomComponentParameters 85 | ): void { 86 | const block: Block = componentData.block; 87 | 88 | if (block.dimension.id == 'minecraft:nether') { 89 | block.setType('minecraft:air'); 90 | return; 91 | } 92 | 93 | const block_below: Block | undefined = block.below(); 94 | 95 | if (!block_below) return; 96 | if (adk.BlockHelper.blocksMovement(block_below) || block.isLiquid) { 97 | const param = paramData.params as ParameterMelt; 98 | block.setType(param.melted_state); 99 | return; 100 | } 101 | } 102 | } 103 | 104 | class DoubleSlab extends OnPlayerBreak { 105 | onPlayerBreak(componentData: BlockComponentPlayerBreakEvent): void { 106 | onPlayerDestroyDoubleSlab(componentData); 107 | } 108 | } 109 | 110 | enum OnPlayerDestroyKey { 111 | Debug = 'debug', 112 | SpawnItem = 'spawn_item', 113 | Regenerate = 'regenerate', 114 | DropExperience = 'drop_experience', 115 | Melt = 'melt', 116 | DoubleSlab = 'double_slab' 117 | } 118 | 119 | export const ON_PLAYER_DESTROY_REGISTRY: Map< 120 | OnPlayerDestroyKey, 121 | OnPlayerBreak 122 | > = new Map([ 123 | [OnPlayerDestroyKey.Debug, new Debug()], 124 | [OnPlayerDestroyKey.Regenerate, new Regenerate()], 125 | [OnPlayerDestroyKey.SpawnItem, new SpawnItem()], 126 | [OnPlayerDestroyKey.DropExperience, new DropExperience()], 127 | [OnPlayerDestroyKey.Melt, new Melt()], 128 | [OnPlayerDestroyKey.DoubleSlab, new DoubleSlab()] 129 | ]); 130 | -------------------------------------------------------------------------------- /experimental/scripts/blocks/registry/on_player_break.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Block, 3 | BlockComponentPlayerBreakEvent, 4 | BlockCustomComponent, 5 | CustomComponentParameters, 6 | GameMode, 7 | ItemStack, 8 | world 9 | } from '@minecraft/server'; 10 | import { onPlayerDestroyDoubleSlab } from '../double_slab'; 11 | import * as adk from 'adk-scripts-server'; 12 | import { ParameterMelt } from 'utils/shared_parameters'; 13 | 14 | abstract class OnPlayerBreak implements BlockCustomComponent { 15 | abstract onPlayerBreak( 16 | componentData: BlockComponentPlayerBreakEvent, 17 | paramData?: CustomComponentParameters 18 | ): void; 19 | } 20 | 21 | class Debug extends OnPlayerBreak { 22 | onPlayerBreak(componentData: BlockComponentPlayerBreakEvent) { 23 | console.log(adk.Debug.logEventData(componentData)); 24 | } 25 | } 26 | 27 | type ParameterSpawnItem = { 28 | items: string[]; 29 | }; 30 | 31 | class SpawnItem extends OnPlayerBreak { 32 | onPlayerBreak( 33 | componentData: BlockComponentPlayerBreakEvent, 34 | paramData: CustomComponentParameters 35 | ) { 36 | if (!componentData.player) return; 37 | 38 | if (componentData.player.getGameMode() == GameMode.Creative) return; 39 | if (!world.gameRules.doTileDrops) return; 40 | const param = paramData.params as ParameterSpawnItem; 41 | 42 | param.items.forEach((item) => { 43 | adk.Cache.getDimension(componentData.dimension.id).spawnItem( 44 | new ItemStack(item), 45 | componentData.block.location 46 | ); 47 | }); 48 | } 49 | } 50 | 51 | class Regenerate extends OnPlayerBreak { 52 | onPlayerBreak(componentData: BlockComponentPlayerBreakEvent) { 53 | componentData.block.setType(componentData.brokenBlockPermutation.type); 54 | } 55 | } 56 | 57 | type ParameterDropExperience = { 58 | experience_reward: number; 59 | }; 60 | 61 | class DropExperience extends OnPlayerBreak { 62 | onPlayerBreak( 63 | componentData: BlockComponentPlayerBreakEvent, 64 | paramData: CustomComponentParameters 65 | ) { 66 | if (!componentData.player) return; 67 | 68 | if (componentData.player.getGameMode() == GameMode.Creative) return; 69 | if (!world.gameRules.doTileDrops) return; 70 | 71 | const param = paramData.params as ParameterDropExperience; 72 | 73 | for (let a = 0; a < param.experience_reward; a++) 74 | adk.Cache.getDimension(componentData.dimension.id).spawnEntity( 75 | 'minecraft:xp_orb', 76 | componentData.block.center() 77 | ); 78 | } 79 | } 80 | 81 | class Melt extends OnPlayerBreak { 82 | onPlayerBreak( 83 | componentData: BlockComponentPlayerBreakEvent, 84 | paramData: CustomComponentParameters 85 | ): void { 86 | const block: Block = componentData.block; 87 | 88 | if (block.dimension.id == 'minecraft:nether') { 89 | block.setType('minecraft:air'); 90 | return; 91 | } 92 | 93 | const block_below: Block | undefined = block.below(); 94 | 95 | if (!block_below) return; 96 | if (adk.BlockHelper.blocksMovement(block_below) || block.isLiquid) { 97 | const param = paramData.params as ParameterMelt; 98 | block.setType(param.melted_state); 99 | return; 100 | } 101 | } 102 | } 103 | 104 | class DoubleSlab extends OnPlayerBreak { 105 | onPlayerBreak(componentData: BlockComponentPlayerBreakEvent): void { 106 | onPlayerDestroyDoubleSlab(componentData); 107 | } 108 | } 109 | 110 | enum OnPlayerDestroyKey { 111 | Debug = 'debug', 112 | SpawnItem = 'spawn_item', 113 | Regenerate = 'regenerate', 114 | DropExperience = 'drop_experience', 115 | Melt = 'melt', 116 | DoubleSlab = 'double_slab' 117 | } 118 | 119 | export const ON_PLAYER_DESTROY_REGISTRY: Map< 120 | OnPlayerDestroyKey, 121 | OnPlayerBreak 122 | > = new Map([ 123 | [OnPlayerDestroyKey.Debug, new Debug()], 124 | [OnPlayerDestroyKey.Regenerate, new Regenerate()], 125 | [OnPlayerDestroyKey.SpawnItem, new SpawnItem()], 126 | [OnPlayerDestroyKey.DropExperience, new DropExperience()], 127 | [OnPlayerDestroyKey.Melt, new Melt()], 128 | [OnPlayerDestroyKey.DoubleSlab, new DoubleSlab()] 129 | ]); 130 | -------------------------------------------------------------------------------- /rc/scripts/item/registry/on_before_durability_damage.ts: -------------------------------------------------------------------------------- 1 | import { 2 | CustomComponentParameters, 3 | ItemComponentBeforeDurabilityDamageEvent, 4 | ItemCustomComponent, 5 | ItemDurabilityComponent, 6 | ItemStack, 7 | system 8 | } from '@minecraft/server'; 9 | import * as adk from 'adk-scripts-server'; 10 | import { ParameterRunCommand } from 'utils/shared_parameters'; 11 | 12 | abstract class OnBeforeDurabilityDamage implements ItemCustomComponent { 13 | abstract onBeforeDurabilityDamage( 14 | componentData: ItemComponentBeforeDurabilityDamageEvent, 15 | paramData?: CustomComponentParameters 16 | ): void; 17 | } 18 | 19 | class Debug extends OnBeforeDurabilityDamage { 20 | onBeforeDurabilityDamage( 21 | componentData: ItemComponentBeforeDurabilityDamageEvent 22 | ) { 23 | console.log(adk.Debug.logEventData(componentData)); 24 | } 25 | } 26 | 27 | /** 28 | * This was supposed to be a custom component that implements the elytra functionality of not being able to be damaged if the item has 1 durability left. 29 | * Unfortunately, I forgot that onBeforeDurabilityDamage only activates if the item gets damaged by hitting an entity, not by using it. 30 | * I'll leave this here for reference. 31 | */ 32 | class ElytraIsUseable extends OnBeforeDurabilityDamage { 33 | onBeforeDurabilityDamage( 34 | componentData: ItemComponentBeforeDurabilityDamageEvent 35 | ) { 36 | const item: ItemStack | undefined = componentData.itemStack; 37 | if (!item) return; 38 | 39 | const durability: ItemDurabilityComponent = 40 | adk.ComponentItemDurability.get(item); 41 | const potentialDurabilityDamage = 42 | durability.maxDurability + 1 - (durability.damage + 1); 43 | componentData.durabilityDamage = potentialDurabilityDamage > 0 ? 1 : 0; 44 | } 45 | } 46 | 47 | class RunCommand extends OnBeforeDurabilityDamage { 48 | onBeforeDurabilityDamage( 49 | componentData: ItemComponentBeforeDurabilityDamageEvent, 50 | paramData: CustomComponentParameters 51 | ) { 52 | const param = paramData.params as ParameterRunCommand; 53 | system.run(() => { 54 | param.command.forEach((command) => { 55 | componentData.attackingEntity.runCommand(command); 56 | }); 57 | }); 58 | } 59 | } 60 | 61 | type ParameterModifyDurabilityDamageAmount = { 62 | damage_amount: number; 63 | entity_filter?: string[]; 64 | }[]; 65 | 66 | class ModifyDurabilityDamageAmount extends OnBeforeDurabilityDamage { 67 | onBeforeDurabilityDamage( 68 | componentData: ItemComponentBeforeDurabilityDamageEvent, 69 | paramData: CustomComponentParameters 70 | ): void { 71 | const param = paramData.params as ParameterModifyDurabilityDamageAmount; 72 | for (const entry of param) { 73 | const entity_filter: string[] | undefined = entry.entity_filter; 74 | const damage: number = entry.damage_amount; 75 | 76 | // Check if player_equipment matches any transform_from 77 | const matches: boolean = (entity_filter ?? []).some( 78 | (entity: string) => { 79 | return componentData.hitEntity.typeId === entity; 80 | } 81 | ); 82 | 83 | // If there's a match, log the corresponding transform_to 84 | if (matches) { 85 | componentData.durabilityDamage = damage; 86 | return; // Stop further checks if a match is found 87 | } 88 | } 89 | } 90 | } 91 | 92 | class PreventDamageDurability extends OnBeforeDurabilityDamage { 93 | onBeforeDurabilityDamage( 94 | componentData: ItemComponentBeforeDurabilityDamageEvent 95 | ): void { 96 | componentData.durabilityDamage = 0; 97 | } 98 | } 99 | 100 | enum OnBeforeDurabilityDamageKey { 101 | Debug = 'debug', 102 | RunCommand = 'run_command', 103 | ModifyDurabilityDamageAmount = 'modify_durability_damage_amount', 104 | PreventDamageDurability = 'prevent_damage_durability' 105 | } 106 | 107 | export const ON_BEFORE_DURABILITY_DAMAGE_REGISTRY: Map< 108 | OnBeforeDurabilityDamageKey, 109 | OnBeforeDurabilityDamage 110 | > = new Map([ 111 | [OnBeforeDurabilityDamageKey.Debug, new Debug()], 112 | [OnBeforeDurabilityDamageKey.RunCommand, new RunCommand()], 113 | [ 114 | OnBeforeDurabilityDamageKey.ModifyDurabilityDamageAmount, 115 | new ModifyDurabilityDamageAmount() 116 | ], 117 | [ 118 | OnBeforeDurabilityDamageKey.PreventDamageDurability, 119 | new PreventDamageDurability() 120 | ] 121 | ]); 122 | -------------------------------------------------------------------------------- /stable/scripts/item/registry/on_before_durability_damage.ts: -------------------------------------------------------------------------------- 1 | import { 2 | CustomComponentParameters, 3 | ItemComponentBeforeDurabilityDamageEvent, 4 | ItemCustomComponent, 5 | ItemDurabilityComponent, 6 | ItemStack, 7 | system 8 | } from '@minecraft/server'; 9 | import * as adk from 'adk-scripts-server'; 10 | import { ParameterRunCommand } from 'utils/shared_parameters'; 11 | 12 | abstract class OnBeforeDurabilityDamage implements ItemCustomComponent { 13 | abstract onBeforeDurabilityDamage( 14 | componentData: ItemComponentBeforeDurabilityDamageEvent, 15 | paramData?: CustomComponentParameters 16 | ): void; 17 | } 18 | 19 | class Debug extends OnBeforeDurabilityDamage { 20 | onBeforeDurabilityDamage( 21 | componentData: ItemComponentBeforeDurabilityDamageEvent 22 | ) { 23 | console.log(adk.Debug.logEventData(componentData)); 24 | } 25 | } 26 | 27 | /** 28 | * This was supposed to be a custom component that implements the elytra functionality of not being able to be damaged if the item has 1 durability left. 29 | * Unfortunately, I forgot that onBeforeDurabilityDamage only activates if the item gets damaged by hitting an entity, not by using it. 30 | * I'll leave this here for reference. 31 | */ 32 | class ElytraIsUseable extends OnBeforeDurabilityDamage { 33 | onBeforeDurabilityDamage( 34 | componentData: ItemComponentBeforeDurabilityDamageEvent 35 | ) { 36 | const item: ItemStack | undefined = componentData.itemStack; 37 | if (!item) return; 38 | 39 | const durability: ItemDurabilityComponent = 40 | adk.ComponentItemDurability.get(item); 41 | const potentialDurabilityDamage = 42 | durability.maxDurability + 1 - (durability.damage + 1); 43 | componentData.durabilityDamage = potentialDurabilityDamage > 0 ? 1 : 0; 44 | } 45 | } 46 | 47 | class RunCommand extends OnBeforeDurabilityDamage { 48 | onBeforeDurabilityDamage( 49 | componentData: ItemComponentBeforeDurabilityDamageEvent, 50 | paramData: CustomComponentParameters 51 | ) { 52 | const param = paramData.params as ParameterRunCommand; 53 | system.run(() => { 54 | param.command.forEach((command) => { 55 | componentData.attackingEntity.runCommand(command); 56 | }); 57 | }); 58 | } 59 | } 60 | 61 | type ParameterModifyDurabilityDamageAmount = { 62 | damage_amount: number; 63 | entity_filter?: string[]; 64 | }[]; 65 | 66 | class ModifyDurabilityDamageAmount extends OnBeforeDurabilityDamage { 67 | onBeforeDurabilityDamage( 68 | componentData: ItemComponentBeforeDurabilityDamageEvent, 69 | paramData: CustomComponentParameters 70 | ): void { 71 | const param = paramData.params as ParameterModifyDurabilityDamageAmount; 72 | for (const entry of param) { 73 | const entity_filter: string[] | undefined = entry.entity_filter; 74 | const damage: number = entry.damage_amount; 75 | 76 | // Check if player_equipment matches any transform_from 77 | const matches: boolean = (entity_filter ?? []).some( 78 | (entity: string) => { 79 | return componentData.hitEntity.typeId === entity; 80 | } 81 | ); 82 | 83 | // If there's a match, log the corresponding transform_to 84 | if (matches) { 85 | componentData.durabilityDamage = damage; 86 | return; // Stop further checks if a match is found 87 | } 88 | } 89 | } 90 | } 91 | 92 | class PreventDamageDurability extends OnBeforeDurabilityDamage { 93 | onBeforeDurabilityDamage( 94 | componentData: ItemComponentBeforeDurabilityDamageEvent 95 | ): void { 96 | componentData.durabilityDamage = 0; 97 | } 98 | } 99 | 100 | enum OnBeforeDurabilityDamageKey { 101 | Debug = 'debug', 102 | RunCommand = 'run_command', 103 | ModifyDurabilityDamageAmount = 'modify_durability_damage_amount', 104 | PreventDamageDurability = 'prevent_damage_durability' 105 | } 106 | 107 | export const ON_BEFORE_DURABILITY_DAMAGE_REGISTRY: Map< 108 | OnBeforeDurabilityDamageKey, 109 | OnBeforeDurabilityDamage 110 | > = new Map([ 111 | [OnBeforeDurabilityDamageKey.Debug, new Debug()], 112 | [OnBeforeDurabilityDamageKey.RunCommand, new RunCommand()], 113 | [ 114 | OnBeforeDurabilityDamageKey.ModifyDurabilityDamageAmount, 115 | new ModifyDurabilityDamageAmount() 116 | ], 117 | [ 118 | OnBeforeDurabilityDamageKey.PreventDamageDurability, 119 | new PreventDamageDurability() 120 | ] 121 | ]); 122 | -------------------------------------------------------------------------------- /experimental/scripts/item/registry/on_before_durability_damage.ts: -------------------------------------------------------------------------------- 1 | import { 2 | CustomComponentParameters, 3 | ItemComponentBeforeDurabilityDamageEvent, 4 | ItemCustomComponent, 5 | ItemDurabilityComponent, 6 | ItemStack, 7 | system 8 | } from '@minecraft/server'; 9 | import * as adk from 'adk-scripts-server'; 10 | import { ParameterRunCommand } from 'utils/shared_parameters'; 11 | 12 | abstract class OnBeforeDurabilityDamage implements ItemCustomComponent { 13 | abstract onBeforeDurabilityDamage( 14 | componentData: ItemComponentBeforeDurabilityDamageEvent, 15 | paramData?: CustomComponentParameters 16 | ): void; 17 | } 18 | 19 | class Debug extends OnBeforeDurabilityDamage { 20 | onBeforeDurabilityDamage( 21 | componentData: ItemComponentBeforeDurabilityDamageEvent 22 | ) { 23 | console.log(adk.Debug.logEventData(componentData)); 24 | } 25 | } 26 | 27 | /** 28 | * This was supposed to be a custom component that implements the elytra functionality of not being able to be damaged if the item has 1 durability left. 29 | * Unfortunately, I forgot that onBeforeDurabilityDamage only activates if the item gets damaged by hitting an entity, not by using it. 30 | * I'll leave this here for reference. 31 | */ 32 | class ElytraIsUseable extends OnBeforeDurabilityDamage { 33 | onBeforeDurabilityDamage( 34 | componentData: ItemComponentBeforeDurabilityDamageEvent 35 | ) { 36 | const item: ItemStack | undefined = componentData.itemStack; 37 | if (!item) return; 38 | 39 | const durability: ItemDurabilityComponent = 40 | adk.ComponentItemDurability.get(item); 41 | const potentialDurabilityDamage = 42 | durability.maxDurability + 1 - (durability.damage + 1); 43 | componentData.durabilityDamage = potentialDurabilityDamage > 0 ? 1 : 0; 44 | } 45 | } 46 | 47 | class RunCommand extends OnBeforeDurabilityDamage { 48 | onBeforeDurabilityDamage( 49 | componentData: ItemComponentBeforeDurabilityDamageEvent, 50 | paramData: CustomComponentParameters 51 | ) { 52 | const param = paramData.params as ParameterRunCommand; 53 | system.run(() => { 54 | param.command.forEach((command) => { 55 | componentData.attackingEntity.runCommand(command); 56 | }); 57 | }); 58 | } 59 | } 60 | 61 | type ParameterModifyDurabilityDamageAmount = { 62 | damage_amount: number; 63 | entity_filter?: string[]; 64 | }[]; 65 | 66 | class ModifyDurabilityDamageAmount extends OnBeforeDurabilityDamage { 67 | onBeforeDurabilityDamage( 68 | componentData: ItemComponentBeforeDurabilityDamageEvent, 69 | paramData: CustomComponentParameters 70 | ): void { 71 | const param = paramData.params as ParameterModifyDurabilityDamageAmount; 72 | for (const entry of param) { 73 | const entity_filter: string[] | undefined = entry.entity_filter; 74 | const damage: number = entry.damage_amount; 75 | 76 | // Check if player_equipment matches any transform_from 77 | const matches: boolean = (entity_filter ?? []).some( 78 | (entity: string) => { 79 | return componentData.hitEntity.typeId === entity; 80 | } 81 | ); 82 | 83 | // If there's a match, log the corresponding transform_to 84 | if (matches) { 85 | componentData.durabilityDamage = damage; 86 | return; // Stop further checks if a match is found 87 | } 88 | } 89 | } 90 | } 91 | 92 | class PreventDamageDurability extends OnBeforeDurabilityDamage { 93 | onBeforeDurabilityDamage( 94 | componentData: ItemComponentBeforeDurabilityDamageEvent 95 | ): void { 96 | componentData.durabilityDamage = 0; 97 | } 98 | } 99 | 100 | enum OnBeforeDurabilityDamageKey { 101 | Debug = 'debug', 102 | RunCommand = 'run_command', 103 | ModifyDurabilityDamageAmount = 'modify_durability_damage_amount', 104 | PreventDamageDurability = 'prevent_damage_durability' 105 | } 106 | 107 | export const ON_BEFORE_DURABILITY_DAMAGE_REGISTRY: Map< 108 | OnBeforeDurabilityDamageKey, 109 | OnBeforeDurabilityDamage 110 | > = new Map([ 111 | [OnBeforeDurabilityDamageKey.Debug, new Debug()], 112 | [OnBeforeDurabilityDamageKey.RunCommand, new RunCommand()], 113 | [ 114 | OnBeforeDurabilityDamageKey.ModifyDurabilityDamageAmount, 115 | new ModifyDurabilityDamageAmount() 116 | ], 117 | [ 118 | OnBeforeDurabilityDamageKey.PreventDamageDurability, 119 | new PreventDamageDurability() 120 | ] 121 | ]); 122 | -------------------------------------------------------------------------------- /rc/scripts/item/item_wax.ts: -------------------------------------------------------------------------------- 1 | import { 2 | ItemComponentUseOnEvent, 3 | BlockSignComponent, 4 | Player, 5 | Block, 6 | BlockPermutation, 7 | MolangVariableMap, 8 | Direction, 9 | Dimension, 10 | Vector3 11 | } from '@minecraft/server'; 12 | import * as adk from 'adk-scripts-server'; 13 | import { getRandomVelocity, nextDouble, vectorOfCenter } from 'utils/math'; 14 | 15 | export function onUseOnWax(componentData: ItemComponentUseOnEvent) { 16 | const REGEX: RegExp = new RegExp( 17 | 'minecraft:(?:[a-z]\\w+_)?(?:standing|wall|hanging)_sign' 18 | ); 19 | const sign_component: BlockSignComponent = adk.ComponentBlockSign.get( 20 | componentData.block 21 | ); 22 | const player: Player = componentData.source as Player; 23 | const block: Block = componentData.block; 24 | 25 | if (REGEX.test(block.typeId)) { 26 | sign_component.setWaxed(true); 27 | adk.PlayerHelper.decrementStack(player); 28 | spawnWaxParticles(block); 29 | 30 | return; 31 | } 32 | if (block.typeId.includes('copper') && !block.typeId.includes('waxed')) { 33 | adk.PlayerHelper.decrementStack(player); 34 | let new_block: string = 'minecraft:waxed_' + block.typeId.substring(10); 35 | if (new_block == 'minecraft:waxed_copper_block') 36 | new_block = 'minecraft:waxed_copper'; 37 | 38 | if ( 39 | block.typeId.includes('door') && 40 | !block.typeId.includes('trapdoor') 41 | ) { 42 | if (!block.permutation.getState('upper_block_bit')) 43 | player.runCommand( 44 | `setblock ${block.location.x} ${block.location.y} ${ 45 | block.location.z 46 | } ${new_block}["direction"=${block.permutation.getState( 47 | 'direction' 48 | )}, "door_hinge_bit"=${block.permutation.getState( 49 | 'door_hinge_bit' 50 | )}, "open_bit"=${block.permutation.getState('open_bit')}]` 51 | ); 52 | else { 53 | const block_below: Block | undefined = block.below(); 54 | if (!block_below) return; 55 | player.runCommand( 56 | `setblock ${block.location.x} ${block.location.y - 1} ${ 57 | block.location.z 58 | } ${new_block}["direction"=${block_below.permutation.getState( 59 | 'direction' 60 | )}, "door_hinge_bit"=${block_below.permutation.getState( 61 | 'door_hinge_bit' 62 | )}, "open_bit"=${block_below.permutation.getState( 63 | 'open_bit' 64 | )}]` 65 | ); 66 | } 67 | spawnWaxParticles(block); 68 | 69 | return; 70 | } 71 | 72 | if (Object.keys(block.permutation.getAllStates()).length == 0) { 73 | block.setType(new_block); 74 | spawnWaxParticles(block); 75 | 76 | return; 77 | } 78 | 79 | block.setPermutation( 80 | BlockPermutation.resolve( 81 | new_block, 82 | block.permutation.getAllStates() 83 | ) 84 | ); 85 | spawnWaxParticles(block); 86 | 87 | return; 88 | } 89 | } 90 | 91 | function spawnWaxParticles(block: Block) { 92 | for (const direction in Direction) { 93 | const count: number = Math.floor(Math.random() * 2) + 3; 94 | for (let b: number = 0; b < count; b++) { 95 | spawnParticle( 96 | block.dimension, 97 | block.location, 98 | 'minecraft:wax_particle', 99 | direction as Direction, 100 | getRandomVelocity(), 101 | 0.5 102 | ); 103 | } 104 | } 105 | } 106 | 107 | function spawnParticle( 108 | dimension: Dimension, 109 | block_location: Vector3, 110 | effect: string, 111 | direction: Direction, 112 | velocity: Vector3, 113 | offset_multiplier: number 114 | ): void { 115 | const vector: Vector3 = vectorOfCenter(block_location); 116 | const { x, y, z } = adk.DirectionHelper.toVector3(direction); 117 | const world_x: number = 118 | vector.x + (x == 0 ? nextDouble(-0.5, 0.5) : x * offset_multiplier); 119 | const world_y: number = 120 | vector.y + (y == 0 ? nextDouble(-0.5, 0.5) : y * offset_multiplier); 121 | const world_z: number = 122 | vector.z + (z == 0 ? nextDouble(-0.5, 0.5) : z * offset_multiplier); 123 | const particle_velocity_x: number = x == 0 ? velocity.x : 0; 124 | const particle_velocity_y: number = y == 0 ? velocity.y : 0; 125 | const particle_velocity_z: number = z == 0 ? velocity.z : 0; 126 | const molang: MolangVariableMap = new MolangVariableMap(); 127 | molang.setColorRGB('variable.color', { 128 | red: 0.91, 129 | green: 0.55, 130 | blue: 0.08 131 | }); 132 | molang.setVector3('variable.direction', { 133 | x: (particle_velocity_x * 0.01) / 2.0, 134 | y: particle_velocity_y * 0.01, 135 | z: (particle_velocity_z * 0.01) / 2.0 136 | }); 137 | dimension.spawnParticle( 138 | effect, 139 | { x: world_x, y: world_y, z: world_z }, 140 | molang 141 | ); 142 | } 143 | --------------------------------------------------------------------------------