1
1
// Script example for ScriptAPI
2
2
// Author: Jayly <https://github.com/JaylyDev>
3
3
// Project: https://github.com/JaylyDev/ScriptAPI
4
- import { Block , Entity , EntityHitAfterEvent , Player , world } from "@minecraft/server" ;
4
+ import { Block , Entity , EntityHitEntityAfterEvent , Player , world } from "@minecraft/server" ;
5
5
6
6
/**
7
- * @implements {Omit<EntityHitAfterEvent , "entity ">}
7
+ * @implements {Omit<EntityHitEntityAfterEvent , "damagingEntity ">}
8
8
*/
9
9
export class EntityCriticalHitAfterEvent {
10
10
/**
11
- * @param {Entity } entity
12
- * @param {Block } hitBlock
11
+ * @param {Entity } damagingEntity
13
12
* @param {Entity } hitEntity
14
13
*/
15
- constructor ( entity , hitBlock , hitEntity ) {
16
- if ( ! ( entity instanceof Player ) ) {
17
- console . log ( "Failed to call function EntityCriticalHitAfterEvent, entity is not a player" ) ;
14
+ constructor ( damagingEntity , hitEntity ) {
15
+ if ( ! ( damagingEntity instanceof Player ) ) {
16
+ console . log ( "Failed to call function EntityCriticalHitAfterEvent, damagingEntity is not a player" ) ;
18
17
return ;
19
18
} ;
20
19
21
- this . player = entity ;
22
- this . hitBlock = hitBlock ;
20
+ this . player = damagingEntity ;
23
21
this . hitEntity = hitEntity ;
24
22
} ;
25
23
/**
@@ -29,21 +27,11 @@ export class EntityCriticalHitAfterEvent {
29
27
* @type {Player }
30
28
*/
31
29
player ;
32
- /**
33
- * @remarks
34
- * Block that was hit by the attack, or undefined if the hit
35
- * attack did not hit a block. If both hitEntity and hitBlock
36
- * are undefined, then the entity basically swiped into the
37
- * air.
38
- * @readonly
39
- * @type {Block | undefined }
40
- */
41
- hitBlock ;
42
30
/**
43
31
* @remarks
44
32
* Entity that was hit by the attack, or undefined if the hit
45
- * attack did not hit an entity . If both hitEntity and hitBlock
46
- * are undefined, then the entity basically swiped into the
33
+ * attack did not hit an damagingEntity . If both hitEntity and hitBlock
34
+ * are undefined, then the damagingEntity basically swiped into the
47
35
* air.
48
36
* @readonly
49
37
* @type {Entity | undefined }
@@ -73,17 +61,17 @@ export class EntityCriticalHitAfterEventSignal {
73
61
}
74
62
/**
75
63
* @private
76
- * @param {EntityHitAfterEvent } event
64
+ * @param {EntityHitEntityAfterEvent } event
77
65
*/
78
66
trigger ( event ) {
79
- this . handlers . forEach ( ( callback ) => callback ( new EntityCriticalHitAfterEvent ( event . entity , event . hitBlock , event . hitEntity ) ) ) ;
67
+ this . handlers . forEach ( ( callback ) => callback ( new EntityCriticalHitAfterEvent ( event . damagingEntity , event . hitEntity ) ) ) ;
80
68
}
81
69
constructor ( ) {
82
- world . afterEvents . entityHit . subscribe ( ( event ) => {
83
- // checks if entity has a critical hit and is a player
84
- if ( event . entity instanceof Player && ! ! event . hitEntity && event . entity . getVelocity ( ) . y !== 0 ) this . trigger ( event ) ;
70
+ world . afterEvents . entityHitEntity . subscribe ( ( event ) => {
71
+ // checks if damagingEntity has a critical hit and is a player
72
+ if ( event . damagingEntity instanceof Player && ! ! event . hitEntity && event . damagingEntity . getVelocity ( ) . y !== 0 ) this . trigger ( event ) ;
85
73
} ) ;
86
74
}
87
75
}
88
76
89
- export const entityCriticalHit = new EntityCriticalHitAfterEventSignal ( ) ;
77
+ export const damagingEntityCriticalHit = new EntityCriticalHitAfterEventSignal ( ) ;
0 commit comments