Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

entity's position still changing, even when returning before ticking movement in Tick() #534

Closed
RestartFU opened this issue Jul 5, 2022 · 5 comments

Comments

@RestartFU
Copy link
Contributor

RestartFU commented Jul 5, 2022

here is the Tick() code, I am setting lock to true when the entity hits something that isn't another entity:

func (f *FishingHook) Tick(w *world.World, current int64) {
	if f.close {
		_ = f.Close()
		return
	}

	held, _ := f.owner.HeldItems()
	if r, ok := held.Item().(interface {
		Rod() bool
	}); !ok || !r.Rod() {
		f.close = true
		return
	}
	if f.lock {
		return
	}

	f.mu.Lock()
	vel := f.vel
	m, result := f.c.TickMovement(f, f.pos, vel, 0, 0, f.ignores)
	f.pos, f.vel = m.Position(), m.Velocity()

	f.age++
	f.mu.Unlock()

	m.Send()

	if result != nil {
		if res, ok := result.(trace.EntityResult); ok {
			if l, ok := res.Entity().(entity.Living); ok && !l.AttackImmune() {
				if _, vulnerable := l.Hurt(0.0, damage.SourceProjectile{Projectile: f, Owner: f.Owner()}); vulnerable {
					if p, ok := l.(*player.Player); ok {
						// Push back the target.
						p.KnockBack(l.Position().Sub(vel), 0.274, 0.372)
						if p.Sprinting() {
							p.StopSprinting()
							time.AfterFunc(time.Millisecond*100, func() {
								p.StartSprinting()
							})
						}
					}
				}
			}
			f.close = true
		} else {
			f.lock = true
		}
	}
} 

and here is a video showing it: https://youtu.be/776Z-EpTKGA

@RestartFU RestartFU changed the title entity's position still changing, even when not returning before ticking movement in Tick() entity's position still changing, even when returning before ticking movement in Tick() Jul 5, 2022
@Sandertv
Copy link
Member

Sandertv commented Jul 5, 2022

Could you do some debugging to see if that bool is actually changed?

@Sandertv
Copy link
Member

Sandertv commented Jul 5, 2022

Also could you verify that this is not a client-side thing by logging or otherwise showing the current position of the entity?

@RestartFU
Copy link
Contributor Author

image
the bool is changed, and the position isn't changed. So this seems to be client-sided, any way I could still avoid that behavior ?

@Sandertv
Copy link
Member

Sandertv commented Jul 5, 2022

Try giving it an Immobile() method and returning false there if f.lock is true. That should make it stop moving client-side. (Also make sure to resend the entity state when doing that).

@RestartFU
Copy link
Contributor Author

Try giving it an Immobile() method and returning false there if f.lock is true. That should make it stop moving client-side. (Also make sure to resend the entity state when doing that).

thanks, that worked!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants