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