Checking to see if the player has right-clicked a catcus

Discussion in 'Plugin Development' started by Jaker232, Aug 22, 2011.

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

    Jaker232

    I'm building a plugin, however I'll need the line for the right-clicking and making sure it's a catcus. I already got the action set, but I'll need to make sure it checked to see if it's catcus.

    How can I achieve this?
     
  2. Offline

    Taco

    In your onPlayerInteractEvent method, check to see if the interaction was them right clicking a block using I think (could be wrong) event.getAction() and then check the block Id and compare it to that of cactus using event.getBlock().getTypeId()
     
  3. Offline

    DrBowe

    @Taco
    You're not wrong. It's event.getAction() :)
     
  4. Offline

    Jaker232

    I'm running into problems.

    I had defined the action, then the block, now I setted the ID, but I need to set the data type (15) so I can make this functioning properly.
     
  5. I do not understand your new problem.
    What do you want to do? Do you want to change the cactus to an Iron Ore block? (15)
     
  6. Offline

    Taco

    That should simply be event.getBlock().setData(int data);
     
  7. Offline

    Crash

    Actually it's event.getClickedBlock()
    I don't know why it's not just event.getBlock()
     
  8. Offline

    Jaker232

    My event is this:

    Code:java
    1.  
    2. public void onPlayerInteract(PlayerInteractEvent event) {
    3. if(event.getAction() == Action.RIGHT_CLICK_BLOCK) {
    4. if(event.getClickedBlock() == 81 && event.getItem().getTypeId() == 351) {
    5. }
    6. }
    7. }
    8. }
    9.  

    I don't know how I can get the items and find the data. Maybe I should do something else.
     
  9. Offline

    Taco

    event.getClickedBlock() == 81 - This compares a block to an int. Not the id of said block. A block never equals an int.

    Try this:

    Code:java
    1.  
    2. public void onPlayerInteract(PlayerInteractEvent event) {
    3. if(event.getAction() == Action.RIGHT_CLICK_BLOCK) {
    4. if(event.getClickedBlock().getTypeId() == 81 && event.getItem() != null && event.getItem().getTypeId() == 351 && event.getItem().getData == 15) { //I'm assuming you wanted to check the data as well.
    5. }
    6. }
    7. }
    8. }
    9.  


    Just to avoid further confusion, event.getItem() returns the item in hand. You need a null check in case they are holding nothing.
     
  10. Offline

    Jaker232

    Generates an error. Please check it.
     
  11. Offline

    Taco

    I need the error to help you with that.
     
  12. Offline

    Pencil

    Code:
    if(event.getAction() == Action.RIGHT_CLICK_BLOCK) {
    This line isn't really needed is it? D: Its not like the right clicked block will ever be anything if nothing was right clicked D:
     
  13. Offline

    feildmaster

    it's needed otherwise it will call on any click. :eek:
     
  14. Offline

    Pencil

    D: But if u left click it its the blockdamage event :/

    I fail to see any other ''clicks'' xD
     
  15. Offline

    feildmaster

    onPlayerInteract will be called, along with blockDamageEvent... >.>
     
  16. Offline

    Pencil

    oh D: I see xD Makes sense :p Never actually cared wether it was left or right click :)
     
  17. Offline

    Jaker232

    P.S. I'm already following this thread, so I don't need to be tagged.
    @Taco
    Error:

    "getData cannot be resolved or is not a field."

    Line:
    Code:java
    1.  
    2. if(event.getClickedBlock().getTypeId() == 81 && event.getItem() != null && event.getItem().getTypeId() == 351 && event.getItem().getData == 15) {
    3.  


    Help?
     
  18. Offline

    badbh222

    Code:
    if(event.hasBlock()){
    	Block block = event.getClickedBlock();
    	if(block.getType() == Material.CACTUS && event.getAction() == Action.RIGHT_CLICK_BLOCK){
    Is that what you need? :confused:
     
  19. I has to be
    Code:java
    1.  
    2. if(event.getClickedBlock().getTypeId() == 81 && event.getItem() != null && event.getItem().getTypeId() == 351 && event.getItem().getData().getData() == 15) {
    3.  
     
  20. Offline

    Taco

    Hehe. I may have made a typo in the code I gave you, this one should work. Thank you Pandemoneus for catching that. :p
     
Thread Status:
Not open for further replies.

Share This Page