Development Assistance Collision checking snowballs in fallingblocks

Discussion in 'Plugin Help/Development/Requests' started by goodstuff20, Jun 16, 2015.

Thread Status:
Not open for further replies.
  1. Hi guys,

    Is there any way an entity (I.e. snowball) can report collision when colliding in a fallingblock?

    Cheers guys
     
    Last edited: Jun 16, 2015
  2. It's actually pretty easy. When you get the nms class of the snowball, there's an getBoundingBox() method in there. This will return an AxisAlignedBB class. in there you have the b(AxisAlignedBB) method that will return a boolean. True if it collides and false if it doesn't. Now you only need to have the other AxisAlignedBB class to pass into the b method. So you get the bukkit world class of the snowball, and you get all the entities of the type FallingBlock.class (or something else) and you also get the nms entity class of it, and in there you also have the getBoundingBox() method, and that gives you the AxisAlignedBB to pass in into the b method of the AxisAlignedBB class of the snowball class. When it collides with the fallingBlock I recommend to use the break; keyword to stop the for loop to increase performance. If you don't know how to get the nms class, you just do "((CraftEntity)Entity).getHandle()" to get the net.minecraft.server.VERSION.Entity class.
    You can also create this in reflection, but it will be harder to do. But if you do it in reflection you don't need to change the imports on the nms classes.
     
    goodstuff20 likes this.
  3. @Bram0101 wow thanks mate!!! I thought fallingblocks didnt have a hitbox...
    Nms always seems to surprise me...
     
  4. I always just look into the server jar with a java decompiler and look at the nms if I need to know something.
     
  5. @Bram0101 hmm yeah thats a good idea - I just rarely need to use nms...
     
  6. Offline

    xTrollxDudex

    Yes, NMS, well, it is... Wait for it... "good stuff"
     
    goodstuff20 likes this.
Thread Status:
Not open for further replies.

Share This Page