All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.nukkit.block.IBlockOreRedstoneGlowing Maven / Gradle / Ivy

There is a newer version: 1.20.40-r1
Show newest version
package cn.nukkit.block;

import cn.nukkit.api.PowerNukkitOnly;
import cn.nukkit.api.Since;
import cn.nukkit.blockstate.BlockState;
import cn.nukkit.blockstate.IMutableBlockState;
import cn.nukkit.event.block.BlockFadeEvent;
import cn.nukkit.item.Item;
import cn.nukkit.level.Level;

/**
 * @author joserobjr
 * @since 2021-06-14
 */
@PowerNukkitOnly
@Since("FUTURE")
public interface IBlockOreRedstoneGlowing extends IMutableBlockState {
    @PowerNukkitOnly
    @Since("FUTURE")
    BlockState getUnlitState();

    @PowerNukkitOnly
    @Since("FUTURE")
    BlockState getLitState();

    @PowerNukkitOnly
    @Since("FUTURE")
    Level getLevel();

    @PowerNukkitOnly
    @Since("FUTURE")
    default Item toItem() {
        return getUnlitState().asItemBlock();
    }

    @PowerNukkitOnly
    @Since("FUTURE")
    default int onUpdate(int type) {
        if (type == Level.BLOCK_UPDATE_SCHEDULED || type == Level.BLOCK_UPDATE_RANDOM) {
            Block block = getBlock();
            Level level = getLevel();
            BlockFadeEvent event = new BlockFadeEvent(block, getUnlitState().getBlock());
            level.getServer().getPluginManager().callEvent(event);
            if (!event.isCancelled()) {
                level.setBlock(block, event.getNewState(), false, true);
            }

            return Level.BLOCK_UPDATE_WEAK;
        }

        return 0;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy