当前位置: 首页>>代码示例>>Java>>正文


Java CompoundTag类代码示例

本文整理汇总了Java中cn.nukkit.nbt.tag.CompoundTag的典型用法代码示例。如果您正苦于以下问题:Java CompoundTag类的具体用法?Java CompoundTag怎么用?Java CompoundTag使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CompoundTag类属于cn.nukkit.nbt.tag包,在下文中一共展示了CompoundTag类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getSpawnCompound

import cn.nukkit.nbt.tag.CompoundTag; //导入依赖的package包/类
@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());
}
 
开发者ID:FrontierDevs,项目名称:Jenisys3,代码行数:19,代码来源:BlockEntityItemFrame.java

示例2: clearCustomName

import cn.nukkit.nbt.tag.CompoundTag; //导入依赖的package包/类
public Item clearCustomName() {
    if (!this.hasCompoundTag()) {
        return this;
    }

    CompoundTag tag = this.getNamedTag();

    if (tag.contains("display") && tag.get("display") instanceof CompoundTag) {
        tag.getCompound("display").remove("Name");
        if (tag.getCompound("display").isEmpty()) {
            tag.remove("display");
        }

        this.setNamedTag(tag);
    }

    return this;
}
 
开发者ID:FrontierDevs,项目名称:Jenisys3,代码行数:19,代码来源:Item.java

示例3: place

import cn.nukkit.nbt.tag.CompoundTag; //导入依赖的package包/类
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
    this.getLevel().setBlock(block, this, true, true);
    CompoundTag nbt = new CompoundTag("")
            .putString("id", BlockEntity.MOB_SPAWNER)
            .putInt("x", (int) this.x)
            .putInt("y", (int) this.y)
            .putInt("z", (int) this.z)
            .putInt("EntityId", 0);

    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 BlockEntityMobSpawner(this.getLevel().getChunk((int) this.x >> 4, (int) this.z >> 4), nbt);
    return true;
}
 
开发者ID:JupiterDevelopmentTeam,项目名称:Jupiter,代码行数:21,代码来源:BlockMobSpawner.java

示例4: getSpawnCompound

import cn.nukkit.nbt.tag.CompoundTag; //导入依赖的package包/类
@Override
   public CompoundTag getSpawnCompound() {
       CompoundTag nbt = new CompoundTag()
               .putString("id", BlockEntity.COMMAND_BLOCK)
               .putInt("x", this.getFloorX())
               .putInt("y", this.getFloorY())
               .putInt("z", this.getFloorZ())
               .putString("CustomName", this.namedTag.getString("CustomName"))
               .putInt("commandBlockMode", this.namedTag.getInt("commandBlockMode"))
               .putString("Command", this.namedTag.getString("Command"))
               .putString("LastOutput", this.namedTag.getString("LastOutput"))
               .putBoolean("powered", this.namedTag.getBoolean("powered"))
               .putBoolean("auto", this.namedTag.getBoolean("auto"))
               .putBoolean("conditionalMode", this.namedTag.getBoolean("conditionalMode"));
	return nbt;
}
 
开发者ID:JupiterDevelopmentTeam,项目名称:Jupiter,代码行数:17,代码来源:BlockEntityCommandBlock.java

示例5: setItem

import cn.nukkit.nbt.tag.CompoundTag; //导入依赖的package包/类
@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);
    }
}
 
开发者ID:FrontierDevs,项目名称:Jenisys3,代码行数:17,代码来源:BlockEntityFurnace.java

示例6: BlockEntityFlowerPot

import cn.nukkit.nbt.tag.CompoundTag; //导入依赖的package包/类
public BlockEntityFlowerPot(FullChunk chunk, CompoundTag nbt) {
    super(chunk, nbt);
    if (!nbt.contains("item")) {
        nbt.putShort("item", 0);
    }

    if (!nbt.contains("data")) {
        if (nbt.contains("mData")) {
            nbt.putInt("data", nbt.getInt("mData"));
            nbt.remove("mData");
        } else {
            nbt.putInt("data", 0);
        }
    }

    this.namedTag = nbt;
}
 
开发者ID:CoreXDevelopment,项目名称:CoreX,代码行数:18,代码来源:BlockEntityFlowerPot.java

示例7: getEnchantment

import cn.nukkit.nbt.tag.CompoundTag; //导入依赖的package包/类
public Enchantment getEnchantment(short id) {
    if (!this.hasEnchantments()) {
        return null;
    }

    for (CompoundTag entry : this.getNamedTag().getList("ench", CompoundTag.class).getAll()) {
        if (entry.getShort("id") == id) {
            Enchantment e = Enchantment.getEnchantment(entry.getShort("id"));
            if (e != null) {
                e.setLevel(entry.getShort("lvl"));
                return e;
            }
        }
    }

    return null;
}
 
开发者ID:FrontierDevs,项目名称:Jenisys3,代码行数:18,代码来源:Item.java

示例8: BlockEntitySign

import cn.nukkit.nbt.tag.CompoundTag; //导入依赖的package包/类
public BlockEntitySign(FullChunk chunk, CompoundTag nbt) {
    super(chunk, nbt);
    if (!nbt.contains("Text1")) {
        nbt.putString("Text1", "");
    }
    if (!nbt.contains("Text2")) {
        nbt.putString("Text2", "");
    }
    if (!nbt.contains("Text3")) {
        nbt.putString("Text3", "");
    }
    if (!nbt.contains("Text4")) {
        nbt.putString("Text4", "");
    }
    this.namedTag = nbt;
}
 
开发者ID:JupiterDevelopmentTeam,项目名称:Jupiter,代码行数:17,代码来源:BlockEntitySign.java

示例9: spawnTo

import cn.nukkit.nbt.tag.CompoundTag; //导入依赖的package包/类
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);
}
 
开发者ID:FrontierDevs,项目名称:Jenisys3,代码行数:18,代码来源:BlockEntitySpawnable.java

示例10: place

import cn.nukkit.nbt.tag.CompoundTag; //导入依赖的package包/类
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
    if (super.place(item, block, target, face, fx, fy, fz, player)) {
        CompoundTag nbt = new CompoundTag()
                .putList(new ListTag<>("Items"))
                .putString("id", BlockEntity.COMPARATOR)
                .putInt("x", (int) this.x)
                .putInt("y", (int) this.y)
                .putInt("z", (int) this.z);
        new BlockEntityComparator(this.level.getChunk((int) this.x >> 4, (int) this.z >> 4), nbt);

        onUpdate(Level.BLOCK_UPDATE_REDSTONE);
        return true;
    }

    return false;
}
 
开发者ID:FrontierDevs,项目名称:Jenisys3,代码行数:18,代码来源:BlockRedstoneComparator.java

示例11: place

import cn.nukkit.nbt.tag.CompoundTag; //导入依赖的package包/类
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
    CompoundTag nbt = new CompoundTag("")
            .putString("id", BlockEntity.CHEST)
            .putInt("x", (int) this.x)
            .putInt("y", (int) this.y)
            .putInt("z", (int) this.z)
            .putShort("PotionId", 0xffff)
            .putByte("SplashPotion", 0);

    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 BlockEntityCauldron(this.level.getChunk((int) this.x >> 4, (int) this.z >> 4), nbt);
    this.getLevel().setBlock(block, this, true, true);
    return true;
}
 
开发者ID:CoreXDevelopment,项目名称:CoreX,代码行数:22,代码来源:BlockCauldron.java

示例12: getEnchantments

import cn.nukkit.nbt.tag.CompoundTag; //导入依赖的package包/类
public Enchantment[] getEnchantments() {
    if (!this.hasEnchantments()) {
        return new Enchantment[0];
    }

    List<Enchantment> enchantments = new ArrayList<>();

    ListTag<CompoundTag> ench = this.getNamedTag().getList("ench", CompoundTag.class);
    for (CompoundTag entry : ench.getAll()) {
        Enchantment e = Enchantment.getEnchantment(entry.getShort("id"));
        if (e != null) {
            e.setLevel(entry.getShort("lvl"));
            enchantments.add(e);
        }
    }

    return enchantments.stream().toArray(Enchantment[]::new);
}
 
开发者ID:JupiterDevelopmentTeam,项目名称:Jupiter,代码行数:19,代码来源:Item.java

示例13: place

import cn.nukkit.nbt.tag.CompoundTag; //导入依赖的package包/类
@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
    if (!target.isTransparent() && face.getIndex() > 1 && !block.isSolid()) {
        switch (face) {
            case NORTH:
                this.meta = 3;
                break;
            case SOUTH:
                this.meta = 2;
                break;
            case WEST:
                this.meta = 1;
                break;
            case EAST:
                this.meta = 0;
                break;
            default:
                return false;
        }
        this.getLevel().setBlock(block, this, true, true);
        CompoundTag nbt = new CompoundTag()
                .putString("id", BlockEntity.ITEM_FRAME)
                .putInt("x", (int) block.x)
                .putInt("y", (int) block.y)
                .putInt("z", (int) block.z)
                .putByte("ItemRotation", 0)
                .putFloat("ItemDropChance", 1.0f);
        if (item.hasCustomBlockData()) {
            for (Tag aTag : item.getCustomBlockData().getAllTags()) {
                nbt.put(aTag.getName(), aTag);
            }
        }
        new BlockEntityItemFrame(this.getLevel().getChunk((int) this.x >> 4, (int) this.z >> 4), nbt);
        this.getLevel().addSound(new ItemFramePlacedSound(this));
        return true;
    }
    return false;
}
 
开发者ID:FrontierDevs,项目名称:Jenisys3,代码行数:39,代码来源:BlockItemFrame.java

示例14: getSlotIndex

import cn.nukkit.nbt.tag.CompoundTag; //导入依赖的package包/类
protected int getSlotIndex(int index) {
    ListTag<CompoundTag> list = this.namedTag.getList("Items", CompoundTag.class);
    for (int i = 0; i < list.size(); i++) {
        if (list.get(i).getByte("Slot") == index) {
            return i;
        }
    }

    return -1;
}
 
开发者ID:JupiterDevelopmentTeam,项目名称:Jupiter,代码行数:11,代码来源:BlockEntityHopper.java

示例15: safeWrite

import cn.nukkit.nbt.tag.CompoundTag; //导入依赖的package包/类
public static void safeWrite(CompoundTag tag, File file) throws IOException {
    File tmpFile = new File(file.getAbsolutePath() + "_tmp");
    if (tmpFile.exists()) {
        tmpFile.delete();
    }
    write(tag, tmpFile);
    Files.move(tmpFile.toPath(), file.toPath(), StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.ATOMIC_MOVE);
}
 
开发者ID:FrontierDevs,项目名称:Jenisys3,代码行数:9,代码来源:NBTIO.java


注:本文中的cn.nukkit.nbt.tag.CompoundTag类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。