How to create blocks?

Discussion in 'Plugin Development' started by streedie, Jul 9, 2011.

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

    streedie

    Hello all,
    I want to make a new plugin, but I need to know how to place a block beneath and next too the player. Please help!
    AT, streedie.
     
  2. Offline

    bergerkiller

    Well, you don't actually place a block, all you do is change blocks. When you see "no block", actually there is! The block you see there is an "Air" block. When you "place a block", you change the specified air block to another Material type.

    So to the question, you need to obtain the "Block" object you wish to change from air to another material:
    Code:
    Block b = event.getBlock(); //obtain a block
    b.setTypeId(5); //set block to wood
    Block above = b.getFace(BlockFace.Up); //get block above
    if (above.getType() == Material.AIR) { //Check if the block is air
        above.setTypeId(1); //stone
    }
    (written from scratch)

    Note: I tried to use "b.setType(Material.WOOD)" before but it seems to fail, although it could be a different error that was occurring. :)

    For next the player it can become a little harder. You first need to obtain a Player object (from an event or World) and use its "getLocation()" property.
    Use the x/y/z coordinates to obtain the block at those coordinates in the World. (Player.getWorld())

    Other than this you need an event to work in, for example when a player places a block or when a player right clicks an entity/block. There are plenty tutorials around that can help you with that. :)
     
  3. Offline

    streedie

    Thanks, my idea is too place a floor and stuff like that.
     
Thread Status:
Not open for further replies.

Share This Page