How to set block on target location

Discussion in 'Plugin Development' started by Etarus, Sep 29, 2011.

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

    Etarus

    How can I set one block at the postition i look at.
    This should be activated by a command.

    So if I make the onCommand(), what do I need in the onCommand method to set a block where the player is looking at?

    Have anyone an example code?
    Thanks for all help.
     
  2. Offline

    stelar7

    something like :

    player.getTargetBlock().setBlock()
     
  3. Offline

    Etarus

    I don't understand it right now.
    can you please make an example with changing one target block with a command?
     
  4. Offline

    ZNickq

    getTargetBlock gets the block the player is looking at...setBlock sets the block! How can it be easier? :/
     
  5. Offline

    Etarus

    yeah i have it but how could i now change this block?

    Code:
        public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
            if (command.getName().equalsIgnoreCase("test")) {
                Player player = (Player) sender;
                player.getTargetBlock(null, 100);
                player.sendMessage("Hallo");
                return true;
            }
            return false;
        }
     
  6. Offline

    ZNickq

    Block blocky=player.getTargetBlock(null,100);
    blocky.setType(Material.BEDROCK);
     
  7. Offline

    Etarus

    thanks it works

    another question:

    if i want get the 4 blocks over them or other block next to them, how is the best way to get these out of the target block?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 20, 2016
  8. Offline

    ZNickq

    blocky2=blocky.getRelative(BlockFace.UP),etc.
     
  9. Offline

    Etarus

    works fine, too

    in the Material List. (setType(Material.---);) I can't find Stone Brick. I want to change the target block to Stone Bricks (ID: 98:2)

    Can I write the ID in this material field? and how did i use it with damage values?
     
  10. Offline

    Darkman2412

    It's SMOOTH_BRICK.
     
  11. Offline

    Etarus

    oh sry^^
    but how can i make it to the damage value 2?
     
  12. Offline

    Darkman2412

    You don't need to :)

    Well, if you really want to know it:
    Code:
    setTypeIdAndData(98, 2, true);
    I think that's the method, but there isn't any information on it on the javadocs.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 20, 2016
  13. Offline

    Etarus


    If I type this, it gives me an error at the line:
    Code:
    Description    Resource    Path    Location    Type
    The method setTypeIdAndData(int, byte, boolean) in the type Block is not applicable for the arguments (int, int, boolean)    eTowerDefenser.java    /eTowerDefenser/src/me/Etarus/eTowerDefenser    line 39    Java Problem
    
     
  14. Offline

    ZNickq

    use
    setTypeIdAndData(98,(byte) 2,true);
     
  15. Offline

    Etarus

    Thank you, works fine
     
Thread Status:
Not open for further replies.

Share This Page