cn.nukkit.blockentity.BlockEntityBed Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of powernukkit Show documentation
Show all versions of powernukkit Show documentation
A Minecraft Bedrock Edition server software implementation made in Java from scratch which supports all new features.
package cn.nukkit.blockentity;
import cn.nukkit.item.Item;
import cn.nukkit.level.format.FullChunk;
import cn.nukkit.nbt.tag.CompoundTag;
import cn.nukkit.utils.DyeColor;
/**
* @author CreeperFace
* @since 2.6.2017
*/
public class BlockEntityBed extends BlockEntitySpawnable {
public int color;
public BlockEntityBed(FullChunk chunk, CompoundTag nbt) {
super(chunk, nbt);
}
@Override
protected void initBlockEntity() {
if (!this.namedTag.contains("color")) {
this.namedTag.putByte("color", 0);
}
this.color = this.namedTag.getByte("color");
super.initBlockEntity();
}
@Override
public boolean isBlockEntityValid() {
return this.level.getBlockIdAt(this.getFloorX(), this.getFloorY(), this.getFloorZ()) == Item.BED_BLOCK;
}
@Override
public void saveNBT() {
super.saveNBT();
this.namedTag.putByte("color", this.color);
}
@Override
public CompoundTag getSpawnCompound() {
return new CompoundTag()
.putString("id", BlockEntity.BED)
.putInt("x", (int) this.x)
.putInt("y", (int) this.y)
.putInt("z", (int) this.z)
.putByte("color", this.color);
}
public DyeColor getDyeColor() {
return DyeColor.getByWoolData(color);
}
}