Cuberite Forum
how to ignore player knockback effect in creative mode - Printable Version

+- Cuberite Forum (https://forum.cuberite.org)
+-- Forum: Cuberite (https://forum.cuberite.org/forum-4.html)
+--- Forum: Development (https://forum.cuberite.org/forum-13.html)
+--- Thread: how to ignore player knockback effect in creative mode (/thread-3185.html)



how to ignore player knockback effect in creative mode - changyongGuo - 06-26-2018

Hi ,

I want to fix bug about player can be knockback by TNT explosion in creative mode.

I checked source code and found explosion use cEntity::AddSpeed method to apply knockback effect.

What I am not sure is this:

is it proper to override AddSpeed method in cPlayer class to ignore knockback effect?
I searched source code, AddSpeed is used for all knockback effect including knockback from mob attack, I am not sure if I miss others that need to call this function in creative mode?

Best regards
Changyong


RE: how to ignore player knockback effect in creative mode - NiLSPACE - 06-26-2018

Something like this might work:
// If not a player or not in creative mode
if (!a_Entity.IsPlayer() || !static_cast<cPlayer *>(a_Entity).IsGameModeCreative()) {
	a_Entity.AddSpeed(DistanceFromExplosion);
}



RE: how to ignore player knockback effect in creative mode - changyongGuo - 06-26-2018

(06-26-2018, 05:14 PM)NiLSPACE Wrote: Something like this might work:
// If not a player or not in creative mode
if (!a_Entity.IsPlayer() || !static_cast<cPlayer *>(a_Entity).IsGameModeCreative()) {
 a_Entity.AddSpeed(DistanceFromExplosion);
}

But this is kind of violate d[font=微软雅黑]ependency inversion, Maybe we should override method in Player class to ignore knockback?[/font]

[font=微软雅黑]Since there are more knockback effot such as knockback by attach need to fix in creative mode too?[/font]

[font=微软雅黑]I don't know if addSpeed is the right method to modify..[/font]


RE: how to ignore player knockback effect in creative mode - NiLSPACE - 06-26-2018

Overriding it completely means nothing can ever move it again, including plugins. That would make plugins like these would suddenly stop working for users in creative.