The first challegne “shared life” is done.
The core mechanic is when a player takes damage, everyone else gets the same amount. sounds simple, but it took me quiet a bit to get that right. the method i needed to use is called hurtServer in 26.x, not hurt like every tutorial says (cause of old yarn mappings like alr said in last devlog).
@Inject(method = [“hurtServer”], at = [At(“TAIL”)])
private fun onHurtServer(level: ServerLevel, source: DamageSource, amount: Float, cir: CallbackInfoReturnable) {
if (!cir.returnValue) return
if (ChallengeState.activeChallenge !is SharedLifeChallenge) return
val entity = this as? ServerPlayer ?: return
if (source.directEntity == null && source.entity == null) return
SharedLifeChallenge.onPlayerHurt(entity, amount)
}
the directEntity == null check is to prevent an infinite loop. When we deal damage to the other players, that would trigger the mixin again. Generic damage (the kind I use to pass the damage to other players) has no entity source so we can filter it out that way.
Comments 0
No comments yet. Be the first!
Sign in to join the conversation.