How to place a block at a specific location in the world?

Discussion in 'Plugin Development' started by Connor Mahaffey, May 24, 2011.

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

    Connor Mahaffey

    This seems like it would be so easy, something like World.setBlock(location, type). But it's not.

    Can anyone tell me how to set a block at a specific location in the world?

    (For a bonus, you could tell me how I could set that block on fire - but if you only know the answer to the first one thats ok).
     
  2. Offline

    The_Tree_Maker

    Code:
    public void onPlayerAnimation(PlayerAnimationEvent evt) {
            thePlayer = evt.getPlayer();
    
            if(evt.getAnimationType() == PlayerAnimationType.ARM_SWING) {
                //Scan 2 Blocks Ahead then getFace 1 Up from the Target Block
                thePlayer.getTargetBlock(null, 2).getFace(BlockFace.UP, 1).setTypeId(1);
            }
        }
    Sample Code, on a Player Animation, Arm Swing, Set the Block 1 Up from the Target Block to Stone.
    I suppose you can get more specific by getting the player location and setting the block below the player.

    I'm not sure exactly what specific point you mean. This is what I can give you.
     
  3. Offline

    Connor Mahaffey


    Thank you for the reply. I was looking about it the wrong way. I was thinking that you "place bock type here", when really you need to get the block in question, then change it's value.

    Your code helped. Thanks.
     
  4. Offline

    The_Tree_Maker

    No problem, I just kind of whipped it up for you. It should work. It's kind of like WorldEdit, you select a given block, shift the position "face" and set it as a certain block type. Good Luck
     
Thread Status:
Not open for further replies.

Share This Page