Cocoa rotation and state

Discussion in 'Plugin Development' started by Mads_Vilhelm, Nov 12, 2020.

  1. Offline

    Mads_Vilhelm

    Hey..


    I am new to programming so I am trying to make a simple plugin that plants a new cocoa when you break one. You can only break the cocoa when it is full grown. The problem is that when I set the Crop state of the cocoa the cocoa change direction. I have tried but i can't find a way to rotate a cocoa automatically.

    I hope you can help

    Here is my code:

    Code:
    @SuppressWarnings("deprecation")
        @EventHandler
        public void onBlockBreak(BlockBreakEvent breakevent) {
            Player p = breakevent.getPlayer();
            Block blc = breakevent.getBlock();
           
            //if it is a cocoa
            if (blc.getTypeId() == 127) {
               
                //I have checked that this is a full grown cocoa number
                if (blc.getData() > 7) {
                    p.sendMessage(ChatColor.GREEN + "Du høstede en kokusnød");
                    blc.setData(CropState.SMALL.getData());
                    breakevent.setCancelled(true);
    
                }
                //If it's not a full grown cocoa
                else {
                    p.sendMessage(ChatColor.RED + "Kokusnøden skal være fuldvoksen før du kan høste den");
                    breakevent.setCancelled(true);
                   
                }
               
               
            }
       
        }
     
  2. Offline

    xelatercero

    So i am not sure , but maybe you could get the BlockFace of the broken cocoa and the set as the BlockFace of the new one
     
  3. Offline

    Mads_Vilhelm

    I will try that.

    I have tried to make a line of code that prints the face direction but it just prints out SELF. Can you tell me what that mean? I can't find the meaning on it any where.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Nov 15, 2020
  4. Offline

    MrDaniel

    @Mads_Vilhelm
    Instead of checking the TypeID, get the type (Material) and compare it to another material using .equals()

    A problem you have, is that you are cancelling the event both times, which will just end up not letting the player break the cocoa
     

Share This Page