Solved Can't Check if Byte != (byte) 0

Discussion in 'Plugin Development' started by ipodtouch0218, Jul 13, 2016.

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

    ipodtouch0218

    I've been developing a plugin that stacks buckets for a player, asked for in the Plugin Requests location.

    While I have been doing this, I've noticed that when players use a bucket when they are stacked, they all are used instead of one at a time.
    Because of this, I have to write my own code for using buckets when they have more than 1 in a stack.

    When doing this, I noticed that when using a normal bucket and trying to place it into a full water source block, it is not used up. I used the method Block#getData() and checked if it is != 0... which doesn't work.

    Any help on why this happens? Maybe this is a Java problem not Bukkit, sorry...

    Code: http://pastebin.com/6zZPtbFL

    EDIT: It seems I set the to expire time on the PasteBin to 10 minutes instead of a week. whoops
     
    Last edited: Jul 13, 2016
  2. You are comparing a byte with an int. You need to compare with null instead.
     
  3. Offline

    ipodtouch0218

    @AlvinB
    Nope, that's not it. When I output the byte in a sendMessage it says 0.
    I've tried using == (byte) 0 too.

    "The operator == is undefined for the argument type(s) byte, null"
     
  4. I guess I was wrong then. But are you sure comparing to 0 doesn't work? Because I read up on how things work (should've done that before writing the first post) and if there is no data in a byte, it is stored as a 0.
     
  5. Code:
    if(b.getData() == 0)
    This worked fine for me, deprecated but worked fine.
     
  6. Offline

    ipodtouch0218

    @bwfcwalshy
    I'm testing this on water, could that be the reason for it?

    (also, why is #getData() deprecated? We still use ':1' etc for blocks)
     
    Last edited: Jul 14, 2016
  7. Code:
    class Test
    {
        public static void main (String[] args) throws java.lang.Exception
        {
            byte b = 1;
            if (b != 0)
               System.out.println("hi");
        }
    }
    This works just fine.. Are you sure it even reaches that if statement when you run the code?
     
    ipodtouch0218 likes this.
  8. Offline

    ipodtouch0218

    Wow.. it was because the Material enum was STATIONARY_WATER and not WATER...

    if (getBlockWithFace(bf, cb).getType() != Material.WATER)
    e.getPlayer().sendMessage("block is not water, it is " + getBlockWithFace(bf, cb).getType().toString());

    ==

    "block is not water, it is STATIONARY_WATER"

    Thanks @bwfcwalshy and @AlvinB
     
  9. I believe the getData values have been abandoned when it comes to blocks. I believe blockstates has replaced it (Not 100% sure on this, it's just how the MinecraftForge API has done it).
     
Thread Status:
Not open for further replies.

Share This Page