ITADN

proposal: make DamageContainer carry settable (from EntityDamageEvent) knockback values

#804Closedzernix2077 创建于 2026-01-25
Z
zernix2077commented
Currently, knockback during damage is handled in `EntityLivingComponentImpl.applyDamage` long after the `DamageContainer` instance is constructed and the `EntityDamageEvent` is called, and there is no way to override it: https://github.com/AllayMC/Allay/blob/c91322b157f8a538eee840fc21e562ce1741cd9b/server/src/main/java/org/allaymc/server/entity/component/EntityLivingComponentImpl.java#L143-L157 The simplest solution seems to be introducing `protected double knockback = EntityPhysicsComponent.DEFAULT_KNOCKBACK` and `protected double knockbackY = EntityPhysicsComponent.DEFAULT_KNOCKBACK` in `DamageContainer`, and then using `var kb = damage.getKnockback();` and `var kby = damage.getKnockbackY();` in `applyDamage`. However, this would not make it possible to change the `additionalMotion` field and may miss some use cases, such as knockback being set due to arrow damage: https://github.com/AllayMC/Allay/blob/c91322b157f8a538eee840fc21e562ce1741cd9b/server/src/main/java/org/allaymc/server/entity/component/projectile/EntityArrowPhysicsComponentImpl.java#L96-L107 A more advanced solution would be to introduce a separate knockback calculation method for entities, refactor all hardcoded knockback handling into it, and use it as the default value for a `Vector3f knockback` field in `DamageContainer` during event construction rather than after it. However, this approach may be opinionated and would require deeper knowledge of the codebase, which I do not yet have, so I'm making this feature proposal here. Rationale: this is essentially a musthave for pvp practice servers.
关闭于 2026-01-27 1 条评论