use of cn.nukkit.nbt.tag.CompoundTag in project Nukkit by Nukkit.
the class BlockFallable method onUpdate.
public int onUpdate(int type) {
if (type == Level.BLOCK_UPDATE_NORMAL) {
Block down = this.down();
if (down.getId() == AIR || down instanceof BlockLiquid) {
this.level.setBlock(this, Block.get(Block.AIR), true, true);
CompoundTag nbt = new CompoundTag().putList(new ListTag<DoubleTag>("Pos").add(new DoubleTag("", this.x + 0.5)).add(new DoubleTag("", this.y)).add(new DoubleTag("", this.z + 0.5))).putList(new ListTag<DoubleTag>("Motion").add(new DoubleTag("", 0)).add(new DoubleTag("", 0)).add(new DoubleTag("", 0))).putList(new ListTag<FloatTag>("Rotation").add(new FloatTag("", 0)).add(new FloatTag("", 0))).putInt("TileID", this.getId()).putByte("Data", this.getDamage());
EntityFallingBlock fall = new EntityFallingBlock(this.getLevel().getChunk((int) this.x >> 4, (int) this.z >> 4), nbt);
fall.spawnToAll();
}
}
return type;
}
use of cn.nukkit.nbt.tag.CompoundTag in project Nukkit by Nukkit.
the class BlockEntityChest method setItem.
@Override
public void setItem(int index, Item item) {
int i = this.getSlotIndex(index);
CompoundTag d = NBTIO.putItemHelper(item, index);
// If item is air or count less than 0, remove the item from the "Items" list
if (item.getId() == Item.AIR || item.getCount() <= 0) {
if (i >= 0) {
this.namedTag.getList("Items").remove(i);
}
} else if (i < 0) {
// If it is less than i, then it is a new item, so we are going to add it at the end of the list
(this.namedTag.getList("Items", CompoundTag.class)).add(d);
} else {
// If it is more than i, then it is an update on a inventorySlot, so we are going to overwrite the item in the list
(this.namedTag.getList("Items", CompoundTag.class)).add(i, d);
}
}
use of cn.nukkit.nbt.tag.CompoundTag in project Nukkit by Nukkit.
the class BlockEntityFurnace method setItem.
@Override
public void setItem(int index, Item item) {
int i = this.getSlotIndex(index);
CompoundTag d = NBTIO.putItemHelper(item, index);
if (item.getId() == Item.AIR || item.getCount() <= 0) {
if (i >= 0) {
this.namedTag.getList("Items").getAll().remove(i);
}
} else if (i < 0) {
(this.namedTag.getList("Items", CompoundTag.class)).add(d);
} else {
(this.namedTag.getList("Items", CompoundTag.class)).add(i, d);
}
}
use of cn.nukkit.nbt.tag.CompoundTag in project Nukkit by Nukkit.
the class BlockEntityFurnace method initBlockEntity.
@Override
protected void initBlockEntity() {
this.inventory = new FurnaceInventory(this);
if (!this.namedTag.contains("Items") || !(this.namedTag.get("Items") instanceof ListTag)) {
this.namedTag.putList(new ListTag<CompoundTag>("Items"));
}
for (int i = 0; i < this.getSize(); i++) {
this.inventory.setItem(i, this.getItem(i));
}
if (!this.namedTag.contains("BurnTime") || this.namedTag.getShort("BurnTime") < 0) {
burnTime = 0;
} else {
burnTime = this.namedTag.getShort("BurnTime");
}
if (!this.namedTag.contains("CookTime") || this.namedTag.getShort("CookTime") < 0 || (this.namedTag.getShort("BurnTime") == 0 && this.namedTag.getShort("CookTime") > 0)) {
cookTime = 0;
} else {
cookTime = this.namedTag.getShort("CookTime");
}
if (!this.namedTag.contains("MaxTime")) {
maxTime = burnTime;
burnDuration = 0;
} else {
maxTime = this.namedTag.getShort("MaxTime");
}
if (this.namedTag.contains("BurnTicks")) {
burnDuration = this.namedTag.getShort("BurnTicks");
this.namedTag.remove("BurnTicks");
}
if (burnTime > 0) {
this.scheduleUpdate();
}
super.initBlockEntity();
}
use of cn.nukkit.nbt.tag.CompoundTag in project Nukkit by Nukkit.
the class BlockEntityHopper method initBlockEntity.
@Override
protected void initBlockEntity() {
if (this.namedTag.contains("TransferCooldown")) {
this.transferCooldown = this.namedTag.getInt("TransferCooldown");
}
this.inventory = new HopperInventory(this);
if (!this.namedTag.contains("Items") || !(this.namedTag.get("Items") instanceof ListTag)) {
this.namedTag.putList(new ListTag<CompoundTag>("Items"));
}
for (int i = 0; i < this.getSize(); i++) {
this.inventory.setItem(i, this.getItem(i));
}
this.pickupArea = new SimpleAxisAlignedBB(this.x, this.y, this.z, this.x + 1, this.y + 2, this.z + 1);
this.scheduleUpdate();
super.initBlockEntity();
}
Aggregations