-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
54 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/main/java/xyz/nucleoid/stimuli/event/entity/EntityDamageEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package xyz.nucleoid.stimuli.event.entity; | ||
|
||
import net.minecraft.entity.LivingEntity; | ||
import net.minecraft.entity.damage.DamageSource; | ||
import net.minecraft.util.ActionResult; | ||
import xyz.nucleoid.stimuli.event.StimulusEvent; | ||
|
||
/** | ||
* Called when a {@link LivingEntity} is damaged. | ||
* | ||
* <p>Upon return: | ||
* <ul> | ||
* <li>{@link ActionResult#SUCCESS} cancels further processing and damages the entity. | ||
* <li>{@link ActionResult#FAIL} cancels further processing and does not damage the entity. | ||
* <li>{@link ActionResult#PASS} moves on to the next listener.</ul> | ||
* <p> | ||
* If all listeners return {@link ActionResult#PASS}, the entity is damaged as per normal behavior. | ||
*/ | ||
public interface EntityDamageEvent { | ||
StimulusEvent<EntityDamageEvent> EVENT = StimulusEvent.create(EntityDamageEvent.class, ctx -> (entity, source, amount) -> { | ||
try { | ||
for (var listener : ctx.getListeners()) { | ||
var result = listener.onDamage(entity, source, amount); | ||
if (result != ActionResult.PASS) { | ||
return result; | ||
} | ||
} | ||
} catch (Throwable t) { | ||
ctx.handleException(t); | ||
} | ||
return ActionResult.PASS; | ||
}); | ||
|
||
ActionResult onDamage(LivingEntity entity, DamageSource source, float amount); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters