Block from location

Discussion in 'Plugin Development' started by new-ewrs728, Nov 28, 2018.

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

    new-ewrs728

    Hey. I saw such topics on the forum, but I did not find the exact one I need. I need to get blocks from LOCATION1 to LOCATION2. And I do not need all the block (CUBOID), and specifically on the diagonal

    I need specific blocks from location1 to location2

    Thanks

    mi913.png
     
  2. Offline

    CraftCreeper6

    @new-ewrs728
    You want all the blocks on that red line between the two locations?
     
  3. Offline

    Zombie_Striker

    I don't think anyone wrote anything yet that can do this, but you should be able to do it by doing the following:
    1. Create a double called "step". This represents the size of the steps that will be taken to get all blocks. Setting it to 1 will mean that the check will jump 1 block each time, which means that some blocks could be missed if it passages through a corner. I would recommend choosing either 0.5 or 0.25 for this, but you can also do 0.1 if it really needs to be precise.
    2. Create a list to store all the blocks.
    3. Create a new location. This will will be the location object that checks for blocks. Set it equal to the Clone of location 1.
    4. Create a new Vector. This is equal to the location 2 minus location one, then normalized and then multiplied by step. This represent the direction needed to get from location 1 to location 2.
    5. Create a for double loop. It will equal 0, and as long as it less than the distance between the two object, += the step.
    6. Every time the loop runs, add the vector to the location. Then, check if the block is in the list. If it is not, add it to the list.
    7. Once the loop is done, you know have a list of all blocks along that line.
     
  4. Offline

    new-ewrs728

    Something too hard: D

    I just need to know the number of blocks from one location to another.
     
  5. Offline

    CraftCreeper6

    @new-ewrs728
    Pythagoras can do this, get the x difference and y difference, square each, add them together and square root the answer. Another way is to use location#distance(location2);

    And if you wanted the number of blocks, divide the answer by the length of one block.
     
  6. Dividing by the length of 1 block would only work if the blocks are lined up in the same direction as the line between the locations. And by the way, the length of 1 block is exactly 1 meter, so it is a bit pointless.
     
  7. Offline

    CraftCreeper6

    @knokko
    Just use loc1#distance(loc2)
     
  8. @CraftCreeper6

    Those lines both hit 3 blocks, but I wouldn't say they have the same length. The distance method returns the length between 2 points, but that length is not exactly the amount of blocks that is hit (although it is a fair approach for long distances).

    <Edit by Moderator: Redacted mediafire url>
     
    Last edited by a moderator: Dec 14, 2018
Thread Status:
Not open for further replies.

Share This Page