Skip to content

Commit f770983

Browse files
authored
Fix scripts for Minecraft 1.20.10.23 (#270)
* development * Update jaylydb to 1.1.0 * fix * f * Update testScriptChecks.ts * tes
1 parent 03a06d3 commit f770983

File tree

63 files changed

+903
-3302
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+903
-3302
lines changed

legacyPackages.json

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"packages": [
33
"chat-rank",
4-
"dimension-entities",
54
"dimensions",
65
"get-scores",
76
"is-host",

packages/minecraft-editor/@minecraft/server-editor-bindings.d.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
declare module '@minecraft/server-editor-bindings' {
1313
import { BlockLocationIterator, BlockVolume, BoundingBox, Color, CompoundBlockVolumeAction, Player, Vector3, } from '@minecraft/server';
1414
export class ClipboardItem {
15-
protected constructor();
15+
private constructor();
1616
readFromSelection(selection: Selection): void;
1717
readFromWorld(a: Vector3, b: Vector3): any;
1818
writeToWorld(location: Vector3, options: ClipboardWriteOptions): void;
@@ -22,7 +22,7 @@ declare module '@minecraft/server-editor-bindings' {
2222
isEmpty: boolean;
2323
}
2424
export class ClipboardManager {
25-
protected constructor();
25+
private constructor();
2626
create(): ClipboardItem;
2727
clipboard: ClipboardItem;
2828
}
@@ -73,10 +73,10 @@ declare module '@minecraft/server-editor-bindings' {
7373
Face = 1
7474
}
7575
export class Extension {
76-
protected constructor();
76+
private constructor();
7777
}
7878
export class ExtensionContext {
79-
protected constructor();
79+
private constructor();
8080
extensionName: string;
8181
player: Player;
8282
selectionManager: SelectionManager;
@@ -95,7 +95,7 @@ declare module '@minecraft/server-editor-bindings' {
9595
debug(message: string, properties?: LogProperties): void;
9696
}
9797
export class MinecraftEditor {
98-
protected constructor();
98+
private constructor();
9999
registerExtension_Internal(extensionName: string, activationFunction: (context: ExtensionContext) => void, shutdownFunction: (context: ExtensionContext) => void, optionalParameters?: ExtensionOptionalParameters): Extension;
100100
readonly log: Logger;
101101
}
@@ -104,7 +104,7 @@ declare module '@minecraft/server-editor-bindings' {
104104
volume: BlockVolume;
105105
}
106106
export class Selection {
107-
protected constructor();
107+
private constructor();
108108
clear(): void;
109109
pushVolume(options: PushVolumeOptions): void;
110110
popVolume(): void;
@@ -122,12 +122,12 @@ declare module '@minecraft/server-editor-bindings' {
122122
visible: boolean;
123123
}
124124
export class SelectionManager {
125-
protected constructor();
125+
private constructor();
126126
create(): Selection;
127127
selection: Selection;
128128
}
129129
export class TransactionManager {
130-
protected constructor();
130+
private constructor();
131131
undo(): void;
132132
redo(): void;
133133
undoSize(): number;

packages/minecraft-editor/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ Then you must include the following in TSConfig. This allows the editor API modu
1717
```json
1818
{
1919
"compilerOptions": {
20-
"types": ["@jayly/minecraft-editor"],
21-
"typeRoots": ["./node_modules/@jayly/minecraft-editor"],
20+
"types": ["minecraft-editor"],
21+
"typeRoots": ["./node_modules/@jayly"],
2222
},
2323
}
2424
```

packages/minecraft-editor/package-lock.json

+9-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/minecraft-editor/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@jayly/minecraft-editor",
3-
"version": "0.3.6-4",
3+
"version": "0.3.7-0",
44
"description": "Unofficial Minecraft Bedrock Editor API modules type definitions.",
55
"types": "index.d.ts",
66
"main": "",
@@ -15,6 +15,6 @@
1515
},
1616
"homepage": "https://github.com/JaylyDev/ScriptAPI#readme",
1717
"dependencies": {
18-
"@minecraft/server": "1.4.0-beta.1.20.10-preview.21"
18+
"@minecraft/server": "1.4.0-beta.1.20.10-preview.23"
1919
}
2020
}

scripts/cps-counter/index.js

-24
This file was deleted.

scripts/cps-counter/index.ts

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Script example for ScriptAPI
2+
// Author: Jayly <https://github.com/JaylyDev>
3+
// Project: https://github.com/JaylyDev/ScriptAPI
4+
import { Player, world } from "@minecraft/server";
5+
6+
interface ClickInfo {
7+
readonly timestamp: number
8+
};
9+
10+
// Using map because typescript doesn't support prototype property declaration properly
11+
const clicks = new Map<Player, ClickInfo[]>();
12+
13+
world.afterEvents.entityHitBlock.subscribe(function ({ damagingEntity }) {
14+
if (!(damagingEntity instanceof Player)) return;
15+
const clickInfo = { timestamp: Date.now() };
16+
const playerClicks = clicks.get(damagingEntity) || [];
17+
playerClicks.push(clickInfo);
18+
clicks.set(damagingEntity, playerClicks);
19+
});
20+
21+
world.afterEvents.entityHitEntity.subscribe(function ({ damagingEntity }) {
22+
if (!(damagingEntity instanceof Player)) return;
23+
const clickInfo = { timestamp: Date.now() };
24+
const playerClicks = clicks.get(damagingEntity) || [];
25+
playerClicks.push(clickInfo);
26+
clicks.set(damagingEntity, playerClicks);
27+
});
28+
29+
/**
30+
* Get a player's clicks per second
31+
* @param player
32+
* @returns
33+
*/
34+
export function getPlayerCPS(player: Player) {
35+
const currentTime = Date.now();
36+
const playerClicks = clicks.get(player) || [];
37+
const recentClicks = playerClicks.filter(({ timestamp }) => currentTime - 1000 < timestamp);
38+
clicks.set(player, recentClicks);
39+
40+
return recentClicks.length;
41+
};

scripts/critical-hit/index.js

+15-27
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
11
// Script example for ScriptAPI
22
// Author: Jayly <https://github.com/JaylyDev>
33
// Project: https://github.com/JaylyDev/ScriptAPI
4-
import { Block, Entity, EntityHitAfterEvent, Player, world } from "@minecraft/server";
4+
import { Block, Entity, EntityHitEntityAfterEvent, Player, world } from "@minecraft/server";
55

66
/**
7-
* @implements {Omit<EntityHitAfterEvent, "entity">}
7+
* @implements {Omit<EntityHitEntityAfterEvent, "damagingEntity">}
88
*/
99
export class EntityCriticalHitAfterEvent {
1010
/**
11-
* @param {Entity} entity
12-
* @param {Block} hitBlock
11+
* @param {Entity} damagingEntity
1312
* @param {Entity} hitEntity
1413
*/
15-
constructor(entity, hitBlock, hitEntity) {
16-
if (!(entity instanceof Player)) {
17-
console.log("Failed to call function EntityCriticalHitAfterEvent, entity is not a player");
14+
constructor(damagingEntity, hitEntity) {
15+
if (!(damagingEntity instanceof Player)) {
16+
console.log("Failed to call function EntityCriticalHitAfterEvent, damagingEntity is not a player");
1817
return;
1918
};
2019

21-
this.player = entity;
22-
this.hitBlock = hitBlock;
20+
this.player = damagingEntity;
2321
this.hitEntity = hitEntity;
2422
};
2523
/**
@@ -29,21 +27,11 @@ export class EntityCriticalHitAfterEvent {
2927
* @type {Player}
3028
*/
3129
player;
32-
/**
33-
* @remarks
34-
* Block that was hit by the attack, or undefined if the hit
35-
* attack did not hit a block. If both hitEntity and hitBlock
36-
* are undefined, then the entity basically swiped into the
37-
* air.
38-
* @readonly
39-
* @type {Block | undefined}
40-
*/
41-
hitBlock;
4230
/**
4331
* @remarks
4432
* Entity that was hit by the attack, or undefined if the hit
45-
* attack did not hit an entity. If both hitEntity and hitBlock
46-
* are undefined, then the entity basically swiped into the
33+
* attack did not hit an damagingEntity. If both hitEntity and hitBlock
34+
* are undefined, then the damagingEntity basically swiped into the
4735
* air.
4836
* @readonly
4937
* @type {Entity | undefined}
@@ -73,17 +61,17 @@ export class EntityCriticalHitAfterEventSignal {
7361
}
7462
/**
7563
* @private
76-
* @param {EntityHitAfterEvent} event
64+
* @param {EntityHitEntityAfterEvent} event
7765
*/
7866
trigger(event) {
79-
this.handlers.forEach((callback) => callback(new EntityCriticalHitAfterEvent(event.entity, event.hitBlock, event.hitEntity)));
67+
this.handlers.forEach((callback) => callback(new EntityCriticalHitAfterEvent(event.damagingEntity, event.hitEntity)));
8068
}
8169
constructor() {
82-
world.afterEvents.entityHit.subscribe((event) => {
83-
// checks if entity has a critical hit and is a player
84-
if (event.entity instanceof Player && !!event.hitEntity && event.entity.getVelocity().y !== 0) this.trigger(event);
70+
world.afterEvents.entityHitEntity.subscribe((event) => {
71+
// checks if damagingEntity has a critical hit and is a player
72+
if (event.damagingEntity instanceof Player && !!event.hitEntity && event.damagingEntity.getVelocity().y !== 0) this.trigger(event);
8573
});
8674
}
8775
}
8876

89-
export const entityCriticalHit = new EntityCriticalHitAfterEventSignal();
77+
export const damagingEntityCriticalHit = new EntityCriticalHitAfterEventSignal();

scripts/dimension-entities/index.js

+15-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
1+
// Script example for ScriptAPI
2+
// Author: Jayly#1397 <Jayly Discord>
3+
// Project: https://github.com/JaylyDev/ScriptAPI
14
import { Dimension, world } from "@minecraft/server";
25

36
/**
47
* Get entities that are in specific dimension
58
* @param {Dimension} dimension
6-
* @param {import("@minecraft/server").EntityQueryOptions} [getEntities]
9+
* @param {import("@minecraft/server").EntityQueryOptions} [options]
710
*/
8-
export function getEntities(dimension, getEntities) {
9-
return [...dimension.getEntities(getEntities)].filter((entity) => entity.dimension === dimension);
11+
export function getEntities(dimension, options) {
12+
const mergedOptions = {
13+
minDistance: 0,
14+
...(typeof options.minDistance !== 'undefined' ? { minDistance: options.minDistance } : {})
15+
};
16+
return dimension.getEntities(mergedOptions);
1017
};
1118

1219
/**
@@ -15,5 +22,9 @@ export function getEntities(dimension, getEntities) {
1522
* @param {import("@minecraft/server").EntityQueryOptions} [options]
1623
*/
1724
export function getPlayers(dimension, options) {
18-
return [...world.getPlayers(options)].filter((player) => player.dimension === dimension);
25+
const mergedOptions = {
26+
minDistance: 0,
27+
...(typeof options.minDistance !== 'undefined' ? { minDistance: options.minDistance } : {})
28+
};
29+
return dimension.getPlayers(mergedOptions);
1930
};

scripts/dimension-entities/tests.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import { GameMode, MinecraftEffectTypes, world } from "@minecraft/server";
1+
import { GameMode, world } from "@minecraft/server";
22
import { getEntities, getPlayers } from "dimension-entities/index";
3+
import { MinecraftEffectTypes } from "@minecraft/vanilla-data";
34

45
const overworldEntities = getEntities(world.getDimension('overworld'));
56

67
for (const entity of overworldEntities) {
7-
entity.addEffect(MinecraftEffectTypes.absorption, 10);
8+
entity.addEffect(MinecraftEffectTypes.Absorption, 10);
89
};
910

1011
const netherCreativePlayers = getPlayers(world.getDimension('nether'), {

scripts/editor-extensions/Extensions/Actions/NightVision/Start.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as Server from "@minecraft/server";
22
import * as Editor from "@minecraft/server-editor";
3+
import { MinecraftEffectTypes } from "@minecraft/vanilla-data";
34
/**
45
* @param {import("@minecraft/server-editor").IPlayerUISession} uiSession
56
*/
@@ -13,7 +14,7 @@ export const Start = (uiSession) => {
1314
uiSession.actionManager.createAction(
1415
{
1516
actionType: Editor.ActionTypes.NoArgsAction,
16-
onExecute: () => uiSession.extensionContext.player.addEffect( Server.MinecraftEffectTypes.nightVision, 20000000, { amplifier: 1, showParticles: false } ),
17+
onExecute: () => uiSession.extensionContext.player.addEffect( MinecraftEffectTypes.NightVision, 20000000, { amplifier: 1, showParticles: false } ),
1718
},
1819
),
1920
);
@@ -23,7 +24,7 @@ export const Start = (uiSession) => {
2324
uiSession.actionManager.createAction(
2425
{
2526
actionType: Editor.ActionTypes.NoArgsAction,
26-
onExecute: () => uiSession.extensionContext.player.removeEffect( Server.MinecraftEffectTypes.nightVision ),
27+
onExecute: () => uiSession.extensionContext.player.removeEffect( MinecraftEffectTypes.NightVision ),
2728
},
2829
),
2930
);

scripts/editor-fullbright/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Author: Jayly <https://github.com/JaylyDev>
33
// Project: https://github.com/JaylyDev/ScriptAPI
44
import { ActionTypes, EditorInputContext, IMenu, InputModifier, IPlayerUISession, KeyboardKey } from "@minecraft/server-editor";
5-
import { MinecraftEffectTypes } from "@minecraft/server";
5+
import { MinecraftEffectTypes } from "@minecraft/vanilla-data";
66

77
/**
88
* Class to enable toggles for full bright in menu in editor mode
@@ -14,13 +14,13 @@ export class FullbrightToggle {
1414
const enableAction = uiSession.actionManager.createAction({
1515
actionType: ActionTypes.NoArgsAction,
1616
onExecute: () => {
17-
player.addEffect(MinecraftEffectTypes.nightVision, 20000000, { amplifier: 1, showParticles: false });
17+
player.addEffect(MinecraftEffectTypes.NightVision, 20000000, { amplifier: 1, showParticles: false });
1818
},
1919
});
2020
const disableAction = uiSession.actionManager.createAction({
2121
actionType: ActionTypes.NoArgsAction,
2222
onExecute: () => {
23-
player.runCommand("effect @s " + MinecraftEffectTypes.nightVision.getName() + " 0");
23+
player.removeEffect(MinecraftEffectTypes.NightVision);
2424
},
2525
});
2626
// Add actions to menu

scripts/entity-hit/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
// Project: https://github.com/JaylyDev/ScriptAPI
44
import { EntityHealthComponent, world } from "@minecraft/server";
55

6-
world.afterEvents.entityHit.subscribe((evd) => {
7-
if (evd.entity.typeId !== 'minecraft:player') return;
6+
world.afterEvents.entityHitEntity.subscribe((evd) => {
7+
if (evd.damagingEntity.typeId !== 'minecraft:player') return;
88

99
const ent = evd.hitEntity;
1010
if (!ent) return;

0 commit comments

Comments
 (0)