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

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

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

import cn.nukkit.Player;
import cn.nukkit.api.PowerNukkitOnly;
import cn.nukkit.api.Since;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemTool;
import cn.nukkit.level.Level;
import cn.nukkit.level.generator.object.ObjectNyliumVegetation;
import cn.nukkit.level.particle.BoneMealParticle;
import cn.nukkit.math.NukkitRandom;
import org.jetbrains.annotations.NotNull;

import javax.annotation.Nullable;

@PowerNukkitOnly
@Since("1.4.0.0-PN")
public abstract class BlockNylium extends BlockSolid {
    @PowerNukkitOnly
    @Since("1.4.0.0-PN")
    public BlockNylium() {
        // Does nothing
    }

    @Override
    public int getToolType() {
        return ItemTool.TYPE_PICKAXE;
    }

    @Override
    public int onUpdate(int type) {
        if (type == Level.BLOCK_UPDATE_RANDOM && !up().isTransparent()) {
            level.setBlock(this, Block.get(NETHERRACK), false);
            return type;
        }
        return 0;
    }

    @Override
    public boolean canBeActivated() {
        return true;
    }

    @Override
    public boolean onActivate(@NotNull Item item, @Nullable Player player) {
        Block up = up();
        if (item.isNull() || !item.isFertilizer() || up.getId() != AIR) {
            return false;
        }

        if (player != null && !player.isCreative()) {
            item.count--;
        }

        grow();

        level.addParticle(new BoneMealParticle(up));
        
        return true;
    }

    @PowerNukkitOnly
    @Since("1.4.0.0-PN")
    public boolean grow() {
        ObjectNyliumVegetation.growVegetation(level, this, new NukkitRandom());
        return true;
    }

    @Override
    public double getResistance() {
        return 0.4;
    }

    @Override
    public double getHardness() {
        return 0.4;
    }

    @Override
    public Item[] getDrops(Item item) {
        if (item.isPickaxe() && item.getTier() >= ItemTool.TIER_WOODEN) {
            return new Item[]{ Item.get(NETHERRACK) };
        }
        return Item.EMPTY_ARRAY;
    }

    @Override
    public boolean canSilkTouch() {
        return true;
    }

    @Override
    public boolean canHarvestWithHand() {
        return false;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy