Solved Spawning blocks in front of Player depending on direction facing

Discussion in 'Spigot Plugin Development' started by Puyodead1, Feb 26, 2020.

  1. Hello, I'm working on a plugin that spawns an outline ofa cube in front of a player, the problem I'm facing is that the cube doesn't spawn directly outward in front of the player, for example, when the player is facing north and tries to place it, it generates ontop of the player and traps them inside. It's working fine in the south facing direction.

    This is a video of the problem: https://streamable.com/w0cs0

    And this is the code I'm using to generate the outline:
    Code (Text):

    for (int x = 0; x < boxSize; x++) {
        for (int y = 0; y < boxSize; y++) {
            for (int z = 0; z < boxSize; z++) {

                Block bl = getCenter().getBlock().getRelative(x, y, z);

                if ((x == 0 || x == boxSize - 1) && (y == 0 || y == boxSize - 1) || (x == 0 || x == boxSize - 1) && (z == 0 || z == boxSize - 1) || (y == 0 || y == boxSize - 1) && (z == 0 || z == boxSize - 1)) {
                    bl.setType(Material.BEDROCK);
                }
            }
        }
    }

     
     
  2. you have to account for the directional difference when they face a different direction. for instance, your relative values will always point the same direction (im assuming they all point south so it works that way). you need to make the x or z values when you get the relative negative depending on the direction you face. play around with values and see what values need to be negative when you face north or east or west. i think z is the coordinate for north/south, so if theyre facing north, then make z negative before you get the relative
     
  3. Aight, that's sorta what I was realizing, just wasn't sure what I needed to do. Thank you.
     
    #3 Puyodead1, Feb 26, 2020
    Last edited: Feb 26, 2020