Search in sources :

Example 1 with ListTag

use of cn.nukkit.nbt.tag.ListTag in project Nukkit by Nukkit.

the class BlockBrewingStand method place.

@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
    if (!block.down().isTransparent()) {
        getLevel().setBlock(block, this, true, true);
        CompoundTag nbt = new CompoundTag().putList(new ListTag<>("Items")).putString("id", BlockEntity.BREWING_STAND).putInt("x", (int) this.x).putInt("y", (int) this.y).putInt("z", (int) this.z);
        if (item.hasCustomName()) {
            nbt.putString("CustomName", item.getCustomName());
        }
        if (item.hasCustomBlockData()) {
            Map<String, Tag> customData = item.getCustomBlockData().getTags();
            for (Map.Entry<String, Tag> tag : customData.entrySet()) {
                nbt.put(tag.getKey(), tag.getValue());
            }
        }
        new BlockEntityBrewingStand(getLevel().getChunk((int) this.x >> 4, (int) this.z >> 4), nbt);
        return true;
    }
    return false;
}
Also used : StringTag(cn.nukkit.nbt.tag.StringTag) CompoundTag(cn.nukkit.nbt.tag.CompoundTag) Tag(cn.nukkit.nbt.tag.Tag) ListTag(cn.nukkit.nbt.tag.ListTag) Map(java.util.Map) CompoundTag(cn.nukkit.nbt.tag.CompoundTag) BlockEntityBrewingStand(cn.nukkit.blockentity.BlockEntityBrewingStand)

Example 2 with ListTag

use of cn.nukkit.nbt.tag.ListTag in project Nukkit by Nukkit.

the class BlockFurnaceBurning method place.

@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
    int[] faces = { 2, 5, 3, 4 };
    this.setDamage(faces[player != null ? player.getDirection().getHorizontalIndex() : 0]);
    this.getLevel().setBlock(block, this, true, true);
    CompoundTag nbt = new CompoundTag().putList(new ListTag<>("Items")).putString("id", BlockEntity.FURNACE).putInt("x", (int) this.x).putInt("y", (int) this.y).putInt("z", (int) this.z);
    if (item.hasCustomName()) {
        nbt.putString("CustomName", item.getCustomName());
    }
    if (item.hasCustomBlockData()) {
        Map<String, Tag> customData = item.getCustomBlockData().getTags();
        for (Map.Entry<String, Tag> tag : customData.entrySet()) {
            nbt.put(tag.getKey(), tag.getValue());
        }
    }
    new BlockEntityFurnace(this.getLevel().getChunk((int) (this.x) >> 4, (int) (this.z) >> 4), nbt);
    return true;
}
Also used : BlockEntityFurnace(cn.nukkit.blockentity.BlockEntityFurnace) StringTag(cn.nukkit.nbt.tag.StringTag) CompoundTag(cn.nukkit.nbt.tag.CompoundTag) Tag(cn.nukkit.nbt.tag.Tag) ListTag(cn.nukkit.nbt.tag.ListTag) Map(java.util.Map) CompoundTag(cn.nukkit.nbt.tag.CompoundTag)

Example 3 with ListTag

use of cn.nukkit.nbt.tag.ListTag 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 4 with ListTag

use of cn.nukkit.nbt.tag.ListTag 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 5 with ListTag

use of cn.nukkit.nbt.tag.ListTag 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)27 ListTag (cn.nukkit.nbt.tag.ListTag)27 DoubleTag (cn.nukkit.nbt.tag.DoubleTag)13 FloatTag (cn.nukkit.nbt.tag.FloatTag)13 Entity (cn.nukkit.entity.Entity)5 StringTag (cn.nukkit.nbt.tag.StringTag)5 Tag (cn.nukkit.nbt.tag.Tag)5 BlockRail (cn.nukkit.block.BlockRail)4 BlockEntity (cn.nukkit.blockentity.BlockEntity)4 Rail (cn.nukkit.utils.Rail)4 Map (java.util.Map)4 ArrayList (java.util.ArrayList)3 Player (cn.nukkit.Player)2 BlockEntityChest (cn.nukkit.blockentity.BlockEntityChest)2 EntityProjectile (cn.nukkit.entity.projectile.EntityProjectile)2 ProjectileLaunchEvent (cn.nukkit.event.entity.ProjectileLaunchEvent)2 FullChunk (cn.nukkit.level.format.FullChunk)2 Random (java.util.Random)2 BlockAir (cn.nukkit.block.BlockAir)1 BlockEntityBrewingStand (cn.nukkit.blockentity.BlockEntityBrewingStand)1