For a plugin I’m writing I’d like to fine-tune the players gravity, so I can for example set it to let’s say 0.75, so the player can jump fences.
Manipulating the gravity in such a way would also require the FallDamage to be corrected (multiplied with gravity?).
So what would be the best way to implement it with Sponge as it is right now?
Of course I could fix the player-speed every tick by tracking the y delta, and moving the player back by a small amount, but I don’t think that would run very smooth.
You can try using the Sethbling’s method, just adapt the code to Sponge, I’ve done it using Mixin to offer better performances but it’s still difficult to implement and a bit buggy sometimes. For now my sources are under a private license but I will try to help you if you need some help.
Fixing the player speed while tracking the y delta works fine for players on my side but is a bit buggy for mobs. At least for players it’s smooth.
I will try to recover some pieces of my code to help you if you want.
I would really really love that SpongeAPI supports custom gravity (and maybe other movement modifications) per entity.
I don’t really have the knowledge to decompile the bukkit plugin and I’ve never even looked at the Mixin system, so since Yeregorix seems to have no problem I guess I’ll just go with manipulating the y delta.
I just wanted to see if someone could come up with a better idea.
I’ll report back once I’ve played around with it for a bit
Ok so I played around and noticed, the MoveEntityEvent produced strange results for me.
Running
public static void tickGravity(Entity ent) {
Vector3d newv = ent.getVelocity();
UUID uuid = ent.getUniqueId();
if (gravityModifiers.containsKey(uuid) && velocities.containsKey(uuid) && !ent.isOnGround() && !ent.getVehicle().isPresent()) {
Vector3d oldv = velocities.get(uuid);
Vector3d d = newv.sub(oldv);
double gravity = gravityModifiers.get(uuid);
double dy = d.getY();
if (Math.abs(dy)>0.01) {
newv = new Vector3d(newv.getX(), oldv.getY()+dy*gravity, newv.getZ());
ent.setVelocity(newv);
}
}
velocities.put(uuid, newv);
}
Worked pretty good scheduled every half tick, but setting a gravity of 0.5 allows me to jump 3x the hight and higher gravity values result in lower gravity
Well since it’s not too important I think I’ll leave it at that and hope Sponge will get support for that