Solved Getting the center point of a block

Discussion in 'Spigot Plugin Development' started by nokoa, Jun 10, 2016.

  1. I need help getting the center point of an interacted block as a Location.

    I am trying to spawn a firework in the location a player presses on the ground, and it just looks odd when it's not in the middle.
     
  2. You either add or subtract 0.5 from x and z (can't remember which)
     
  3. Because the locations are from a corner of a block, really no matter if you add or subtract you will always be getting the centre of A block but to get the center of a specific block a simple google search would have solved your problem:

    https://bukkit.org/threads/center-of-the-block.14265/
     
  4. Yeah I was on my phone and I couldn't remember which corner the location object refers to. xD
     
  5. oh lol forgot to quit the OP (the second part was in reply to the OP, the first was aimed at both of you :/)
     
  6. Yes I need to get the center of the specific block a player had interacted with. I looked at that thread before, it did not seem to help.
     
  7. Lets say loc = blocks location

    loc.add(0.5, 0, 0.5);
    would be the centre of the block face down and 2D

    loc.add(0.5,-0.5,0.5);
    would be the centre of the block 3D
     
    • Like Like x 1
  8. That did not seem to work.

    I was able to resolve the issue like so:

    Code (Text):
    location.add(x > 0 ? 0.5 : -0.5, 0.0, z > 0 ? 0.5 : -0.5);
    That will get the center of the block in 2D

    Thank you all for your help!
     
    • Useful Useful x 2
    • Friendly Friendly x 1
  9. the center of blocks do not change for x < 0 or x > 0 same with y and z, it will always be -0.5
     
  10. That's what I thought, but it would just got me a different block.
     
  11. If you use your current method you will be unable to set:

    0.5,y,z
    And
    X,y,0.5

    Which in my calculations is like 1 billion locations that you are just skipping.