How do you get the **blocks** a player is 'standing' on?

This forum post is all about collisions.

I have a few questions, and I’m hoping someone can explain how best to use bounding boxes to do it the same method vanilla can, or expose methods in the API.

What Block am I standing on?

How do you get the blocks a player is ‘standing’ on?

Naive response:

Just get one block below the player!

image

Steve is very clearly standing on a slab. a 1 block offset is the gold block!

In addition, Steve could be standing on 4 blocks given his bounding box size.

In this image:

image

Steve is very clearly again standing on a single slab, because he is above the lava.

Oh, that’s easy, just get the 3 air blocks around the slab!

image
Steve is clearly not on fire.
image

What about cactus? Ladders? Vines? Molten Rock?

image

What about mods?

???

The Answers

Bounding Boxes! (Specifically for Minecraft, Axis Aligned Bounding Boxes.)

Pressing F3 + B shows you the bounding boxes on debug mode.

image

Whilst this guy is in creative, you can clearly see that the bounding box is barely touching. in programming terms, not touching at all.

So, how does vanilla/Sponge do collisions with cactii?

You can listen to the collision with block event:

Warning, it spams, HARD. But if you need it you need it.

You can use an API method: (I hope already, maybe one day? leave a reply)

But doing both of these, it’s hard to tell whether you are colliding side on, or colliding downwards.

Depending on what you want to do, you could need either.

At the moment I don’t have concrete explanations for these. But I’m hoping with time, someone can flesh out this thread with replies. Thanks.


Creepers blew my test rig up :frowning:

image

4 Likes