cn.nukkit.block.BlockConcretePowder Maven / Gradle / Ivy
package cn.nukkit.block;
import cn.nukkit.Player;
import cn.nukkit.api.PowerNukkitDifference;
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.item.ItemTool;
import cn.nukkit.level.Level;
import cn.nukkit.math.BlockFace;
import cn.nukkit.utils.DyeColor;
import org.jetbrains.annotations.NotNull;
/**
* @author CreeperFace
* @since 2.6.2017
*/
@PowerNukkitDifference(info = "Extends BlockFallableMeta instead of BlockFallable")
public class BlockConcretePowder extends BlockFallableMeta {
@PowerNukkitOnly
@Since("1.5.0.0-PN")
public static final BlockProperties PROPERTIES = CommonBlockProperties.COLOR_BLOCK_PROPERTIES;
public BlockConcretePowder() {
// Does nothing
}
public BlockConcretePowder(int meta) {
super(meta);
}
@Override
public int getId() {
return CONCRETE_POWDER;
}
@Since("1.4.0.0-PN")
@PowerNukkitOnly
@NotNull
@Override
public BlockProperties getProperties() {
return PROPERTIES;
}
@Override
public String getName() {
return getDyeColor().getName() + " Concrete Powder";
}
@Override
public double getResistance() {
return 2.5;
}
@Override
public double getHardness() {
return 0.5;
}
@Override
public int getToolType() {
return ItemTool.TYPE_SHOVEL;
}
@Override
public int onUpdate(int type) {
if (type == Level.BLOCK_UPDATE_NORMAL) {
super.onUpdate(Level.BLOCK_UPDATE_NORMAL);
for (int side = 1; side <= 5; side++) {
Block block = this.getSide(BlockFace.fromIndex(side));
if (block.getId() == Block.FLOWING_WATER || block.getId() == Block.STILL_WATER) {
this.level.setBlock(this, Block.get(Block.CONCRETE, getDamage()), true, true);
}
}
return Level.BLOCK_UPDATE_NORMAL;
}
return 0;
}
@Override
public boolean place(@NotNull Item item, @NotNull Block b, @NotNull Block target, @NotNull BlockFace face, double fx, double fy, double fz, Player player) {
boolean concrete = false;
for (int side = 1; side <= 5; side++) {
Block block = this.getSide(BlockFace.fromIndex(side));
if (block.getId() == Block.FLOWING_WATER || block.getId() == Block.STILL_WATER) {
concrete = true;
break;
}
}
if (concrete) {
this.level.setBlock(this, Block.get(Block.CONCRETE, this.getDamage()), true, true);
} else {
this.level.setBlock(this, this, true, true);
}
return true;
}
@PowerNukkitOnly
public DyeColor getDyeColor() {
return getPropertyValue(CommonBlockProperties.COLOR);
}
}