@starktma/minecraft-utils 1.3.23 → 1.3.25
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/dist/database/database.d.ts +1 -19
- package/dist/database/database.d.ts.map +1 -1
- package/dist/database/database.js +16 -44
- package/dist/database/database.js.map +1 -1
- package/dist/minecraft/effectsAPI.d.ts +82 -0
- package/dist/minecraft/effectsAPI.d.ts.map +1 -0
- package/dist/minecraft/effectsAPI.js +438 -0
- package/dist/minecraft/effectsAPI.js.map +1 -0
- package/dist/minecraft/index.d.ts +4 -0
- package/dist/minecraft/index.d.ts.map +1 -1
- package/dist/minecraft/index.js +4 -0
- package/dist/minecraft/index.js.map +1 -1
- package/dist/minecraft/potionAPI.d.ts +74 -0
- package/dist/minecraft/potionAPI.d.ts.map +1 -0
- package/dist/minecraft/potionAPI.js +228 -0
- package/dist/minecraft/potionAPI.js.map +1 -0
- package/dist/minecraft/projectileAPI.d.ts +61 -0
- package/dist/minecraft/projectileAPI.d.ts.map +1 -0
- package/dist/minecraft/projectileAPI.js +146 -0
- package/dist/minecraft/projectileAPI.js.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { MolangVariableMap, system, world, } from "@minecraft/server";
|
|
2
|
+
// ========================== Utility Functions ================================
|
|
3
|
+
/**
|
|
4
|
+
* Parse effect key from projectile entity type ID
|
|
5
|
+
*/
|
|
6
|
+
export function parseProjectileTypeId(typeId) {
|
|
7
|
+
const parts = typeId.split(":");
|
|
8
|
+
if (parts.length !== 2)
|
|
9
|
+
return null;
|
|
10
|
+
const [namespace, entityName] = parts;
|
|
11
|
+
if (!entityName.endsWith("_potion_entity"))
|
|
12
|
+
return null;
|
|
13
|
+
const effectKey = entityName.replace("_potion_entity", "");
|
|
14
|
+
return { namespace, effectKey };
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Extract RGBA color from entity properties
|
|
18
|
+
*/
|
|
19
|
+
export function getColorFromEntity(entity, namespace) {
|
|
20
|
+
return {
|
|
21
|
+
red: entity.getProperty(`${namespace}:color_r`),
|
|
22
|
+
green: entity.getProperty(`${namespace}:color_g`),
|
|
23
|
+
blue: entity.getProperty(`${namespace}:color_b`),
|
|
24
|
+
alpha: entity.getProperty(`${namespace}:color_a`),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Spawn splash particle effect
|
|
29
|
+
*/
|
|
30
|
+
export function spawnSplashParticle(dimension, location, color, range) {
|
|
31
|
+
const variables = new MolangVariableMap();
|
|
32
|
+
variables.setFloat("splash_range", range);
|
|
33
|
+
variables.setFloat("splash_power", 1);
|
|
34
|
+
variables.setColorRGBA("color", color);
|
|
35
|
+
dimension.spawnParticle("minecraft:splash_spell_emitter", location, variables);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Spawn lingering cloud particle effect
|
|
39
|
+
*/
|
|
40
|
+
export function spawnLingeringParticle(dimension, location, color, radius, maxRadius, lifetime) {
|
|
41
|
+
const variables = new MolangVariableMap();
|
|
42
|
+
variables.setFloat("cloud_lifetime", lifetime / 20);
|
|
43
|
+
variables.setFloat("cloud_radius", radius);
|
|
44
|
+
variables.setFloat("particle_multiplier", radius / maxRadius);
|
|
45
|
+
variables.setColorRGBA("color", color);
|
|
46
|
+
dimension.spawnParticle("minecraft:mobspell_lingering", location, variables);
|
|
47
|
+
}
|
|
48
|
+
// ========================== Potion Manager ===================================
|
|
49
|
+
class PotionManager {
|
|
50
|
+
configs = new Map();
|
|
51
|
+
activeAOEClouds = new Map();
|
|
52
|
+
cloudIdCounter = 0;
|
|
53
|
+
isRunning = false;
|
|
54
|
+
/**
|
|
55
|
+
* Register a potion effect with its configuration and handler
|
|
56
|
+
*/
|
|
57
|
+
registerPotion(config) {
|
|
58
|
+
const key = `${config.namespace}:${config.effectKey}`;
|
|
59
|
+
// Apply defaults
|
|
60
|
+
const fullConfig = {
|
|
61
|
+
splashRange: 4,
|
|
62
|
+
lingeringMaxRadius: 3,
|
|
63
|
+
lingeringLifetime: 600,
|
|
64
|
+
lingeringDurationMultiplier: 0.25,
|
|
65
|
+
...config,
|
|
66
|
+
};
|
|
67
|
+
this.configs.set(key, fullConfig);
|
|
68
|
+
return { handler: config.handler };
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Start the potion system - must be called in beforeEvents.worldInitialize
|
|
72
|
+
*/
|
|
73
|
+
start(startup) {
|
|
74
|
+
if (this.isRunning)
|
|
75
|
+
return;
|
|
76
|
+
this.isRunning = true;
|
|
77
|
+
this.registerCustomComponents(startup);
|
|
78
|
+
this.registerProjectileEvents();
|
|
79
|
+
this.startCloudUpdater();
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Get a registered potion configuration (public method)
|
|
83
|
+
*/
|
|
84
|
+
getConfig(effectKey, namespace) {
|
|
85
|
+
return this.configs.get(`${namespace}:${effectKey}`);
|
|
86
|
+
}
|
|
87
|
+
registerCustomComponents(startup) {
|
|
88
|
+
// Register potion effect components
|
|
89
|
+
for (const [, config] of this.configs.entries()) {
|
|
90
|
+
const componentId = `${config.namespace}:${config.effectKey}_potion_effect`;
|
|
91
|
+
startup.itemComponentRegistry.registerCustomComponent(componentId, {
|
|
92
|
+
onConsume: (event, params) => this.handleConsume(event, params, config),
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
registerProjectileEvents() {
|
|
97
|
+
world.afterEvents.projectileHitBlock.subscribe((event) => {
|
|
98
|
+
this.handleProjectileHit(event.projectile);
|
|
99
|
+
});
|
|
100
|
+
world.afterEvents.projectileHitEntity.subscribe((event) => {
|
|
101
|
+
this.handleProjectileHit(event.projectile);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
startCloudUpdater() {
|
|
105
|
+
system.runInterval(() => {
|
|
106
|
+
for (const cloud of this.activeAOEClouds.values()) {
|
|
107
|
+
this.updateAreaEffectCloud(cloud);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
handleConsume(event, params, config) {
|
|
112
|
+
const itemParams = params.params;
|
|
113
|
+
const color = {
|
|
114
|
+
red: itemParams.potion_color[0],
|
|
115
|
+
green: itemParams.potion_color[1],
|
|
116
|
+
blue: itemParams.potion_color[2],
|
|
117
|
+
alpha: itemParams.potion_color[3],
|
|
118
|
+
};
|
|
119
|
+
config.handler(event.source, itemParams.amplifier, itemParams.duration, color);
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Handle projectile hit (splash or lingering)
|
|
123
|
+
*/
|
|
124
|
+
handleProjectileHit(projectile) {
|
|
125
|
+
const parsed = parseProjectileTypeId(projectile.typeId);
|
|
126
|
+
if (!parsed)
|
|
127
|
+
return;
|
|
128
|
+
const config = this.getConfig(parsed.effectKey, parsed.namespace);
|
|
129
|
+
if (!config)
|
|
130
|
+
return;
|
|
131
|
+
const potionType = projectile.getProperty(`${parsed.namespace}:type`);
|
|
132
|
+
switch (potionType) {
|
|
133
|
+
case 1:
|
|
134
|
+
this.handleSplashPotion(projectile, config);
|
|
135
|
+
break;
|
|
136
|
+
case 2:
|
|
137
|
+
this.handleLingeringPotion(projectile, config);
|
|
138
|
+
break;
|
|
139
|
+
default:
|
|
140
|
+
projectile.remove();
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Handle splash potion effect
|
|
145
|
+
*/
|
|
146
|
+
handleSplashPotion(projectile, config) {
|
|
147
|
+
const location = { ...projectile.location, y: projectile.location.y + 0.1 };
|
|
148
|
+
const color = getColorFromEntity(projectile, config.namespace);
|
|
149
|
+
const amplifier = projectile.getProperty(`${config.namespace}:amplifier`);
|
|
150
|
+
const duration = projectile.getProperty(`${config.namespace}:duration`);
|
|
151
|
+
spawnSplashParticle(projectile.dimension, location, color, config.splashRange);
|
|
152
|
+
const nearbyEntities = projectile.dimension.getEntities({
|
|
153
|
+
excludeTypes: ["minecraft:item", "minecraft:arrow"],
|
|
154
|
+
location: projectile.location,
|
|
155
|
+
maxDistance: config.splashRange,
|
|
156
|
+
});
|
|
157
|
+
for (const entity of nearbyEntities) {
|
|
158
|
+
if (entity.id !== projectile.id) {
|
|
159
|
+
config.handler(entity, amplifier, duration, color);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
projectile.remove();
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Handle lingering potion effect (creates area cloud)
|
|
166
|
+
*/
|
|
167
|
+
handleLingeringPotion(projectile, config) {
|
|
168
|
+
const location = { ...projectile.location, y: projectile.location.y + 0.1 };
|
|
169
|
+
const color = getColorFromEntity(projectile, config.namespace);
|
|
170
|
+
const amplifier = projectile.getProperty(`${config.namespace}:amplifier`);
|
|
171
|
+
const duration = projectile.getProperty(`${config.namespace}:duration`);
|
|
172
|
+
const cloud = {
|
|
173
|
+
id: `aoe_cloud_${this.cloudIdCounter++}`,
|
|
174
|
+
dimension: projectile.dimension.id,
|
|
175
|
+
location,
|
|
176
|
+
color,
|
|
177
|
+
amplifier,
|
|
178
|
+
duration,
|
|
179
|
+
currentRadius: config.lingeringMaxRadius,
|
|
180
|
+
maxRadius: config.lingeringMaxRadius,
|
|
181
|
+
createdTick: system.currentTick,
|
|
182
|
+
maxLifetime: config.lingeringLifetime,
|
|
183
|
+
affectedEntities: new Set(),
|
|
184
|
+
handler: config.handler,
|
|
185
|
+
};
|
|
186
|
+
this.activeAOEClouds.set(cloud.id, cloud);
|
|
187
|
+
projectile.remove();
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Update lingering area effect cloud
|
|
191
|
+
*/
|
|
192
|
+
updateAreaEffectCloud(cloud) {
|
|
193
|
+
const dimension = world.getDimension(cloud.dimension);
|
|
194
|
+
const age = system.currentTick - cloud.createdTick;
|
|
195
|
+
const ageProgress = Math.min(age / cloud.maxLifetime, 1);
|
|
196
|
+
cloud.currentRadius = Math.max(0, cloud.maxRadius * (1 - ageProgress));
|
|
197
|
+
if (age >= cloud.maxLifetime || cloud.currentRadius <= 0) {
|
|
198
|
+
this.activeAOEClouds.delete(cloud.id);
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
spawnLingeringParticle(dimension, cloud.location, cloud.color, cloud.currentRadius, cloud.maxRadius, cloud.maxLifetime);
|
|
202
|
+
if (age < 20)
|
|
203
|
+
return; // Skip entity effects for first second
|
|
204
|
+
this.applyCloudEffects(dimension, cloud);
|
|
205
|
+
}
|
|
206
|
+
applyCloudEffects(dimension, cloud) {
|
|
207
|
+
const nearbyEntities = dimension.getEntities({
|
|
208
|
+
location: cloud.location,
|
|
209
|
+
maxDistance: cloud.currentRadius + 1,
|
|
210
|
+
excludeTypes: ["minecraft:item", "minecraft:arrow", "minecraft:xp_orb"],
|
|
211
|
+
});
|
|
212
|
+
for (const entity of nearbyEntities) {
|
|
213
|
+
if (cloud.affectedEntities.has(entity.id))
|
|
214
|
+
continue;
|
|
215
|
+
const reducedDuration = Math.floor(cloud.duration * 0.25);
|
|
216
|
+
cloud.handler(entity, cloud.amplifier, reducedDuration, cloud.color);
|
|
217
|
+
cloud.currentRadius = Math.max(0, cloud.currentRadius - 0.5);
|
|
218
|
+
cloud.maxLifetime = Math.max(0, cloud.maxLifetime - 100);
|
|
219
|
+
cloud.affectedEntities.add(entity.id);
|
|
220
|
+
system.runTimeout(() => {
|
|
221
|
+
cloud.affectedEntities.delete(entity.id);
|
|
222
|
+
}, 60); // 3 seconds
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
const potionManager = new PotionManager();
|
|
227
|
+
export { PotionManager, potionManager };
|
|
228
|
+
//# sourceMappingURL=potionAPI.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"potionAPI.js","sourceRoot":"","sources":["../../src/minecraft/potionAPI.ts"],"names":[],"mappings":"AAAA,OAAO,EAIN,iBAAiB,EAGjB,MAAM,EAEN,KAAK,GAEL,MAAM,mBAAmB,CAAC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AAa,GAAG,GAAG,CAAC,CAAC;YAC7D,KAAK,CAAC,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,WAAW,GAAG,GAAG,CAAC,CAAC;YAEzD,KAAK,CAAC,gBAAgB,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;YAEtC,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE;gBACtB,KAAK,CAAC,gBAAgB,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;YAC1C,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,YAAY;QACrB,CAAC;IACF,CAAC;CACD;AAED,MAAM,aAAa,GAAG,IAAI,aAAa,EAAE,CAAC;AAE1C,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Entity, Player, Vector3, Dimension, StartupEvent, CustomComponentParameters, ItemComponentUseEvent } from "@minecraft/server";
|
|
2
|
+
export interface CustomProjectileItemParameters {
|
|
3
|
+
identifier: string;
|
|
4
|
+
spawn_event?: string;
|
|
5
|
+
offset?: [number, number, number];
|
|
6
|
+
power?: number;
|
|
7
|
+
angle_offset?: number;
|
|
8
|
+
}
|
|
9
|
+
export type ProjectileItemCallback = (event: ItemComponentUseEvent, params: CustomComponentParameters) => void;
|
|
10
|
+
/**
|
|
11
|
+
* Calculate the launch direction for a projectile based on player rotation
|
|
12
|
+
*/
|
|
13
|
+
export declare function calculateLaunchDirection(rotation: {
|
|
14
|
+
x: number;
|
|
15
|
+
y: number;
|
|
16
|
+
}, angleOffset?: number): Vector3;
|
|
17
|
+
/**
|
|
18
|
+
* Calculate spawn position for projectile with rotation-based offset
|
|
19
|
+
*/
|
|
20
|
+
export declare function calculateProjectileSpawnPosition(playerLocation: Vector3, rotation: {
|
|
21
|
+
x: number;
|
|
22
|
+
y: number;
|
|
23
|
+
}, offset?: [number, number, number]): Vector3;
|
|
24
|
+
/**
|
|
25
|
+
* Apply velocity scaling to a direction vector
|
|
26
|
+
*/
|
|
27
|
+
export declare function scaleVelocity(direction: Vector3, power: number): Vector3;
|
|
28
|
+
/**
|
|
29
|
+
* Spawn a projectile entity with velocity
|
|
30
|
+
*/
|
|
31
|
+
export declare function spawnProjectile(dimension: Dimension, projectileId: string, spawnLocation: Vector3, velocity: Vector3, spawnEvent?: string): Entity | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* Consume item from player's hand (creative mode safe)
|
|
34
|
+
*/
|
|
35
|
+
export declare function consumeItemStack(player: Player, itemStack: any): void;
|
|
36
|
+
/**
|
|
37
|
+
* Launch a projectile from a player with specified options
|
|
38
|
+
*/
|
|
39
|
+
export declare function launchProjectileFromPlayer(player: Player, options: CustomProjectileItemParameters): Entity | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* Launch a projectile from any entity with manual direction
|
|
42
|
+
*/
|
|
43
|
+
export declare function launchProjectileFromEntity(entity: Entity, projectileId: string, direction: Vector3, power?: number, offset?: [number, number, number], spawnEvent?: string): Entity | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* Launch a projectile from a specific location with direction
|
|
46
|
+
*/
|
|
47
|
+
export declare function launchProjectileFromLocation(dimension: Dimension, location: Vector3, projectileId: string, direction: Vector3, power?: number, spawnEvent?: string): Entity | undefined;
|
|
48
|
+
/**
|
|
49
|
+
* Register a callback for a specific item identifier
|
|
50
|
+
*/
|
|
51
|
+
export declare function registerProjectileItemCallback(itemId: string, callback: ProjectileItemCallback): void;
|
|
52
|
+
/**
|
|
53
|
+
* Handle custom projectile component use event
|
|
54
|
+
*/
|
|
55
|
+
export declare function handleCustomProjectileUse(event: ItemComponentUseEvent, params: CustomComponentParameters): Entity | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* Register the custom projectile component
|
|
58
|
+
* Call this in your startup event to register the custom projectile throwing component
|
|
59
|
+
*/
|
|
60
|
+
export declare function registerCustomProjectileComponent(startup: StartupEvent): void;
|
|
61
|
+
//# sourceMappingURL=projectileAPI.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"projectileAPI.d.ts","sourceRoot":"","sources":["../../src/minecraft/projectileAPI.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,MAAM,EACN,MAAM,EACN,OAAO,EACP,SAAS,EAIT,YAAY,EACZ,yBAAyB,EACzB,qBAAqB,EACrB,MAAM,mBAAmB,CAAC;AAM3B,MAAM,WAAW,8BAA8B;IAC9C,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,MAAM,sBAAsB,GAAG,CAAC,KAAK,EAAE,qBAAqB,EAAE,MAAM,EAAE,yBAAyB,KAAK,IAAI,CAAC;AAI/G;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,EAAE,WAAW,GAAE,MAAU,GAAG,OAAO,CAU7G;AAED;;GAEG;AACH,wBAAgB,gCAAgC,CAC/C,cAAc,EAAE,OAAO,EACvB,QAAQ,EAAE;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,EAClC,MAAM,GAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAa,GAC1C,OAAO,CAkBT;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAMxE;AAED;;GAEG;AACH,wBAAgB,eAAe,CAC9B,SAAS,EAAE,SAAS,EACpB,YAAY,EAAE,MAAM,EACpB,aAAa,EAAE,OAAO,EACtB,QAAQ,EAAE,OAAO,EACjB,UAAU,GAAE,MAAmC,GAC7C,MAAM,GAAG,SAAS,CASpB;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,GAAG,IAAI,CAYrE;AAID;;GAEG;AACH,wBAAgB,0BAA0B,CACzC,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,8BAA8B,GACrC,MAAM,GAAG,SAAS,CAYpB;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CACzC,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,MAAM,EACpB,SAAS,EAAE,OAAO,EAClB,KAAK,GAAE,MAAU,EACjB,MAAM,GAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAa,EAC5C,UAAU,CAAC,EAAE,MAAM,GACjB,MAAM,GAAG,SAAS,CAUpB;AAED;;GAEG;AACH,wBAAgB,4BAA4B,CAC3C,SAAS,EAAE,SAAS,EACpB,QAAQ,EAAE,OAAO,EACjB,YAAY,EAAE,MAAM,EACpB,SAAS,EAAE,OAAO,EAClB,KAAK,GAAE,MAAU,EACjB,UAAU,CAAC,EAAE,MAAM,GACjB,MAAM,GAAG,SAAS,CAIpB;AAOD;;GAEG;AACH,wBAAgB,8BAA8B,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,sBAAsB,GAAG,IAAI,CAErG;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CACxC,KAAK,EAAE,qBAAqB,EAC5B,MAAM,EAAE,yBAAyB,GAC/B,MAAM,GAAG,SAAS,CAsBpB;AAED;;;GAGG;AACH,wBAAgB,iCAAiC,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI,CAI7E"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { GameMode, EntityEquippableComponent, EquipmentSlot, } from "@minecraft/server";
|
|
2
|
+
import { toRadians, VectorOperations } from "@starktma/minecraft-utils/math";
|
|
3
|
+
import { getNamespace } from "../constants";
|
|
4
|
+
// ========================== Core Utility Functions ======================
|
|
5
|
+
/**
|
|
6
|
+
* Calculate the launch direction for a projectile based on player rotation
|
|
7
|
+
*/
|
|
8
|
+
export function calculateLaunchDirection(rotation, angleOffset = 0) {
|
|
9
|
+
const yaw = toRadians(rotation.y);
|
|
10
|
+
const pitch = toRadians(rotation.x);
|
|
11
|
+
const adjustedPitch = pitch + toRadians(angleOffset);
|
|
12
|
+
return {
|
|
13
|
+
x: -Math.sin(yaw) * Math.cos(adjustedPitch),
|
|
14
|
+
y: -Math.sin(adjustedPitch),
|
|
15
|
+
z: Math.cos(yaw) * Math.cos(adjustedPitch),
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Calculate spawn position for projectile with rotation-based offset
|
|
20
|
+
*/
|
|
21
|
+
export function calculateProjectileSpawnPosition(playerLocation, rotation, offset = [0, 0, 0]) {
|
|
22
|
+
const yaw = toRadians(rotation.y);
|
|
23
|
+
const pitch = toRadians(rotation.x);
|
|
24
|
+
const pitchAdjustment = -Math.sin(pitch) * 0.5;
|
|
25
|
+
const rawOffset = {
|
|
26
|
+
x: offset[0],
|
|
27
|
+
y: offset[1] + 1.7 + pitchAdjustment,
|
|
28
|
+
z: offset[2],
|
|
29
|
+
};
|
|
30
|
+
const rotatedOffset = {
|
|
31
|
+
x: rawOffset.x * Math.cos(yaw) - rawOffset.z * Math.sin(yaw),
|
|
32
|
+
y: rawOffset.y,
|
|
33
|
+
z: rawOffset.x * Math.sin(yaw) + rawOffset.z * Math.cos(yaw),
|
|
34
|
+
};
|
|
35
|
+
return VectorOperations.add(playerLocation, rotatedOffset);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Apply velocity scaling to a direction vector
|
|
39
|
+
*/
|
|
40
|
+
export function scaleVelocity(direction, power) {
|
|
41
|
+
return {
|
|
42
|
+
x: direction.x * power * 2,
|
|
43
|
+
y: direction.y * power,
|
|
44
|
+
z: direction.z * power * 2,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Spawn a projectile entity with velocity
|
|
49
|
+
*/
|
|
50
|
+
export function spawnProjectile(dimension, projectileId, spawnLocation, velocity, spawnEvent = "minecraft:entity_spawned") {
|
|
51
|
+
if (!dimension.isChunkLoaded(spawnLocation))
|
|
52
|
+
return undefined;
|
|
53
|
+
const entity = dimension.spawnEntity(projectileId, spawnLocation, { spawnEvent });
|
|
54
|
+
if (entity?.isValid) {
|
|
55
|
+
entity.applyImpulse(velocity);
|
|
56
|
+
return entity;
|
|
57
|
+
}
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Consume item from player's hand (creative mode safe)
|
|
62
|
+
*/
|
|
63
|
+
export function consumeItemStack(player, itemStack) {
|
|
64
|
+
if (player.getGameMode() === GameMode.Creative)
|
|
65
|
+
return;
|
|
66
|
+
const equippable = player.getComponent(EntityEquippableComponent.componentId);
|
|
67
|
+
if (!equippable)
|
|
68
|
+
return;
|
|
69
|
+
if (itemStack.amount > 1) {
|
|
70
|
+
itemStack.amount--;
|
|
71
|
+
equippable.setEquipment(EquipmentSlot.Mainhand, itemStack);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
equippable.setEquipment(EquipmentSlot.Mainhand, undefined);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
// ========================== Advanced Projectile Functions ===============
|
|
78
|
+
/**
|
|
79
|
+
* Launch a projectile from a player with specified options
|
|
80
|
+
*/
|
|
81
|
+
export function launchProjectileFromPlayer(player, options) {
|
|
82
|
+
const spawnLocation = calculateProjectileSpawnPosition(player.location, player.getRotation(), options.offset || [0, 0, 0]);
|
|
83
|
+
const direction = calculateLaunchDirection(player.getRotation(), options.angle_offset || 0);
|
|
84
|
+
const velocity = scaleVelocity(direction, (options.power || 1) * 0.2);
|
|
85
|
+
return spawnProjectile(player.dimension, options.identifier, spawnLocation, velocity, options.spawn_event);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Launch a projectile from any entity with manual direction
|
|
89
|
+
*/
|
|
90
|
+
export function launchProjectileFromEntity(entity, projectileId, direction, power = 1, offset = [0, 0, 0], spawnEvent) {
|
|
91
|
+
const spawnLocation = VectorOperations.add(entity.location, {
|
|
92
|
+
x: offset[0],
|
|
93
|
+
y: offset[1],
|
|
94
|
+
z: offset[2],
|
|
95
|
+
});
|
|
96
|
+
const velocity = scaleVelocity(direction, power * 0.2);
|
|
97
|
+
return spawnProjectile(entity.dimension, projectileId, spawnLocation, velocity, spawnEvent);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Launch a projectile from a specific location with direction
|
|
101
|
+
*/
|
|
102
|
+
export function launchProjectileFromLocation(dimension, location, projectileId, direction, power = 1, spawnEvent) {
|
|
103
|
+
const velocity = scaleVelocity(direction, power * 0.2);
|
|
104
|
+
return spawnProjectile(dimension, projectileId, location, velocity, spawnEvent);
|
|
105
|
+
}
|
|
106
|
+
// ========================== Custom Component Handlers ====================
|
|
107
|
+
// Simple map for item callbacks
|
|
108
|
+
const itemCallbacks = new Map();
|
|
109
|
+
/**
|
|
110
|
+
* Register a callback for a specific item identifier
|
|
111
|
+
*/
|
|
112
|
+
export function registerProjectileItemCallback(itemId, callback) {
|
|
113
|
+
itemCallbacks.set(itemId, callback);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Handle custom projectile component use event
|
|
117
|
+
*/
|
|
118
|
+
export function handleCustomProjectileUse(event, params) {
|
|
119
|
+
const player = event.source;
|
|
120
|
+
const itemStack = event.itemStack;
|
|
121
|
+
const projectileParams = params.params;
|
|
122
|
+
// Launch projectile using default behavior
|
|
123
|
+
const projectile = launchProjectileFromPlayer(player, projectileParams);
|
|
124
|
+
// Handle item consumption
|
|
125
|
+
if (projectile && itemStack) {
|
|
126
|
+
consumeItemStack(player, itemStack);
|
|
127
|
+
}
|
|
128
|
+
// Check for registered callback for this item
|
|
129
|
+
if (itemStack) {
|
|
130
|
+
const callback = itemCallbacks.get(itemStack.typeId);
|
|
131
|
+
if (callback) {
|
|
132
|
+
callback(event, params);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return projectile;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Register the custom projectile component
|
|
139
|
+
* Call this in your startup event to register the custom projectile throwing component
|
|
140
|
+
*/
|
|
141
|
+
export function registerCustomProjectileComponent(startup) {
|
|
142
|
+
startup.itemComponentRegistry.registerCustomComponent(`${getNamespace()}:custom_projectile`, {
|
|
143
|
+
onUse: handleCustomProjectileUse,
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=projectileAPI.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"projectileAPI.js","sourceRoot":"","sources":["../../src/minecraft/projectileAPI.ts"],"names":[],"mappings":"AAAA,OAAO,EAKN,QAAQ,EACR,yBAAyB,EACzB,aAAa,GAIb,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAC7E,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAc5C,2EAA2E;AAE3E;;GAEG;AACH,MAAM,UAAU,wBAAwB,CAAC,QAAkC,EAAE,cAAsB,CAAC;IACnG,MAAM,GAAG,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IAClC,MAAM,KAAK,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IACpC,MAAM,aAAa,GAAG,KAAK,GAAG,SAAS,CAAC,WAAW,CAAC,CAAC;IAErD,OAAO;QACN,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,aAAa,CAAC;QAC3C,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,aAAa,CAAC;QAC3B,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@starktma/minecraft-utils",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.25",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"LICENSE"
|
|
48
48
|
],
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@minecraft/server": "^2.
|
|
50
|
+
"@minecraft/server": "^2.3.0",
|
|
51
51
|
"@minecraft/server-ui": "^2.0.0",
|
|
52
52
|
"typescript": "^5.9.2"
|
|
53
53
|
}
|