getBlock().getLocation.add(-1, 0, 0) is buggy?

Discussion in 'Plugin Development' started by Wolftic, Mar 19, 2013.

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

    Wolftic

    I'm trying to place blocks on the location with getBlock().getLocation.add(-1, 0, 0); but it places it acting weird and stuff (also used substract bugged too).
     
  2. Offline

    skipperguy12

    What are you trying to do? ._.

    Setting the block? block.setMaterial(<Material here>);
     
  3. Offline

    Wolftic

    I'm trying to make this:

    #
    #
    # #@# #
    #
    #

    But it ends up like this:

    # # # #@

    #
    #

    #
    #

    Not like it's supposed to.
     
  4. Offline

    skipperguy12

    Wolftic

    Create a new location variable and use getLocation and subtract 2 from the get block Y or X, depending which way it is?
     
  5. Show your actual code.
     
  6. Offline

    Wolftic

    spaces got f*cked up.. making a screenie.
    It should be this:
    [​IMG]

    But it makes this:
    [​IMG]

    Code:
            Block b = event.getBlock().getRelative(BlockFace.UP);
            Location l = b.getLocation();
            b.setType(Material.DOUBLE_STEP);
            World s = event.getPlayer().getWorld();
           
            l.add(new Location(s, 1, 0, 0)).getBlock().setType(Material.STEP);
            l.add(new Location(s, 2, 0, 0)).getBlock().setType(Material.STEP);
            l.add(new Location(s, -1, 0, 0)).getBlock().setType(Material.STEP);
            l.add(new Location(s, -2, 0, 0)).getBlock().setType(Material.STEP);
     
            l.add(new Location(s, 0, 0, 1)).getBlock().setType(Material.STEP);
            l.add(new Location(s, 0, 0, 2)).getBlock().setType(Material.STEP);
            l.add(new Location(s, 0, 0, -1)).getBlock().setType(Material.STEP);
            l.add(new Location(s, 0, 0, -2)).getBlock().setType(Material.STEP);
           
            l.add(new Location(s, 1, 0, 0)).getBlock().setData((byte) 2);
            l.add(new Location(s, 2, 0, 0)).getBlock().setData((byte) 2);
            l.add(new Location(s, -1, 0, 0)).getBlock().setData((byte) 2);
            l.add(new Location(s, -2, 0, 0)).getBlock().setData((byte) 2);
           
            l.add(new Location(s, 0, 0, 1)).getBlock().setData((byte) 2);
            l.add(new Location(s, 0, 0, 2)).getBlock().setData((byte) 2);
            l.add(new Location(s, 0, 0, -1)).getBlock().setData((byte) 2);
            l.add(new Location(s, 0, 0, -2)).getBlock().setData((byte) 2);
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  7. Offline

    nisovin

    You're assuming your "l" variable resets to its initial value after each line. It doesn't, it keeps the changes you made.
     
  8. Offline

    Wolftic

    How should I do it then?
     
  9. Offline

    XbannisherX

    set it to zero after every change
     
  10. XbannisherX
    That would go horribly wrong.

    Wolftic
    I suggest you use getBlock().getRelative() instead... and you should also use setTypeIdAndData() instead of getting the block twice to set type then data.
     
  11. Offline

    Barinade

    Say your x is 5, if you do (1,0,0) your x is now 6, and then on the next line down instead of doing (2,0,0) to get 7, you just do (1,0,0) because it's set to 6. Basically, location is being modified every time you do add()

    Use block.getRelative(BlockFace.NORTH).getRelative(BlockFace.NORTH).whatever
    This will get the block 2 blocks north of the source block.

    There is a much better way to do this but I don't feel like writing it right now, add me on Skype if you want it
    ira.sancti
     
  12. Offline

    devilquak

    I had problems like this when I was making a Christmas tree plugin. In the end it was too much of a hassle to place all the blocks manually, so I went with pasting schematic files with WorldEdit.
     
Thread Status:
Not open for further replies.

Share This Page