Java Code Examples for cn.nukkit.level.Level#BLOCK_UPDATE_SCHEDULED

The following examples show how to use cn.nukkit.level.Level#BLOCK_UPDATE_SCHEDULED . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BlockRailPowered.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public int onUpdate(int type) {
    // Warning: I din't recommended this on slow networks server or slow client
    //          Network below 86Kb/s. This will became unresponsive to clients 
    //          When updating the block state. Espicially on the world with many rails. 
    //          Trust me, I tested this on my server.
    if (type == Level.BLOCK_UPDATE_NORMAL || type == Level.BLOCK_UPDATE_REDSTONE || type == Level.BLOCK_UPDATE_SCHEDULED) {
        super.onUpdate(type);
        boolean wasPowered = isActive();
        boolean isPowered = level.isBlockPowered(this)
                || checkSurrounding(this, true, 0)
                || checkSurrounding(this, false, 0);

        // Avoid Block minstake
        if (wasPowered != isPowered) {
            setActive(isPowered);
            level.updateAround(down());
            if (getOrientation().isAscending()) {
                level.updateAround(up());
            }
        }
        return type;
    }
    return 0;
}
 
Example 2
Source File: BlockPressurePlateBase.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public int onUpdate(int type) {
    if (type == Level.BLOCK_UPDATE_NORMAL) {
        if (this.down().isTransparent()) {
            this.level.useBreakOn(this);
        }
    } else if (type == Level.BLOCK_UPDATE_SCHEDULED) {
        int power = this.getRedstonePower();

        if (power > 0) {
            this.updateState(power);
        }
    }

    return 0;
}
 
Example 3
Source File: BlockPressurePlateBase.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public int onUpdate(int type) {
    if (type == Level.BLOCK_UPDATE_NORMAL) {
        if (this.down().isTransparent()) {
            this.level.useBreakOn(this);
        }
    } else if (type == Level.BLOCK_UPDATE_SCHEDULED) {
        int power = this.getRedstonePower();

        if (power > 0) {
            this.updateState(power);
        }
    }

    return 0;
}
 
Example 4
Source File: BlockRedstoneLampLit.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public int onUpdate(int type) {
    if ((type == Level.BLOCK_UPDATE_NORMAL || type == Level.BLOCK_UPDATE_REDSTONE) && !this.level.isBlockPowered(this.getLocation())) {
        // Redstone event
        RedstoneUpdateEvent ev = new RedstoneUpdateEvent(this);
        getLevel().getServer().getPluginManager().callEvent(ev);
        if (ev.isCancelled()) {
            return 0;
        }
        this.level.scheduleUpdate(this, 4);
        return 1;
    }

    if (type == Level.BLOCK_UPDATE_SCHEDULED && !this.level.isBlockPowered(this.getLocation())) {
        this.level.setBlock(this, Block.get(BlockID.REDSTONE_LAMP), false, false);
    }
    return 0;
}
 
Example 5
Source File: BlockRailActivator.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public int onUpdate(int type) {
    if (type == Level.BLOCK_UPDATE_NORMAL || type == Level.BLOCK_UPDATE_REDSTONE || type == Level.BLOCK_UPDATE_SCHEDULED) {
        super.onUpdate(type);
        boolean wasPowered = isActive();
        boolean isPowered = level.isBlockPowered(this)
                || checkSurrounding(this, true, 0)
                || checkSurrounding(this, false, 0);
        boolean hasUpdate = false;

        if (wasPowered != isPowered) {
            setActive(isPowered);
            hasUpdate = true;
        }

        if (hasUpdate) {
            level.updateAround(down());
            if (getOrientation().isAscending()) {
                level.updateAround(up());
            }
        }
        return type;
    }
    return 0;
}
 
Example 6
Source File: BlockRedstoneTorch.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public int onUpdate(int type) {
    if (super.onUpdate(type) == 0) {
        if (type == Level.BLOCK_UPDATE_NORMAL || type == Level.BLOCK_UPDATE_REDSTONE) {
            this.level.scheduleUpdate(this, tickRate());
        } else if (type == Level.BLOCK_UPDATE_SCHEDULED) {
            RedstoneUpdateEvent ev = new RedstoneUpdateEvent(this);
            getLevel().getServer().getPluginManager().callEvent(ev);

            if (ev.isCancelled()) {
                return 0;
            }

            if (checkState()) {
                return 1;
            }
        }
    }

    return 0;
}
 
Example 7
Source File: BlockButton.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public int onUpdate(int type) {
    if (type == Level.BLOCK_UPDATE_NORMAL) {
        if (this.getSide(getFacing().getOpposite()).isTransparent()) {
            this.level.useBreakOn(this);
            return Level.BLOCK_UPDATE_NORMAL;
        }
    } else if (type == Level.BLOCK_UPDATE_SCHEDULED) {
        if (this.isActivated()) {
            this.level.getServer().getPluginManager().callEvent(new BlockRedstoneEvent(this, 15, 0));

            this.setDamage(this.getDamage() ^ 0x08);
            this.level.setBlock(this, this, true, false);
            this.level.addSound(this.add(0.5, 0.5, 0.5), Sound.RANDOM_CLICK);

            Vector3 pos = getLocation();
            level.updateAroundRedstone(pos, null);
            level.updateAroundRedstone(pos.getSide(getFacing().getOpposite()), null);
        }

        return Level.BLOCK_UPDATE_SCHEDULED;
    }

    return 0;
}
 
Example 8
Source File: BlockRedstoneTorchUnlit.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public int onUpdate(int type) {
    if (super.onUpdate(type) == 0) {
        if (type == Level.BLOCK_UPDATE_NORMAL || type == Level.BLOCK_UPDATE_REDSTONE) {
            this.level.scheduleUpdate(this, tickRate());
        } else if (type == Level.BLOCK_UPDATE_SCHEDULED) {
            RedstoneUpdateEvent ev = new RedstoneUpdateEvent(this);
            getLevel().getServer().getPluginManager().callEvent(ev);
            if (ev.isCancelled()) {
                return 0;
            }

            if (checkState()) {
                return 1;
            }
        }
    }

    return 0;
}
 
Example 9
Source File: BlockOreRedstoneGlowing.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int onUpdate(int type) {
    if (type == Level.BLOCK_UPDATE_SCHEDULED || type == Level.BLOCK_UPDATE_RANDOM) {
        BlockFadeEvent event = new BlockFadeEvent(this, get(REDSTONE_ORE));
        level.getServer().getPluginManager().callEvent(event);
        if (!event.isCancelled()) {
            level.setBlock(this, event.getNewState(), false, false);
        }

        return Level.BLOCK_UPDATE_WEAK;
    }

    return 0;
}
 
Example 10
Source File: BlockRedstoneDiode.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int onUpdate(int type) {
    if (type == Level.BLOCK_UPDATE_SCHEDULED) {
        if (!this.isLocked()) {
            Vector3 pos = getLocation();
            boolean shouldBePowered = this.shouldBePowered();

            if (this.isPowered && !shouldBePowered) {
                this.level.setBlock(pos, this.getUnpowered(), true, true);

                this.level.updateAroundRedstone(this.getLocation().getSide(getFacing().getOpposite()), null);
            } else if (!this.isPowered) {
                this.level.setBlock(pos, this.getPowered(), true, true);
                this.level.updateAroundRedstone(this.getLocation().getSide(getFacing().getOpposite()), null);

                if (!shouldBePowered) {
                    level.scheduleUpdate(getPowered(), this, this.getDelay());
                }
            }
        }
    } else if (type == Level.BLOCK_UPDATE_NORMAL || type == Level.BLOCK_UPDATE_REDSTONE) {
        if (type == Level.BLOCK_UPDATE_NORMAL && this.getSide(BlockFace.DOWN).isTransparent()) {
            this.level.useBreakOn(this);
            return Level.BLOCK_UPDATE_NORMAL;
        } else {
            this.updateState();
            return Level.BLOCK_UPDATE_NORMAL;
        }
    }
    return 0;
}
 
Example 11
Source File: BlockTripWireHook.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int onUpdate(int type) {
    if (type == Level.BLOCK_UPDATE_NORMAL) {
        if (!this.getSide(this.getFacing().getOpposite()).isNormalBlock()) {
            this.level.useBreakOn(this);
        }

        return type;
    } else if (type == Level.BLOCK_UPDATE_SCHEDULED) {
        this.calculateState(false, true, -1, null);
        return type;
    }

    return 0;
}
 
Example 12
Source File: BlockRailDetector.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int onUpdate(int type) {
    if (type == Level.BLOCK_UPDATE_SCHEDULED) {
        updateState();
        return type;
    }
    return super.onUpdate(type);
}
 
Example 13
Source File: BlockTripWireHook.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int onUpdate(int type) {
    if (type == Level.BLOCK_UPDATE_NORMAL) {
        if (!this.getSide(this.getFacing().getOpposite()).isNormalBlock()) {
            this.level.useBreakOn(this);
        }

        return type;
    } else if (type == Level.BLOCK_UPDATE_SCHEDULED) {
        this.calculateState(false, true, -1, null);
        return type;
    }

    return 0;
}
 
Example 14
Source File: BlockTripWire.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int onUpdate(int type) {
    if (type == Level.BLOCK_UPDATE_SCHEDULED) {
        if (!isPowered()) {
            return type;
        }

        boolean found = false;
        for (Entity entity : this.level.getCollidingEntities(this.getCollisionBoundingBox())) {
            if (!entity.doesTriggerPressurePlate()) {
                continue;
            }

            found = true;
        }

        if (found) {
            this.level.scheduleUpdate(this, 10);
        } else {
            this.setPowered(false);
            this.level.setBlock(this, this, true, false);
            this.updateHook(false);
        }
        return type;
    }

    return 0;
}
 
Example 15
Source File: BlockLavaStill.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int onUpdate(int type) {
    if (type != Level.BLOCK_UPDATE_SCHEDULED) {
        return super.onUpdate(type);
    }
    return 0;
}
 
Example 16
Source File: BlockRedstoneComparator.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int onUpdate(int type) {
    if (type == Level.BLOCK_UPDATE_SCHEDULED) {
        this.onChange();
        return type;
    }

    return super.onUpdate(type);
}
 
Example 17
Source File: BlockTripWireHook.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int onUpdate(int type) {
    if (type == Level.BLOCK_UPDATE_NORMAL) {
        if (!this.getSide(this.getFacing().getOpposite()).isNormalBlock()) {
            this.level.useBreakOn(this);
        }

        return type;
    } else if (type == Level.BLOCK_UPDATE_SCHEDULED) {
        this.calculateState(false, true, -1, null);
        return type;
    }

    return 0;
}
 
Example 18
Source File: BlockRedstoneLampLit.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int onUpdate(int type) {
    if ((type == Level.BLOCK_UPDATE_NORMAL || type == Level.BLOCK_UPDATE_REDSTONE) && !this.level.isBlockPowered(this)) {
        this.level.scheduleUpdate(this, 4);
        return 1;
    }

    if (type == Level.BLOCK_UPDATE_SCHEDULED && !this.level.isBlockPowered(this)) {
        this.level.setBlock(this, new BlockRedstoneLamp(), false, false);
    }
    return 0;
}
 
Example 19
Source File: BlockTripWire.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int onUpdate(int type) {
    if (type == Level.BLOCK_UPDATE_SCHEDULED) {
        if (!isPowered()) {
            return type;
        }

        boolean found = false;
        for (Entity entity : this.level.getCollidingEntities(this.getCollisionBoundingBox())) {
            if (!entity.doesTriggerPressurePlate()) {
                continue;
            }

            found = true;
        }

        if (found) {
            this.level.scheduleUpdate(this, 10);
        } else {
            this.setPowered(false);
            this.level.setBlock(this, this, true, false);
            this.updateHook(false);
        }
        return type;
    }

    return 0;
}
 
Example 20
Source File: BlockFire.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public int onUpdate(int type) {
    if (type == Level.BLOCK_UPDATE_NORMAL || type == Level.BLOCK_UPDATE_RANDOM) {
        if (!this.isBlockTopFacingSurfaceSolid(this.down()) && !this.canNeighborBurn()) {
            this.getLevel().setBlock(this, new BlockAir(), true);
        }

        return Level.BLOCK_UPDATE_NORMAL;
    } else if (type == Level.BLOCK_UPDATE_SCHEDULED && this.level.gameRules.getBoolean(GameRule.DO_FIRE_TICK)) {
        boolean forever = this.down().getId() == Block.NETHERRACK;

        ThreadLocalRandom random = ThreadLocalRandom.current();

        //TODO: END

        if (!this.isBlockTopFacingSurfaceSolid(this.down()) && !this.canNeighborBurn()) {
            this.getLevel().setBlock(this, new BlockAir(), true);
        }

        if (!forever && this.getLevel().isRaining() &&
                (this.getLevel().canBlockSeeSky(this) ||
                        this.getLevel().canBlockSeeSky(this.east()) ||
                        this.getLevel().canBlockSeeSky(this.west()) ||
                        this.getLevel().canBlockSeeSky(this.south()) ||
                        this.getLevel().canBlockSeeSky(this.north()))
                ) {
            this.getLevel().setBlock(this, new BlockAir(), true);
        } else {
            int meta = this.getDamage();

            if (meta < 15) {
                this.setDamage(meta + random.nextInt(3));
                this.getLevel().setBlock(this, this, true);
            }

            this.getLevel().scheduleUpdate(this, this.tickRate() + random.nextInt(10));

            if (!forever && !this.canNeighborBurn()) {
                if (!this.isBlockTopFacingSurfaceSolid(this.down()) || meta > 3) {
                    this.getLevel().setBlock(this, new BlockAir(), true);
                }
            } else if (!forever && !(this.down().getBurnAbility() > 0) && meta == 15 && random.nextInt(4) == 0) {
                this.getLevel().setBlock(this, new BlockAir(), true);
            } else {
                int o = 0;

                //TODO: decrease the o if the rainfall values are high

                this.tryToCatchBlockOnFire(this.east(), 300 + o, meta);
                this.tryToCatchBlockOnFire(this.west(), 300 + o, meta);
                this.tryToCatchBlockOnFire(this.down(), 250 + o, meta);
                this.tryToCatchBlockOnFire(this.up(), 250 + o, meta);
                this.tryToCatchBlockOnFire(this.south(), 300 + o, meta);
                this.tryToCatchBlockOnFire(this.north(), 300 + o, meta);

                for (int x = (int) (this.x - 1); x <= (int) (this.x + 1); ++x) {
                    for (int z = (int) (this.z - 1); z <= (int) (this.z + 1); ++z) {
                        for (int y = (int) (this.y - 1); y <= (int) (this.y + 4); ++y) {
                            if (x != (int) this.x || y != (int) this.y || z != (int) this.z) {
                                int k = 100;

                                if (y > this.y + 1) {
                                    k += (y - (this.y + 1)) * 100;
                                }

                                Block block = this.getLevel().getBlock(new Vector3(x, y, z));
                                int chance = this.getChanceOfNeighborsEncouragingFire(block);

                                if (chance > 0) {
                                    int t = (chance + 40 + this.getLevel().getServer().getDifficulty() * 7) / (meta + 30);

                                    //TODO: decrease the t if the rainfall values are high

                                    if (t > 0 && random.nextInt(k) <= t) {
                                        int damage = meta + random.nextInt(5) / 4;

                                        if (damage > 15) {
                                            damage = 15;
                                        }

                                        BlockIgniteEvent e = new BlockIgniteEvent(block, this, null, BlockIgniteEvent.BlockIgniteCause.SPREAD);
                                        this.level.getServer().getPluginManager().callEvent(e);

                                        if (!e.isCancelled()) {
                                            this.getLevel().setBlock(block, new BlockFire(damage), true);
                                            this.getLevel().scheduleUpdate(block, this.tickRate());
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    return 0;
}