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

The following examples show how to use cn.nukkit.level.Level#BLOCK_UPDATE_REDSTONE . 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: 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 2
Source File: BlockDoor.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().getId() == AIR) {
            Block up = this.up();

            if (up instanceof BlockDoor) {
                this.getLevel().setBlock(up, Block.get(BlockID.AIR), false);
                this.getLevel().useBreakOn(this);
            }

            return Level.BLOCK_UPDATE_NORMAL;
        }
    }

    if (type == Level.BLOCK_UPDATE_REDSTONE) {
        if ((!isOpen() && this.level.isBlockPowered(this.getLocation())) || (isOpen() && !this.level.isBlockPowered(this.getLocation()))) {
            this.level.getServer().getPluginManager().callEvent(new BlockRedstoneEvent(this, isOpen() ? 15 : 0, isOpen() ? 0 : 15));

            this.toggle(null);
        }
    }

    return 0;
}
 
Example 3
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 4
Source File: BlockRedstoneWire.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) {
        return 0;
    }
    // Redstone event
    RedstoneUpdateEvent ev = new RedstoneUpdateEvent(this);
    getLevel().getServer().getPluginManager().callEvent(ev);
    if (ev.isCancelled()) {
        return 0;
    }

    if (type == Level.BLOCK_UPDATE_NORMAL && !this.canBePlacedOn(this.getLocation().down())) {
        this.getLevel().useBreakOn(this);
        return Level.BLOCK_UPDATE_NORMAL;
    }

    this.updateSurroundingRedstone(false);

    return Level.BLOCK_UPDATE_NORMAL;
}
 
Example 5
Source File: BlockNoteblock.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_REDSTONE) {
        BlockEntityMusic blockEntity = this.getBlockEntity();
        if (blockEntity != null) {
            if (this.getLevel().isBlockPowered(this)) {
                if (!blockEntity.isPowered()) {
                    this.emitSound();
                }
                blockEntity.setPowered(true);
            } else {
                blockEntity.setPowered(false);
            }
        }
    }
    return super.onUpdate(type);
}
 
Example 6
Source File: BlockRailActivator.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 || 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 7
Source File: BlockDoor.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().getId() == AIR) {
            Block up = this.up();

            if (up instanceof BlockDoor) {
                this.getLevel().setBlock(up, new BlockAir(), false);
                this.getLevel().useBreakOn(this);
            }

            return Level.BLOCK_UPDATE_NORMAL;
        }
    }

    if (type == Level.BLOCK_UPDATE_REDSTONE) {
        if ((!isOpen() && this.level.isBlockPowered(this)) || (isOpen() && !this.level.isBlockPowered(this))) {
            this.level.getServer().getPluginManager().callEvent(new BlockRedstoneEvent(this, isOpen() ? 15 : 0, isOpen() ? 0 : 15));

            this.toggle(null);
        }
    }

    return 0;
}
 
Example 8
Source File: BlockDropper.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_REDSTONE) {
        if (this.getLevel().isBlockPowered(this)) {
            BlockEntity blockEntity = this.level.getBlockEntity(this);
            if (blockEntity instanceof BlockEntityDropper) {
                ((BlockEntityDropper) blockEntity).activate();
            }
        }
    }
    return 0;
}
 
Example 9
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 10
Source File: BlockFenceGate.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_REDSTONE) {
        if ((!isOpen() && this.level.isBlockPowered(this)) || (isOpen() && !this.level.isBlockPowered(this))) {
            this.toggle(null);
            return type;
        }
    }

    return 0;
}
 
Example 11
Source File: BlockNoteblock.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) {
        //TODO: redstone
    }

    return 0;
}
 
Example 12
Source File: BlockRedstoneLampLit.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.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 13
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 14
Source File: BlockTrapdoor.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_REDSTONE || type == Level.BLOCK_UPDATE_NORMAL) {
        if ((!isOpen() && this.level.isBlockPowered(this)) || (isOpen() && !this.level.isBlockPowered(this))) {
            this.level.getServer().getPluginManager().callEvent(new BlockRedstoneEvent(this, isOpen() ? 15 : 0, isOpen() ? 0 : 15));
            this.toggle(null);
            return type;
        }
    }

    return 0;
}
 
Example 15
Source File: BlockRedstoneDiode.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 (!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) {
//                        System.out.println("schedule update 2");
                        level.scheduleUpdate(getPowered(), this, this.getDelay());
                    }
                }
            }
        } else if (type == Level.BLOCK_UPDATE_NORMAL || type == Level.BLOCK_UPDATE_REDSTONE) {
            // Redstone event
            RedstoneUpdateEvent ev = new RedstoneUpdateEvent(this);
            getLevel().getServer().getPluginManager().callEvent(ev);
            if (ev.isCancelled()) {
                return 0;
            }
            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 16
Source File: BlockTrapdoor.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_REDSTONE || type == Level.BLOCK_UPDATE_NORMAL) {
        if ((!isOpen() && this.level.isBlockPowered(this)) || (isOpen() && !this.level.isBlockPowered(this))) {
            this.level.getServer().getPluginManager().callEvent(new BlockRedstoneEvent(this, isOpen() ? 15 : 0, isOpen() ? 0 : 15));
            this.toggle(null);
            return type;
        }
    }

    return 0;
}
 
Example 17
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.getLocation())) {
        this.prime();
    }

    return 0;
}
 
Example 18
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 19
Source File: BlockRedstoneLamp.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) {
        if (this.level.isBlockPowered(this)) {
            this.level.setBlock(this, new BlockRedstoneLampLit(), false, false);
            return 1;
        }
    }

    return 0;
}
 
Example 20
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;
}