Manipulate Gravity

I don’t know exactly where to put it, so I’m just writing it here.
I tried to change player/world gravity using Bukkit once but horribly failed.
I know it is possible (i think sethbling did something like this) but i just couldn’t get it to work.

So I would suggest to add this to the World or Player class and to use it like:
World.setGravity(float) or Player.setGravity(float)

In case you think this would be pointless and i was just too stupid to get it to work feel free to yell at me, I’m sorry ^^

4 Likes

That would be AWESOME. Imagine it - creating a Moon land, or even different planets with custom world generators, combined with custom gravity for even more interesting effects.

I’d say applying specific gravity to a player shouldn’t actually be covered by the Sponge API. This is more like a second layer issue that needs to be handled by the developer. It should be easily feasible with the tools the API provides.

1 Like

Search for a Forge mod called Galacticraft.

1 Like

One thing to mention: Player movement(walking, jumping, velocity, ext) is all handled by the CLIENT. Changing gravity is near impossible without modifying the client(yes I understand this is sponge).

There is a way to mimic gravity, you can run a looping task that is always setting players velocity up(or down).

You might want to work directly with Forge instead, it might be more fitting as Forge is a more versatile and powerful API.

This is quite easy.
Simply grab the gravity value, devide it by 2 and multiply it by -1
then add it to the entities motY every thick, you will jump higher and fall slower

3 Likes

Gravity is not handled by the client. All movement is handled by the server. Hence the rubberbanding when having lag. Prediction however is done on the client. So by adjusting movement only on the server side it might become jittery on the client side.

@Zerot Actually, no. The client calculates movement and sends its location to the server. It’s why things like flight hacks exists. The system you’re thinking of is the system used by games like Quake - it also happens to be the only reasonable system, but that thinking has never stopped Mojang.

3 Likes

@Zerot Download a “test minecraft client” (text mc client) and see by yourself. Many of them does not supports moving, so the player entity is just flying in air. So the gravity is actually handled by client.

@DosMike I think you can make effect of gravity by using Player.setVelocity() function. At least, you could in Bukkit. Don’t know if songe will have simillar function, but I think, It will.

1 Like

I just checked the protocol and you guys are right. I’m extremely surprised by that. I assumed that MC would have followed normal authoritative server design as is usual for client-server setups. This also explains the horrible horse and boat movement on servers, because apparently they don’t have any lag compensation in there.

@dobrakmato setVelocity() is what i tried on bukkit but it wasn’t that great.

@all thanks for your response.
This explains why setting the velocity frequently onPlayerMove did not work that well ^^
I guess I’d need to wait for the movement to switch to the server for this to work correctly…

Maybe You can get better result if You apply velocty on each tick, instead of setting it in onPlayerMove.

function tick() {
    for(Player p : Bukkit.getOnlinePlayers())
        if(p.isOnGround())
             p.setVelocity(new Vector(0, 0.5, 0));
}

pretty sure that would not let you move because it would override any movement sent by the client. You would float up at 0.5 blocks/s with no control of direction

From that point of view I would agree for sure.
There is more than just setting the velocity. You want to grab it then do math then reapply it. Just setting it is just asking for… Imploding organs due to space… hehe. Minecraft does not have that though.

1 Like

Like he said, Sethbling did make a plugin like this before called BlingGravity. I decompiled his plugin to have a look at the code, and its not too complicated, although I have not worked with vectors so I do not know how to do it myself.

This is what I got from looking at the code to his plugin:

if (entity is not on ground and not in vehicle) {
get the first block below entity
if certain block then set write velocity to variable
set new velocity to variable based on current entity velocity
}
else if (entity is player) {
get current position
get position of player (again)
subtract position from position
write velocity to variable (really just means doesn’t work on player)
}
set velocity to entity