Attach torch and check torch placement

Discussion in 'Plugin Development' started by Psychokiller1888, Mar 14, 2013.

Thread Status:
Not open for further replies.
  1. Hi there!

    The plugin listens on player right clicks. It then places a torch on the block you right clicked. Simple.

    But

    Was wondering if there's a simple method to check wheter or not a torch can be placed on a block. Per exemple, how do I know I can't place a torch on snow, or on a bed... Is there anything existing?

    How to I attach a torch to a block face. With event.getClickedBlock() I get the block itself. With event.getClickedFace I get a BlockFace face of the block I clicked. Now, how do I attach a torch on that particular face?

    Thanks for your replies.
     
  2. Offline

    chasechocolate

    Get the block on that BlockFace and use setType(Material.TORCH).
     
  3. Thanks for the answer. Did not yet figure out how to get the block attached to that blockface...

    And about the second question?
     
  4. Code:
    block.getRelative(blockFace);
    To get the block relative to that block face.

    Also, the attachment direction of a torch it's its data value.

    But I guess you can use something like this...
    Code:
    Torch t = new Torch(); // just used to calculate the data value for the block
    t.setFacingDirection(blockFace.getOppositeFace());
    block.setData(t.getData());
    And if it doesn't work try other combinations...
     
Thread Status:
Not open for further replies.

Share This Page