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

The following examples show how to use cn.nukkit.level.Level#BLOCK_UPDATE_NORMAL . 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 Jupiter 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: BlockSnowLayer.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.getLevel().useBreakOn(this);

            return Level.BLOCK_UPDATE_NORMAL;
        }
    } else if (type == Level.BLOCK_UPDATE_RANDOM) {
        if (this.getLevel().getBlockLightAt((int) this.x, (int) this.y, (int) this.z) >= 10) {
            this.getLevel().setBlock(this, new BlockAir(), true);
            return Level.BLOCK_UPDATE_NORMAL;
        }
    }
    return 0;
}
 
Example 3
Source File: BlockDoublePlant.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.getDamage() & TOP_HALF_BITMASK) == TOP_HALF_BITMASK) {
            // Top
            if (!(this.down().getId() == DOUBLE_PLANT)) {
                this.getLevel().setBlock(this, Block.get(BlockID.AIR), false, true);
                return Level.BLOCK_UPDATE_NORMAL;
            }
        } else {
            // Bottom
            if (this.down().isTransparent() || !(this.up().getId() == DOUBLE_PLANT)) {
                this.getLevel().useBreakOn(this);
                return Level.BLOCK_UPDATE_NORMAL;
            }
        }
    }
    return 0;
}
 
Example 4
Source File: BlockTorch.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) {
        Block below = this.down();
        int side = this.getDamage();
        int[] faces = new int[]{
                0, //0
                4, //1
                5, //2
                2, //3
                3, //4
                0, //5
                0  //6
        };

        if (this.getSide(BlockFace.fromIndex(faces[side])).isTransparent() && !(side == 0 && (below instanceof BlockFence || below.getId() == COBBLE_WALL))) {
            this.getLevel().useBreakOn(this);

            return Level.BLOCK_UPDATE_NORMAL;
        }
    }

    return 0;
}
 
Example 5
Source File: BlockDoublePlant.java    From Jupiter 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.meta & 0x08) == 8) {
            // Top
            if (!(this.down().getId() == DOUBLE_PLANT)) {
                this.getLevel().setBlock(this, new BlockAir(), true, true);
                return Level.BLOCK_UPDATE_NORMAL;
            }
        } else {
            // Bottom
            if (this.down().isTransparent() || !(this.up().getId() == DOUBLE_PLANT)) {
                this.getLevel().useBreakOn(this);
                return Level.BLOCK_UPDATE_NORMAL;
            }
        }
    }
    return 0;
}
 
Example 6
Source File: BlockNoteblock.java    From Jupiter 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) {
        if (this.level.isBlockPowered(this)) {
        	if (!this.isPowered) {
        		this.isPowered = true;
                if (this.up().getId() == Block.AIR) {
                    this.emitSound();
                }
        	}
        } else {
        	if (this.isPowered) {
        		this.isPowered = false;
        	}
        }
    }
    return 0;
}
 
Example 7
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 8
Source File: BlockSapling.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public int onUpdate(int type) {
    if (type == Level.BLOCK_UPDATE_NORMAL) {
        if (this.down().isTransparent()) {
            this.getLevel().useBreakOn(this);
            return Level.BLOCK_UPDATE_NORMAL;
        }
    } else if (type == Level.BLOCK_UPDATE_RANDOM) { //Growth
        if (ThreadLocalRandom.current().nextInt(1, 8) == 1) {
            if ((this.getDamage() & 0x08) == 0x08) {
                this.grow();
            } else {
                this.setDamage(this.getDamage() | 0x08);
                this.getLevel().setBlock(this, this, true);
                return Level.BLOCK_UPDATE_RANDOM;
            }
        } else {
            return Level.BLOCK_UPDATE_RANDOM;
        }
    }
    return Level.BLOCK_UPDATE_NORMAL;
}
 
Example 9
Source File: BlockWallSign.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public int onUpdate(int type) {
    int[] faces = {
            3,
            2,
            5,
            4,
    };
    if (type == Level.BLOCK_UPDATE_NORMAL) {
        if (this.getDamage() >= 2 && this.getDamage() <= 5) {
            if (this.getSide(BlockFace.fromIndex(faces[this.getDamage() - 2])).getId() == Item.AIR) {
                this.getLevel().useBreakOn(this);
            }
            return Level.BLOCK_UPDATE_NORMAL;
        }
    }
    return 0;
}
 
Example 10
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 11
Source File: BlockWallSign.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
@Override
public int onUpdate(int type) {
    int[] faces = {
            3,
            2,
            5,
            4,
    };
    if (type == Level.BLOCK_UPDATE_NORMAL) {
        if (this.meta >= 2 && this.meta <= 5) {
            if (this.getSide(BlockFace.fromIndex(faces[this.meta - 2])).getId() == Item.AIR) {
                this.getLevel().useBreakOn(this);
            }
            return Level.BLOCK_UPDATE_NORMAL;
        }
    }
    return 0;
}
 
Example 12
Source File: BlockItemFrame.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(getFacing()).isTransparent()) {
            this.level.useBreakOn(this);
            return type;
        }
    }

    return 0;
}
 
Example 13
Source File: BlockDeadBush.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.down().isTransparent()) {
            this.getLevel().useBreakOn(this);

            return Level.BLOCK_UPDATE_NORMAL;
        }
    }
    return 0;
}
 
Example 14
Source File: BlockCarpet.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.down().getId() == Item.AIR) {
            this.getLevel().useBreakOn(this);

            return Level.BLOCK_UPDATE_NORMAL;
        }
    }

    return 0;
}
 
Example 15
Source File: BlockSnowLayer.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int onUpdate(int type) {
    super.onUpdate(type);
    if (type == Level.BLOCK_UPDATE_RANDOM) {
        if (this.getLevel().getBlockLightAt((int) this.x, (int) this.y, (int) this.z) >= 10) {
            BlockFadeEvent event = new BlockFadeEvent(this, get(AIR));
            level.getServer().getPluginManager().callEvent(event);
            if (!event.isCancelled()) {
                level.setBlock(this, event.getNewState(), true);
            }
            return Level.BLOCK_UPDATE_NORMAL;
        }
    }
    return 0;
}
 
Example 16
Source File: BlockDeadBush.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.down().isTransparent()) {
            this.getLevel().useBreakOn(this);

            return Level.BLOCK_UPDATE_NORMAL;
        }
    }
    return 0;
}
 
Example 17
Source File: BlockTNT.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 || type == Level.BLOCK_UPDATE_REDSTONE) && this.level.isBlockPowered(this)) {
        this.prime();
    }
    return 0;
}
 
Example 18
Source File: BlockSugarcane.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) {
        Block down = this.down();
        if (down.isTransparent() && down.getId() != SUGARCANE_BLOCK) {
            this.getLevel().useBreakOn(this);
            return Level.BLOCK_UPDATE_NORMAL;
        }
    } else if (type == Level.BLOCK_UPDATE_RANDOM) {
        if (this.down().getId() != SUGARCANE_BLOCK) {
            if (this.getDamage() == 0x0F) {
                for (int y = 1; y < 3; ++y) {
                    Block b = this.getLevel().getBlock(new Vector3(this.x, this.y + y, this.z));
                    if (b.getId() == AIR) {
                        this.getLevel().setBlock(b, new BlockSugarcane(), false);
                        break;
                    }
                }
                this.setDamage(0);
                this.getLevel().setBlock(this, this, false);
            } else {
                this.setDamage(this.getDamage() + 1);
                this.getLevel().setBlock(this, this, false);
            }
            return Level.BLOCK_UPDATE_RANDOM;
        }
    }
    return 0;
}
 
Example 19
Source File: BlockTNT.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.prime();
    }
    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;
}