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());
}
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;
}
}
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);
}
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);
}
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();
}
Aggregations