Paper icon indicating copy to clipboard operation
Paper copied to clipboard

Expose "EntitySize"/"EntityDimensions"

Open jaylawl opened this issue 3 years ago • 2 comments

Is your feature request related to a problem?

"EntitySize"/"EntityDimensions" is responsible for handling the functional server-side bounding box of an entity. The server will use this bounding box to calculate entity collisions (and propably other things i am not aware of).

However what it doesn't do, is to change the bounding box in any way regarding hit-detection from players.

I am unaware of the correct name of this class, but i am currently (still stuck on 1.17.1 (because of this issue)) accesing it via:

  • net.minecraft.world.entity.EntitySize
  • net.minecraft.world.entity.Entity.class.getDeclaredField("aW");

I would assume that this all of this still works in versions past 1.17, but i am unable to test it. In #3479 dear aikar advised me to use this while i was having other issues regarding entity bounding boxes. But i do not know how to access NMS via the new maven/gradle-enforced-api-coding-environment that has been established in paper releases 1.18+.

Unfornatunately i do absolutely need to the ability to change entity bounding boxes.

Describe the solution you'd like.

The ability to change entity bounding boxes via either:

  1. Entity#setBoundingBox(float width, float height)
  2. Entity#setSize(float width, float height)
  3. Bukkit.getUnsafe().setEntityBoundingBox(Entity, float width, float height) // edit: changed "BoundingBox" to "float, float" - entity dimensions only accept two parameters.

To prevent paper users from opening issues regarding why usage of 1. and 2. doesn't change the entity bounding box for them client side, 3. could be used.

Describe alternatives you've considered.

Maybe could use some hacky packet magic to achieve something similar. But... hacky. And it would put one at the mercy of finding an entity that has the exact bounding box dimensions that one requires.

//edit: Example of what i am doing with this in case you wish to test the functionality: I have a ball based mini game where i am setting the size of an armor stand to be 0.25x0.25 which allows it to fit under half blocks, through the "holes" in stair blocks etc.

Other

Thank you!

jaylawl avatar Nov 06 '22 13:11 jaylawl

I am unsure if this is something to really add. I see where you are coming from here but as you already pointed out, this does only affect server side hit boxes of the entity which could lead to some very interesting behaviour in regards to hitscan of attacks etc.

I don't see why reflective access here does not work ?

The type is called EntityDimensions under mojang mappings and is stored in the Entity type under the field name dimensions in mojang mappings or aZ in a re-obfuscated server environment. You could also use tooling like https://github.com/jpenilla/reflection-remapper to write your reflective access in mojang mappings as well.

Obviously open to other opinions here, nor am I really set on my opinion tbh, more of a hinge or gut feeling about such API.

lynxplay avatar Nov 07 '22 18:11 lynxplay

Changing the bounding box like that is I agree a big yikes. Generally, it's better to reflectively do this yourself in my opinion.

Owen1212055 avatar Nov 14 '22 23:11 Owen1212055

Closing on the terms mentioned above. In general this is quite unsafe behavior, and might be better off doing yourself reflectively as the client really does not support this nicely, and it's not expected by the client for entities to have different bounding boxes like this.

Owen1212055 avatar Nov 28 '22 13:11 Owen1212055