-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Expand file tree
/
Copy pathLivingEntity.java
More file actions
1559 lines (1416 loc) · 52.5 KB
/
LivingEntity.java
File metadata and controls
1559 lines (1416 loc) · 52.5 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package org.bukkit.entity;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import io.papermc.paper.world.damagesource.CombatTracker;
import io.papermc.paper.world.damagesource.FallLocationType;
import net.kyori.adventure.key.Key;
import org.bukkit.Color;
import org.bukkit.FluidCollisionMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.Sound;
import org.bukkit.World;
import org.bukkit.attribute.Attributable;
import org.bukkit.block.Block;
import org.bukkit.entity.memory.MemoryKey;
import org.bukkit.inventory.EntityEquipment;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.projectiles.ProjectileSource;
import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.Team;
import org.bukkit.util.RayTraceResult;
import org.bukkit.util.Vector;
import org.checkerframework.checker.index.qual.NonNegative;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* Represents a living entity, such as a monster or player
*/
public interface LivingEntity extends Attributable, Damageable, ProjectileSource, io.papermc.paper.entity.Frictional { // Paper
/**
* Gets the height of the living entity's eyes above its Location.
*
* @return height of the living entity's eyes above its location
*/
public double getEyeHeight();
/**
* Gets the height of the living entity's eyes above its Location.
*
* @param ignorePose if set to true, the effects of pose changes, eg
* sneaking and gliding will be ignored
* @return height of the living entity's eyes above its location
*/
public double getEyeHeight(boolean ignorePose);
/**
* Get a Location detailing the current eye position of the living entity.
*
* @return a location at the eyes of the living entity
*/
@NotNull
public Location getEyeLocation();
/**
* Gets all blocks along the living entity's line of sight.
* <p>
* This list contains all blocks from the living entity's eye position to
* target inclusive. This method considers all blocks as 1x1x1 in size.
*
* @param transparent Set containing all transparent block Materials (set to
* null for only air)
* @param maxDistance this is the maximum distance to scan (may be limited
* by server by at least 100 blocks, no less)
* @return list containing all blocks along the living entity's line of
* sight
*/
@NotNull
public List<Block> getLineOfSight(@Nullable Set<Material> transparent, int maxDistance);
/**
* Gets the block that the living entity has targeted.
* <p>
* This method considers all blocks as 1x1x1 in size. To take exact block
* collision shapes into account, see {@link #getTargetBlockExact(int,
* FluidCollisionMode)}.
*
* @param transparent Set containing all transparent block Materials (set to
* null for only air)
* @param maxDistance this is the maximum distance to scan (may be limited
* by server by at least 100 blocks, no less)
* @return block that the living entity has targeted
*/
@NotNull
public Block getTargetBlock(@Nullable Set<Material> transparent, int maxDistance);
// Paper start
/**
* Gets the block that the living entity has targeted, ignoring fluids
*
* @param maxDistance this is the maximum distance to scan
* @return block that the living entity has targeted,
* or null if no block is within maxDistance
* @deprecated use {@link #getTargetBlockExact(int)}
*/
@Deprecated(forRemoval = true, since = "1.19.3")
@Nullable
public default Block getTargetBlock(int maxDistance) {
return getTargetBlock(maxDistance, com.destroystokyo.paper.block.TargetBlockInfo.FluidMode.NEVER);
}
/**
* Gets the block that the living entity has targeted
*
* @param maxDistance this is the maximum distance to scan
* @param fluidMode whether to check fluids or not
* @return block that the living entity has targeted,
* or null if no block is within maxDistance
* @deprecated use {@link #getTargetBlockExact(int, FluidCollisionMode)}
*/
@Deprecated(forRemoval = true, since = "1.19.3")
@Nullable
public Block getTargetBlock(int maxDistance, @NotNull com.destroystokyo.paper.block.TargetBlockInfo.FluidMode fluidMode);
/**
* Gets the blockface of that block that the living entity has targeted, ignoring fluids
*
* @param maxDistance this is the maximum distance to scan
* @return blockface of the block that the living entity has targeted,
* or null if no block is targeted
*/
@Nullable
public default org.bukkit.block.BlockFace getTargetBlockFace(int maxDistance) {
return getTargetBlockFace(maxDistance, org.bukkit.FluidCollisionMode.NEVER);
}
/**
* Gets the blockface of that block that the living entity has targeted
*
* @param maxDistance this is the maximum distance to scan
* @param fluidMode whether to check fluids or not
* @return blockface of the block that the living entity has targeted,
* or null if no block is targeted
* @deprecated use {@link #getTargetBlockFace(int, FluidCollisionMode)}
*/
@Deprecated(forRemoval = true, since = "1.19.3")
@Nullable
public org.bukkit.block.BlockFace getTargetBlockFace(int maxDistance, @NotNull com.destroystokyo.paper.block.TargetBlockInfo.FluidMode fluidMode);
/**
* Gets the blockface of that block that the living entity has targeted
*
* @param maxDistance this is the maximum distance to scan
* @param fluidMode whether to check fluids or not
* @return blockface of the block that the living entity has targeted,
* or null if no block is targeted
*/
@Nullable
public org.bukkit.block.BlockFace getTargetBlockFace(int maxDistance, @NotNull FluidCollisionMode fluidMode);
/**
* Gets information about the block the living entity has targeted, ignoring fluids
*
* @param maxDistance this is the maximum distance to scan
* @return TargetBlockInfo about the block the living entity has targeted,
* or null if no block is targeted
* @deprecated use {@link #rayTraceBlocks(double)}
*/
@Deprecated(forRemoval = true, since = "1.19.3")
@Nullable
public default com.destroystokyo.paper.block.TargetBlockInfo getTargetBlockInfo(int maxDistance) {
return getTargetBlockInfo(maxDistance, com.destroystokyo.paper.block.TargetBlockInfo.FluidMode.NEVER);
}
/**
* Gets information about the block the living entity has targeted
*
* @param maxDistance this is the maximum distance to scan
* @param fluidMode whether to check fluids or not
* @return TargetBlockInfo about the block the living entity has targeted,
* or null if no block is targeted
* @deprecated use {@link #rayTraceBlocks(double, FluidCollisionMode)}
*/
@Deprecated(forRemoval = true, since = "1.19.3")
@Nullable
public com.destroystokyo.paper.block.TargetBlockInfo getTargetBlockInfo(int maxDistance, @NotNull com.destroystokyo.paper.block.TargetBlockInfo.FluidMode fluidMode);
/**
* Gets information about the entity being targeted
*
* @param maxDistance this is the maximum distance to scan
* @return entity being targeted, or null if no entity is targeted
*/
@Nullable
public default Entity getTargetEntity(int maxDistance) {
return getTargetEntity(maxDistance, false);
}
/**
* Gets information about the entity being targeted
*
* @param maxDistance this is the maximum distance to scan
* @param ignoreBlocks true to scan through blocks
* @return entity being targeted, or null if no entity is targeted
*/
@Nullable
public Entity getTargetEntity(int maxDistance, boolean ignoreBlocks);
/**
* Gets information about the entity being targeted
*
* @param maxDistance this is the maximum distance to scan
* @return TargetEntityInfo about the entity being targeted,
* or null if no entity is targeted
* @deprecated use {@link #rayTraceEntities(int)}
*/
@Deprecated(forRemoval = true, since = "1.19.3")
@Nullable
public default com.destroystokyo.paper.entity.TargetEntityInfo getTargetEntityInfo(int maxDistance) {
return getTargetEntityInfo(maxDistance, false);
}
/**
* Gets information about the entity being targeted
*
* @param maxDistance this is the maximum distance to scan
* @return RayTraceResult about the entity being targeted,
* or null if no entity is targeted
*/
@Nullable
default RayTraceResult rayTraceEntities(int maxDistance) {
return this.rayTraceEntities(maxDistance, false);
}
/**
* Gets information about the entity being targeted
*
* @param maxDistance this is the maximum distance to scan
* @param ignoreBlocks true to scan through blocks
* @return TargetEntityInfo about the entity being targeted,
* or null if no entity is targeted
* @deprecated use {@link #rayTraceEntities(int, boolean)}
*/
@Deprecated(forRemoval = true, since = "1.19.3")
@Nullable
public com.destroystokyo.paper.entity.TargetEntityInfo getTargetEntityInfo(int maxDistance, boolean ignoreBlocks);
/**
* Gets information about the entity being targeted
*
* @param maxDistance this is the maximum distance to scan
* @param ignoreBlocks true to scan through blocks
* @return RayTraceResult about the entity being targeted,
* or null if no entity is targeted
*/
@Nullable
RayTraceResult rayTraceEntities(int maxDistance, boolean ignoreBlocks);
// Paper end
/**
* Gets the last two blocks along the living entity's line of sight.
* <p>
* The target block will be the last block in the list. This method
* considers all blocks as 1x1x1 in size.
*
* @param transparent Set containing all transparent block Materials (set to
* null for only air)
* @param maxDistance this is the maximum distance to scan. This may be
* further limited by the server, but never to less than 100 blocks
* @return list containing the last 2 blocks along the living entity's
* line of sight
*/
@NotNull
public List<Block> getLastTwoTargetBlocks(@Nullable Set<Material> transparent, int maxDistance);
/**
* Gets the block that the living entity has targeted.
* <p>
* This takes the blocks' precise collision shapes into account. Fluids are
* ignored.
* <p>
* This may cause loading of chunks! Some implementations may impose
* artificial restrictions on the maximum distance.
*
* @param maxDistance the maximum distance to scan
* @return block that the living entity has targeted
* @see #getTargetBlockExact(int, org.bukkit.FluidCollisionMode)
*/
@Nullable
default Block getTargetBlockExact(int maxDistance) {
return this.getTargetBlockExact(maxDistance, FluidCollisionMode.NEVER);
}
/**
* Gets the block that the living entity has targeted.
* <p>
* This takes the blocks' precise collision shapes into account.
* <p>
* This may cause loading of chunks! Some implementations may impose
* artificial restrictions on the maximum distance.
*
* @param maxDistance the maximum distance to scan
* @param fluidCollisionMode the fluid collision mode
* @return block that the living entity has targeted
* @see #rayTraceBlocks(double, FluidCollisionMode)
*/
@Nullable
public Block getTargetBlockExact(int maxDistance, @NotNull FluidCollisionMode fluidCollisionMode);
/**
* Performs a ray trace that provides information on the targeted block.
* <p>
* This takes the blocks' precise collision shapes into account. Fluids are
* ignored.
* <p>
* This may cause loading of chunks! Some implementations may impose
* artificial restrictions on the maximum distance.
*
* @param maxDistance the maximum distance to scan
* @return information on the targeted block, or <code>null</code> if there
* is no targeted block in range
* @see #rayTraceBlocks(double, FluidCollisionMode)
*/
@Nullable
default RayTraceResult rayTraceBlocks(double maxDistance) {
return this.rayTraceBlocks(maxDistance, FluidCollisionMode.NEVER);
}
/**
* Performs a ray trace that provides information on the targeted block.
* <p>
* This takes the blocks' precise collision shapes into account.
* <p>
* This may cause loading of chunks! Some implementations may impose
* artificial restrictions on the maximum distance.
*
* @param maxDistance the maximum distance to scan
* @param fluidCollisionMode the fluid collision mode
* @return information on the targeted block, or <code>null</code> if there
* is no targeted block in range
* @see World#rayTraceBlocks(Location, Vector, double, FluidCollisionMode)
*/
@Nullable
public RayTraceResult rayTraceBlocks(double maxDistance, @NotNull FluidCollisionMode fluidCollisionMode);
/**
* Returns the amount of air that the living entity has remaining, in
* ticks.
*
* @return amount of air remaining
*/
public int getRemainingAir();
/**
* Sets the amount of air that the living entity has remaining, in ticks.
*
* @param ticks amount of air remaining
*/
public void setRemainingAir(int ticks);
/**
* Returns the maximum amount of air the living entity can have, in ticks.
*
* @return maximum amount of air
*/
public int getMaximumAir();
/**
* Sets the maximum amount of air the living entity can have, in ticks.
*
* @param ticks maximum amount of air
*/
public void setMaximumAir(int ticks);
/**
* Gets the item that the player is using (eating food, drawing back a bow,
* blocking, etc.)
*
* @return the item being used by the player, or null if they are not using
* an item
* @deprecated Use {@link #getActiveItem()}
*/
@Nullable
@Deprecated(forRemoval = true, since = "1.20.4") // Paper
public ItemStack getItemInUse();
/**
* Gets the number of ticks remaining for the current item's usage.
*
* @return The number of ticks remaining
* @deprecated use {@link #getActiveItemRemainingTime()}
*/
@Deprecated(forRemoval = true, since = "1.20.4") // Paper
public int getItemInUseTicks();
/**
* Sets the number of ticks that remain for the current item's usage.
* Applies to items that take time to use, like eating food, drawing a bow,
* or throwing a trident.
*
* @param ticks The number of ticks remaining
* @deprecated use {@link #setActiveItemRemainingTime(int)}
*/
@Deprecated(forRemoval = true, since = "1.20.4") // Paper
public void setItemInUseTicks(int ticks);
/**
* Gets the time in ticks until the next arrow leaves the entity's body.
*
* @return ticks until arrow leaves
*/
public @NonNegative int getArrowCooldown();
/**
* Sets the time in ticks until the next arrow leaves the entity's body.
* <p>
* A value of 0 will cause the server to re-calculate the time on the next tick.
*
* @param ticks time until arrow leaves
*/
public void setArrowCooldown(@NonNegative int ticks);
/**
* Gets the amount of arrows in an entity's body.
*
* @return amount of arrows in body
*/
public @NonNegative int getArrowsInBody();
/**
* Set the amount of arrows in the entity's body.
* <p>
* Does not fire the {@link org.bukkit.event.entity.ArrowBodyCountChangeEvent}.
*
* @param count amount of arrows in entity's body
*/
default void setArrowsInBody(final @NonNegative int count) {
this.setArrowsInBody(count, false);
}
/**
* Set the amount of arrows in the entity's body.
*
* @param count amount of arrows in entity's body
* @param fireEvent whether to fire the {@link org.bukkit.event.entity.ArrowBodyCountChangeEvent} event
*/
void setArrowsInBody(@NonNegative int count, boolean fireEvent); // Paper
/**
* Sets the amount of ticks before the next arrow gets removed from the entities body.
* <p>
* A value of 0 will cause the server to re-calculate the amount of ticks on the next tick.
*
* @param ticks Amount of ticks
* @deprecated use {@link #setArrowCooldown(int)}
*/
@Deprecated(since = "1.21.10")
default void setNextArrowRemoval(@NonNegative int ticks) {
this.setArrowCooldown(ticks);
}
/**
* Gets the amount of ticks before the next arrow gets removed from the entities body.
*
* @return ticks Amount of ticks
* @deprecated use {@link #getArrowCooldown()}
*/
@Deprecated(since = "1.21.10")
default @NonNegative int getNextArrowRemoval() {
return this.getArrowCooldown();
}
/**
* Gets the time in ticks until the next bee stinger leaves the entity's body.
*
* @return ticks until bee stinger leaves
*/
public @NonNegative int getBeeStingerCooldown();
/**
* Sets the time in ticks until the next stinger leaves the entity's body.
* <p>
* A value of 0 will cause the server to re-calculate the time on the next tick.
*
* @param ticks time until bee stinger leaves
*/
public void setBeeStingerCooldown(@NonNegative int ticks);
/**
* Gets the amount of bee stingers in an entity's body.
*
* @return amount of bee stingers in body
*/
public @NonNegative int getBeeStingersInBody();
/**
* Set the amount of bee stingers in the entity's body.
*
* @param count amount of bee stingers in entity's body
*/
public void setBeeStingersInBody(@NonNegative int count);
/**
* Sets the amount of ticks before the next bee stinger gets removed from the entities body.
* <p>
* A value of 0 will cause the server to re-calculate the amount of ticks on the next tick.
*
* @param ticks Amount of ticks
* @deprecated use {@link #setBeeStingerCooldown(int)}
*/
@Deprecated(since = "1.21.10")
default void setNextBeeStingerRemoval(@NonNegative int ticks) {
this.setBeeStingerCooldown(ticks);
}
/**
* Gets the amount of ticks before the next bee stinger gets removed from the entities body.
*
* @return ticks Amount of ticks
* @deprecated use {@link #getBeeStingerCooldown()}
*/
@Deprecated(since = "1.21.10")
default @NonNegative int getNextBeeStingerRemoval() {
return this.getBeeStingerCooldown();
}
/**
* Returns the living entity's current maximum no damage ticks.
* <p>
* This is the maximum duration in which the living entity will not take
* damage.
*
* @return maximum no damage ticks
*/
public int getMaximumNoDamageTicks();
/**
* Sets the living entity's current maximum no damage ticks.
*
* @param ticks maximum amount of no damage ticks
*/
public void setMaximumNoDamageTicks(int ticks);
/**
* Returns the living entity's last damage taken in the current no damage
* ticks time.
* <p>
* Only damage higher than this amount will further damage the living
* entity.
*
* @return damage taken since the last no damage ticks time period
*/
public double getLastDamage();
/**
* Sets the damage dealt within the current no damage ticks time period.
*
* @param damage amount of damage
*/
public void setLastDamage(double damage);
/**
* Returns the living entity's current no damage ticks.
*
* @return amount of no damage ticks
*/
public int getNoDamageTicks();
/**
* Sets the living entity's current no damage ticks.
*
* @param ticks amount of no damage ticks
*/
public void setNoDamageTicks(int ticks);
/**
* Get the ticks that this entity has performed no action.
* <p>
* The details of what "no action ticks" entails varies from entity to entity
* and cannot be specifically defined. Some examples include squid using this
* value to determine when to swim, raiders for when they are to be expelled
* from raids, or creatures (such as withers) as a requirement to be despawned.
*
* @return amount of no action ticks
*/
public int getNoActionTicks();
/**
* Set the ticks that this entity has performed no action.
* <p>
* The details of what "no action ticks" entails varies from entity to entity
* and cannot be specifically defined. Some examples include squid using this
* value to determine when to swim, raiders for when they are to be expelled
* from raids, or creatures (such as withers) as a requirement to be despawned.
*
* @param ticks amount of no action ticks
*/
public void setNoActionTicks(int ticks);
/**
* Gets the player identified as the killer of the living entity.
* <p>
* May be null.
*
* @return killer player, or null if none found
*/
@Nullable
public Player getKiller();
// Paper start
/**
* Sets the player identified as the killer of the living entity.
*
* @param killer player
*/
public void setKiller(@Nullable Player killer);
// Paper end
/**
* Adds the given {@link PotionEffect} to the living entity.
* <p>
* Note: {@link PotionEffect#getHiddenPotionEffect()} is ignored when
* adding the effect to the entity.
*
* @param effect PotionEffect to be added
* @return whether the effect could be added
*/
default boolean addPotionEffect(@NotNull PotionEffect effect) {
return this.addPotionEffect(effect, false);
}
/**
* Adds the given {@link PotionEffect} to the living entity.
* <p>
* Only one potion effect can be present for a given {@link PotionEffectType}.
*
* @param effect PotionEffect to be added
* @param force whether conflicting effects should be removed
* @return whether the effect could be added
* @deprecated no need to force since multiple effects of the same type are
* now supported.
*/
@Deprecated(since = "1.15.2")
public boolean addPotionEffect(@NotNull PotionEffect effect, boolean force);
/**
* Attempts to add all of the given {@link PotionEffect} to the living
* entity.
* <p>
* Note: {@link PotionEffect#getHiddenPotionEffect()} is ignored when
* adding the effect to the entity.
*
* @param effects the effects to add
* @return whether all of the effects could be added
*/
public boolean addPotionEffects(@NotNull Collection<PotionEffect> effects);
/**
* Returns whether the living entity already has an existing effect of
* the given {@link PotionEffectType} applied to it.
*
* @param type the potion type to check
* @return whether the living entity has this potion effect active on them
*/
public boolean hasPotionEffect(@NotNull PotionEffectType type);
/**
* Returns the active {@link PotionEffect} of the specified type.
* <p>
* If the effect is not present on the entity then null will be returned.
*
* @param type the potion type to check
* @return the effect active on this entity, or null if not active.
*/
@Nullable
public PotionEffect getPotionEffect(@NotNull PotionEffectType type);
/**
* Removes any effects present of the given {@link PotionEffectType}.
*
* @param type the potion type to remove
*/
public void removePotionEffect(@NotNull PotionEffectType type);
/**
* Returns all currently active {@link PotionEffect}s on the living
* entity.
*
* @return a collection of {@link PotionEffect}s
*/
@NotNull
public Collection<PotionEffect> getActivePotionEffects();
/**
* Removes all active potion effects for this entity.
*
* @return true if any were removed
*/
boolean clearActivePotionEffects();
/**
* Checks whether the living entity has block line of sight to another.
* <p>
* This uses the same algorithm that hostile mobs use to find the closest
* player.
*
* @param other the entity to determine line of sight to
* @return true if there is a line of sight, false if not
*/
public boolean hasLineOfSight(@NotNull Entity other);
/**
* Checks whether the living entity has block line of sight to the given block.
* <p>
* This uses the same algorithm that hostile mobs use to find the closest
* player.
*
* @param location the location to determine line of sight to
* @return true if there is a line of sight, false if not
*/
public boolean hasLineOfSight(@NotNull Location location);
/**
* Returns if the living entity despawns when away from players or not.
* <p>
* By default, animals are not removed while other mobs are.
*
* @return true if the living entity is removed when away from players
*/
public boolean getRemoveWhenFarAway();
/**
* Sets whether or not the living entity despawns when away from players
* or not.
*
* @param remove the removal status
*/
public void setRemoveWhenFarAway(boolean remove);
/**
* Gets the inventory with the equipment worn by the living entity.
*
* @return the living entity's inventory
*/
@Nullable
public EntityEquipment getEquipment();
/**
* Sets whether or not the living entity can pick up items.
*
* @param pickup whether or not the living entity can pick up items
*/
public void setCanPickupItems(boolean pickup);
/**
* Gets if the living entity can pick up items.
*
* @return whether or not the living entity can pick up items
*/
public boolean getCanPickupItems();
/**
* Returns whether the entity is currently leashed.
*
* @return whether the entity is leashed
*/
public boolean isLeashed();
/**
* Gets the entity that is currently leading this entity.
*
* @return the entity holding the leash
* @throws IllegalStateException if not currently leashed
*/
@NotNull
public Entity getLeashHolder() throws IllegalStateException;
/**
* Sets the leash on this entity to be held by the supplied entity.
* <p>
* This method has no effect on players.
* Non-living entities excluding leashes will not persist as leash
* holders.
*
* @param holder the entity to leash this entity to, or null to unleash
* @return whether the operation was successful
*/
public boolean setLeashHolder(@Nullable Entity holder);
/**
* Checks to see if an entity is gliding, such as using an Elytra.
* @return True if this entity is gliding.
*/
public boolean isGliding();
/**
* Makes entity start or stop gliding. This will work even if an Elytra
* is not equipped, but will be reverted by the server immediately after
* unless an event-cancelling mechanism is put in place.
* @param gliding True if the entity is gliding.
*/
public void setGliding(boolean gliding);
/**
* Checks to see if an entity is swimming.
*
* @return True if this entity is swimming.
*/
public boolean isSwimming();
/**
* Makes entity start or stop swimming.
*
* This may have unexpected results if the entity is not in water.
*
* @param swimming True if the entity is swimming.
* @deprecated This does nothing and is immediately reverted by the server, in the next tick <!-- Paper - future note: should wait a mojang input client/server side -->
*/
@Deprecated // Paper
public void setSwimming(boolean swimming);
/**
* Checks to see if an entity is currently riptiding.
*
* @return True if this entity is currently riptiding.
*/
public boolean isRiptiding();
/**
* Makes entity start or stop riptiding.
* <p>
* Note: This does not damage attackable entities.
*
* @param riptiding whether the entity should start riptiding.
* @see HumanEntity#startRiptideAttack(int, float, ItemStack)
*/
public void setRiptiding(boolean riptiding);
/**
* Returns whether this entity is slumbering.
*
* @return slumber state
*/
public boolean isSleeping();
/**
* Attempts to make the entity sleep at the given location.
* <br>
* The location must be in the current world and have a bed placed at the
* location.
*
* @param location the location of the bed
* @return whether the sleep was successful
*/
public boolean sleep(@NotNull Location location);
/**
* Causes this entity to wake up if it is currently sleeping.
*
* @throws IllegalStateException if not sleeping
*/
public void wakeup();
/**
* Gets if the entity is climbing.
*
* @return if the entity is climbing
*/
public boolean isClimbing();
/**
* Sets whether an entity will have AI.
*
* The entity will be completely unable to move if it has no AI.
*
* @param ai whether the mob will have AI or not.
*/
void setAI(boolean ai);
/**
* Checks whether an entity has AI.
*
* The entity will be completely unable to move if it has no AI.
*
* @return true if the entity has AI, otherwise false.
*/
boolean hasAI();
/**
* Makes this entity attack the given entity with a melee attack.
*
* Attack damage is calculated by the server from the attributes and
* equipment of this mob, and knockback is applied to {@code target} as
* appropriate.
*
* @param target entity to attack.
*/
public void attack(@NotNull Entity target);
/**
* Makes this entity swing their main hand.
*
* This method does nothing if this entity does not have an animation for
* swinging their main hand.
*/
public void swingMainHand();
/**
* Makes this entity swing their off hand.
*
* This method does nothing if this entity does not have an animation for
* swinging their off hand.
*/
public void swingOffHand();
/**
* Makes this entity flash red as if they were damaged.
*
* @param yaw The direction the damage is coming from in relation to the
* entity, where 0 is in front of the player, 90 is to the right, 180 is
* behind, and 270 is to the left
*/
public void playHurtAnimation(float yaw);
/**
* Set if this entity will be subject to collisions with other entities.
* <p>
* Exemptions to this rule can be managed with
* {@link #getCollidableExemptions()}
* <p>
* Note that the client may predict the collision between itself and another
* entity, resulting in this flag not working for player collisions. This
* method should therefore only be used to set the collision status of
* non-player entities.
* <p>
* To control player collisions, use {@link Team.Option#COLLISION_RULE} in
* combination with a {@link Scoreboard} and a {@link Team}.
*
* @param collidable collision status
*/
void setCollidable(boolean collidable);
/**
* Gets if this entity is subject to collisions with other entities.
* <p>
* Some entities might be exempted from the collidable rule of this entity.
* Use {@link #getCollidableExemptions()} to get these.
* <p>
* Please note that this method returns only the custom collidable state,
* not whether the entity is non-collidable for other reasons such as being
* dead.
* <p>
* Note that the client may predict the collision between itself and another
* entity, resulting in this flag not being accurate for player collisions.
* This method should therefore only be used to check the collision status
* of non-player entities.
* <p>
* To check the collision behavior for a player, use
* {@link Team.Option#COLLISION_RULE} in combination with a
* {@link Scoreboard} and a {@link Team}.
*
* @return collision status
*/
boolean isCollidable();
/**
* Gets a mutable set of UUIDs of the entities which are exempt from the
* entity's collidable rule and which's collision with this entity will
* behave the opposite of it.
* <p>
* This set can be modified to add or remove exemptions.
* <p>
* For example if collidable is true and an entity is in the exemptions set
* then it will not collide with it. Similarly if collidable is false and an
* entity is in this set then it will still collide with it.
* <p>
* Note these exemptions are not (currently) persistent.
* <p>
* Note that the client may predict the collision between itself and another
* entity, resulting in those exemptions not being accurate for player
* collisions. This method should therefore only be used to exempt
* non-player entities.
* <p>
* To exempt collisions for a player, use {@link Team.Option#COLLISION_RULE}
* in combination with a {@link Scoreboard} and a {@link Team}.
*
* @return the collidable exemption set
*/
@NotNull
Set<UUID> getCollidableExemptions();
/**
* Returns the value of the memory specified.
* <p>
* Note that the value is null when the specific entity does not have that
* value by default.
*
* @param memoryKey memory to access
* @param <T> the type of the return value
* @return an instance of the memory section value or null if not present
*/
@Nullable