Skip to content

Commit ffa6007

Browse files
committed
Cleanup new PR + clarified javadocs and nullability
1 parent a784072 commit ffa6007

File tree

2 files changed

+38
-25
lines changed

2 files changed

+38
-25
lines changed

src/main/java/net/minecraftforge/common/ForgeHooks.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -583,12 +583,14 @@ public static void onLivingSetAttackTarget(EntityLivingBase entity, EntityLiving
583583
MinecraftForge.EVENT_BUS.post(new LivingSetAttackTargetEvent(entity, target));
584584
}
585585

586-
public static EntityLivingBase onLivingSetAttackTarget(EntityLiving living, EntityLivingBase target)
586+
public static EntityLivingBase onLivingSetAttackTarget(EntityLiving living, @Nullable EntityLivingBase target)
587587
{
588588
LivingSetAttackTargetEvent event = new LivingSetAttackTargetEvent(living, target);
589-
if (MinecraftForge.EVENT_BUS.post(event)){
589+
if (MinecraftForge.EVENT_BUS.post(event))
590+
{
590591
return living.getAttackTarget();
591-
}else return event.getTarget();
592+
}
593+
return event.getTarget();
592594
}
593595

594596
public static boolean onLivingUpdate(EntityLivingBase entity)

src/main/java/net/minecraftforge/event/entity/living/LivingSetAttackTargetEvent.java

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,16 @@
2525
import net.minecraftforge.common.MinecraftForge;
2626
import net.minecraftforge.fml.common.eventhandler.Cancelable;
2727

28+
import javax.annotation.Nullable;
29+
2830
/**
2931
* LivingSetAttackTargetEvent is fired when an Entity sets a target to attack.<br>
3032
* This event is fired whenever an Entity sets a target to attack in
3133
* {@link EntityLiving#setAttackTarget(EntityLivingBase)}.<br>
3234
* <br>
3335
* This event is fired via the {@link ForgeHooks#onLivingSetAttackTarget(EntityLiving, EntityLivingBase)}.<br>
3436
* <br>
35-
* {@link #originalTarget} contains the newly targeted Entity.<br>
36-
* <br>
37+
* {@link #originalTarget} contains the targeted Entity. Can be null.<br>
3738
* {@link #newTarget} contains the redirected Targeted Entity.<br>
3839
* <br>
3940
* This event is {@link Cancelable}.<br>
@@ -43,46 +44,56 @@
4344
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
4445
**/
4546
@Cancelable
46-
public class LivingSetAttackTargetEvent extends LivingEvent{
47+
public class LivingSetAttackTargetEvent extends LivingEvent
48+
{
49+
@Nullable
4750
private final EntityLivingBase originalTarget;
51+
4852
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)
5256
{
5357
super(entity);
5458
this.originalTarget = target;
5559
this.newTarget = null;
56-
this.isModified = false;
5760
}
5861

5962
/**
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
6266
public EntityLivingBase getTarget()
6367
{
64-
return isModified ? newTarget : originalTarget;
68+
return this.isModified() ? this.newTarget : this.originalTarget;
6569
}
6670

6771
/**
68-
* return the original attack target
69-
**/
70-
public EntityLivingBase getOriginalTarget(){
72+
* @return Original attack target
73+
*/
74+
@Nullable
75+
public EntityLivingBase getOriginalTarget()
76+
{
7177
return originalTarget;
7278
}
7379

7480
/**
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;
8086
}
8187

8288
/**
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;
8797
}
98+
8899
}

0 commit comments

Comments
 (0)