how to ignore player knockback effect in creative mode
#1
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
Reply
Thanks given by:
#2
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);
}
Reply
Thanks given by:
#3
(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]
Reply
Thanks given by:
#4
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.
Reply
Thanks given by:




Users browsing this thread: 1 Guest(s)