Solved Where is PotateState and CarrotState?

Discussion in 'Plugin Development' started by Dyukusi, Jan 8, 2015.

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


    Thank you for help.

    I found CropState and NetherWartsState but it seems there aren't PotatoState, CarrotState, CocoaState and so on.
    I try to cast them to CropState but it out cast error.
    How do I get the state of them?
  2. hope this will help you :)
            Block b;
    should also work with potato
    ChipDev likes this.
  3. Offline


    It returns a BlockState and it hasn't growth state of Carrot and Potato.
    I think it need to cast..?
  4. sorry misunderstood you question...
    casting would be an idea but the Materials "Carrot" and "Potato" doesn't exist to import/cast it
  5. Offline


    Sorry I should have wrote more detail about the question.
    I wanna get the state that whether they state RIPE or not.

    So, anyone has an idea?
  6. Offline


    CropState is what you would use for all of those. You don't need a different one...

    Also CropState is not a BlockState.

    Off the top of my head you might be able to check a crop's damage/meta value.
  7. Offline


    Yeah I thought so too but it seems can't cast to CropState.
    If can, could you provide a example code?

    Thank you for comments.
  8. now i got what you meant
            Block b;
                //cast the block as corpstate
                Crops c = (Crops) b.getState().getData();
                //get a crepitate
                //set a cropstate
    you have to define the block but i hope that will help :)
  9. Offline


    1. Block b = /*...*/;
    2. b.setData(CropState.RIPE.getData());

    However I recommend the api-orientated solution above.
    sn1cko likes this.
  10. is there also a way to get the CropState without casting the block to crops ?
  11. @sn1cko You could get the raw data value and get the CropState from that I suppose. However, since one should check if they actually are crops first anyway, you might as well go with the casting approach.
  12. Offline


    I did this cast but it outs the cast error.

    I tried to some method and get the bad(?) solution.
    This code seems correctly returns the state of the crop, carrot, potato, and others but getByData method and last getData method is now deprecated.
    So I guess there is more smart method to do this.

    Even my awful English skill, thank you for helpful comments.
  13. but i can't get any more data from the block than b.getData()

    and yep the method where i cast the block works i think :)

    thanks for the reply
  14. @sn1cko That's true, but you don't need anymore data than that - the byte that getData() returns will depend on the CropState that the crop is.
    sn1cko likes this.
  15. @AdamQpzm i see
    thanks :)

    @AdamQpzm but my first code will work too...

    isn't that right ?
    Last edited by a moderator: Jan 8, 2015
    AdamQpzm likes this.
  16. @sn1cko That's right. I'd advise people to use the code you first posted rather than the raw byte value method... but it's nice to know both can work :)
    sn1cko likes this.
  17. yep haha that's why i asked how to get the data with raw block data

    thanks again @AdamQpzm
Thread Status:
Not open for further replies.

Share This Page