Solved Block cordinates help

Discussion in 'Plugin Development' started by ArthurHoeke, Jun 23, 2014.

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

    ArthurHoeke

    Hello,

    I got a question, How to make that if a player clicks on a piston a block will be placed 1 block above the piston? I know how to check if the player clicks on the piston, But how to let a block place 1 above it?

    - Arthur
     
  2. Offline

    teej107

    Use Location and the getBlock method/setType method.
     
  3. Offline

    ReggieMOL

  4. Offline

    ArthurHoeke

    teej107 ReggieMOL I got this now:

    Code:
            @EventHandler
            public void onPlayerInteract5(PlayerInteractEvent evt){
            Player player = evt.getPlayer();
                if(player.getItemInHand().getType()==Material.GOLD_NUGGET){
                    if (evt.getAction() == Action.RIGHT_CLICK_BLOCK){
                        Block block = evt.getClickedBlock();
                        if (block.getType() == Material.PISTON_EXTENSION) {
                            block.getLocation().setY(+ 1);
                                player.getInventory().removeItem(new ItemStack[] {
                                  new ItemStack(Material.FEATHER, 1) });
                                block.setType(Material.WOOL);
                                block.setData((byte) 2);
                                player.updateInventory();
                        }
                    }
                }
            }
    But this dont work... I get the block.getLocation().setY(+ 1) but it still places itself not 1 higher
     
  5. Offline

    Traks

    You need to get the block above the clicked block and set its type (and other data) to that of the clicked block. Afterwards you set the type of the clicked block to Material.AIR or something else you desire.
     
  6. Offline

    fireblast709

    ArthurHoeke setY(+1) will set the Y to 1. Just use block.getRelative() to get the block above it, then call the rest of the set methods on the block that is returned by getRelative
     
  7. Offline

    ArthurHoeke

    fireblast709 So i got this now:
    Code:
    if(player.getItemInHand().getType()==Material.GOLD_NUGGET){
                    if (evt.getAction() == Action.RIGHT_CLICK_BLOCK){
                        Block block = evt.getClickedBlock();
                        if (block.getType() == Material.PISTON_EXTENSION) {
                            block.getRelative(null);
    Is this good?
     
  8. Offline

    fireblast709

    ArthurHoeke Read the documentation I linked... (the javadocs link to the method)
     
  9. Offline

    ArthurHoeke

    fireblast709 Thanks you, It works now but the bug is that if i right click the block the expended piston turns it self to the left side...

    EDIT: Bug is fixed, I changed the block material and now it works! Thanks for your help!
     
  10. Offline

    Zupsub

    Btw.: Instead of removing an array of itemstacks (with only one item), you can use the remove function with a singualr ItemStack.
     
Thread Status:
Not open for further replies.

Share This Page