Activating a Button Using a Location

Discussion in 'Plugin Development' started by phimt, Jun 2, 2012.

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

    phimt

    I'm trying to activate a button on the map by using its position so it would be the equivalent of someone pressing it in-game. The current code I'm using looks fine, and I can't find more information from searching.

    Code:
    Location buttonLoc = new Location(player.getWorld(), -887, 73, 1347);
    Button startButton = new Button(buttonLoc.getBlock().getData());
    startButton.setPowered(true);
    
    Running block.toString() returns air where the button should be, so it could be a problem with the location. If my head is where the button is, shouldn't the f3 coordinates be the same?
     
  2. Offline

    Njol

    You have to set the data back to the block:
    buttonLoc.getBlock().setData(startButton.getData());
     
  3. Offline

    phimt

    I found the correct location of the button. It looks like the debug screen coordinates are +1 x of the actual coordinates of your head.

    Unfortunately, using this code makes the button come off the block it's attached to and float in air as if it were attached to a block -1 x of the original block. I don't know whats going on.
    Code:
    Location buttonLoc = new Location(player.getWorld(), -888, 73, 1346);
    Button startButton = new Button(buttonLoc.getBlock().getData());
    startButton.setPowered(true);
    buttonLoc.getBlock().setData(startButton.getData());
    
     
Thread Status:
Not open for further replies.

Share This Page