Skip to content

Commit 2de43f7

Browse files
authored
1.20.20-beta.21 Content Update (JaylyDev#290)
* bug fixes * markdown * Update index.ts * Update index.js * fix
1 parent b58be04 commit 2de43f7

17 files changed

Lines changed: 329 additions & 210 deletions

File tree

CONTRIBUTING.md

Lines changed: 39 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,56 +2,47 @@
22

33
Contributing infomation. This info changes because Script API is currently in active development, and breaking changes are frequent.
44

5-
## Scripts
6-
7-
When submitting a new package. The scripts are assumed that they can be used with the latest beta module of script modules in latest version of Minecraft Preview, the following is a reference of a manifest dependencies and NPM packages for meeting the criteria of submitting or updating a script sample.
8-
9-
**manifest.json**
10-
11-
This repository may have scripts that requires the following dependencies with their latest module version:
12-
13-
```json
14-
"dependencies": [
15-
{
16-
"module_name": "@minecraft/server",
17-
"version": "1.2.0-beta"
18-
},
19-
{
20-
"module_name": "@minecraft/server-editor",
21-
"version": "0.1.0-beta"
22-
}
23-
{
24-
"module_name": "@minecraft/server-ui",
25-
"version": "1.0.0-beta"
26-
},
27-
{
28-
"module_name": "@minecraft/server-gametest",
29-
"version": "1.0.0-beta"
30-
},
31-
{
32-
"module_name": "@minecraft/server-admin",
33-
"version": "1.0.0-beta"
34-
},
35-
{
36-
"module_name": "@minecraft/server-net",
37-
"version": "1.0.0-beta"
38-
}
39-
]
40-
```
5+
## Creating a new script sample
6+
7+
- Create a new directory for your script sample in the [**scripts**](./scripts/) directory. The directory name is your sample name and should be is unique and infomative.
8+
9+
- Create a folder structure based on the following:
10+
11+
| File | Purpose |
12+
| ------------------------ | ---------------------------------- |
13+
| `index.js` or `index.ts` | This is main file for the package. |
14+
| `README.md` | Infomation for the package. |
4115

42-
This repository may have scripts that requires the following capabilities:
16+
In the main file, you must input basic credentials for the scripts with the right format. For example, here are the first few lines of script example:
4317

44-
```json
45-
"capabilities": [
46-
"editorExtension",
47-
"script_eval"
48-
]
18+
```js
19+
// Script example for ScriptAPI
20+
// Author: Alice <https://github.com/alice>
21+
// Bob <https://github.com/bob>
22+
// Steve <https://steve.com/>
23+
// Project: https://github.com/JaylyDev/ScriptAPI
4924
```
5025

51-
**NPM packages:**
26+
In order for the pull request to be merged, the scripts must pass TypeScript Compiling process for all JavaScript/TypeScript files.
27+
28+
![image](https://github.com/JaylyDev/ScriptAPI/assets/121162959/a0db5db6-864a-4f56-a8f5-01fc5c12167e)
29+
30+
> Above image shows all checks have passed and the pull request should be able to be merged.
31+
32+
If the check did not pass, go to the 'details' section and see what section of the check went wrong, and attempt to fix the issue by pushing another commit to your branch.
33+
34+
## Create an editor extension sample
35+
36+
An editor extension sample should only be used in Minecraft Editor, otherwise the sample should be hosted in 'scripts' folder.
37+
38+
- Create an editor extension sample in [editorExtensions](./editorExtensions/) directory.
39+
40+
- Create the same folder structure as used in scripts folder and a header in main file like creating a new script sample.
41+
42+
- We recommend using TypeScript for editor extension samples.
43+
44+
## Don't edit docs folder
45+
46+
Documentation are no longer being updated as mentioned in README.
5247

53-
- [`@minecraft/server@beta`](https://www.npmjs.com/package/@minecraft/server/v/beta)
54-
- [`@minecraft/server-ui@beta`](https://www.npmjs.com/package/@minecraft/server-ui/v/beta)
55-
- [`@minecraft/server-net@beta`](https://www.npmjs.com/package/@minecraft/server-net/v/beta)
56-
- [`@minecraft/server-gametest@beta`](https://www.npmjs.com/package/@minecraft/server-gametest/v/beta)
57-
- [`@minecraft/server-admin@beta`](https://www.npmjs.com/package/@minecraft/server-admin/v/beta)
48+
Please do not submit any pull requests that changes any content to the docs directory. Instead, please visit [Bedrock Wiki](https://wiki.bedrock.dev/scripting/starting-scripts) and perhaps contribute scripting documentation in Bedrock Wiki GitHub repository: https://github.com/Bedrock-OSS/bedrock-wiki/tree/wiki/docs/scripting

README.md

Lines changed: 21 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -2,73 +2,39 @@
22

33
This repository is filled with community driven script samples for Minecraft Bedrock Script API.
44

5-
## Script Samples
5+
<hr/>
66

7-
- ### [scripts](./scripts/)
7+
### 🔴 USE `stable` not `main` 🔴
88

9-
Community driven scripts that use Script API to do all kinds of crazy stuff in Minecraft.
10-
11-
> ⚠️ Some scripts might use API modules that are only enabled in specific environments, including:
12-
> - `@minecraft/server-net` and `@minecraft/server-admin`: Modules that can only be used in [Bedrock Dedicated Servers](https://www.minecraft.net/en-us/download/server/bedrock).
13-
> - `@minecraft/server-editor` and `@minecraft/server-editor-bindings`: Modules that can only be used on Editor projects in [Minecraft Editor](https://github.com/mojang/minecraft-editor).
14-
15-
- ### [docs](./docs/)
16-
Contains technical documentation of Script API features.
17-
> 🚫 Documentation are no longer being updated. Check out [Bedrock Wiki](https://wiki.bedrock.dev/scripting/starting-scripts) and [Microsoft Learn](https://learn.microsoft.com/en-us/minecraft/creator/scriptapi/) for up-to-date infomation.
18-
19-
## Contributing
20-
21-
Please contribute to this repository if you can.
22-
23-
The repository features a Pull Request system that inspires heavily from [DefinitelyTyped](https://github.com/DefinitelyTyped/DefinitelyTyped). This implementation serves to ensure the attribution of code ownership to the script authors who manages of their scripts.
9+
**Check out the `stable` branch from here: https://github.com/JaylyDev/ScriptAPI/tree/stable**.
10+
The `main` branch is used for script development for Minecraft Preview and may often be in a **broken** state.
2411

25-
To create a new script package, create a folder structure based on the following:
12+
<hr/>
2613

27-
| File | Purpose |
28-
| ------------------------ | ---------------------------------------------------------------------------------------------------- |
29-
| `index.js` or `index.ts` | This is main file for the package. |
30-
| `tests.js` or `tests.ts` | This contains sample code which tests the typings. This code does _not_ run, but it is type-checked. |
31-
| `tsconfig.json` | This allows you to run `tsc` within the package. |
32-
| `README.md` | Infomation for the package. |
14+
- ### [Scripts](./scripts/)
3315

34-
To add yourself as a script author:
35-
36-
Adding your name to the end of the line, as in `// Author: Alice <url>, Bob <url>`.
37-
Or if there are more people, it can be multiline
38-
39-
```js
40-
// Author: Alice <url>
41-
// Bob <url>
42-
// Steve <url>
43-
// John <url>
44-
```
45-
46-
Each package is versioned via GitHub repository tags. In order to secure credentials for scripts, each main file requires basic credentials with the right format. For example, here are the first few lines of script example:
47-
48-
```js
49-
// Script example for ScriptAPI
50-
// Author: Alice <https://github.com/alice>
51-
// Bob <https://github.com/bob>
52-
// Steve <https://steve.com/>
53-
// Project: https://github.com/JaylyDev/ScriptAPI
54-
```
16+
Community driven scripts that use Script API to do all kinds of crazy stuff in Minecraft.
5517

56-
### Script Versioning
18+
> ⚠️ Some scripts might use API modules that are only enabled in specific runtime environments, including:
19+
>
20+
> - `@minecraft/server-net` and `@minecraft/server-admin`: Modules that can only be used in [Bedrock Dedicated Servers](https://www.minecraft.net/en-us/download/server/bedrock).
5721
58-
The script samples are intended to be used within the latest version of Minecraft or Minecraft Preview, using latest development version of Script API modules.
22+
- ### [Editor Extensions](./editorExtensions/)
5923

60-
For submitting or updating script samples, you must upload scripts that works in the latest version of Script API modules in latest Minecraft Preview. For more infomation please visit [here](./CONTRIBUTING.md).
24+
Community driven editor extensions samples for editing Minecraft worlds. Only available on Editor projects in [Minecraft Editor](https://github.com/mojang/minecraft-editor).
6125

62-
To access older versions of scripts, this repository uses [GitHub's tags feature](https://github.com/JaylyDev/ScriptAPI/tags) to allow users to access previous versions of repository for scripts that uses a specific Minecraft version.
26+
Highly recommend checking out Mojang's [editor extension starter kit](https://github.com/Mojang/minecraft-editor-extension-starter-kit) if you're experimenting with editor API for the first time!
6327

64-
![github_tags](https://user-images.githubusercontent.com/65847850/222926832-8c8db1d5-f6d6-41be-bfeb-f4efdd5d46b5.png)
28+
- ### [docs](./docs/)
29+
Contains technical documentation of Script API features.
30+
> **🚫 Documentation are no longer being updated**. Check out [Microsoft Learn](https://learn.microsoft.com/en-us/minecraft/creator/scriptapi/) and [Bedrock Wiki](https://wiki.bedrock.dev/scripting/starting-scripts) for up-to-date infomation.
6531
66-
## Script status
32+
## Contributing
6733

68-
This repository uses TypeScript compiler to test script files by validing with declaration files of Script API modules, making sure they are up-to-date when using in the latest Minecraft versions.
34+
Please contribute to this repository if you can. Check out [**Contributing Guidelines**](./CONTRIBUTING.md) for more infomation.
6935

70-
![success_checks](https://user-images.githubusercontent.com/65847850/222813970-7f24a869-37a5-4e73-b2fd-03f321fdb4d1.png)
36+
## License
37+
This project is licensed under the MIT license.
7138

72-
Most of the time the checks succeed, which means scripts inside should not have any syntax errors when using in stable version of Minecraft.
39+
Copyrights on the script files are each contributor listed at the beginning of each script file.
7340

74-
If the check failed, it's worth creating a bug report if a fix is not implemented, or a pull request if you may find a solution to a fix to the problem.

editorExtensions/editor-fullbright/tests.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,11 @@ registerEditorExtension('nightVision', (uiSession) => {
1818
uiSession.toolRail.show();
1919
// Add selection functionality
2020
new FullbrightToggle(uiSession, createMenu(uiSession));
21-
});
21+
return [
22+
{
23+
teardown() {
24+
this.uiSession.log.debug("Shutting down FullbrightToggle behavior\n");
25+
}
26+
}
27+
];
28+
}, () => { });

editorExtensions/editor-random-fill/index.js

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -618,12 +618,10 @@ export class SelectionBehavior {
618618
},
619619
],
620620
onChange: (_obj, _property, _oldValue, _newValue) => {
621-
const oldVal = _oldValue;
622-
const newVal = _newValue;
623621
let cursorControlMode = CursorControlMode.KeyboardAndMouse;
624622
let cursorTargetMode = CursorTargetMode.Block;
625-
if (oldVal !== newVal) {
626-
switch (newVal) {
623+
if (_oldValue !== _newValue) {
624+
switch (_newValue) {
627625
case SelectionCursorMode.Freeform:
628626
cursorControlMode = CursorControlMode.KeyboardAndMouse;
629627
cursorTargetMode = CursorTargetMode.Block;
@@ -716,24 +714,26 @@ export class SelectionBehavior {
716714
min: 1,
717715
max: 16,
718716
showSlider: true,
719-
onChange: async (_obj, _property, _oldValue, _newValue) => {
720-
console.warn(_property, _oldValue, _newValue, blockPickers.length);
721-
while (blockPickers.length < _newValue) {
722-
await null; // using await null in an async function to avoid making the server hangs
723-
blockPickers.push(subPaneFill.addBlockPicker(this.settingsObject, 'block', {
724-
titleAltText: 'Block Type',
725-
allowedBlocks
726-
}));
727-
}
728-
while (blockPickers.length > _newValue) {
729-
await null; // using await null in an async function to avoid making the server hangs
730-
const lastBlockPicker = blockPickers[blockPickers.length - 1];
731-
lastBlockPicker.visible = false;
732-
lastBlockPicker.enable = false;
733-
lastBlockPicker.dispose();
734-
blockPickers.pop();
717+
onChange: (_obj, _property, _oldValue, _newValue) => {
718+
function adjustBlockPickers() {
719+
if (blockPickers.length < _newValue) {
720+
blockPickers.push(subPaneFill.addBlockPicker(this.settingsObject, 'block', {
721+
titleAltText: 'Block Type',
722+
allowedBlocks
723+
}));
724+
}
725+
else if (blockPickers.length > _newValue) {
726+
const lastBlockPicker = blockPickers[blockPickers.length - 1];
727+
lastBlockPicker.visible = false;
728+
lastBlockPicker.enable = false;
729+
lastBlockPicker.dispose();
730+
blockPickers.pop();
731+
}
732+
if (blockPickers.length === _newValue) {
733+
system.clearRun(id);
734+
}
735735
}
736-
subPaneFill.update(true);
736+
const id = system.runInterval(adjustBlockPickers);
737737
},
738738
});
739739
subPaneFill.addButton(this.executeFillAction, {
@@ -758,7 +758,7 @@ export class SelectionBehavior {
758758
// Add a modal tool to the tool rail and set up an activation subscription to set/unset the cursor states
759759
this.addTool = (uiSession) => {
760760
const tool = uiSession.toolRail.addTool({
761-
displayStringId: 'Random Fill (CTRL + S)',
761+
displayAltText: 'Random Fill (CTRL + S)',
762762
icon: 'pack://textures/editor/Select-Fill.png?filtering=point',
763763
tooltipStringId: 'Random Fill Tool',
764764
});
@@ -825,6 +825,7 @@ export class SelectionBehavior {
825825
// Create pane.
826826
this.pane = uiSession.createPropertyPane({
827827
titleAltText: 'Random Fill',
828+
titleStringId: getLocalizationId('selectionTool.title'),
828829
});
829830
/**
830831
* Allowed blocks for the block picker
@@ -875,5 +876,13 @@ registerEditorExtension('randomFill', (uiSession) => {
875876
// Initialize tool rail.
876877
uiSession.toolRail.show();
877878
// Add selection functionality
878-
new SelectionBehavior(uiSession);
879+
return [
880+
new SelectionBehavior(uiSession)
881+
];
882+
}, (uiSession) => {
883+
uiSession.log.info('Shutting down minecraft::selection behavior');
884+
// Shutdown
885+
uiSession.scratchStorage = undefined;
886+
}, {
887+
description: 'Randomly fills blocks in the selection',
879888
});
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Script example for ScriptAPI
2+
// Author: Ciosciaa <https://github.com/Ciosciaa>
3+
// Project: https://github.com/JaylyDev/ScriptAPI
4+
import * as server from "@minecraft/server";
5+
import * as editor from "@minecraft/server-editor";
6+
const entityTypes = [...server.EntityTypes.getAll()].map(({ id }) => id);
7+
editor.registerEditorExtension("entitySpawner", uiSession => {
8+
const tool = uiSession.toolRail.addTool({
9+
displayAltText: "Spawn Entity (Ctrl + E)",
10+
displayStringId: "editor.toolRail.entitySpawnerTool.title",
11+
tooltipAltText: "Spawns an entity at the selected position",
12+
tooltipStringId: "editor.toolRail.entitySpawnerTool.description",
13+
icon: "pack://textures/editor/entity.png?filtering=point"
14+
});
15+
const currentCursorState = uiSession.extensionContext.cursor.getProperties();
16+
currentCursorState.outlineColor = { red: 1, green: 0, blue: 1, alpha: 1 };
17+
currentCursorState.controlMode = editor.CursorControlMode.KeyboardAndMouse;
18+
currentCursorState.targetMode = editor.CursorTargetMode.Face;
19+
currentCursorState.visible = true;
20+
uiSession.scratchStorage = { spawnerCursorState: currentCursorState };
21+
tool.onModalToolActivation.subscribe(eventData => {
22+
if (eventData.isActiveTool)
23+
uiSession.extensionContext.cursor.setProperties(uiSession.scratchStorage.spawnerCursorState);
24+
});
25+
uiSession.inputManager.registerKeyBinding(editor.EditorInputContext.GlobalToolMode, uiSession.actionManager.createAction({
26+
actionType: editor.ActionTypes.NoArgsAction,
27+
onExecute: () => {
28+
uiSession.toolRail.setSelectedOptionId(tool.id, true);
29+
},
30+
}), editor.KeyboardKey.KEY_E, editor.InputModifier.Control);
31+
const settings = {
32+
entityType: "minecraft:creeper"
33+
};
34+
const pane = uiSession.createPropertyPane({
35+
titleStringId: "editor.toolRail.entitySpawnerTool.pane.title",
36+
titleAltText: "Entity Spawner Settings",
37+
});
38+
const binding = editor.bindDataSource(pane, settings);
39+
pane.addDropdown(binding, "entityType", {
40+
titleStringId: "editor.toolRail.entitySpawnerTool.pane.controls.entityType",
41+
titleAltText: "Entity Type",
42+
dropdownItems: entityTypes.map((entityType, index) => ({
43+
value: index,
44+
displayAltText: entityType,
45+
displayStringId: `entity.${entityType.replace("minecraft:", "")}.name`
46+
}))
47+
});
48+
tool.bindPropertyPane(pane);
49+
tool.registerMouseButtonBinding(uiSession.actionManager.createAction({
50+
actionType: editor.ActionTypes.MouseRayCastAction,
51+
onExecute: async (mouseRay, mouseProps) => {
52+
if (mouseProps.mouseAction === editor.MouseActionType.LeftButton) {
53+
if (mouseProps.inputType === editor.MouseInputType.ButtonDown) {
54+
uiSession.extensionContext.transactionManager.openTransaction("tool.spawnEntity");
55+
uiSession.extensionContext.selectionManager.selection.clear();
56+
const cursorPosition = mouseRay.cursorBlockLocation;
57+
server.world.getDimension("minecraft:overworld").spawnEntity(settings.entityType, {
58+
x: cursorPosition.x + 0.5,
59+
y: cursorPosition.y,
60+
z: cursorPosition.z + 0.5
61+
});
62+
}
63+
else if (mouseProps.inputType === editor.MouseInputType.ButtonUp) {
64+
uiSession.extensionContext.transactionManager.commitOpenTransaction();
65+
uiSession.extensionContext.selectionManager.selection.clear();
66+
}
67+
}
68+
}
69+
}));
70+
return []; // Likely unneeded, but untested
71+
}, () => { });

scripts/bow-ding/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// Script example for ScriptAPI
22
// Author: JaylyDev <https://github.com/JaylyDev>
33
// Project: https://github.com/JaylyDev/ScriptAPI
4-
import { Player, world, MinecraftEntityTypes } from "@minecraft/server";
4+
import { Player, world } from "@minecraft/server";
55

66
world.afterEvents.entitySpawn.subscribe(({ entity }) => {
77
// Since you cannot retrive projectile infomation from projectileHit event, we have to
88
// subscribe to entitySpawn event to compare with the projectile information fired by projectileHit event.
9-
if (entity.typeId !== MinecraftEntityTypes.arrow.id) return;
9+
if (entity.typeId !== "minecraft:arrow") return;
1010

1111
const callback = world.afterEvents.projectileHit.subscribe((arg) => {
1212
const { source, projectile } = arg;

scripts/event-listener/tests.js

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)