Event triggered whenever an entity’s velocity changes? For example, player slowdown effect when their hunger is low or player is walking on cob web or on ice. I need to disable/customize those effects.
If an entity’s velocity changes, it would be represented with some sort of movement. Using some simple math, you could then get the Entity’s old XYZ and new XYZ to determine the velocity of the movement.
TL;DR Subscribe to EntityMoveEvent
. (Note, I have no idea if that’s a real event, but it should be something like that)
By what you described, you would be finding the average velocity between the old position and the new. To get the exact velocity, you would have to use some Calculus to find the actual velocity, which would be considerably more difficult given the context of the issue.
This returns the velocity of a player, you could check that each time a movement is detected(when the EntityMoveEvent
, as FerusGrim said, is fired).
Isn’t that considered inefficient checking if velocity changes on player movement? I still can’t figure out how to disallow any slowdown effect.
I recommend using EntityMoveEvent
(Or PlayerMoveEvent
if it’s just for players). Another way could be to look at when the entity collides with things like cobwebs, however you’d have to add a case for every type of slowdown/speed-up, a move event should cover them all.
related issue
edit: also, doesn’t the client just assume it should change its movement for ice? there might be a data tag existing for cobwebs since you’re able to ignore them if you’re in creative mode or something, but i don’t think there’s one for moving on ice.
The ice slowdown effect, and the disabled sprinting on low hunger, are both done client side. Since the client never sends its velocity to the server (only position), the only way to detect these would be looking at PlayerMoveEvent
, or checking the block they’re standing on.
As for disabling it…you’re out of luck without a mod (apart from changing the block they’re standing on :D)
You -are- able to tell the client its current velocity, and it’ll move accordingly; thus, control of knockback is available. Can’t do much about what the client does all on its own, though.
I understand about the ice one. But what about sprinting getting disable due to low hunger? There must be a way to still be able to sprint even if you are in low hunger.
Edit: I want to use the hunger bar for showing other data on the game. Sorta like a secondary exp bar.
You can try faking sprinting by changing the user’s speed whenever they move. You’ll have to figure out a way to let the player flag when they want to sprint, though; I don’t think the client sends a packet for when a player double-taps W / taps Sprint key. The client pretty much ignores the server in deciding being able to sprint; its always gonna be no sprint if <= 30% hunger.
But if you are in creative, that whole flag is disabled. In Bukkit there was an event whenever a player toggles their sprint but it didn’t detect hunger slowdown. I guess it’s pretty hardcoded into Minecraft.
There was an event on it; but, considering the client doesn’t care about what the server says, I’d assume the event was fired when the player sent a packet to start or stop sprinting as opposed to sending one that says they attempted to sprint.