Skip to content

Commit 70f42d3

Browse files
Upload generated files.
1 parent 62c64ff commit 70f42d3

File tree

11 files changed

+316
-5
lines changed

11 files changed

+316
-5
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# editor-random-fill
2+
3+
## Description
4+
5+
6+
## Credits
7+
These scripts were written by [Jayly](https://github.com/JaylyDev)
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
// Script example for ScriptAPI
2+
// Author: Jayly <https://github.com/JaylyDev>
3+
// Project: https://github.com/JaylyDev/ScriptAPI
4+
import { MinecraftBlockTypes, Vector } from "@minecraft/server";
5+
import { registerEditorExtension, CursorControlMode, CursorTargetMode, EditorInputContext, ActionTypes, KeyboardKey, InputModifier, createPaneBindingObject, BlockVolume, SelectionBlockVolumeAction, MouseActionType, MouseInputType, executeLargeOperation } from "@minecraft/server-editor";
6+
import { getRotationCorrectedDirectionVector, Direction } from "editor-utilities/index";
7+
registerEditorExtension('randomFill', (uiSession) => {
8+
const tool = uiSession.toolRail.addTool({
9+
displayString: "Random Fill (CTRL + R)",
10+
tooltip: "Left mouse click or drag-to-paint",
11+
icon: "pack://textures/editor/Select-Fill.png?filtering=point",
12+
});
13+
const currentCursorState = uiSession.extensionContext.cursor.getState();
14+
currentCursorState.color = {
15+
red: 1,
16+
green: 1,
17+
blue: 0,
18+
alpha: 1
19+
};
20+
currentCursorState.controlMode = CursorControlMode.KeyboardAndMouse;
21+
currentCursorState.targetMode = CursorTargetMode.Block;
22+
currentCursorState.visible = true;
23+
const previewSelection = uiSession.extensionContext.selectionManager.createSelection();
24+
previewSelection.visible = true;
25+
previewSelection.borderColor = {
26+
red: 0,
27+
green: 0.5,
28+
blue: 0.5,
29+
alpha: 0.2
30+
};
31+
previewSelection.fillColor = {
32+
red: 0,
33+
green: 0,
34+
blue: 0.5,
35+
alpha: 0.1
36+
};
37+
uiSession.scratchStorage = {
38+
currentCursorState,
39+
previewSelection,
40+
};
41+
tool.onModalToolActivation.subscribe(eventData => {
42+
if (eventData.isActiveTool)
43+
uiSession.extensionContext.cursor.setState(uiSession.scratchStorage.currentCursorState);
44+
});
45+
uiSession.inputManager.registerKeyBinding(EditorInputContext.GlobalToolMode, uiSession.actionManager.createAction({
46+
actionType: ActionTypes.NoArgsAction,
47+
onExecute: () => {
48+
uiSession.toolRail.setSelectedOptionId(tool.id, true);
49+
},
50+
}), KeyboardKey.KEY_R, InputModifier.Control);
51+
const pane = uiSession.createPropertyPane({
52+
titleAltText: "Cube",
53+
});
54+
const settings = createPaneBindingObject(pane, {
55+
size: 3,
56+
hollow: false,
57+
face: false,
58+
blockType: MinecraftBlockTypes.stone,
59+
});
60+
pane.addNumber(settings, "size", {
61+
titleAltText: "Brush Size",
62+
min: 1,
63+
max: 16,
64+
showSlider: true,
65+
});
66+
pane.addBool(settings, "hollow", {
67+
titleAltText: "Hollow",
68+
});
69+
pane.addBool(settings, "face", {
70+
titleAltText: "Face Mode",
71+
onChange: (_obj, _property, _oldValue, _newValue) => {
72+
if (uiSession.scratchStorage === undefined) {
73+
console.error('Cylinder storage was not initialized.');
74+
return;
75+
}
76+
uiSession.scratchStorage.currentCursorState.targetMode = settings.face
77+
? CursorTargetMode.Face
78+
: CursorTargetMode.Block;
79+
uiSession.extensionContext.cursor.setState(uiSession.scratchStorage.currentCursorState);
80+
},
81+
});
82+
pane.addBlockPicker(settings, "blockType", {
83+
titleAltText: "Block Type",
84+
});
85+
tool.bindPropertyPane(pane);
86+
const onExecute = () => {
87+
if (!uiSession.scratchStorage?.previewSelection) {
88+
console.error('Cube storage was not initialized.');
89+
return;
90+
}
91+
;
92+
const previewSelection = uiSession.scratchStorage.previewSelection;
93+
const player = uiSession.extensionContext.player;
94+
const targetBlock = player.dimension.getBlock(uiSession.extensionContext.cursor.position);
95+
if (!targetBlock)
96+
return;
97+
const rotationY = uiSession.extensionContext.player.getRotation().y;
98+
const directionRight = getRotationCorrectedDirectionVector(rotationY, Direction.Right);
99+
const directionForward = getRotationCorrectedDirectionVector(rotationY, Direction.Back);
100+
const relativeDirection = Vector.add(Vector.add(directionRight, directionForward), Vector.up);
101+
const sizeHalf = Math.floor(settings.size / 2);
102+
let fromOffset = Vector.multiply(relativeDirection, -sizeHalf);
103+
const toOffset = Vector.multiply(relativeDirection, settings.size - 1);
104+
const isEven = settings.size % 2 === 0;
105+
if (isEven)
106+
fromOffset = Vector.add(fromOffset, Vector.up);
107+
const location = targetBlock.location;
108+
const from = {
109+
x: location.x + fromOffset.x,
110+
y: location.y + fromOffset.y,
111+
z: location.z + fromOffset.z,
112+
};
113+
const to = { x: from.x + toOffset.x, y: from.y + toOffset.y, z: from.z + toOffset.z };
114+
const blockVolume = new BlockVolume(from, to);
115+
if (uiSession.scratchStorage.lastVolumePlaced?.equals(blockVolume.boundingBox))
116+
return;
117+
previewSelection.pushVolume(SelectionBlockVolumeAction.add, blockVolume);
118+
uiSession.scratchStorage.lastVolumePlaced = blockVolume.boundingBox;
119+
if (settings.hollow &&
120+
blockVolume.boundingBox.spanX > 2 &&
121+
blockVolume.boundingBox.spanY > 2 &&
122+
blockVolume.boundingBox.spanZ > 2) {
123+
const subtractBlockVolume = new BlockVolume({ x: from.x, y: from.y + 1, z: from.z }, { x: to.x, y: to.y - 1, z: to.z });
124+
previewSelection.pushVolume(SelectionBlockVolumeAction.subtract, subtractBlockVolume);
125+
}
126+
;
127+
};
128+
tool.registerMouseButtonBinding(uiSession.actionManager.createAction({
129+
actionType: ActionTypes.MouseRayCastAction,
130+
onExecute: async (mouseRay, mouseProps) => {
131+
if (mouseProps.mouseAction == MouseActionType.LeftButton) {
132+
if (mouseProps.inputType == MouseInputType.ButtonDown) {
133+
uiSession.extensionContext.transactionManager.openTransaction("cylinderTool");
134+
uiSession.scratchStorage.previewSelection.clear();
135+
onExecute();
136+
}
137+
else if (mouseProps.inputType == MouseInputType.ButtonUp) {
138+
const player = uiSession.extensionContext.player;
139+
uiSession.extensionContext.transactionManager.trackBlockChangeSelection(uiSession.scratchStorage.previewSelection);
140+
await executeLargeOperation(uiSession.scratchStorage.previewSelection, blockLocation => {
141+
const block = player.dimension.getBlock(blockLocation);
142+
block.setType(settings.blockType);
143+
}).catch(() => {
144+
uiSession.extensionContext.transactionManager.commitOpenTransaction();
145+
uiSession.scratchStorage?.previewSelection.clear();
146+
}).then(() => {
147+
uiSession.extensionContext.transactionManager.commitOpenTransaction();
148+
uiSession.scratchStorage?.previewSelection.clear();
149+
});
150+
}
151+
;
152+
}
153+
;
154+
},
155+
}));
156+
tool.registerMouseDragBinding(uiSession.actionManager.createAction({
157+
actionType: ActionTypes.MouseRayCastAction,
158+
onExecute: (mouseRay, mouseProps) => {
159+
if (mouseProps.inputType === MouseInputType.Drag)
160+
onExecute();
161+
},
162+
}));
163+
});

scripts/minecraft-language/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9473,7 +9473,7 @@ export const languageKeys = [
94739473
"gathering.info.modal.body.connectFail",
94749474
"gathering.connect.title",
94759475
];
9476-
export class MinecraftLanguageKeys {
9476+
class MinecraftLanguageKeys {
94779477
}
94789478
MinecraftLanguageKeys["accessibility.disableTTS"] = { rawtext: [{ translate: "accessibility.disableTTS", },], };
94799479
MinecraftLanguageKeys["accessibility.enableTTS"] = { rawtext: [{ translate: "accessibility.enableTTS", },], };
@@ -18945,3 +18945,4 @@ MinecraftLanguageKeys["gathering.info.body.liveIsComing"] = { rawtext: [{ transl
1894518945
MinecraftLanguageKeys["gathering.info.modal.title.connectFail"] = { rawtext: [{ translate: "gathering.info.modal.title.connectFail", },], };
1894618946
MinecraftLanguageKeys["gathering.info.modal.body.connectFail"] = { rawtext: [{ translate: "gathering.info.modal.body.connectFail", },], };
1894718947
MinecraftLanguageKeys["gathering.connect.title"] = { rawtext: [{ translate: "gathering.connect.title", },], };
18948+
export { MinecraftLanguageKeys };

scripts/player-impulse/index.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Script example for ScriptAPI
2+
// Author: Usernam#2058 <Jayly Discord>
3+
// Remember M9#8416 <Bedrock Add-Ons>
4+
// SI Silicon <https://github.com/SIsilicon>
5+
// Project: https://github.com/JaylyDev/ScriptAPI
6+
/**
7+
* Workaround to apply impulse vector to the current velocity of the player.
8+
* @param player Only Player class, not Entity.
9+
* @param vector
10+
*/
11+
export function applyImpulse(player, vector) {
12+
const { x, y, z } = vector;
13+
const horizontal = Math.sqrt(x * x + z * z) * 2.0;
14+
const vertical = y < 0.0 ? 0.5 * y : y;
15+
player.applyKnockback(x, z, horizontal, vertical);
16+
}

scripts/player-impulse/tests.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Script example for ScriptAPI
2+
// Author: Usernam#2058 <Jayly Discord>
3+
// Project: https://github.com/JaylyDev/ScriptAPI
4+
import { applyImpulse } from "./index";
5+
import { world } from "@minecraft/server";
6+
const armorStand = [...world.getDimension("overworld").getEntities({ type: 'minecraft:armor_stand' })][0];
7+
const player = world.getAllPlayers()[0];
8+
const vector = { x: 0, y: 2, z: 0 };
9+
armorStand.applyImpulse(vector);
10+
applyImpulse(player, vector);

scripts/player-velocity-fix/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99
import { Player, MinecraftEntityTypes, MinecraftEffectTypes } from "@minecraft/server";
1010
import { Commands } from "../commands/index.js";
11-
import { clearInterval, setInterval } from "../timers/timers.js";
11+
import { clearInterval, setInterval } from "../timers/index.js";
1212
function trunc(x, decimal) {
1313
let y = 10 ** decimal;
1414
return Math.trunc(x * y) / y;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {};

scripts/run-command/index.js

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
// Script example for ScriptAPI
2+
// Author: Jayly <https://github.com/JaylyDev>
3+
// Project: https://github.com/JaylyDev/ScriptAPI
4+
import { world } from "@minecraft/server";
5+
export function displayHelp(target, page = 0, command) {
6+
if (!!command)
7+
return target.runCommand('help ' + command);
8+
else
9+
return target.runCommand('help ' + page);
10+
}
11+
;
12+
export class CameraShake {
13+
/**
14+
* Applies shaking to the players' camera with a specified intensity and duration.
15+
* @param player
16+
* @param intensity
17+
* @param seconds
18+
* @param shakeType
19+
* @returns
20+
*/
21+
applyShake(player, intensity, seconds, shakeType) {
22+
return player.runCommand(`camerashake add @s ${intensity} ${seconds} ${shakeType}`);
23+
}
24+
;
25+
stop(player) {
26+
return player.runCommand(`camerashake stop @s`);
27+
}
28+
;
29+
}
30+
;
31+
/**
32+
* Clones blocks from one region to another.
33+
*/
34+
export class Clone {
35+
basic(begin, end, destination, dimension) {
36+
return dimension.runCommand(`clone ${begin.x} ${begin.y} ${begin.z} ${end.x} ${end.y} ${end.z} ${destination.x} ${destination.y} ${destination.z}`);
37+
}
38+
;
39+
masked(begin, end, destination, dimension, maskMode, cloneMode) {
40+
return dimension.runCommand(`clone ${begin.x} ${begin.y} ${begin.z} ${end.x} ${end.y} ${end.z} ${destination.x} ${destination.y} ${destination.z} ${maskMode} ${cloneMode}`);
41+
}
42+
;
43+
filtered(begin, end, destination, dimension, cloneMode, blockType, properties) {
44+
const blockStates = Object.keys(properties).map(key => `${key}=${properties[key]}`);
45+
return dimension.runCommand(`clone ${begin.x} ${begin.y} ${begin.z} ${end.x} ${end.y} ${end.z} ${destination.x} ${destination.y} ${destination.z} filtered ${cloneMode} ${blockType.id}[${blockStates.toString()}]`);
46+
}
47+
;
48+
}
49+
;
50+
/**
51+
* Locks and unlocks the day-night cycle.
52+
*/
53+
export function dayLock(lock) {
54+
return world.getDimension('overworld').runCommand('daylock ' + lock);
55+
}
56+
;
57+
/**
58+
* Opens NPC dialogue for a player.
59+
*/
60+
export class Dialogue {
61+
open(npc, player, sceneName) {
62+
return npc.runCommand(`dialogue open @s "${player.name}" ${sceneName}`);
63+
}
64+
;
65+
change(npc, player, sceneName) {
66+
return npc.runCommand(`dialogue change @s "${player.name}" ${sceneName}`);
67+
}
68+
;
69+
}
70+
;
71+
export function setDifficulty(difficulty) {
72+
return world.getDimension('overworld').runCommand('difficulty ' + difficulty);
73+
}
74+
/**
75+
* Add or remove fog settings file.
76+
*/
77+
export class Fog {
78+
add(player, fogId) {
79+
player.runCommand(`fog @s add ${fogId}`);
80+
}
81+
;
82+
remove(player, fogId) {
83+
player.runCommand(`fog @s delete ${fogId}`);
84+
}
85+
;
86+
}
87+
;
88+
/**
89+
* Runs commands found in the corresponding function file.
90+
* @param path
91+
*/
92+
export function runMCFunction(path, target) {
93+
target.runCommand('function ' + path);
94+
}
95+
;
96+
/**
97+
* Sets a player's game mode.
98+
* @param player
99+
*/
100+
export function setGameMode(player, gameMode) {
101+
player.runCommand("gamemode " + gameMode);
102+
}
103+
/**
104+
* Sets or queries a game rule value.
105+
* @param gameRule
106+
* @param value
107+
*/
108+
export function setGameRule(gameRule, value) {
109+
world.getDimension("overworld").runCommand(`gamerule ${gameRule} ${value}`);
110+
}
111+
;

scripts/timers/tests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { setTimeout, setImmediate, setInterval, clearImmediate, clearInterval, clearTimeout } from "./timers.js";
1+
import { setTimeout, setImmediate, setInterval, clearImmediate, clearInterval, clearTimeout } from "./index.js";
22
import { world } from "@minecraft/server";
33
function stdout(...data) {
44
return world.getDimension("overworld").runCommandAsync(`say §r` + data.join(" "));

scripts/vector3-polyfill/Vector.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ var _a;
33
* Contains a description of a vector.
44
* @implements {Vector3}
55
*/
6-
export class Vector {
6+
class Vector {
77
/**
88
* @remarks
99
* Creates a new instance of an abstract vector.
@@ -268,3 +268,4 @@ Vector.up = new _a(0, 1, 0);
268268
* @readonly
269269
*/
270270
Vector.zero = new _a(0, 0, 0);
271+
export { Vector };

0 commit comments

Comments
 (0)