Solved Trying to set CocoaPlant to CocoaPlant.SMALL then update the block!?

Discussion in 'Plugin Development' started by Pizza371, Aug 3, 2014.

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

    Pizza371

    Hi!
    I'm trying to make a cocoa plant small again, when someone breaks a cocoa plant block I do this (cp=CocoaPlant object, b=event#getBlock):
    cp.setSize(CocoaPlantSize.SMALL);
    b.getState().update();

    doesn't work, I'm not sure what else to do :p
    Any help?

    Thanks!
     
  2. Offline

    TheMcScavenger

    Show your actual code using proper formatting.
     
  3. Offline

    Pizza371

    TheMcScavenger
    Code:
    if(b.getType() == Material.COCOA) {
    Bukkit.broadcastMessage("block is cocoa");
    CocoaPlant cp = (CocoaPlant) b.getState().getData();
    if(cp.getSize() == CocoaPlantSize.LARGE) {
    Bukkit.broadcastMessage("block is ccoa.LARGE");
    cp.setSize(CocoaPlantSize.SMALL);
    b.getState().update();
    I was expecting it to just make the CocoaPlant just like its placed again, but I don't know why ):.
    How do i update it?
     
  4. Offline

    FabeGabeMC

  5. Offline

    fireblast709

    And receive a ClassCastException.
    Pizza371 setData before you update
     
  6. Offline

    Pizza371

    fireblast709 Thanks!

    It still doesnt work though (it does print out 'block is ccoa.LARGE'):
    Code:
    if(b.getType() == Material.COCOA) {
    Bukkit.broadcastMessage("block is cocoa");
    CocoaPlant cp = (CocoaPlant) b.getState().getData();
    if(cp.getSize() == CocoaPlantSize.LARGE) {
    Bukkit.broadcastMessage("block is ccoa.LARGE");
    cp.setSize(CocoaPlantSize.SMALL);
    b.getState().setData(cp);
    b.getState().update();
    Since it is on BlockBreakEvent, could that be modifying it?
    Essentially what I am trying to do is set the cocoa plant back to small instead of erasing it completely when someone breaks it.

    Thanks,
    Pizza.
     
  7. Offline

    fireblast709

    Pizza371 cancel the event. If you want drops, drop them manually
     
  8. Offline

    Pizza371

    fireblast709
    I could do that, however it still doesnt replace it with a small one if I call e.setCancelleled() right before cp.setSize(...);
    Any help?
     
  9. Offline

    fireblast709

    Pizza371 delay the update() call by 1 tick
     
    Pizza371 likes this.
  10. Offline

    Pizza371

    fireblast709
    Ok, I tried that.
    I also tried setting the force boolean to true (update(true)).
    and tried each Size, but none of them changed the size.
    Still no luck :(

    Any more ideas?
    Thanks.
     
  11. Offline

    Esophose

    Pizza371
    Here's an idea. In the block break event... Instead of changing the cocoa bean from large to small, let it break and set the block at the locaction to be a cocoa bean.
     
    Pizza371 likes this.
  12. Offline

    Pizza371

    Esophose
    Welp, that would seem like a good idea!
    It worked, thanks! :)
     
Thread Status:
Not open for further replies.

Share This Page