Cannot cast CraftBlockState to Sign

Discussion in 'Plugin Development' started by Debels, Sep 18, 2013.

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

    Debels

    I'm having this strange error while casting from BlockState to Sign, I say strange since I have done this many times now, what could be causing it?
    The error is on line 4 on the following:
    Code:java
    1. Sign s = null;
    2. final Location l = b.getLocation();
    3. if (l.add(1, 0, 0).getBlock().getType()==Material.WALL_SIGN){
    4. s = (Sign) l.add(1, 0, 0).getBlock().getState();
    5. }


    b is referring to "Block b" which in the moment of the error was a block of Stone (I know it doesn't matter, just to say its not null)
     
  2. Offline

    Rocoty

    Simple. Your location l, in the evaluation part of the if-statement you are adding 1, 0, 0 to it. And checking if the block at its position is a sign. Then, when you cast, you take the already modified location and add 1, 0, 0 to it yet again, The location is now no longer at the sign location. See now? :)
     
    tommycake50 likes this.
  3. Offline

    Debels

    Hmmm I thought that by making the Location final it wouldn't be affected by the add, thanks.
     
  4. Offline

    Rocoty

    Declaring the variable final only means you cannot change the reference. The object will still be mutable.
     
    Janmm14 likes this.
Thread Status:
Not open for further replies.

Share This Page