cn.nukkit.block.BlockRedstoneLamp 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.Player;
import cn.nukkit.event.redstone.RedstoneUpdateEvent;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemBlock;
import cn.nukkit.item.ItemTool;
import cn.nukkit.level.Level;
import cn.nukkit.math.BlockFace;
import cn.nukkit.utils.BlockColor;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
/**
* @author Nukkit Project Team
*/
public class BlockRedstoneLamp extends BlockSolid {
public BlockRedstoneLamp() {
}
@Override
public String getName() {
return "Redstone Lamp";
}
@Override
public int getId() {
return REDSTONE_LAMP;
}
@Override
public double getHardness() {
return 0.3D;
}
@Override
public double getResistance() {
return 1.5D;
}
@Override
public int getToolType() {
return ItemTool.TYPE_PICKAXE;
}
@Override
public boolean place(@Nonnull Item item, @Nonnull Block block, @Nonnull Block target, @Nonnull BlockFace face, double fx, double fy, double fz, @Nullable Player player) {
if (this.level.isBlockPowered(this.getLocation())) {
this.level.setBlock(this, Block.get(BlockID.LIT_REDSTONE_LAMP), false, true);
} else {
this.level.setBlock(this, this, false, true);
}
return true;
}
@Override
public int onUpdate(int type) {
if (type == Level.BLOCK_UPDATE_NORMAL || type == Level.BLOCK_UPDATE_REDSTONE) {
if (!this.level.getServer().isRedstoneEnabled()) {
return 0;
}
// Redstone event
RedstoneUpdateEvent ev = new RedstoneUpdateEvent(this);
getLevel().getServer().getPluginManager().callEvent(ev);
if (ev.isCancelled()) {
return 0;
}
if (this.level.isBlockPowered(this.getLocation())) {
this.level.setBlock(this, Block.get(BlockID.LIT_REDSTONE_LAMP), false, false);
return 1;
}
}
return 0;
}
@Override
public Item[] getDrops(Item item) {
return new Item[]{
new ItemBlock(Block.get(BlockID.REDSTONE_LAMP))
};
}
@Override
public BlockColor getColor() {
return BlockColor.AIR_BLOCK_COLOR;
}
}