BlockRedstoneEvent doesn't work as expected

Discussion in 'Plugin Development' started by rcth, May 29, 2014.

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

    rcth

    Hello Bukkit community,

    Lately, I've been working with the BlockRedstonEevent, to check whether a specific sign is powered and execute some methods. I fixed most of it, but it does show some unexpected behaviour.

    It's all explained in a video, as that says way more than a 1000 words:

    The code:
    http://pastebin.com/PCtVLbJ1


    Anyone knows what's wrong?
     
  2. Offline

    RawCode

    not going to view video and guess what you dont like.

    carefully explain what you expected and what you recieved in result.
     
    Someone_Like_You likes this.
  3. Offline

    rcth

    RawCode
    I use redstone wire or a repeater next to a [fountain] sign to power it.

    If the sign stands alone, and I power it with the wire, it works perfectly: While powered, [fountain] is changed to [fountain-on], and when it is no longer powered, it changes back to [fountain].

    The bugs occur when I place two [fountain] signs next to eachother or when I use a repeater.

    TWO SIGNS NEXT TO EACHOTHER:
    I use wire for this one, so for the left sign, I place the wire on the front, for the right sign I place the wire on the back.
    If I power the left one (and keep it powered), it works fine. It spawns the fallingblock and change to [fountain-on]. I can easily depower it, which acts normal. But if I leave it powered, and power the right sign, it spawns a fallingblock on the left AND right sign, instead of only the right sign.
    If I depower the right sign (left sign is still powered), it again spawns a fallingblock at the left sign. The right sign changes back to [fountain], that's expected. After I depower the left sign, it changes to [fountain] and doesn't spawn a block, which is good.

    REPEATER TO POWER THE SIGN:
    1. Power: Doesn't change to [fountain-on], does spawn a fallingblock.
    2. Depower: Changes to [fountain-on], spawns a fallingblock again.
    3. Power: Still [fountain-on], spawns a fallingblock.
    4. Depower: Changes back to [fountain], no fallingblock (good!)

    I guess you can guess what I expect to happen: While powered, change to [fountain-on] and spawn a fallingblock. While depowered, no fallingblock, change to [fountain].


    Still, for the best description, you need to watch the video.
     
  4. RawCode he tries to create some kind of fountain but the event only shoot once (when the block being powered and when it isnt)
    rcth bukkit runnables <3 , use them to spawn the water blocks for the fountain (and check if the fountain is alredy exists)
    edit: I think this even called when block updated with redstone signal (and update the nearby blocks too), also when block being un-powered
     
  5. Offline

    RawCode

    Code:
            // CraftBukkit start
            if (block != null && block.isPowerSource()) {
                org.bukkit.block.Block bukkitBlock = world.getWorld().getBlockAt(i, j, k);
                int power = bukkitBlock.getBlockPower();
    
                BlockRedstoneEvent eventRedstone = new BlockRedstoneEvent(bukkitBlock, power, power);
                world.getServer().getPluginManager().callEvent(eventRedstone);
            }
            // CraftBukkit end
        }
    }
    
    You shoud trigger only if block strongly powered and ignore indirect power events.

    Same event shoud run if block depowered.

    i will suggest to make debug version of code, that does nothing and only output debug messages about power ratios and other stuff about block.

    also spawning block next to sign will force state update and may messup things.
     
Thread Status:
Not open for further replies.

Share This Page