Skip to content

Commit bd1208c

Browse files
authored
New package: vanilla_data_library and fix issues (#265)
* New packages: vanilla_data_library and vanilla_data_library_preview * Remove preview library
1 parent 38e9e50 commit bd1208c

File tree

9 files changed

+11435
-32
lines changed

9 files changed

+11435
-32
lines changed

scripts/bow-ding/index.js

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,27 @@
33
// Project: https://github.com/JaylyDev/ScriptAPI
44
import { Player, world, MinecraftEntityTypes } from "@minecraft/server";
55

6-
world.afterEvents.projectileHit.subscribe((arg) => {
7-
if (arg.getEntityHit()?.entity instanceof Player
8-
&& arg.source instanceof Player
9-
&& arg.projectile.typeId === MinecraftEntityTypes.arrow.id
10-
) {
11-
/**
12-
* @type {import("@minecraft/server").PlayerSoundOptions}
13-
*/
14-
const soundOption = {
6+
world.afterEvents.entitySpawn.subscribe(({ entity }) => {
7+
// Since you cannot retrive projectile infomation from projectileHit event, we have to
8+
// subscribe to entitySpawn event to compare with the projectile information fired by projectileHit event.
9+
if (entity.typeId !== MinecraftEntityTypes.arrow.id) return;
10+
11+
const callback = world.afterEvents.projectileHit.subscribe((arg) => {
12+
const { source, projectile } = arg;
13+
const hitInfo = arg.getEntityHit();
14+
15+
if (hitInfo?.entity instanceof Player && source instanceof Player && projectile === entity) {
16+
/**
17+
* @type {import("@minecraft/server").PlayerSoundOptions}
18+
*/
19+
const soundOption = {
1520
volume: 0.4,
1621
pitch: 0.5,
17-
}
18-
19-
arg.source.playSound("random.orb", soundOption);
20-
};
22+
}
23+
24+
source.playSound("random.orb", soundOption);
25+
world.afterEvents.projectileHit.unsubscribe(callback);
26+
};
27+
});
2128
});
29+

scripts/jaylydb/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ class JaylyDB implements Map<string, string | number | boolean> {
189189
* Clears every element in the database.
190190
*/
191191
clear(): void {
192-
this.participants.forEach(this.objective.removeParticipant);
192+
this.participants.forEach(participant => this.objective.removeParticipant(participant));
193193
this.updateParticipants();
194194
}
195195
/**

scripts/ui-wrapper/ActionForm.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export class ActionFormButton {
1414
* Builds a simple player form with buttons that let the player
1515
* take action.
1616
*/
17-
export class ActionFormBuilder extends ActionFormData {
17+
export class ActionFormBuilder implements ActionFormData {
1818
/**
1919
* Title of the the modal dialog.
2020
*/
@@ -36,11 +36,12 @@ export class ActionFormBuilder extends ActionFormData {
3636
return this;
3737
}
3838
show(player: Player): Promise<ActionFormResponse> {
39-
if (!!this.titleText) super.title(this.titleText);
40-
if (!!this.bodyText) super.body(this.bodyText);
41-
this.buttons.forEach(item => super.button(item.text, item.iconPath));
39+
const form = new ActionFormData();
40+
if (!!this.titleText) form.title(this.titleText);
41+
if (!!this.bodyText) form.body(this.bodyText);
42+
this.buttons.forEach(item => form.button(item.text, item.iconPath));
4243

43-
return super.show(player);
44+
return form.show(player);
4445
}
4546
title(titleText: string | RawMessage): this {
4647
this.titleText = titleText;

scripts/ui-wrapper/MessageForm.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export class MessageFormButton {
1212
* Builds a simple player form with buttons that let the player
1313
* take action.
1414
*/
15-
export class MessageFormBuilder extends MessageFormData {
15+
export class MessageFormBuilder implements MessageFormData {
1616
/**
1717
* Title of the the modal dialog.
1818
*/
@@ -33,12 +33,14 @@ export class MessageFormBuilder extends MessageFormData {
3333
}
3434
show(player: Player): Promise<MessageFormResponse> {
3535
const [ button1, button2 ] = this.buttons;
36-
if (!!this.titleText) super.title(this.titleText);
37-
if (!!this.bodyText) super.body(this.bodyText);
38-
if (!!button1) super.button1(button1.text);
39-
if (!!button2) super.button2(button2.text);
36+
const form = new MessageFormData();
37+
38+
if (!!this.titleText) form.title(this.titleText);
39+
if (!!this.bodyText) form.body(this.bodyText);
40+
if (!!button1) form.button1(button1.text);
41+
if (!!button2) form.button2(button2.text);
4042

41-
return super.show(player);
43+
return form.show(player);
4244
}
4345
title(titleText: string | RawMessage): this {
4446
this.titleText = titleText;

scripts/ui-wrapper/ModalForm.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export type ModalFormContent = ModalFormDropdown | ModalFormSlider | ModalFormTe
5353
* Used to create a fully customizable pop-up form for a
5454
* player.
5555
*/
56-
export class ModalFormBuilder extends ModalFormData {
56+
export class ModalFormBuilder implements ModalFormData {
5757
/**
5858
* Title of the pop-up form.
5959
*/
@@ -67,15 +67,17 @@ export class ModalFormBuilder extends ModalFormData {
6767
return this;
6868
}
6969
show(player: Player): Promise<ModalFormResponse> {
70-
if (!!this.titleText) super.title(this.titleText);
70+
const form = new ModalFormData();
71+
72+
if (!!this.titleText) form.title(this.titleText);
7173
for (const item of this.content) {
72-
if (item instanceof ModalFormDropdown) super.dropdown(item.label, item.options, item.defaultValueIndex);
73-
else if (item instanceof ModalFormSlider) super.slider(item.label, item.minimumValue, item.maximumValue, item.valueStep, item.defaultValue);
74-
else if (item instanceof ModalFormTextField) super.textField(item.label, item.placeholderText, item.defaultValue);
75-
else if (item instanceof ModalFormToggle) super.toggle(item.label, item.defaultValue);
74+
if (item instanceof ModalFormDropdown) form.dropdown(item.label, item.options, item.defaultValueIndex);
75+
else if (item instanceof ModalFormSlider) form.slider(item.label, item.minimumValue, item.maximumValue, item.valueStep, item.defaultValue);
76+
else if (item instanceof ModalFormTextField) form.textField(item.label, item.placeholderText, item.defaultValue);
77+
else if (item instanceof ModalFormToggle) form.toggle(item.label, item.defaultValue);
7678
};
7779

78-
return super.show(player);
80+
return form.show(player);
7981
}
8082
slider(label: string | RawMessage, minimumValue: number, maximumValue: number, valueStep: number = 1, defaultValue?: number | undefined): this {
8183
this.content.push(new ModalFormSlider(label, minimumValue, maximumValue, valueStep, defaultValue));
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# @minecraft/vanilla-data
2+
3+
This module contains type definitions and enumarations for vanilla content within the game, such as Blocks, Items, Entities, and more. This module is versioned accordingly with Minecraft release and preview versions, and contain the up to date types available in the game.
4+
5+
Version: 1.20.0
6+
7+
## Credits
8+
These scripts were written by [Jake Shirley](https://github.com/JakeShirley), [Mike Ammerlaan](https://github.com/mammerla), [Raphael Landaverde](https://github.com/rlandav)

0 commit comments

Comments
 (0)