Search in sources :

Example 16 with ListTag

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

the class BlockEntityBrewingStand method initBlockEntity.

@Override
protected void initBlockEntity() {
    inventory = new BrewingInventory(this);
    if (!namedTag.contains("Items") || !(namedTag.get("Items") instanceof ListTag)) {
        namedTag.putList(new ListTag<CompoundTag>("Items"));
    }
    for (int i = 0; i < getSize(); i++) {
        inventory.setItem(i, this.getItem(i));
    }
    if (!namedTag.contains("CookTime") || namedTag.getShort("CookTime") > MAX_BREW_TIME) {
        this.brewTime = MAX_BREW_TIME;
    } else {
        this.brewTime = namedTag.getShort("CookTime");
    }
    this.fuelAmount = namedTag.getShort("FuelAmount");
    this.fuelTotal = namedTag.getShort("FuelTotal");
    if (brewTime < MAX_BREW_TIME) {
        this.scheduleUpdate();
    }
    super.initBlockEntity();
}
Also used : BrewingInventory(cn.nukkit.inventory.BrewingInventory) ListTag(cn.nukkit.nbt.tag.ListTag) CompoundTag(cn.nukkit.nbt.tag.CompoundTag)

Example 17 with ListTag

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

the class BlockTrappedChest 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 };
    BlockEntityChest chest = null;
    this.setDamage(faces[player != null ? player.getDirection().getHorizontalIndex() : 0]);
    for (BlockFace side : Plane.HORIZONTAL) {
        if ((this.getDamage() == 4 || this.getDamage() == 5) && (side == BlockFace.WEST || side == BlockFace.EAST)) {
            continue;
        } else if ((this.getDamage() == 3 || this.getDamage() == 2) && (side == BlockFace.NORTH || side == BlockFace.SOUTH)) {
            continue;
        }
        Block c = this.getSide(side);
        if (c instanceof BlockTrappedChest && c.getDamage() == this.getDamage()) {
            BlockEntity blockEntity = this.getLevel().getBlockEntity(c);
            if (blockEntity instanceof BlockEntityChest && !((BlockEntityChest) blockEntity).isPaired()) {
                chest = (BlockEntityChest) blockEntity;
                break;
            }
        }
    }
    this.getLevel().setBlock(block, this, true, true);
    CompoundTag nbt = new CompoundTag("").putList(new ListTag<>("Items")).putString("id", BlockEntity.CHEST).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());
        }
    }
    BlockEntity blockEntity = new BlockEntityChest(this.getLevel().getChunk((int) (this.x) >> 4, (int) (this.z) >> 4), nbt);
    if (chest != null) {
        chest.pairWith(((BlockEntityChest) blockEntity));
        ((BlockEntityChest) blockEntity).pairWith(chest);
    }
    return true;
}
Also used : BlockFace(cn.nukkit.math.BlockFace) BlockEntityChest(cn.nukkit.blockentity.BlockEntityChest) 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) BlockEntity(cn.nukkit.blockentity.BlockEntity)

Example 18 with ListTag

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

the class ItemMinecart method onActivate.

@Override
public boolean onActivate(Level level, Player player, Block block, Block target, BlockFace face, double fx, double fy, double fz) {
    if (Rail.isRailBlock(target)) {
        Rail.Orientation type = ((BlockRail) target).getOrientation();
        double adjacent = 0.0D;
        if (type.isAscending()) {
            adjacent = 0.5D;
        }
        EntityMinecartEmpty minecart = new EntityMinecartEmpty(level.getChunk(target.getFloorX() >> 4, target.getFloorZ() >> 4), new CompoundTag("").putList(new ListTag<>("Pos").add(new DoubleTag("", target.getX() + 0.5)).add(new DoubleTag("", target.getY() + 0.0625D + adjacent)).add(new DoubleTag("", target.getZ() + 0.5))).putList(new ListTag<>("Motion").add(new DoubleTag("", 0)).add(new DoubleTag("", 0)).add(new DoubleTag("", 0))).putList(new ListTag<>("Rotation").add(new FloatTag("", 0)).add(new FloatTag("", 0))));
        minecart.spawnToAll();
        count -= 1;
        return true;
    }
    return false;
}
Also used : BlockRail(cn.nukkit.block.BlockRail) Rail(cn.nukkit.utils.Rail) FloatTag(cn.nukkit.nbt.tag.FloatTag) EntityMinecartEmpty(cn.nukkit.entity.item.EntityMinecartEmpty) DoubleTag(cn.nukkit.nbt.tag.DoubleTag) ListTag(cn.nukkit.nbt.tag.ListTag) BlockRail(cn.nukkit.block.BlockRail) CompoundTag(cn.nukkit.nbt.tag.CompoundTag)

Example 19 with ListTag

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

the class ItemMinecartChest method onActivate.

@Override
public boolean onActivate(Level level, Player player, Block block, Block target, BlockFace face, double fx, double fy, double fz) {
    if (Rail.isRailBlock(target)) {
        Rail.Orientation type = ((BlockRail) target).getOrientation();
        double adjacent = 0.0D;
        if (type.isAscending()) {
            adjacent = 0.5D;
        }
        EntityMinecartChest minecart = new EntityMinecartChest(level.getChunk(target.getFloorX() >> 4, target.getFloorZ() >> 4), new CompoundTag("").putList(new ListTag<>("Pos").add(new DoubleTag("", target.getX() + 0.5)).add(new DoubleTag("", target.getY() + 0.0625D + adjacent)).add(new DoubleTag("", target.getZ() + 0.5))).putList(new ListTag<>("Motion").add(new DoubleTag("", 0)).add(new DoubleTag("", 0)).add(new DoubleTag("", 0))).putList(new ListTag<>("Rotation").add(new FloatTag("", 0)).add(new FloatTag("", 0))));
        minecart.spawnToAll();
        count -= 1;
        return true;
    }
    return false;
}
Also used : BlockRail(cn.nukkit.block.BlockRail) Rail(cn.nukkit.utils.Rail) EntityMinecartChest(cn.nukkit.entity.item.EntityMinecartChest) FloatTag(cn.nukkit.nbt.tag.FloatTag) DoubleTag(cn.nukkit.nbt.tag.DoubleTag) ListTag(cn.nukkit.nbt.tag.ListTag) BlockRail(cn.nukkit.block.BlockRail) CompoundTag(cn.nukkit.nbt.tag.CompoundTag)

Example 20 with ListTag

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

the class ItemMinecartHopper method onActivate.

@Override
public boolean onActivate(Level level, Player player, Block block, Block target, BlockFace face, double fx, double fy, double fz) {
    if (Rail.isRailBlock(target)) {
        Rail.Orientation type = ((BlockRail) target).getOrientation();
        double adjacent = 0.0D;
        if (type.isAscending()) {
            adjacent = 0.5D;
        }
        EntityMinecartHopper minecart = new EntityMinecartHopper(level.getChunk(target.getFloorX() >> 4, target.getFloorZ() >> 4), new CompoundTag("").putList(new ListTag<>("Pos").add(new DoubleTag("", target.getX() + 0.5)).add(new DoubleTag("", target.getY() + 0.0625D + adjacent)).add(new DoubleTag("", target.getZ() + 0.5))).putList(new ListTag<>("Motion").add(new DoubleTag("", 0)).add(new DoubleTag("", 0)).add(new DoubleTag("", 0))).putList(new ListTag<>("Rotation").add(new FloatTag("", 0)).add(new FloatTag("", 0))));
        minecart.spawnToAll();
        count -= 1;
        return true;
    }
    return false;
}
Also used : BlockRail(cn.nukkit.block.BlockRail) Rail(cn.nukkit.utils.Rail) FloatTag(cn.nukkit.nbt.tag.FloatTag) DoubleTag(cn.nukkit.nbt.tag.DoubleTag) EntityMinecartHopper(cn.nukkit.entity.item.EntityMinecartHopper) ListTag(cn.nukkit.nbt.tag.ListTag) BlockRail(cn.nukkit.block.BlockRail) 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