Search in sources :

Example 16 with CompoundTag

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

the class BlockEntityItemFrame method getSpawnCompound.

@Override
public CompoundTag getSpawnCompound() {
    if (!this.namedTag.contains("Item")) {
        this.setItem(new ItemBlock(new BlockAir()), false);
    }
    CompoundTag NBTItem = namedTag.getCompound("Item").copy();
    NBTItem.setName("Item");
    boolean item = NBTItem.getShort("id") == Item.AIR;
    return new CompoundTag().putString("id", BlockEntity.ITEM_FRAME).putInt("x", (int) this.x).putInt("y", (int) this.y).putInt("z", (int) this.z).putCompound("Item", item ? NBTIO.putItemHelper(new ItemBlock(new BlockAir())) : NBTItem).putByte("ItemRotation", item ? 0 : this.getItemRotation());
// TODO: This crashes the client, why?
// .putFloat("ItemDropChance", this.getItemDropChance());
}
Also used : BlockAir(cn.nukkit.block.BlockAir) ItemBlock(cn.nukkit.item.ItemBlock) CompoundTag(cn.nukkit.nbt.tag.CompoundTag)

Example 17 with CompoundTag

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

the class BlockEntity method getCleanedNBT.

public CompoundTag getCleanedNBT() {
    this.saveNBT();
    CompoundTag tag = this.namedTag.clone();
    tag.remove("x").remove("y").remove("z").remove("id");
    if (tag.getTags().size() > 0) {
        return tag;
    } else {
        return null;
    }
}
Also used : CompoundTag(cn.nukkit.nbt.tag.CompoundTag)

Example 18 with CompoundTag

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

the class BlockEntitySpawnable method spawnTo.

public void spawnTo(Player player) {
    if (this.closed) {
        return;
    }
    CompoundTag tag = this.getSpawnCompound();
    BlockEntityDataPacket pk = new BlockEntityDataPacket();
    pk.x = (int) this.x;
    pk.y = (int) this.y;
    pk.z = (int) this.z;
    try {
        pk.namedTag = NBTIO.write(tag, ByteOrder.LITTLE_ENDIAN, true);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    player.dataPacket(pk);
}
Also used : BlockEntityDataPacket(cn.nukkit.network.protocol.BlockEntityDataPacket) IOException(java.io.IOException) CompoundTag(cn.nukkit.nbt.tag.CompoundTag)

Example 19 with CompoundTag

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

the class BlockTNT method prime.

public void prime(int fuse) {
    this.getLevel().setBlock(this, new BlockAir(), true);
    double mot = (new NukkitRandom()).nextSignedFloat() * Math.PI * 2;
    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("", -Math.sin(mot) * 0.02)).add(new DoubleTag("", 0.2)).add(new DoubleTag("", -Math.cos(mot) * 0.02))).putList(new ListTag<FloatTag>("Rotation").add(new FloatTag("", 0)).add(new FloatTag("", 0))).putShort("Fuse", fuse);
    Entity tnt = new EntityPrimedTNT(this.getLevel().getChunk(this.getFloorX() >> 4, this.getFloorZ() >> 4), nbt);
    tnt.spawnToAll();
    this.level.addSound(this, Sound.RANDOM_FUSE);
}
Also used : Entity(cn.nukkit.entity.Entity) FloatTag(cn.nukkit.nbt.tag.FloatTag) EntityPrimedTNT(cn.nukkit.entity.item.EntityPrimedTNT) DoubleTag(cn.nukkit.nbt.tag.DoubleTag) NukkitRandom(cn.nukkit.math.NukkitRandom) ListTag(cn.nukkit.nbt.tag.ListTag) CompoundTag(cn.nukkit.nbt.tag.CompoundTag)

Example 20 with CompoundTag

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

the class ProjectileDispenseBehavior method dispense.

@Override
public void dispense(BlockDispenser source, Item item) {
    Position dispensePos = Position.fromObject(source.getDispensePosition(), source.getLevel());
    CompoundTag nbt = Entity.getDefaultNBT(dispensePos);
    this.correctNBT(nbt);
    BlockFace face = source.getFacing();
    Entity projectile = Entity.createEntity(getEntityType(), dispensePos.getLevel().getChunk(dispensePos.getFloorX(), dispensePos.getFloorZ()), nbt);
    if (projectile == null) {
        return;
    }
    projectile.setMotion(new Vector3(face.getXOffset(), face.getYOffset() + 0.1f, face.getZOffset()).multiply(6));
    projectile.spawnToAll();
}
Also used : Entity(cn.nukkit.entity.Entity) Position(cn.nukkit.level.Position) BlockFace(cn.nukkit.math.BlockFace) Vector3(cn.nukkit.math.Vector3) 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