Redstone repeaters event handling

Discussion in 'Plugin Development' started by ntvf, Oct 20, 2011.

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

    ntvf

    Hello.

    I'm trying to manage diode delay.
    I have investigated general diode work but I still have issues.
    As I understand, diode work cycle triggers 20 events ( ten for DIODE_BLOCK_OFF and ten DIODE_BLOCK_ON )

    So, I want to put some delay between steps 2 and 3.
    Is it possible?
    Thanks

    Diode working cycle events scheme:
    Code:
    01. DIODE_BLOCK_OFF -- Signal accepted ( first event for diode )
    02. DIODE_BLOCK_OFF
    03. DIODE_BLOCK_ON -- Actually turned on and transmit signal
    04. DIODE_BLOCK_ON
    05. DIODE_BLOCK_ON
    06. DIODE_BLOCK_ON
    07. DIODE_BLOCK_ON
    08. DIODE_BLOCK_ON
    09. DIODE_BLOCK_ON
    10. DIODE_BLOCK_ON
    
    11. DIODE_BLOCK_ON -- Preserve On-state ( until signal faded + diode delay )
    
    12. DIODE_BLOCK_ON -- Signal faded — turned off
    13. DIODE_BLOCK_OFF -- actually turned off
    14. DIODE_BLOCK_OFF
    15. DIODE_BLOCK_OFF
    16. DIODE_BLOCK_OFF
    17. DIODE_BLOCK_OFF
    18. DIODE_BLOCK_OFF
    19. DIODE_BLOCK_OFF
    20. DIODE_BLOCK_OFF -- last event for diode
    Also, if I'm trying to interrupt or block next events on step 02 — it's become unable to preserve diode status ( if circuit is currently turned on by lever ).
    Also I cant just set block state to On ( material DIODE_BLOCK_ON ), because it doesn't keep transmit logic and immediately turning off.

    Generally, I just want to add some additional delay before diode will turn on.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 20, 2016
  2. Offline

    bergerkiller

    @ntvf you should look at the native source code (MC-dev), it contains lots of useful information.

    I guess you have to cancel the 'block physics' event for the redstone repeater, store it in a buffer, and send the physics event again later on.
    Code:
        public void doPhysics(World world, int i, int j, int k, int l) {
            if (!this.f(world, i, j, k)) {
                this.g(world, i, j, k, world.getData(i, j, k));
                world.setTypeId(i, j, k, 0);
            } else {
                int i1 = world.getData(i, j, k);
                boolean flag = this.f(world, i, j, k, i1);
                int j1 = (i1 & 12) >> 2;
    
                if (this.c && !flag) {
                    world.c(i, j, k, this.id, b[j1] * 2);
                } else if (!this.c && flag) {
                    world.c(i, j, k, this.id, b[j1] * 2);
                }
            }
        }
    Include the native Craftbukkit library and call BlockDiode.doPhysics(world, x, y, z, 0). Note that you have to add a simple boolean variable to de-cancel the physics cancelling for your own invoke.

    int l should be something too, not sure what. Perhaps the block ID? Doesn't seem to be used in the function so doesn't really matter.

    Also,
    Code:
    b[j1] * 2
    Is the tick delay. j1 is probably the selected delay and the b array is an array of delays.
     
  3. Offline

    ntvf

    Thanks.
    But I can't understand, how can I call doPhysics.
    It require World as first argument, but I have no suitable variable with type net.minecraft.server.World.
    I can get only org.bukkit.craftbukkit.CraftWorld via event.getBlock().getWorld()

    Also, I can't call BlockDiode.doPhysics statically, it must be initialized. So I need to create and initialize net.minecraft.server.BlockDiode.

    I'm totally confused.
     
Thread Status:
Not open for further replies.

Share This Page