cn.nukkit.block.BlockRedstoneLampLit Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of powernukkit Show documentation
Show all versions of powernukkit Show documentation
A Minecraft Bedrock Edition server software implementation made in Java from scratch which supports all new features.
package cn.nukkit.block;
import cn.nukkit.event.redstone.RedstoneUpdateEvent;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemBlock;
import cn.nukkit.level.Level;
/**
* @author Pub4Game
*/
public class BlockRedstoneLampLit extends BlockRedstoneLamp {
public BlockRedstoneLampLit() {
}
@Override
public String getName() {
return "Lit Redstone Lamp";
}
@Override
public int getId() {
return LIT_REDSTONE_LAMP;
}
@Override
public int getLightLevel() {
return 15;
}
@Override
public Item toItem() {
return new ItemBlock(Block.get(BlockID.REDSTONE_LAMP));
}
@Override
public int onUpdate(int type) {
if (!this.level.getServer().isRedstoneEnabled()) {
return 0;
}
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;
}
}