cn.nukkit.block.BlockCarpet Maven / Gradle / Ivy
package cn.nukkit.block;
import cn.nukkit.Player;
import cn.nukkit.api.PowerNukkitOnly;
import cn.nukkit.api.Since;
import cn.nukkit.blockproperty.BlockProperties;
import cn.nukkit.blockproperty.CommonBlockProperties;
import cn.nukkit.item.Item;
import cn.nukkit.level.Level;
import cn.nukkit.math.AxisAlignedBB;
import cn.nukkit.math.BlockFace;
import cn.nukkit.utils.BlockColor;
import cn.nukkit.utils.DyeColor;
import org.jetbrains.annotations.NotNull;
/**
* @author xtypr
* @since 2015/11/24
*/
public class BlockCarpet extends BlockFlowable {
@PowerNukkitOnly
@Since("1.5.0.0-PN")
public static final BlockProperties PROPERTIES = CommonBlockProperties.COLOR_BLOCK_PROPERTIES;
public BlockCarpet() {
this(0);
}
public BlockCarpet(int meta) {
super(meta);
}
public BlockCarpet(DyeColor dyeColor) {
this(dyeColor.getWoolData());
}
@Override
public int getId() {
return CARPET;
}
@NotNull
@Override
@PowerNukkitOnly
public BlockProperties getProperties() {
return PROPERTIES;
}
@Override
public double getHardness() {
return 0.1;
}
@Override
public double getResistance() {
return 0.5;
}
@Override
public boolean isSolid() {
return false;
}
@Since("1.3.0.0-PN")
@PowerNukkitOnly
@Override
public boolean isSolid(BlockFace side) {
return false;
}
@Override
public String getName() {
return DyeColor.getByWoolData(getDamage()) + " Carpet";
}
@Override
public boolean canPassThrough() {
return false;
}
@PowerNukkitOnly
@Override
public int getWaterloggingLevel() {
return 1;
}
@Override
protected AxisAlignedBB recalculateBoundingBox() {
return this;
}
@Override
public double getMaxY() {
return this.y + 0.0625;
}
@Override
public boolean place(@NotNull Item item, @NotNull Block block, @NotNull Block target, @NotNull BlockFace face, double fx, double fy, double fz, Player player) {
Block down = this.down();
if (down.getId() != Item.AIR) {
this.getLevel().setBlock(block, this, true, true);
return true;
}
return false;
}
@Override
public int onUpdate(int type) {
if (type == Level.BLOCK_UPDATE_NORMAL) {
if (this.down().getId() == Item.AIR) {
this.getLevel().useBreakOn(this);
return Level.BLOCK_UPDATE_NORMAL;
}
}
return 0;
}
@Override
public BlockColor getColor() {
return getDyeColor().getColor();
}
public DyeColor getDyeColor() {
return getPropertyValue(CommonBlockProperties.COLOR);
}
@PowerNukkitOnly
@Since("1.5.0.0-PN")
public void setDyeColor(@NotNull DyeColor color) {
setPropertyValue(CommonBlockProperties.COLOR, color);
}
}