kustom-mc 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +809 -0
- package/dist/commands/build.d.ts +2 -0
- package/dist/commands/build.js +447 -0
- package/dist/commands/bundle.d.ts +2 -0
- package/dist/commands/bundle.js +134 -0
- package/dist/commands/init.d.ts +2 -0
- package/dist/commands/init.js +219 -0
- package/dist/commands/list.d.ts +10 -0
- package/dist/commands/list.js +167 -0
- package/dist/commands/login.d.ts +9 -0
- package/dist/commands/login.js +167 -0
- package/dist/commands/new.d.ts +2 -0
- package/dist/commands/new.js +132 -0
- package/dist/commands/prepare.d.ts +9 -0
- package/dist/commands/prepare.js +267 -0
- package/dist/commands/push.d.ts +9 -0
- package/dist/commands/push.js +205 -0
- package/dist/commands/validate.d.ts +2 -0
- package/dist/commands/validate.js +191 -0
- package/dist/compiler/async-transform.d.ts +21 -0
- package/dist/compiler/async-transform.js +158 -0
- package/dist/compiler/inline.d.ts +32 -0
- package/dist/compiler/inline.js +87 -0
- package/dist/compiler/postprocess.d.ts +19 -0
- package/dist/compiler/postprocess.js +134 -0
- package/dist/compiler/rhino-plugin.d.ts +17 -0
- package/dist/compiler/rhino-plugin.js +324 -0
- package/dist/compiler/transform.d.ts +18 -0
- package/dist/compiler/transform.js +59 -0
- package/dist/config.d.ts +86 -0
- package/dist/config.js +166 -0
- package/dist/credentials.d.ts +65 -0
- package/dist/credentials.js +136 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +28 -0
- package/dist/runtime.d.ts +116 -0
- package/dist/runtime.js +96 -0
- package/dist/types/globals.d.ts +80 -0
- package/dist/types/globals.js +10 -0
- package/dist/types/index.d.ts +2094 -0
- package/dist/types/index.js +9 -0
- package/package.json +57 -0
- package/templates/project/kustom.config.json +26 -0
- package/templates/project/scripts/example.ts +17 -0
- package/templates/project/scripts/lib/utils.ts +19 -0
- package/templates/project/tsconfig.json +27 -0
- package/templates/scripts/block.ts.hbs +14 -0
- package/templates/scripts/gui.ts.hbs +28 -0
- package/templates/scripts/item.ts.hbs +13 -0
- package/templates/scripts/script.ts.hbs +18 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server credentials stored in ~/.kustom/credentials.json
|
|
3
|
+
*/
|
|
4
|
+
export interface ServerCredential {
|
|
5
|
+
token: string;
|
|
6
|
+
playerName?: string;
|
|
7
|
+
savedAt: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Credentials file structure
|
|
11
|
+
*/
|
|
12
|
+
export interface Credentials {
|
|
13
|
+
servers: {
|
|
14
|
+
[serverUrl: string]: ServerCredential;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Get the path to the credentials file.
|
|
19
|
+
* ~/.kustom/credentials.json on Unix
|
|
20
|
+
* %USERPROFILE%\.kustom\credentials.json on Windows
|
|
21
|
+
*/
|
|
22
|
+
export declare function getCredentialsPath(): string;
|
|
23
|
+
/**
|
|
24
|
+
* Get the path to the .kustom directory in user's home.
|
|
25
|
+
*/
|
|
26
|
+
export declare function getKustomHomeDir(): string;
|
|
27
|
+
/**
|
|
28
|
+
* Ensure the .kustom directory exists.
|
|
29
|
+
*/
|
|
30
|
+
export declare function ensureKustomDir(): void;
|
|
31
|
+
/**
|
|
32
|
+
* Load credentials from file.
|
|
33
|
+
* Returns empty credentials if file doesn't exist.
|
|
34
|
+
*/
|
|
35
|
+
export declare function loadCredentials(): Credentials;
|
|
36
|
+
/**
|
|
37
|
+
* Save credentials to file.
|
|
38
|
+
*/
|
|
39
|
+
export declare function saveCredentials(creds: Credentials): void;
|
|
40
|
+
/**
|
|
41
|
+
* Get the token for a server URL.
|
|
42
|
+
* Returns null if no token is stored.
|
|
43
|
+
*/
|
|
44
|
+
export declare function getServerToken(serverUrl: string): string | null;
|
|
45
|
+
/**
|
|
46
|
+
* Get the full credentials for a server URL.
|
|
47
|
+
*/
|
|
48
|
+
export declare function getServerCredential(serverUrl: string): ServerCredential | null;
|
|
49
|
+
/**
|
|
50
|
+
* Save a token for a server URL.
|
|
51
|
+
*/
|
|
52
|
+
export declare function saveServerToken(serverUrl: string, token: string, playerName?: string): void;
|
|
53
|
+
/**
|
|
54
|
+
* Remove credentials for a server URL.
|
|
55
|
+
*/
|
|
56
|
+
export declare function removeServerCredential(serverUrl: string): boolean;
|
|
57
|
+
/**
|
|
58
|
+
* List all stored server URLs.
|
|
59
|
+
*/
|
|
60
|
+
export declare function listStoredServers(): string[];
|
|
61
|
+
/**
|
|
62
|
+
* Normalize a server URL for consistent storage.
|
|
63
|
+
* Removes trailing slashes, ensures protocol.
|
|
64
|
+
*/
|
|
65
|
+
export declare function normalizeServerUrl(url: string): string;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import * as os from 'os';
|
|
4
|
+
/**
|
|
5
|
+
* Get the path to the credentials file.
|
|
6
|
+
* ~/.kustom/credentials.json on Unix
|
|
7
|
+
* %USERPROFILE%\.kustom\credentials.json on Windows
|
|
8
|
+
*/
|
|
9
|
+
export function getCredentialsPath() {
|
|
10
|
+
const homeDir = os.homedir();
|
|
11
|
+
return path.join(homeDir, '.kustom', 'credentials.json');
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Get the path to the .kustom directory in user's home.
|
|
15
|
+
*/
|
|
16
|
+
export function getKustomHomeDir() {
|
|
17
|
+
return path.join(os.homedir(), '.kustom');
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Ensure the .kustom directory exists.
|
|
21
|
+
*/
|
|
22
|
+
export function ensureKustomDir() {
|
|
23
|
+
const dir = getKustomHomeDir();
|
|
24
|
+
if (!fs.existsSync(dir)) {
|
|
25
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Load credentials from file.
|
|
30
|
+
* Returns empty credentials if file doesn't exist.
|
|
31
|
+
*/
|
|
32
|
+
export function loadCredentials() {
|
|
33
|
+
const credPath = getCredentialsPath();
|
|
34
|
+
if (!fs.existsSync(credPath)) {
|
|
35
|
+
return { servers: {} };
|
|
36
|
+
}
|
|
37
|
+
try {
|
|
38
|
+
const content = fs.readFileSync(credPath, 'utf-8');
|
|
39
|
+
const creds = JSON.parse(content);
|
|
40
|
+
// Ensure servers object exists
|
|
41
|
+
if (!creds.servers) {
|
|
42
|
+
creds.servers = {};
|
|
43
|
+
}
|
|
44
|
+
return creds;
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
console.warn(`Warning: Could not parse credentials file: ${error}`);
|
|
48
|
+
return { servers: {} };
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Save credentials to file.
|
|
53
|
+
*/
|
|
54
|
+
export function saveCredentials(creds) {
|
|
55
|
+
ensureKustomDir();
|
|
56
|
+
const credPath = getCredentialsPath();
|
|
57
|
+
const content = JSON.stringify(creds, null, 2);
|
|
58
|
+
fs.writeFileSync(credPath, content, 'utf-8');
|
|
59
|
+
// Set restrictive permissions on Unix systems
|
|
60
|
+
if (process.platform !== 'win32') {
|
|
61
|
+
try {
|
|
62
|
+
fs.chmodSync(credPath, 0o600);
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
// Ignore permission errors
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Get the token for a server URL.
|
|
71
|
+
* Returns null if no token is stored.
|
|
72
|
+
*/
|
|
73
|
+
export function getServerToken(serverUrl) {
|
|
74
|
+
const creds = loadCredentials();
|
|
75
|
+
const normalizedUrl = normalizeServerUrl(serverUrl);
|
|
76
|
+
const serverCred = creds.servers[normalizedUrl];
|
|
77
|
+
if (!serverCred) {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
return serverCred.token;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Get the full credentials for a server URL.
|
|
84
|
+
*/
|
|
85
|
+
export function getServerCredential(serverUrl) {
|
|
86
|
+
const creds = loadCredentials();
|
|
87
|
+
const normalizedUrl = normalizeServerUrl(serverUrl);
|
|
88
|
+
return creds.servers[normalizedUrl] || null;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Save a token for a server URL.
|
|
92
|
+
*/
|
|
93
|
+
export function saveServerToken(serverUrl, token, playerName) {
|
|
94
|
+
const creds = loadCredentials();
|
|
95
|
+
const normalizedUrl = normalizeServerUrl(serverUrl);
|
|
96
|
+
creds.servers[normalizedUrl] = {
|
|
97
|
+
token,
|
|
98
|
+
playerName,
|
|
99
|
+
savedAt: new Date().toISOString()
|
|
100
|
+
};
|
|
101
|
+
saveCredentials(creds);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Remove credentials for a server URL.
|
|
105
|
+
*/
|
|
106
|
+
export function removeServerCredential(serverUrl) {
|
|
107
|
+
const creds = loadCredentials();
|
|
108
|
+
const normalizedUrl = normalizeServerUrl(serverUrl);
|
|
109
|
+
if (creds.servers[normalizedUrl]) {
|
|
110
|
+
delete creds.servers[normalizedUrl];
|
|
111
|
+
saveCredentials(creds);
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* List all stored server URLs.
|
|
118
|
+
*/
|
|
119
|
+
export function listStoredServers() {
|
|
120
|
+
const creds = loadCredentials();
|
|
121
|
+
return Object.keys(creds.servers);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Normalize a server URL for consistent storage.
|
|
125
|
+
* Removes trailing slashes, ensures protocol.
|
|
126
|
+
*/
|
|
127
|
+
export function normalizeServerUrl(url) {
|
|
128
|
+
let normalized = url.trim();
|
|
129
|
+
// Add http:// if no protocol
|
|
130
|
+
if (!normalized.startsWith('http://') && !normalized.startsWith('https://')) {
|
|
131
|
+
normalized = 'http://' + normalized;
|
|
132
|
+
}
|
|
133
|
+
// Remove trailing slash
|
|
134
|
+
normalized = normalized.replace(/\/+$/, '');
|
|
135
|
+
return normalized;
|
|
136
|
+
}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Command } from 'commander';
|
|
3
|
+
import { initCommand } from './commands/init.js';
|
|
4
|
+
import { buildCommand } from './commands/build.js';
|
|
5
|
+
import { bundleCommand } from './commands/bundle.js';
|
|
6
|
+
import { validateCommand } from './commands/validate.js';
|
|
7
|
+
import { newCommand } from './commands/new.js';
|
|
8
|
+
import { prepareCommand } from './commands/prepare.js';
|
|
9
|
+
import { loginCommand } from './commands/login.js';
|
|
10
|
+
import { listCommand } from './commands/list.js';
|
|
11
|
+
import { pushCommand } from './commands/push.js';
|
|
12
|
+
const program = new Command();
|
|
13
|
+
program
|
|
14
|
+
.name('kustom')
|
|
15
|
+
.description('CLI for kustompack development with TypeScript support')
|
|
16
|
+
.version('0.1.0');
|
|
17
|
+
// Build commands
|
|
18
|
+
program.addCommand(initCommand);
|
|
19
|
+
program.addCommand(buildCommand);
|
|
20
|
+
program.addCommand(bundleCommand);
|
|
21
|
+
program.addCommand(validateCommand);
|
|
22
|
+
program.addCommand(newCommand);
|
|
23
|
+
program.addCommand(prepareCommand);
|
|
24
|
+
// Registry commands
|
|
25
|
+
program.addCommand(loginCommand);
|
|
26
|
+
program.addCommand(listCommand);
|
|
27
|
+
program.addCommand(pushCommand);
|
|
28
|
+
program.parse();
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime exports for kustom-mc.
|
|
3
|
+
* These are used at compile time for type checking and at runtime (after build)
|
|
4
|
+
* for structure.
|
|
5
|
+
*
|
|
6
|
+
* Note: The define* functions are no-op passthroughs - they exist only for
|
|
7
|
+
* type safety during development. At build time, they are transformed to
|
|
8
|
+
* plain objects with __type property injected.
|
|
9
|
+
*/
|
|
10
|
+
import './types/globals.js';
|
|
11
|
+
import type { ScriptConfig, ExportedScript, PropSchema, EventSchema, EmptyEventSchema, BlockConfig, BlockDefinition, ItemConfig, ItemDefinition, ScreenConstructor, ContainerConstructor, ElementFactory, ScriptableLocationFactory, PropsAPI, CellStateUtils } from './types/index.js';
|
|
12
|
+
/**
|
|
13
|
+
* Screen constructor - create new screens for GUIs.
|
|
14
|
+
* Actual value is injected by Java at runtime.
|
|
15
|
+
* Build system strips imports, resolving to Java-injected global.
|
|
16
|
+
*/
|
|
17
|
+
export declare const Screen: ScreenConstructor;
|
|
18
|
+
/**
|
|
19
|
+
* Container constructor - create child containers within screens.
|
|
20
|
+
* Actual value is injected by Java at runtime.
|
|
21
|
+
*/
|
|
22
|
+
export declare const Container: ContainerConstructor;
|
|
23
|
+
/**
|
|
24
|
+
* Element factory - create GUI elements (buttons, items, slots, covers).
|
|
25
|
+
* Actual value is injected by Java at runtime.
|
|
26
|
+
*/
|
|
27
|
+
export declare const Element: ElementFactory;
|
|
28
|
+
/**
|
|
29
|
+
* Props factory - create property type definitions for scripts.
|
|
30
|
+
* Actual value is injected by Java at runtime.
|
|
31
|
+
*/
|
|
32
|
+
export declare const Props: PropsAPI;
|
|
33
|
+
/**
|
|
34
|
+
* CellState utility - slot state management constants and helpers.
|
|
35
|
+
* Actual value is injected by Java at runtime.
|
|
36
|
+
*/
|
|
37
|
+
export declare const CellState: CellStateUtils;
|
|
38
|
+
/**
|
|
39
|
+
* ScriptableLocation factory - create location objects.
|
|
40
|
+
* Actual value is injected by Java at runtime.
|
|
41
|
+
*/
|
|
42
|
+
export declare const ScriptableLocation: ScriptableLocationFactory;
|
|
43
|
+
/**
|
|
44
|
+
* Define a kustom script with type safety.
|
|
45
|
+
*
|
|
46
|
+
* This is a type-only helper that returns its input unchanged.
|
|
47
|
+
* The Java ProcessManager extracts the `run` function and calls it
|
|
48
|
+
* with the ScriptContext.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* import { defineScript, Props } from 'kustom-mc';
|
|
52
|
+
*
|
|
53
|
+
* export default defineScript({
|
|
54
|
+
* props: {
|
|
55
|
+
* player: Props.String(),
|
|
56
|
+
* message: Props.String("Hello!"),
|
|
57
|
+
* },
|
|
58
|
+
* events: {
|
|
59
|
+
* onSuccess: Props.Boolean(),
|
|
60
|
+
* onError: Props.String(),
|
|
61
|
+
* },
|
|
62
|
+
* run({ process, props }) {
|
|
63
|
+
* const player = process.getPlayer(props.player);
|
|
64
|
+
* player.sendMessage(props.message);
|
|
65
|
+
* process.emit("onSuccess", true); // Typed!
|
|
66
|
+
* }
|
|
67
|
+
* });
|
|
68
|
+
*/
|
|
69
|
+
export declare function defineScript<P extends PropSchema = Record<string, never>, E extends EventSchema = EmptyEventSchema>(config: ScriptConfig<P, E>): ExportedScript<P, E>;
|
|
70
|
+
/**
|
|
71
|
+
* Define a custom block with type safety.
|
|
72
|
+
*
|
|
73
|
+
* Blocks are registered with the ShaperRegistry and can have collision,
|
|
74
|
+
* auto-place items, and event handlers.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* import { defineBlock } from 'kustom-mc';
|
|
78
|
+
*
|
|
79
|
+
* export default defineBlock({
|
|
80
|
+
* id: "tower",
|
|
81
|
+
* model: "kustom:block/tower",
|
|
82
|
+
* collision: "full",
|
|
83
|
+
* autoPlace: true,
|
|
84
|
+
*
|
|
85
|
+
* onClick(event) {
|
|
86
|
+
* event.player.sendMessage("You clicked the tower!");
|
|
87
|
+
* },
|
|
88
|
+
*
|
|
89
|
+
* onBreak(event) {
|
|
90
|
+
* event.player.sendMessage("Tower destroyed!");
|
|
91
|
+
* }
|
|
92
|
+
* });
|
|
93
|
+
*/
|
|
94
|
+
export declare function defineBlock(config: BlockConfig): BlockDefinition;
|
|
95
|
+
/**
|
|
96
|
+
* Define a custom item with type safety.
|
|
97
|
+
*
|
|
98
|
+
* Items are registered with the CustomItemRegistry and can have
|
|
99
|
+
* custom models, display names, and event handlers.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* import { defineItem } from 'kustom-mc';
|
|
103
|
+
*
|
|
104
|
+
* export default defineItem({
|
|
105
|
+
* id: "magic_wand",
|
|
106
|
+
* material: "STICK",
|
|
107
|
+
* model: "kustom:item/magic_wand",
|
|
108
|
+
* displayName: "<gold>Magic Wand",
|
|
109
|
+
*
|
|
110
|
+
* onRightClick(event) {
|
|
111
|
+
* event.player.sendMessage("Zap!");
|
|
112
|
+
* }
|
|
113
|
+
* });
|
|
114
|
+
*/
|
|
115
|
+
export declare function defineItem(config: ItemConfig): ItemDefinition;
|
|
116
|
+
export type { ScriptConfig, ScriptDefinition, ExportedScript, ScriptContext, PropSchema, PropAPI, InferProps, PropsAPI, EventSchema, EmptyEventSchema, InferEventPayload, ScriptModule, ScriptProcess, TypedScriptProcess, InferScriptModule, McModuleAPI, TypedMcModuleAPI, ProcessExecutorAPI, CameraAPI, SessionAPI, ChatGUIAPI, CommandManager, BetterModelEntityAPI, ShaperAPI, ItemAPI, DefinitionBuilder, ScriptablePlayer, BlockConfig, BlockDefinition, BlockClickEvent, BlockBreakEvent, BlockPlaceEvent, ItemConfig, ItemDefinition, ScreenConstructor, ContainerConstructor, ElementFactory, ScriptableLocationFactory, CellStateUtils, } from './types/index.js';
|
package/dist/runtime.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime exports for kustom-mc.
|
|
3
|
+
* These are used at compile time for type checking and at runtime (after build)
|
|
4
|
+
* for structure.
|
|
5
|
+
*
|
|
6
|
+
* Note: The define* functions are no-op passthroughs - they exist only for
|
|
7
|
+
* type safety during development. At build time, they are transformed to
|
|
8
|
+
* plain objects with __type property injected.
|
|
9
|
+
*/
|
|
10
|
+
// Import globals for side effects - makes console, setTimeout, etc. available
|
|
11
|
+
import './types/globals.js';
|
|
12
|
+
/**
|
|
13
|
+
* Define a kustom script with type safety.
|
|
14
|
+
*
|
|
15
|
+
* This is a type-only helper that returns its input unchanged.
|
|
16
|
+
* The Java ProcessManager extracts the `run` function and calls it
|
|
17
|
+
* with the ScriptContext.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* import { defineScript, Props } from 'kustom-mc';
|
|
21
|
+
*
|
|
22
|
+
* export default defineScript({
|
|
23
|
+
* props: {
|
|
24
|
+
* player: Props.String(),
|
|
25
|
+
* message: Props.String("Hello!"),
|
|
26
|
+
* },
|
|
27
|
+
* events: {
|
|
28
|
+
* onSuccess: Props.Boolean(),
|
|
29
|
+
* onError: Props.String(),
|
|
30
|
+
* },
|
|
31
|
+
* run({ process, props }) {
|
|
32
|
+
* const player = process.getPlayer(props.player);
|
|
33
|
+
* player.sendMessage(props.message);
|
|
34
|
+
* process.emit("onSuccess", true); // Typed!
|
|
35
|
+
* }
|
|
36
|
+
* });
|
|
37
|
+
*/
|
|
38
|
+
export function defineScript(config) {
|
|
39
|
+
// Simply return the config - the Java side will handle execution
|
|
40
|
+
// The return type is ExportedScript which combines:
|
|
41
|
+
// - Definition metadata (props, events, __type) for the Java runtime
|
|
42
|
+
// - ScriptModule interface with .run(props) method for TypeScript imports
|
|
43
|
+
return config;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Define a custom block with type safety.
|
|
47
|
+
*
|
|
48
|
+
* Blocks are registered with the ShaperRegistry and can have collision,
|
|
49
|
+
* auto-place items, and event handlers.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* import { defineBlock } from 'kustom-mc';
|
|
53
|
+
*
|
|
54
|
+
* export default defineBlock({
|
|
55
|
+
* id: "tower",
|
|
56
|
+
* model: "kustom:block/tower",
|
|
57
|
+
* collision: "full",
|
|
58
|
+
* autoPlace: true,
|
|
59
|
+
*
|
|
60
|
+
* onClick(event) {
|
|
61
|
+
* event.player.sendMessage("You clicked the tower!");
|
|
62
|
+
* },
|
|
63
|
+
*
|
|
64
|
+
* onBreak(event) {
|
|
65
|
+
* event.player.sendMessage("Tower destroyed!");
|
|
66
|
+
* }
|
|
67
|
+
* });
|
|
68
|
+
*/
|
|
69
|
+
export function defineBlock(config) {
|
|
70
|
+
// Simply return the config - the Java side will handle registration
|
|
71
|
+
return config;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Define a custom item with type safety.
|
|
75
|
+
*
|
|
76
|
+
* Items are registered with the CustomItemRegistry and can have
|
|
77
|
+
* custom models, display names, and event handlers.
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* import { defineItem } from 'kustom-mc';
|
|
81
|
+
*
|
|
82
|
+
* export default defineItem({
|
|
83
|
+
* id: "magic_wand",
|
|
84
|
+
* material: "STICK",
|
|
85
|
+
* model: "kustom:item/magic_wand",
|
|
86
|
+
* displayName: "<gold>Magic Wand",
|
|
87
|
+
*
|
|
88
|
+
* onRightClick(event) {
|
|
89
|
+
* event.player.sendMessage("Zap!");
|
|
90
|
+
* }
|
|
91
|
+
* });
|
|
92
|
+
*/
|
|
93
|
+
export function defineItem(config) {
|
|
94
|
+
// Simply return the config - the Java side will handle registration
|
|
95
|
+
return config;
|
|
96
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Global type declarations for the Rhino JavaScript runtime.
|
|
3
|
+
* These types are available in all kustom scripts without needing to import them.
|
|
4
|
+
*
|
|
5
|
+
* Note: This file provides minimal declarations that don't conflict with @types/node or DOM libs.
|
|
6
|
+
*
|
|
7
|
+
* The playSound() function is declared in dist/types/index.d.ts generated by `kustom prepare`,
|
|
8
|
+
* which provides project-specific sound autocomplete.
|
|
9
|
+
*/
|
|
10
|
+
declare global {
|
|
11
|
+
interface Console {
|
|
12
|
+
/** Log a message to the server console */
|
|
13
|
+
log(...data: unknown[]): void;
|
|
14
|
+
/** Log a warning message */
|
|
15
|
+
warn(...data: unknown[]): void;
|
|
16
|
+
/** Log an error message */
|
|
17
|
+
error(...data: unknown[]): void;
|
|
18
|
+
/** Log an info message */
|
|
19
|
+
info(...data: unknown[]): void;
|
|
20
|
+
/** Log a debug message */
|
|
21
|
+
debug(...data: unknown[]): void;
|
|
22
|
+
}
|
|
23
|
+
var console: Console;
|
|
24
|
+
/**
|
|
25
|
+
* Schedule a function to run after a delay.
|
|
26
|
+
* @param handler Function to call
|
|
27
|
+
* @param timeout Delay in milliseconds
|
|
28
|
+
* @returns Timer ID that can be passed to clearTimeout
|
|
29
|
+
*/
|
|
30
|
+
function setTimeout(handler: () => void, timeout?: number): number;
|
|
31
|
+
/**
|
|
32
|
+
* Cancel a timeout previously scheduled with setTimeout.
|
|
33
|
+
* @param id Timer ID returned by setTimeout
|
|
34
|
+
*/
|
|
35
|
+
function clearTimeout(id: number | undefined): void;
|
|
36
|
+
/**
|
|
37
|
+
* Schedule a function to run repeatedly at a fixed interval.
|
|
38
|
+
* @param handler Function to call
|
|
39
|
+
* @param timeout Interval in milliseconds
|
|
40
|
+
* @returns Timer ID that can be passed to clearInterval
|
|
41
|
+
*/
|
|
42
|
+
function setInterval(handler: () => void, timeout?: number): number;
|
|
43
|
+
/**
|
|
44
|
+
* Cancel an interval previously scheduled with setInterval.
|
|
45
|
+
* @param id Timer ID returned by setInterval
|
|
46
|
+
*/
|
|
47
|
+
function clearInterval(id: number | undefined): void;
|
|
48
|
+
/**
|
|
49
|
+
* Returns a Promise that resolves after the specified delay.
|
|
50
|
+
* Use with async/await for readable delays in scripts.
|
|
51
|
+
*
|
|
52
|
+
* @param ms Delay in milliseconds
|
|
53
|
+
* @returns Promise that resolves after the delay
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* async function run() {
|
|
58
|
+
* console.log("Starting...");
|
|
59
|
+
* await delay(1000); // Wait 1 second
|
|
60
|
+
* console.log("Done!");
|
|
61
|
+
* }
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
function delay(ms: number): Promise<void>;
|
|
65
|
+
/**
|
|
66
|
+
* Stop all sounds.
|
|
67
|
+
*
|
|
68
|
+
* @param target Optional - if provided, stops all sounds for that player.
|
|
69
|
+
* If omitted, stops all sounds started by this script.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* // Stop all sounds from this script
|
|
73
|
+
* stopAllSounds();
|
|
74
|
+
*
|
|
75
|
+
* // Stop all sounds for a specific player
|
|
76
|
+
* stopAllSounds(player);
|
|
77
|
+
*/
|
|
78
|
+
function stopAllSounds(target?: unknown): void;
|
|
79
|
+
}
|
|
80
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Global type declarations for the Rhino JavaScript runtime.
|
|
3
|
+
* These types are available in all kustom scripts without needing to import them.
|
|
4
|
+
*
|
|
5
|
+
* Note: This file provides minimal declarations that don't conflict with @types/node or DOM libs.
|
|
6
|
+
*
|
|
7
|
+
* The playSound() function is declared in dist/types/index.d.ts generated by `kustom prepare`,
|
|
8
|
+
* which provides project-specific sound autocomplete.
|
|
9
|
+
*/
|
|
10
|
+
export {};
|