|
25 | 25 | import net.minecraftforge.common.MinecraftForge; |
26 | 26 | import net.minecraftforge.fml.common.eventhandler.Cancelable; |
27 | 27 |
|
| 28 | +import javax.annotation.Nullable; |
| 29 | + |
28 | 30 | /** |
29 | 31 | * LivingSetAttackTargetEvent is fired when an Entity sets a target to attack.<br> |
30 | 32 | * This event is fired whenever an Entity sets a target to attack in |
31 | 33 | * {@link EntityLiving#setAttackTarget(EntityLivingBase)}.<br> |
32 | 34 | * <br> |
33 | 35 | * This event is fired via the {@link ForgeHooks#onLivingSetAttackTarget(EntityLiving, EntityLivingBase)}.<br> |
34 | 36 | * <br> |
35 | | - * {@link #originalTarget} contains the newly targeted Entity.<br> |
36 | | - * <br> |
| 37 | + * {@link #originalTarget} contains the targeted Entity. Can be null.<br> |
37 | 38 | * {@link #newTarget} contains the redirected Targeted Entity.<br> |
38 | 39 | * <br> |
39 | 40 | * This event is {@link Cancelable}.<br> |
|
43 | 44 | * This event is fired on the {@link MinecraftForge#EVENT_BUS}. |
44 | 45 | **/ |
45 | 46 | @Cancelable |
46 | | -public class LivingSetAttackTargetEvent extends LivingEvent{ |
| 47 | +public class LivingSetAttackTargetEvent extends LivingEvent |
| 48 | +{ |
| 49 | + @Nullable |
47 | 50 | private final EntityLivingBase originalTarget; |
| 51 | + |
48 | 52 | private EntityLivingBase newTarget; |
49 | | - private boolean isModified; |
50 | | - |
51 | | - public LivingSetAttackTargetEvent(EntityLivingBase entity, EntityLivingBase target) |
| 53 | + private boolean modified; |
| 54 | + |
| 55 | + public LivingSetAttackTargetEvent(EntityLivingBase entity, @Nullable EntityLivingBase target) |
52 | 56 | { |
53 | 57 | super(entity); |
54 | 58 | this.originalTarget = target; |
55 | 59 | this.newTarget = null; |
56 | | - this.isModified = false; |
57 | 60 | } |
58 | 61 |
|
59 | 62 | /** |
60 | | - * Get the target that will be actually applied |
61 | | - **/ |
| 63 | + * @return {@link EntityLivingBase} target that will be the new attack target |
| 64 | + */ |
| 65 | + @Nullable |
62 | 66 | public EntityLivingBase getTarget() |
63 | 67 | { |
64 | | - return isModified ? newTarget : originalTarget; |
| 68 | + return this.isModified() ? this.newTarget : this.originalTarget; |
65 | 69 | } |
66 | 70 |
|
67 | 71 | /** |
68 | | - * return the original attack target |
69 | | - **/ |
70 | | - public EntityLivingBase getOriginalTarget(){ |
| 72 | + * @return Original attack target |
| 73 | + */ |
| 74 | + @Nullable |
| 75 | + public EntityLivingBase getOriginalTarget() |
| 76 | + { |
71 | 77 | return originalTarget; |
72 | 78 | } |
73 | 79 |
|
74 | 80 | /** |
75 | | - * Set the attack target of the living's, null if remove it |
76 | | - **/ |
77 | | - public void setNewTarget(EntityLivingBase living){ |
78 | | - this.newTarget = living; |
79 | | - this.isModified = true; |
| 81 | + * @return If the attack target is modified |
| 82 | + */ |
| 83 | + public boolean isModified() |
| 84 | + { |
| 85 | + return this.modified; |
80 | 86 | } |
81 | 87 |
|
82 | 88 | /** |
83 | | - * Is the attack target is modified |
84 | | - **/ |
85 | | - public boolean isModified(){ |
86 | | - return this.isModified; |
| 89 | + * Sets a new attack target |
| 90 | + * |
| 91 | + * @param target The new attack target, can be null to remove the attack target altogether |
| 92 | + */ |
| 93 | + public void setNewTarget(@Nullable EntityLivingBase target) |
| 94 | + { |
| 95 | + this.newTarget = target; |
| 96 | + this.modified = true; |
87 | 97 | } |
| 98 | + |
88 | 99 | } |
0 commit comments