-
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.
Added EntityTotemActivateEvent (#48)
* Added EntityTotemActivateEvent * Made the mixin not dumb and cleaned up. * Check isClient before invoking event * Return early for the isClient check * Fix the isClient check
- Loading branch information
Showing
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
src/main/java/xyz/nucleoid/stimuli/event/entity/EntityActivateTotemEvent.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,37 @@ | ||
package xyz.nucleoid.stimuli.event.entity; | ||
|
||
import net.minecraft.entity.LivingEntity; | ||
import net.minecraft.entity.damage.DamageSource; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.util.ActionResult; | ||
import xyz.nucleoid.stimuli.event.StimulusEvent; | ||
|
||
/** | ||
* Called when a {@link LivingEntity} activates a totem of undying. | ||
* | ||
* <p>Upon return: | ||
* <ul> | ||
* <li>{@link ActionResult#SUCCESS} cancels further processing and activates the totem. | ||
* <li>{@link ActionResult#FAIL} cancels further processing and does not activate the totem. | ||
* <li>{@link ActionResult#PASS} moves on to the next listener. | ||
* </ul> | ||
* </p> | ||
*/ | ||
public interface EntityActivateTotemEvent { | ||
|
||
StimulusEvent<EntityActivateTotemEvent> EVENT = StimulusEvent.create(EntityActivateTotemEvent.class, ctx -> (entity, source, itemStack) -> { | ||
try { | ||
for (var listener : ctx.getListeners()) { | ||
var result = listener.onTotemActivate(entity, source, itemStack); | ||
if (result != ActionResult.PASS) { | ||
return result; | ||
} | ||
} | ||
} catch (Throwable t) { | ||
ctx.handleException(t); | ||
} | ||
return ActionResult.PASS; | ||
}); | ||
|
||
ActionResult onTotemActivate(LivingEntity entity, DamageSource source, ItemStack itemStack); | ||
} |
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