1.17.x How can I make an NPC Non-Collidable?

Discussion in 'Spigot Plugin Development' started by CablePlays, Jul 17, 2021.

  1. Hey guys! So I can spawn an NPC, but I can't work out how to disable its collision. So far what I've tried is making players not able to collide, which worked because I wasn't able to push animals, and then I set the EntityPlayer "collides" field to false, along with all the other booleans I could find in the EntityPlayer class (including the private ones).

    I know NMS is very version specific so I'm using 1.17.1 to let you guys know. :)

    Any help would be great, thanks!
     
    #1 CablePlays, Jul 17, 2021
    Last edited: Jul 17, 2021
  2. Add it to team and set team's collision rule
     
    • Useful Useful x 1
  3. I'll do that if I have to, but if anybody could suggest something that doesn't require teams, that would be nice. :)
     
  4. I would try:
    Code (Java):
    EntityPlayer NPC;
    LivingEntity livingEntity = (LivingEntity) NPC;
    livingEntity.setCollidable(false);
    Edit: Haven't tested if these casts will work together but if they dont im sure you can find a way around it :)
     
    • Optimistic Optimistic x 1
  5. Hey! Thanks for the suggestion, but that unfortunately doesn't work. Probably because the server thinks that the NPCs don't exist because I spawned them in using packets sent to the client.

    I also just tested this, and it doesn't work either, probably because of the same reason.

    Is there a specific packet I can use to stop collisions?
     
  6. I believe you need to make both the player and the entity non-collidable
     
  7. Quick question… are you trying to set the NPC’s collision before or after you spawn them in?
     
  8. Hey! Yeah this is what I've been trying.

    ...however I did try to see the no collision before it was spawned.
    I've quickly just tried to do it the other way around, and no difference. The way I'm spawning them in is using packets and not actually adding them to the world. So I'm pretty sure that using the setCollidable() method won't do anything.
     
  9. You need to use team sorry