Skip to content

Commit

Permalink
Updated component variable names
Browse files Browse the repository at this point in the history
  • Loading branch information
QuazChick committed Feb 17, 2025
1 parent 19e950a commit 5e92960
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 61 deletions.
23 changes: 13 additions & 10 deletions docs/blocks/applying-effects.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,19 @@ Now we need to register our custom components to hook onto the [`stepOn`](/block

```json
"minecraft:custom_components": [
"wiki:detect_treaders"
"wiki:treader_detection"
]
```

### Custom Component Script

<CodeHeader>BP/scripts/detect_treaders.js</CodeHeader>
<CodeHeader>BP/scripts/treader_detection.js</CodeHeader>

```js
import { BlockPermutation, GameMode, Player, world } from "@minecraft/server";

/** @type {import("@minecraft/server").BlockCustomComponent} */
const DetectTreadersBlockComponent = {
const BlockTreaderDetectionComponent = {
onStepOn({ entity, block }) {
if (entity instanceof Player && entity.getGameMode() === GameMode.creative) return;

Expand All @@ -76,8 +76,8 @@ const DetectTreadersBlockComponent = {

world.beforeEvents.worldInitialize.subscribe(({ blockComponentRegistry }) => {
blockComponentRegistry.registerCustomComponent(
"wiki:detect_treaders",
DetectTreadersBlockComponent
"wiki:treader_detection",
BlockTreaderDetectionComponent
);
});
```
Expand All @@ -95,7 +95,7 @@ We also need the block to tick in order to apply the desired effect every tick.
{
"condition": "q.block_state('wiki:stood_on')",
"components": {
"minecraft:custom_components": ["wiki:detect_treaders", "wiki:wither_treaders"],
"minecraft:custom_components": ["wiki:treader_detection", "wiki:wither_treaders"],
"minecraft:tick": {
"interval_range": [1, 1],
"looping": true
Expand All @@ -115,7 +115,7 @@ Now, let's add our event that will give the entity the wither effect:
import { Entity, GameMode, Player, world } from "@minecraft/server";

/** @type {import("@minecraft/server").BlockCustomComponent} */
const WitherTreadersBlockComponent = {
const BlockWitherTreadersComponent = {
onTick(event) {
const entities = event.dimension.getEntitiesAtBlockLocation(event.block.above().location);

Expand All @@ -128,7 +128,7 @@ const WitherTreadersBlockComponent = {
world.beforeEvents.worldInitialize.subscribe(({ blockComponentRegistry }) => {
blockComponentRegistry.registerCustomComponent(
"wiki:wither_treaders",
WitherTreadersBlockComponent
BlockWitherTreadersComponent
);
});
```
Expand Down Expand Up @@ -160,13 +160,16 @@ And done! The code above will trigger the desired status effect as long as the e
"texture": "wiki:wither_block"
}
},
"minecraft:custom_components": ["wiki:detect_treaders"]
"minecraft:custom_components": ["wiki:treader_detection"]
},
"permutations": [
{
"condition": "q.block_state('wiki:stood_on')",
"components": {
"minecraft:custom_components": ["wiki:detect_treaders", "wiki:wither_treaders"],
"minecraft:custom_components": [
"wiki:treader_detection",
"wiki:wither_treaders"
],
"minecraft:tick": {
"interval_range": [1, 1],
"looping": true
Expand Down
4 changes: 2 additions & 2 deletions docs/blocks/block-events.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ _This example prevents the player from placing the block if they aren't in creat
import { world, GameMode } from "@minecraft/server";

/** @type {import("@minecraft/server").BlockCustomComponent} */
const CreativeModeOnlyBlockComponent = {
const BlockCreativeModeOnlyComponent = {
beforeOnPlayerPlace(event) {
const isInCreative = event.player?.getGameMode() === GameMode.creative;
if (!isInCreative) event.cancel = true;
Expand All @@ -50,7 +50,7 @@ const CreativeModeOnlyBlockComponent = {
world.beforeEvents.worldInitialize.subscribe(({ blockComponentRegistry }) => {
blockComponentRegistry.registerCustomComponent(
"wiki:creative_mode_only",
CreativeModeOnlyBlockComponent
BlockCreativeModeOnlyComponent
);
});
```
Expand Down
4 changes: 2 additions & 2 deletions docs/blocks/custom-crops.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ const randomInt = (min, max) => Math.floor(Math.random() * (max - min + 1)) + mi
const maxGrowth = 7;

/** @type {import("@minecraft/server").BlockCustomComponent} */
const CustomCropGrowthBlockComponent = {
const BlockCustomCropGrowthComponent = {
onRandomTick({ block }) {
const growthChance = 1 / 3;
if (Math.random() > growthChance) return;
Expand Down Expand Up @@ -156,7 +156,7 @@ const CustomCropGrowthBlockComponent = {
world.beforeEvents.worldInitialize.subscribe(({ blockComponentRegistry }) => {
blockComponentRegistry.registerCustomComponent(
"wiki:custom_crop_growth",
CustomCropGrowthBlockComponent
BlockCustomCropGrowthComponent
);
});
```
Expand Down
4 changes: 2 additions & 2 deletions docs/blocks/custom-trapdoors.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ Now, it's time to put these permutations to use. The following script will allow
import { world } from "@minecraft/server";

/** @type {import("@minecraft/server").BlockCustomComponent} */
const CustomTrapdoorBlockComponent = {
const BlockCustomTrapdoorComponent = {
onPlayerInteract({ block, dimension }) {
const isOpen = block.permutation.getState("wiki:open");
const sound = isOpen ? "close.wooden_trapdoor" : "open.wooden_trapdoor";
Expand All @@ -198,7 +198,7 @@ const CustomTrapdoorBlockComponent = {
world.beforeEvents.worldInitialize.subscribe(({ blockComponentRegistry }) => {
blockComponentRegistry.registerCustomComponent(
"wiki:custom_trapdoor",
CustomTrapdoorBlockComponent
BlockCustomTrapdoorComponent
);
});
```
Expand Down
4 changes: 2 additions & 2 deletions docs/blocks/fake-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ For our custom component script, we'll utilize the `beforeOnPlayerPlace` event.
import { world } from "@minecraft/server";

/** @type {import("@minecraft/server").BlockCustomComponent} */
const AlignEntityBlockComponent = {
const BlockAlignEntityComponent = {
beforeOnPlayerPlace(event) {
event.cancel = true;

Expand All @@ -152,7 +152,7 @@ const AlignEntityBlockComponent = {
};

world.beforeEvents.worldInitialize.subscribe(({ blockComponentRegistry }) => {
blockComponentRegistry.registerCustomComponent("wiki:align_entity", AlignEntityBlockComponent);
blockComponentRegistry.registerCustomComponent("wiki:align_entity", BlockAlignEntityComponent);
});
```

Expand Down
6 changes: 3 additions & 3 deletions docs/blocks/precise-interaction.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ const quadrants = new FaceSelectionPlains(
This could be used in a [custom component](/blocks/block-events) to get the selected quadrant:
```js
const QuadrantInteractionBlockComponent = {
const BlockQuadrantInteractionComponent = {
onPlayerInteract({ block, face, faceLocation }) {
// Work around the faceLocation bug - get the location relative to the block
const relativeFaceLocation = {
Expand Down Expand Up @@ -600,15 +600,15 @@ function releasePaper({ block, destroyedBlockPermutation, dimension }) {
}

/** @type {import("@minecraft/server").BlockCustomComponent} */
const PigeonholesStorageBlockComponent = {
const BlockPigeonholesStorageComponent = {
onPlayerInteract: handleInteract,
onPlayerDestroy: releasePaper,
};

world.beforeEvents.worldInitialize.subscribe(({ blockComponentRegistry }) => {
blockComponentRegistry.registerCustomComponent(
"wiki:pigeonholes_storage",
PigeonholesStorageBlockComponent
BlockPigeonholesStorageComponent
);
});
```
Expand Down
8 changes: 4 additions & 4 deletions docs/blocks/precise-rotation.md
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ Think of a unique custom component identifier. There can't be duplicate custom c

```js
/** @type {import("@minecraft/server").BlockCustomComponent} */
const ShellRotationBlockComponent = {
const BlockShellRotationComponent = {
beforeOnPlayerPlace(event) {
const { player } = event;
if (!player) return; // Exit if the player is undefined
Expand All @@ -322,7 +322,7 @@ const ShellRotationBlockComponent = {
world.beforeEvents.worldInitialize.subscribe(({ blockComponentRegistry }) => {
blockComponentRegistry.registerCustomComponent(
"wiki:shell_rotation",
ShellRotationBlockComponent
BlockShellRotationComponent
);
});
```
Expand Down Expand Up @@ -529,7 +529,7 @@ function getPreciseRotation(playerYRotation) {
}

/** @type {import("@minecraft/server").BlockCustomComponent} */
const ShellRotationBlockComponent = {
const BlockShellRotationComponent = {
beforeOnPlayerPlace(event) {
const { player } = event;
if (!player) return;
Expand All @@ -547,7 +547,7 @@ const ShellRotationBlockComponent = {
world.beforeEvents.worldInitialize.subscribe(({ blockComponentRegistry }) => {
blockComponentRegistry.registerCustomComponent(
"wiki:shell_rotation",
ShellRotationBlockComponent
BlockShellRotationComponent
);
});
```
Expand Down
4 changes: 2 additions & 2 deletions docs/entities/npc-dialogues.md
Original file line number Diff line number Diff line change
Expand Up @@ -322,14 +322,14 @@ Lastly, create an item that will open the dialogue when right-clicked/interacted
```js
import { world } from "@minecraft/server";

const TeleportMenuItemComponent = {
const ItemTeleportMenuComponent = {
onUse({ source }) {
source.runCommand("dialogue open @e[type=npc, c=1] @s main_teleport_menu");
},
};

world.beforeEvents.worldInitialize.subscribe(({ itemComponentRegistry }) => {
itemComponentRegistry.registerCustomComponent("wiki:teleport_menu", TeleportMenuItemComponent);
itemComponentRegistry.registerCustomComponent("wiki:teleport_menu", ItemTeleportMenuComponent);
});
```

Expand Down
4 changes: 2 additions & 2 deletions docs/items/item-events.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ _This example prevents the item from taking durability damage when hitting an en
```js
import { world } from "@minecraft/server";

const UnbreakableItemComponent = {
const ItemUnbreakableComponent = {
onBeforeDurabilityDamage(event) {
event.durabilityDamage = 0;
},
};

world.beforeEvents.worldInitialize.subscribe(({ itemComponentRegistry }) => {
itemComponentRegistry.registerCustomComponent("wiki:unbreakable", UnbreakableItemComponent);
itemComponentRegistry.registerCustomComponent("wiki:unbreakable", ItemUnbreakableComponent);
});
```

Expand Down
68 changes: 36 additions & 32 deletions docs/meta/style-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ BP/functions/wiki/event/players/on_death.mcfunction
BP/functions/wiki/event/worlds/on_initialise.mcfunction
```

- All content folders `ability` and `event` are consistently singular.
- The content folders in `event` are also consistent, as both `players` and `worlds` are plural.
- All content folders `ability` and `event` are consistently singular.
- The content folders in `event` are also consistent, as both `players` and `worlds` are plural.

❌️ **Inconsistent**:

Expand Down Expand Up @@ -61,7 +61,7 @@ Do not use identifiers that begin with a number, and especially don't use an ide
| Animations | dragon.animation.json<br>dragon.anim.json |
| Animation Controllers | dragon.animation_controllers.json<br>dragon.ac.json |
| RP Entity | dragon.entity.json<br>dragon.client_entity.json<br>dragon.ce.json |
| BP Entity | dragon.behavior.json<br>dragon.se.json<br>*(se: server entity)* |
| BP Entity | dragon.behavior.json<br>dragon.se.json<br>_(se: server entity)_ |
| Item | dragon_tooth.item.json |
| Legacy Item (BP) | dragon_tooth.item.bp.json |
| Legacy Item (RP) | dragon_tooth.item.rp.json |
Expand Down Expand Up @@ -94,9 +94,9 @@ Where to use namespaces:
When not to use namespaces:

- do not include your namespace in any folder path or file name.
- **Note:** The following folders are exceptions: `functions`, `structures`, `loot_tables`, `trade_tables`, `sounds`, and `textures`.
- Using a **namespace** in these folders is recommended to prevent conflicts with other packs.
- **Example:** `BP/functions/namespace/test.mcfunction`
- **Note:** The following folders are exceptions: `functions`, `structures`, `loot_tables`, `trade_tables`, `sounds`, and `textures`.
- Using a **namespace** in these folders is recommended to prevent conflicts with other packs.
- **Example:** `BP/functions/namespace/test.mcfunction`

## Sub-Indexing

Expand Down Expand Up @@ -136,7 +136,7 @@ When we make short-names of this form, we can use a generic "sit" animation cont

## Functions

1. All your `.mcfunction` files must be go in a namespaced root-folder within the functions folder. On Bedrock Wiki, we use the `wiki` namespace. However, you may choose a namespace based on your name or project. For more info, refer to the [namespaces](/concepts/namespaces) page.
1. All your `.mcfunction` files must be go in a namespaced root-folder within the functions folder. On Bedrock Wiki, we use the `wiki` namespace. However, you may choose a namespace based on your name or project. For more info, refer to the [namespaces](/concepts/namespaces) page.
- ✅️ `BP/functions/wiki/random_number.mcfunction`
- ❌️ `BP/functions/random_number.mcfunction`
2. They must be properly nested:
Expand All @@ -150,12 +150,12 @@ When we make short-names of this form, we can use a generic "sit" animation cont

### Comments in Functions

- When working with functions that contain many commands, it's helpful to keep them organized by using multiple hashtags in comments to indicate different header levels.
- *Optionally*, to further distinguish these levels, you can apply different styles:
- level 1 headers - **# UPPERCASE**
- level 2 headers - **## Title Case**
- level 3 headers - **### Sentence case**
- Try to avoid the use of more than three header levels or too many headers overall, as this can make the code look cluttered. For your reference, see the example file below:
- When working with functions that contain many commands, it's helpful to keep them organized by using multiple hashtags in comments to indicate different header levels.
- _Optionally_, to further distinguish these levels, you can apply different styles:
- level 1 headers - **# UPPERCASE**
- level 2 headers - **## Title Case**
- level 3 headers - **### Sentence case**
- Try to avoid the use of more than three header levels or too many headers overall, as this can make the code look cluttered. For your reference, see the example file below:

<Spoiler title="Example Function File">

Expand Down Expand Up @@ -194,35 +194,38 @@ This practice helps create a consistent format, making it easier for everyone to

## Scorboard Objectives & Tags

- Must begin with a namespace and use `snake_case`.
- This prevents conflicts with packs using identical tags or objectives.
- Only use lowercase letters (a–z), underscores (`_`), and dots (`.`) as special characters.
- Must begin with a namespace and use `snake_case`.
- This prevents conflicts with packs using identical tags or objectives.
- Only use lowercase letters (a–z), underscores (`_`), and dots (`.`) as special characters.

**Example Objectives:**
- `wiki:blocks_travelled.overworld`
- `wiki:q.is_sneaking`
- `wiki:q.is_armed_any`

- `wiki:blocks_travelled.overworld`
- `wiki:q.is_sneaking`
- `wiki:q.is_armed_any`

**Example Tags:**
- `wiki:inventory.full`
- `wiki:inventory.empty`
- `wiki:is_flying`

- `wiki:inventory.full`
- `wiki:inventory.empty`
- `wiki:is_flying`

:::info NOTE:
Tags describe a definite state—if a tag exists, its condition is true. This is why Molang queries represented as tags in a similar manner do not use the `q.` prefix.
:::

### Score Holders

- Must be prefixed with either a dot (`.`) or hashtag (`#`) and use `PascalCase`.
- This prevents conflicts with gamertags using identical names and provides a clear visual distinction since score holders are used closely with objectives.
- A prefix is used instead of a namespace to keep it concise, as the namespaced objective already prevents conflicts with other packs.
- No special characters other than dots (`.`).
- Must be prefixed with either a dot (`.`) or hashtag (`#`) and use `PascalCase`.
- This prevents conflicts with gamertags using identical names and provides a clear visual distinction since score holders are used closely with objectives.
- A prefix is used instead of a namespace to keep it concise, as the namespaced objective already prevents conflicts with other packs.
- No special characters other than dots (`.`).

**Examples:**
- `.Ores.Iron`
- `.Ores.DeepslateIron`
- `.200`

- `.Ores.Iron`
- `.Ores.DeepslateIron`
- `.200`

:::tip **TIP:**
Score holders prefixed with a hashtag (`#`) will not be displayed on the scoreboard sidebar. However, they must be enclosed in double quotes (`" "`) to avoid a syntax error.
Expand Down Expand Up @@ -296,7 +299,7 @@ Blocks, entities and items should follow the format order below.
- `identifier`
- `menu_category`
- `category`
- `group`
- `group`
- `states`
- `traits`
- `components`
Expand Down Expand Up @@ -326,12 +329,13 @@ Blocks, entities and items should follow the format order below.
- `identifier`
- `menu_category`
- `category`
- `group`
- `group`
- `components`

## Custom Components

### Variable Names

PascalCase should be used with `BlockComponent` or `ItemComponent` as a suffix. As an example, `const MeltableBlockComponent = { ... }` rather than `const meltable = { ... }`.
PascalCase should be used with `Block` or `Item` as a prefix and `Component` as a suffix. As an example, `const BlockMeltableComponent = { ... }` rather than `const meltable = { ... }`.

This helps to differentiate what we're using in `registerCustomComponent` and what we're using as values elsewhere.

0 comments on commit 5e92960

Please sign in to comment.