cn.nukkit.block.BlockCandleCake Maven / Gradle / Ivy
package cn.nukkit.block;
import cn.nukkit.Player;
import cn.nukkit.api.PowerNukkitOnly;
import cn.nukkit.api.PowerNukkitXOnly;
import cn.nukkit.api.Since;
import cn.nukkit.blockproperty.BlockProperties;
import cn.nukkit.blockproperty.IntBlockProperty;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemCake;
import cn.nukkit.item.ItemID;
import cn.nukkit.level.Level;
import cn.nukkit.level.Sound;
import cn.nukkit.math.BlockFace;
import cn.nukkit.utils.BlockColor;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@PowerNukkitXOnly
@Since("1.6.0.0-PNX")
public class BlockCandleCake extends BlockTransparentMeta {
@PowerNukkitOnly
@Since("FUTURE")
private static final IntBlockProperty LIT = new IntBlockProperty("lit", false, 1, 0, 1);
@PowerNukkitXOnly
@Since("1.6.0.0-PNX")
public static final BlockProperties PROPERTIES = new BlockProperties(LIT);
public BlockCandleCake(int meta) {
super(meta);
}
public BlockCandleCake() {
this(0);
}
@Override
public String getName() {
return "Cake Block With " + getColorName() + " Candle";
}
protected String getColorName() {
return "Simple";
}
@Override
public int getId() {
return CANDLE_CAKE;
}
@Since("1.6.0.0-PNX")
@PowerNukkitOnly
@Nonnull
@Override
public BlockProperties getProperties() {
return PROPERTIES;
}
@Override
public boolean canBeActivated() {
return true;
}
@Override
public double getHardness() {
return 0.5;
}
@Override
public double getResistance() {
return 0.5;
}
@PowerNukkitOnly
@Override
public int getWaterloggingLevel() {
return 1;
}
@Override
public double getMinX() {
return this.x + (1 + getDamage() * 2) / 16d;
}
@Override
public double getMinY() {
return this.y;
}
@Override
public double getMinZ() {
return this.z + 0.0625;
}
@Override
public double getMaxX() {
return this.x - 0.0625 + 1;
}
@Override
public double getMaxY() {
return this.y + 0.5;
}
@Override
public double getMaxZ() {
return this.z - 0.0625 + 1;
}
@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 (down().getId() != Block.AIR) {
getLevel().setBlock(block, this, true, true);
return true;
}
return false;
}
@Override
public int onUpdate(int type) {
if (type == Level.BLOCK_UPDATE_NORMAL) {
if (down().getId() == Block.AIR) {
getLevel().setBlock(this, Block.get(BlockID.AIR), true);
return Level.BLOCK_UPDATE_NORMAL;
}
}
return 0;
}
protected BlockCandle toCandleForm() {
return new BlockCandle();
}
@Override
public Item[] getDrops(Item item) {
return new Item[]{toCandleForm().toItem()};
}
@Override
public Item toItem() {
return new ItemCake();
}
@SuppressWarnings("DuplicatedCode")
@Override
public boolean onActivate(@Nonnull Item item, Player player) {
if (getPropertyValue(LIT) == 1 && item.getId() != ItemID.FLINT_AND_STEEL) {
setPropertyValue(LIT, 0);
getLevel().addSound(this, Sound.RANDOM_FIZZ);
getLevel().setBlock(this, this, true, true);
return true;
} else if (getPropertyValue(LIT) == 0 && item.getId() == ItemID.FLINT_AND_STEEL) {
setPropertyValue(LIT, 1);
getLevel().addSound(this, Sound.FIRE_IGNITE);
getLevel().setBlock(this, this, true, true);
return true;
} else if (player != null && player.getFoodData().getLevel() < player.getFoodData().getMaxLevel()) {
final Block cake = new BlockCake();
this.getLevel().setBlock(this, cake, true, true);
this.getLevel().dropItem(this.add(0.5, 0.5, 0.5), getDrops(null)[0]);
return this.getLevel().getBlock(this).onActivate(item, player);
}
return false;
}
@Override
public BlockColor getColor() {
return BlockColor.AIR_BLOCK_COLOR;
}
@Override
public int getComparatorInputOverride() {
return 14;
}
@Override
public boolean hasComparatorInputOverride() {
return true;
}
@Override
@PowerNukkitOnly
public boolean breaksWhenMoved() {
return true;
}
@Override
@PowerNukkitOnly
public boolean sticksToPiston() {
return false;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy