Skip to content

Commit 5f58d64

Browse files
jayly-botJaylyDev
andauthored
Update Editor API types to 0.3.3 (1.20.0.20) (JaylyDev#205)
* Update setScore, add Modal form wrapper * add health-display * Update index.ts * Update readme & docs * Update README.md * Update index.ts * 0.3.3 * update to types * resolve ExtensionOptionalParameters * Mirror files from DarkGamerYT/Bedrock-Editor-Extension (JaylyDev#206) * Create readme.md * Add files via upload * Fix stuff --------- Co-authored-by: JaylyDev <[email protected]>
1 parent 726e4bc commit 5f58d64

21 files changed

Lines changed: 1624 additions & 485 deletions

File tree

lib/@minecraft/server-editor-bindings/index.d.ts

Lines changed: 31 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -8,51 +8,7 @@
88
* }
99
* ```
1010
*/
11-
import { Color, Player, Vector3 } from "@minecraft/server";
12-
export class BlockVolume {
13-
constructor(a: Vector3, b: Vector3);
14-
contains(other: Vector3): boolean;
15-
offset(other: Vector3): BlockVolume;
16-
intersects(other: BlockVolume): number;
17-
getBlockPositionIterator(): BlockVolumeIterator;
18-
equals(other: BlockVolume): boolean;
19-
boundingBox: BoundingBox;
20-
min: Vector3;
21-
max: Vector3;
22-
volume: number;
23-
}
24-
export enum BlockVolumeIntersection {
25-
disjoint = 0,
26-
contains = 1,
27-
intersects = 2,
28-
}
29-
export class BlockVolumeIterator implements Iterable<BlockVolume> {
30-
protected constructor();
31-
[Symbol.iterator](): Iterator<BlockVolume>;
32-
}
33-
export class BoundingBox {
34-
constructor(
35-
minX: number,
36-
minY: number,
37-
minZ: number,
38-
maxX: number,
39-
maxY: number,
40-
maxZ: number
41-
);
42-
equals(other: BoundingBox): boolean;
43-
fromBlockLocation(a: Vector3, b: Vector3): BoundingBox;
44-
intersects(other: BoundingBox): number;
45-
expand(other: BoundingBox): BoundingBox;
46-
dilate(x: number, y: number, z: number): BoundingBox;
47-
offset(other: Vector3): BoundingBox;
48-
contains(other: Vector3): boolean;
49-
min: Vector3;
50-
max: Vector3;
51-
center: Vector3;
52-
spanX: number;
53-
spanY: number;
54-
spanZ: number;
55-
}
11+
import { BlockLocationIterator, BlockVolume, BoundingBox, Color, CompoundBlockVolumeAction, Player, Vector3 } from "@minecraft/server";
5612
export class ClipboardItem {
5713
protected constructor();
5814
readFromSelection(selection: Selection): void;
@@ -86,14 +42,21 @@ export class ClipboardWriteOptions {
8642
mirror: ClipboardMirrorAxis;
8743
rotation: ClipboardRotation;
8844
}
45+
export interface CursorProperties {
46+
outlineColor: Color;
47+
controlMode: CursorControlMode;
48+
targetMode: CursorTargetMode;
49+
visible: boolean;
50+
fixedModeDistance?: number;
51+
}
8952
export class Cursor {
90-
getState(): CursorState;
91-
setState(state: CursorState): void;
53+
getProperties(): CursorProperties;
54+
setProperties(properties: CursorProperties): void;
55+
getPosition(): Vector3;
9256
moveBy(vector: Vector3): void;
9357
resetToDefaultState(): void;
9458
show(): void;
9559
hide(): void;
96-
position: Vector3;
9760
faceDirection: number;
9861
isVisible: boolean;
9962
}
@@ -103,24 +66,16 @@ export enum CursorControlMode {
10366
KeyboardAndMouse = 2,
10467
Fixed = 3,
10568
}
106-
export class CursorState {
107-
color: Color;
108-
controlMode: CursorControlMode;
109-
targetMode: CursorTargetMode;
110-
visible: boolean;
111-
fixedModeDistance: number;
112-
}
11369
export enum CursorTargetMode {
11470
Block = 0,
11571
Face = 1,
11672
}
11773
export class Extension {
11874
protected constructor();
119-
description: string;
120-
notes: string;
12175
}
12276
export class ExtensionContext {
12377
protected constructor();
78+
extensionName: string;
12479
player: Player;
12580
selectionManager: SelectionManager;
12681
transactionManager: TransactionManager;
@@ -132,32 +87,35 @@ export class MinecraftEditor {
13287
registerExtension_Internal(
13388
extensionName: string,
13489
activationFunction: (context: ExtensionContext) => void,
135-
shutdownFunction: (context: ExtensionContext) => void
90+
shutdownFunction: (context: ExtensionContext) => void,
91+
optionalParameters?: ExtensionOptionalParameters
13692
): Extension;
13793
}
94+
export interface PushVolumeOptions {
95+
action: CompoundBlockVolumeAction,
96+
volume: BlockVolume
97+
}
13898
export class Selection {
13999
protected constructor();
140100
clear(): void;
141-
pushVolume(action: SelectionBlockVolumeAction, volume: BlockVolume): any;
101+
pushVolume(options: PushVolumeOptions): void;
142102
popVolume(): void;
143103
copyFrom(selection: Selection): void;
144-
getBlockPositionIterator(): BlockVolumeIterator;
104+
getBlockLocationIterator(): BlockLocationIterator;
105+
getBoundingBox(): BoundingBox;
145106
moveBy(vector: Vector3): void;
146107
moveTo(vector: Vector3): void;
147-
peekLastVolume: BlockVolume;
148-
boundingBox: BoundingBox;
108+
peekLastVolume(): PushVolumeOptions | undefined;
109+
getFillColor(): Color;
110+
getOutlineColor(): Color;
111+
setFillColor(color: Color): void;
112+
setOutlineColor(color: Color): void;
149113
isEmpty: boolean;
150114
visible: boolean;
151-
fillColor: Color;
152-
borderColor: Color;
153-
}
154-
export enum SelectionBlockVolumeAction {
155-
add = 0,
156-
subtract = 1,
157115
}
158116
export class SelectionManager {
159117
protected constructor();
160-
createSelection(): Selection;
118+
create(): Selection;
161119
selection: Selection;
162120
}
163121
export class TransactionManager {
@@ -176,4 +134,7 @@ export class TransactionManager {
176134
discardOpenTransaction(): void;
177135
}
178136
export const editor: MinecraftEditor;
179-
export const ExtensionOptionalParameters: undefined
137+
export interface ExtensionOptionalParameters {
138+
description?: string;
139+
notes?: string;
140+
}

lib/@minecraft/server-editor/index.d.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@
99
* ```
1010
*/
1111
import { Events, Player, System, Vector3 } from "@minecraft/server";
12-
import {
13-
Extension,
14-
ExtensionContext,
15-
Selection,
16-
} from "@minecraft/server-editor-bindings";
12+
import { Extension, ExtensionContext, Selection, ExtensionOptionalParameters } from "@minecraft/server-editor-bindings";
1713
export * from "@minecraft/server-editor-bindings";
1814

1915
type BedrockEventType = keyof Events;
@@ -690,7 +686,8 @@ export function getLocalizationId(locId: string): string;
690686
export function registerEditorExtension(
691687
extensionName: string,
692688
activationFunction?: (uiSession: PlayerUISession) => void,
693-
shutdownFunction?: (uiSession: PlayerUISession) => void
689+
shutdownFunction?: (uiSession: PlayerUISession) => void,
690+
optionalParameters?: ExtensionOptionalParameters
694691
): Extension;
695692

696693
/**

scripts/editor-extensions/CubeTool.js

Lines changed: 58 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ import * as Server from "@minecraft/server";
22
import * as Editor from "@minecraft/server-editor";
33
import * as EditorUtilities from "editor-utilities/index";
44
import { Color } from "../color/index";
5-
export default function(uiSession) {
5+
/**
6+
* @param {import("@minecraft/server-editor").IPlayerUISession} uiSession
7+
*/
8+
export default (uiSession) => {
69
const tool = uiSession.toolRail.addTool(
710
{
811
displayString: "Cube (CTRL + B)",
@@ -11,26 +14,26 @@ export default function(uiSession) {
1114
},
1215
);
1316

14-
const currentCursorState = uiSession.extensionContext.cursor.getState();
15-
currentCursorState.color = new Color(1, 1, 0, 1);
16-
currentCursorState.controlMode = Editor.CursorControlMode.KeyboardAndMouse;
17-
currentCursorState.targetMode = Editor.CursorTargetMode.Block;
18-
currentCursorState.visible = true;
19-
20-
const previewSelection = uiSession.extensionContext.selectionManager.createSelection();
17+
const previewSelection = uiSession.extensionContext.selectionManager.create();
2118
previewSelection.visible = true;
22-
previewSelection.borderColor = new Color(0, 0.5, 0.5, 0.2);
23-
previewSelection.fillColor = new Color(0, 0, 0.5, 0.1);
19+
previewSelection.setOutlineColor(new Color(0, 0.5, 0.5, 0.2));
20+
previewSelection.setFillColor(new Color(0, 0, 0.5, 0.1));
2421

2522
uiSession.scratchStorage = {
26-
currentCursorState,
23+
currentCursorState: {
24+
outlineColor: new Color(1, 1, 0, 1),
25+
controlMode: Editor.CursorControlMode.KeyboardAndMouse,
26+
targetMode: Editor.CursorTargetMode.Block,
27+
visible: true,
28+
fixedModeDistance: 5
29+
},
2730
previewSelection,
2831
};
2932

3033
tool.onModalToolActivation.subscribe(
3134
eventData => {
3235
if (eventData.isActiveTool)
33-
uiSession.extensionContext.cursor.setState(uiSession.scratchStorage.currentCursorState);
36+
uiSession.extensionContext.cursor.setProperties(uiSession.scratchStorage.currentCursorState);
3437
},
3538
);
3639

@@ -80,19 +83,23 @@ export default function(uiSession) {
8083
titleAltText: "Hollow",
8184
}
8285
);
83-
pane.addBool(settings, "face", {
84-
titleAltText: "Face Mode",
85-
onChange: (_obj, _property, _oldValue, _newValue) => {
86-
if (uiSession.scratchStorage === undefined) {
87-
console.error('Cylinder storage was not initialized.');
88-
return;
89-
}
90-
uiSession.scratchStorage.currentCursorState.targetMode = settings.face
91-
? Editor.CursorTargetMode.Face
92-
: Editor.CursorTargetMode.Block;
93-
uiSession.extensionContext.cursor.setState(uiSession.scratchStorage.currentCursorState);
94-
},
95-
});
86+
pane.addBool(
87+
settings,
88+
"face",
89+
{
90+
titleAltText: "Face Mode",
91+
onChange: (_obj, _property, _oldValue, _newValue) => {
92+
if (uiSession.scratchStorage === undefined) {
93+
console.error('Cube storage was not initialized.');
94+
return;
95+
}
96+
uiSession.scratchStorage.currentCursorState.targetMode = settings.face
97+
? Editor.CursorTargetMode.Face
98+
: Editor.CursorTargetMode.Block;
99+
uiSession.extensionContext.cursor.setProperties(uiSession.scratchStorage.currentCursorState);
100+
},
101+
}
102+
);
96103
pane.addBlockPicker(
97104
settings,
98105
"blockType",
@@ -111,7 +118,7 @@ export default function(uiSession) {
111118

112119
const previewSelection = uiSession.scratchStorage.previewSelection;
113120
const player = uiSession.extensionContext.player;
114-
const targetBlock = player.dimension.getBlock(uiSession.extensionContext.cursor.position);
121+
const targetBlock = player.dimension.getBlock(uiSession.extensionContext.cursor.getPosition());
115122
if (!targetBlock) return;
116123

117124
const rotationY = uiSession.extensionContext.player.getRotation().y;
@@ -131,18 +138,28 @@ export default function(uiSession) {
131138
z: location.z + fromOffset.z,
132139
};
133140
const to = { x: from.x + toOffset.x, y: from.y + toOffset.y, z: from.z + toOffset.z };
134-
const blockVolume = new Editor.BlockVolume(from, to);
141+
const blockVolume = { from, to };
135142

136-
if (uiSession.scratchStorage.lastVolumePlaced?.equals(blockVolume.boundingBox)) return;
143+
if (uiSession.scratchStorage.lastVolumePlaced && Server.BoundingBoxUtils.equals(uiSession.scratchStorage.lastVolumePlaced, Server.BlockVolumeUtils.getBoundingBox(blockVolume))) return;
137144

138-
previewSelection.pushVolume(Editor.SelectionBlockVolumeAction.add, blockVolume);
139-
uiSession.scratchStorage.lastVolumePlaced = blockVolume.boundingBox;
145+
previewSelection.pushVolume(
146+
{
147+
action: Server.CompoundBlockVolumeAction.Add,
148+
volume: blockVolume
149+
}
150+
);
151+
uiSession.scratchStorage.lastVolumePlaced = Server.BlockVolumeUtils.getBoundingBox(blockVolume);
140152
if (settings.hollow &&
141153
blockVolume.boundingBox.spanX > 2 &&
142154
blockVolume.boundingBox.spanY > 2 &&
143155
blockVolume.boundingBox.spanZ > 2) {
144-
const subtractBlockVolume = new Editor.BlockVolume({ x: from.x, y: from.y + 1, z: from.z }, { x: to.x, y: to.y - 1, z: to.z });
145-
previewSelection.pushVolume(Editor.SelectionBlockVolumeAction.subtract, subtractBlockVolume);
156+
const subtractBlockVolume = { from: { x: from.x, y: from.y + 1, z: from.z }, to: { x: to.x, y: to.y - 1, z: to.z } };
157+
previewSelection.pushVolume(
158+
{
159+
action: Server.CompoundBlockVolumeAction.Subtract,
160+
volume: subtractBlockVolume
161+
}
162+
);
146163
};
147164
};
148165

@@ -161,9 +178,15 @@ export default function(uiSession) {
161178

162179
uiSession.extensionContext.transactionManager.trackBlockChangeSelection(uiSession.scratchStorage.previewSelection);
163180
await Editor.executeLargeOperation(uiSession.scratchStorage.previewSelection, blockLocation => {
164-
const block = player.dimension.getBlock(blockLocation);
165-
block.setType(settings.blockType);
166-
}).catch(() => {
181+
if (
182+
blockLocation.y >= -64
183+
&& blockLocation.y <= 320
184+
) {
185+
const block = player.dimension.getBlock(blockLocation);
186+
block.setType(settings.blockType);
187+
};
188+
}).catch((e) => {
189+
console.warn(e);
167190
uiSession.extensionContext.transactionManager.commitOpenTransaction();
168191
uiSession.scratchStorage?.previewSelection.clear();
169192
}).then(() => {

0 commit comments

Comments
 (0)