Search in sources :

Example 11 with CompoundTag

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;
}
Also used : EntityFallingBlock(cn.nukkit.entity.item.EntityFallingBlock) FloatTag(cn.nukkit.nbt.tag.FloatTag) EntityFallingBlock(cn.nukkit.entity.item.EntityFallingBlock) DoubleTag(cn.nukkit.nbt.tag.DoubleTag) ListTag(cn.nukkit.nbt.tag.ListTag) CompoundTag(cn.nukkit.nbt.tag.CompoundTag)

Example 12 with CompoundTag

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);
    }
}
Also used : CompoundTag(cn.nukkit.nbt.tag.CompoundTag)

Example 13 with CompoundTag

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);
    }
}
Also used : CompoundTag(cn.nukkit.nbt.tag.CompoundTag)

Example 14 with CompoundTag

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();
}
Also used : FurnaceInventory(cn.nukkit.inventory.FurnaceInventory) ListTag(cn.nukkit.nbt.tag.ListTag) CompoundTag(cn.nukkit.nbt.tag.CompoundTag)

Example 15 with CompoundTag

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();
}
Also used : HopperInventory(cn.nukkit.inventory.HopperInventory) ListTag(cn.nukkit.nbt.tag.ListTag) SimpleAxisAlignedBB(cn.nukkit.math.SimpleAxisAlignedBB) CompoundTag(cn.nukkit.nbt.tag.CompoundTag)

Aggregations

CompoundTag (cn.nukkit.nbt.tag.CompoundTag)74 ListTag (cn.nukkit.nbt.tag.ListTag)28 BlockEntity (cn.nukkit.blockentity.BlockEntity)13 DoubleTag (cn.nukkit.nbt.tag.DoubleTag)13 FloatTag (cn.nukkit.nbt.tag.FloatTag)13 Tag (cn.nukkit.nbt.tag.Tag)13 StringTag (cn.nukkit.nbt.tag.StringTag)12 Map (java.util.Map)8 Entity (cn.nukkit.entity.Entity)7 IOException (java.io.IOException)7 Player (cn.nukkit.Player)5 BinaryStream (cn.nukkit.utils.BinaryStream)5 ArrayList (java.util.ArrayList)5 BlockRail (cn.nukkit.block.BlockRail)4 FullChunk (cn.nukkit.level.format.FullChunk)4 BaseFullChunk (cn.nukkit.level.format.generic.BaseFullChunk)4 Rail (cn.nukkit.utils.Rail)4 File (java.io.File)4 BlockEntityChest (cn.nukkit.blockentity.BlockEntityChest)3 BlockEntitySpawnable (cn.nukkit.blockentity.BlockEntitySpawnable)3