Uploaded image for project: 'Spigot'
  1. Spigot
  2. SPIGOT-3942

Preventing collision-effects for specific entities only

XMLWordPrintable

    • Icon: New Feature New Feature
    • Resolution: Fixed
    • Icon: Minor Minor
    • None
    • None
    • None

      Use case:
      Preventing a specific entity (A) from being pushed around by other entities (B, C, .. can be players, mobs, or other types of entities), without interfering with the collision behavior between any of those other entities (B, C, ..).

      Currently there exists LivingEntity#setCollidable(boolean), which doesn't seem to be useable in this case (unless I am missing something here..):

      • A.setCollidable(false): The entity A will be ignored when B, C, .. check for pushable nearby entities (A is not getting pushed and A is not pushing anything). However, when A is ticked, it will itself check for nearby pushable entities (finds B, C, ..), and it will then apply the bidirectional collision behavior (nms.Entity#collide(Entity)) for each of those: A<>B both get pushed, A<>C both get pushed. So A is still getting pushed around regardless of its own collidable flag. (So this doesn't work for the above use case)
      • Proposed solution (as per javadoc of the setCollidable(..) method): A.setCollidable(false), B.setCollidable(false), C.setCollidable(false), ..: This works in the sense that now A is indeed not getting pushed around anymore. However, B and C are not pushing each other around anymore either. And B and C both will no longer get picked up by boats and minecarts, and they will be ignored by projectiles. (Due to these undesired effects on B and C, this doesn't work for the above use case either)

      Proposed solution:
      Check the nms.Entity.collidable flag additionally inside nms.Entity#collide(Entity), before applying the velocity change to an entity.

      One could possibly also add a check for that flag inside nmsEntitySlime#collide(Entity) (before applying damage to an iron golem entity), and inside nms.EntityMinecartAbstract#collide(Entity) (before applying any velocity changes to an entity). Though, there already exist events covering those two cases (damage event, and VehicleEntityCollisionEvent). Additionally checking/'respecting' the collidable flag here might make sense nevertheless though.

      The meaning of entity.setCollidable(false) would then clearly be: "This specific entity is unaffected by any sort of collision effects. Other entities will however still be affected by the collisions with this entity, unless they are set to non-collidable as well."

      I wasn't sure whether to mark this a 'bug' (unintended behavior) or 'feature'/'improvement'-request (since, even though the current behavior is rather unintuitive/limiting, it might be considered in line with the current description of the setCollidable-function).

      If you don't see an issue with the proposed changes, I would be willing to create a corresponding PR for that.

            Unassigned Unassigned
            blablubbabc blablubbabc
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: