Hello i got, 2 questions!

Discussion in 'Plugin Development' started by azyhd, Aug 6, 2012.

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

    azyhd

    1st question is how to get the face of the block, and add x, y, z to it so when u look at the side it will place an block on that side and not on the same block where your looking at?

    2nd question how can i switch a lever from far away?

    I'm getting this error :

    And this is my lil peace of code that creates the error:

    Code:
                    if(BlockFace.DOWN !=null){
                        ((Block) down).setType(player.getItemInHand().getType());
                    }
                    if(BlockFace.UP !=null){
                        ((Block) up).setType(player.getItemInHand().getType());
                    }
                    if(BlockFace.NORTH !=null){
                        ((Block) north).setType(player.getItemInHand().getType());
                    }
                    if(BlockFace.EAST !=null){
                        ((Block) east).setType(player.getItemInHand().getType());
                    }
                    if(BlockFace.SOUTH !=null){
                        ((Block) south).setType(player.getItemInHand().getType());
                    }
                    if(BlockFace.WEST !=null){
                        ((Block) west).setType(player.getItemInHand().getType());
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 27, 2016
  2. Offline

    evilmidget38

    You're casting the different locations(down, up, north, east, south, and west) into blocks. I believe there's a getBlockAt() method or something like that you should use instead.
     
  3. Offline

    azyhd

    It works but, right now they will be placed everywhere, i think the BlockFace is wrong any suggestions for that?
     
  4. Offline

    evilmidget38

    I've honestly got no clue what you're trying to do, so I don't think I can offer a whole lot of helpful feedback.
     
  5. Offline

    azyhd

    I'm making a FarReach plugin, right know it can destroy blocks from far away, but not yet place blocks on the good sides :/
     
  6. Offline

    Limeth

    That is an amazing idea, I would like to help you, but I don't know how.
    At least a bump for you. =)

    Good Luck, I'm looking forward to use this.
     
    azyhd likes this.
  7. Offline

    zeeveener

    Did you try getting the location of that block, then comparing it to the location of the player and making the choice based on which difference is greater?

    So say blockX is at 0,0,0 and you are at -5,10,3
    Compare the values:
    x: 0 - (-5) = 5
    y: 0 - 10 = -10
    z: 0 - 3 = -3

    Now i'm not sure if negative is West, East, North, South, Up, or Down, but you can make temp variables of the values positive, check which is larger, then using that knowledge, choose which direction you are in relation to the block and choose the corresponding face...

    It sounds complicated because it is... I don't really want to code it myself as I am working on my own projects, but if you understand what I mean and can code it for yourself, I am interested to see if it works.

    Also, regarding the lever. Try tinkering with EntityInteractEvent and see if you can work it out from there.
     
  8. Offline

    azyhd

    Right now it can already place blocks and remove them, but when placing it will create on all sides of the block a block, and i only want to add a block on the place you aim at, but i havent found a way yet :/
     
  9. Offline

    zeeveener

    I just tried describing a method of doing just that lol...
     
  10. Offline

    azyhd

    i know

    Thanks!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 27, 2016
  11. Offline

    Firefly

    I think something like:

    Code:
    if (BlockFace.NORTH != null) {
        Block b = event.getClickedBlock().getRelative(BlockFace.NORTH);
        b.setType(//whatever the player had in their hand)
    }
     
  12. Offline

    azyhd

    Didn't work :/ hmm i need it :p.
     
  13. Offline

    Deathmarine

    Wouldn't you look up?
    Code:
    Block b = event.getClickedBlock().getRelative(BlockFace.UP);
    if(b==null || b.getType().equals(Material.AIR))b.setType(player.getItemInHand().getType())
     
Thread Status:
Not open for further replies.

Share This Page