Solved NMS Block Location

Discussion in 'Plugin Development' started by krazytraynz, Aug 11, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    krazytraynz

    Spoiler (open)
    I can't find any way to get the bounding box of a block as easily as it is for entities (entity.boundingBox), and I don't know how to use the methods that seem to return what I need. I'm trying to check for the collision of bounding boxes between entities and water, and I feel like there should be some form of method to check for this because Minecraft manages to detect when a player is drowning, I just can't find anything. Does anyone know what I need to do for this? Any help is appreciated, thanks :)


    UPDATE:
    I copy/pasted this method from World.java, and I changed it a bit so it would do what I need it to. The only problem is getting the location of the block to set it to air, because I don't know how to get the location of a block in NMS and I haven't been able to cast it to anything else. Does anyone have any ideas as to how to get the blocks' locations?

    Code:java
    1. public List<Block> waterBlocks(){
    2. List<Block> blockList = new ArrayList<Block>();
    3. int var3 = MathHelper.floor(boundingBox.a);
    4. int var4 = MathHelper.floor(boundingBox.d + 1.0D);
    5. int var5 = MathHelper.floor(boundingBox.b);
    6. int var6 = MathHelper.floor(boundingBox.e + 1.0D);
    7. int var7 = MathHelper.floor(boundingBox.c);
    8. int var8 = MathHelper.floor(boundingBox.f + 1.0D);
    9.  
    10. for (int var9 = var3; var9 < var4; ++var9)
    11. {
    12. for (int var10 = var5; var10 < var6; ++var10)
    13. {
    14. for (int var11 = var7; var11 < var8; ++var11)
    15. {
    16. net.minecraft.server.v1_7_R4.Material m = world.getType(var9, var10, var11).getMaterial();
    17. if (m == net.minecraft.server.v1_7_R4.Material.WATER)
    18. {
    19. blockList.add(world.getType(var9, var10, var11));
    20. }
    21. }
    22. }
    23. }
    24.  
    25. return blockList;
    26. }
     
  2. Offline

    _Filip

    You can calculate it yourself, walk up to a corner until you cannot walk anymore, then see your x and y in relation to the blocks in front of you
     
  3. Offline

    hintss

    A block's bounding box is...1x1x1?
     
  4. Offline

    Necrodoom

    hintss stairs, slabs, etc.
     
  5. Offline

    hintss

    ah
     
  6. Offline

    krazytraynz

    Water doesn't stop players from moving :p I'm also trying to get all of the blocks the entity is touching, and entities like sheep, cows, slimes, etc. can take up more than one block at a time. Thanks for the idea though, that'll help me with a different plugin.
     
  7. Offline

    krazytraynz

  8. Offline

    krazytraynz

    Found a solution, changed the method to return a list of locations instead of a list of blocks.
    Code:java
    1. public List<Location> waterBlocks(){
    2. List<Location> blockList = new ArrayList<Location>();
    3. int var3 = MathHelper.floor(boundingBox.a);
    4. int var4 = MathHelper.floor(boundingBox.d + 1.0D);
    5. int var5 = MathHelper.floor(boundingBox.b);
    6. int var6 = MathHelper.floor(boundingBox.e + 1.0D);
    7. int var7 = MathHelper.floor(boundingBox.c);
    8. int var8 = MathHelper.floor(boundingBox.f + 1.0D);
    9.  
    10. for (int var9 = var3; var9 < var4; ++var9)
    11. {
    12. for (int var10 = var5; var10 < var6; ++var10)
    13. {
    14. for (int var11 = var7; var11 < var8; ++var11)
    15. {
    16. net.minecraft.server.v1_7_R4.Material m = world.getType(var9, var10, var11).getMaterial();
    17. if (m == net.minecraft.server.v1_7_R4.Material.WATER)
    18. {
    19. blockList.add(new Location(world.getWorld(), var9, var10, var11));
    20. }
    21. }
    22. }
    23. }
    24.  
    25. return blockList;
    26. }
     
Thread Status:
Not open for further replies.

Share This Page