• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java NBTIO类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: saveNBT

import cn.nukkit.nbt.NBTIO; //导入依赖的package包/类
@Override
public void saveNBT() {
    super.saveNBT();
    if (this.item != null) { // Yes, a item can be null... I don't know what causes this, but it can happen.
        this.namedTag.putCompound("Item", NBTIO.putItemHelper(this.item, -1));
        this.namedTag.putShort("Health", (int) this.getHealth());
        this.namedTag.putShort("Age", this.age);
        this.namedTag.putShort("PickupDelay", this.pickupDelay);
        if (this.owner != null) {
            this.namedTag.putString("Owner", this.owner);
        }

        if (this.thrower != null) {
            this.namedTag.putString("Thrower", this.thrower);
        }
    }
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:18,代码来源:EntityItem.java


示例2: BaseLevelProvider

import cn.nukkit.nbt.NBTIO; //导入依赖的package包/类
public BaseLevelProvider(Level level, String path) throws IOException {
    this.level = level;
    this.path = path;
    File file_path = new File(this.path);
    if (!file_path.exists()) {
        file_path.mkdirs();
    }
    CompoundTag levelData = NBTIO.readCompressed(new FileInputStream(new File(this.getPath() + "level.dat")), ByteOrder.BIG_ENDIAN);
    if (levelData.get("Data") instanceof CompoundTag) {
        this.levelData = levelData.getCompound("Data");
    } else {
        throw new LevelException("Invalid level.dat");
    }

    if (!this.levelData.contains("generatorName")) {
        this.levelData.putString("generatorName", Generator.getGenerator("DEFAULT").getSimpleName().toLowerCase());
    }

    if (!this.levelData.contains("generatorOptions")) {
        this.levelData.putString("generatorOptions", "");
    }

}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:24,代码来源:BaseLevelProvider.java


示例3: BlockEntityChest

import cn.nukkit.nbt.NBTIO; //导入依赖的package包/类
public BlockEntityChest(FullChunk chunk, CompoundTag nbt) {
    super(chunk, nbt);
    this.inventory = new ChestInventory(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));
    } */
    
    ListTag<CompoundTag> list = (ListTag<CompoundTag>) this.namedTag.getList("Items");
    for (CompoundTag compound : list.getAll()) {
        Item item = NBTIO.getItemHelper(compound);
        this.inventory.slots.put(compound.getByte("Slot"), item);
    }
}
 
开发者ID:FrontierDevs,项目名称:Jenisys3,代码行数:19,代码来源:BlockEntityChest.java


示例4: ChunkRequestTask

import cn.nukkit.nbt.NBTIO; //导入依赖的package包/类
public ChunkRequestTask(Level level, Chunk chunk) {
    this.levelId = level.getId();
    this.chunk = chunk.toFastBinary();
    this.chunkX = chunk.getX();
    this.chunkZ = chunk.getZ();

    byte[] buffer = new byte[0];

    for (BlockEntity blockEntity : chunk.getBlockEntities().values()) {
        if (blockEntity instanceof BlockEntitySpawnable) {
            try {
                buffer = Binary.appendBytes(buffer, NBTIO.write(((BlockEntitySpawnable) blockEntity).getSpawnCompound(), ByteOrder.BIG_ENDIAN, true));
            } catch (IOException e) {
                throw new RuntimeException(e);
            }

        }
    }

    this.blockEntities = buffer;
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:22,代码来源:ChunkRequestTask.java


示例5: setItem

import cn.nukkit.nbt.NBTIO; //导入依赖的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:Rsplwe,项目名称:Nukkit-Java9,代码行数:17,代码来源:BlockEntityHopper.java


示例6: spawnTo

import cn.nukkit.nbt.NBTIO; //导入依赖的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:Rsplwe,项目名称:Nukkit-Java9,代码行数:18,代码来源:BlockEntitySpawnable.java


示例7: getSpawnCompound

import cn.nukkit.nbt.NBTIO; //导入依赖的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:Rsplwe,项目名称:Nukkit-Java9,代码行数:19,代码来源:BlockEntityItemFrame.java


示例8: BlockEntityChest

import cn.nukkit.nbt.NBTIO; //导入依赖的package包/类
public BlockEntityChest(FullChunk chunk, CompoundTag nbt) {
    super(chunk, nbt);
    this.inventory = new ChestInventory(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));
    } */

    ListTag<CompoundTag> list = (ListTag<CompoundTag>) this.namedTag.getList("Items");
    for (CompoundTag compound : list.getAll()) {
        Item item = NBTIO.getItemHelper(compound);
        this.inventory.slots.put(compound.getByte("Slot"), item);
    }
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:19,代码来源:BlockEntityChest.java


示例9: setItem

import cn.nukkit.nbt.NBTIO; //导入依赖的package包/类
@Override
public void setItem(int index, Item item) {
    int i = this.getSlotIndex(index);

    CompoundTag d = NBTIO.putItemHelper(item, index);

    // If item is air or count less than 0, remove the item from the "Items" list
    if (item.getId() == Item.AIR || item.getCount() <= 0) {
        if (i >= 0) {
            this.namedTag.getList("Items").remove(i);
        }
    } else if (i < 0) {
        // If it is less than i, then it is a new item, so we are going to add it at the end of the list
        (this.namedTag.getList("Items", CompoundTag.class)).add(d);
    } else {
        // If it is more than i, then it is an update on a inventorySlot, so we are going to overwrite the item in the list
        (this.namedTag.getList("Items", CompoundTag.class)).add(i, d);
    }
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:20,代码来源:BlockEntityChest.java


示例10: setItem

import cn.nukkit.nbt.NBTIO; //导入依赖的package包/类
@Override
public void setItem(int index, Item item) {
    int i = this.getSlotIndex(index);

    CompoundTag d = NBTIO.putItemHelper(item, index);

    // If item is air or count less than 0, remove the item from the "Items" list
    if (item.getId() == Item.AIR || item.getCount() <= 0) {
        if (i >= 0) {
            this.namedTag.getList("Items").remove(i);
        }
    } else if (i < 0) {
        // If it is less than i, then it is a new item, so we are going to add it at the end of the list
        (this.namedTag.getList("Items", CompoundTag.class)).add(d);
    } else {
        // If it is more than i, then it is an update on a slot, so we are going to overwrite the item in the list
        (this.namedTag.getList("Items", CompoundTag.class)).add(i, d);
    }
}
 
开发者ID:CoreXDevelopment,项目名称:CoreX,代码行数:20,代码来源:BlockEntityShulkerBox.java


示例11: EntityArmorStand

import cn.nukkit.nbt.NBTIO; //导入依赖的package包/类
public EntityArmorStand(FullChunk chunk, CompoundTag nbt) {
	super(chunk, nbt);

	if (!nbt.contains("HandItems")) {
		nbt.putCompound("HandItems", NBTIO.putItemHelper(Item.get(0)));
	}
	if (!nbt.contains("ArmorItems")) {
		ListTag<CompoundTag> tag = new ListTag<CompoundTag>("ArmorItems")
				.add(NBTIO.putItemHelper(Item.get(0)))
				.add(NBTIO.putItemHelper(Item.get(0)))
				.add(NBTIO.putItemHelper(Item.get(0)))
				.add(NBTIO.putItemHelper(Item.get(0)));
		nbt.putList(tag);
	}

	this.setHealth(2);
	this.setMaxHealth(2);
}
 
开发者ID:JupiterDevelopmentTeam,项目名称:Jupiter,代码行数:19,代码来源:EntityArmorStand.java


示例12: setItem

import cn.nukkit.nbt.NBTIO; //导入依赖的package包/类
@Override
public void setItem(int index, Item item) {
    int i = this.getSlotIndex(index);
    
    CompoundTag d = NBTIO.putItemHelper(item, index);

    // If item is air or count less than 0, remove the item from the "Items" list
    if (item.getId() == Item.AIR || item.getCount() <= 0) {
        if (i >= 0) {
            this.namedTag.getList("Items").remove(i);
        }
    } else if (i < 0) {
        // If it is less than i, then it is a new item, so we are going to add it at the end of the list
        (this.namedTag.getList("Items", CompoundTag.class)).add(d);
    } else {
        // If it is more than i, then it is an update on a slot, so we are going to overwrite the item in the list
        (this.namedTag.getList("Items", CompoundTag.class)).add(i, d);
    }
}
 
开发者ID:CoreXDevelopment,项目名称:CoreX,代码行数:20,代码来源:BlockEntityChest.java


示例13: addTradeItems

import cn.nukkit.nbt.NBTIO; //导入依赖的package包/类
public void addTradeItems(byte rewardExp, int maxUses, int uses, Item buyA, Item buyB, Item sell) {
    CompoundTag tag;
    if (this.namedTag.contains("Offers")) {
        tag = this.namedTag.getCompound("Offers");
    } else {
    	tag = new CompoundTag().putList(new ListTag<CompoundTag>("Recipes"));
    }
    CompoundTag nbt = new CompoundTag()
            .putByte("rewardExp", rewardExp)
            .putInt("maxUses", maxUses)
            .putInt("uses", uses)
            .putCompound("buyA", NBTIO.putItemHelper(buyA))
            .putCompound("buyB", NBTIO.putItemHelper(buyB))
            .putCompound("sell", NBTIO.putItemHelper(sell));
    tag.getList("Recipes", CompoundTag.class).add(nbt);
    this.namedTag.putCompound("Offers", tag);
}
 
开发者ID:JupiterDevelopmentTeam,项目名称:Jupiter,代码行数:18,代码来源:EntityVillager.java


示例14: saveOfflinePlayerData

import cn.nukkit.nbt.NBTIO; //导入依赖的package包/类
public void saveOfflinePlayerData(String name, CompoundTag tag, boolean async) {
    if (this.shouldSavePlayerData()) {
        try {
            if (async) {
                this.getScheduler().scheduleAsyncTask(new FileWriteTask(FastAppender.get(this.getDataPath() + "players/", name.toLowerCase(), ".dat"), NBTIO.writeGZIPCompressed(tag, ByteOrder.BIG_ENDIAN)));
            } else {
                Utils.writeFile(FastAppender.get(this.getDataPath(), "players/", name.toLowerCase(), ".dat"), new ByteArrayInputStream(NBTIO.writeGZIPCompressed(tag, ByteOrder.BIG_ENDIAN)));
            }
        } catch (Exception e) {
            this.logger.critical(this.getLanguage().translateString("nukkit.data.saveError", new String[]{name, e.getMessage()}));
            if (Nukkit.DEBUG > 1) {
                this.logger.logException(e);
            }
        }
    }
}
 
开发者ID:JupiterDevelopmentTeam,项目名称:Jupiter,代码行数:17,代码来源:Server.java


示例15: saveOfflinePlayerData

import cn.nukkit.nbt.NBTIO; //导入依赖的package包/类
public void saveOfflinePlayerData(String name, CompoundTag tag, boolean async) {
    if (this.shouldSavePlayerData()) {
        try {
            if (async) {
                this.getScheduler().scheduleAsyncTask(new FileWriteTask(this.getDataPath() + "players/" + name.toLowerCase() + ".dat", NBTIO.writeGZIPCompressed(tag, ByteOrder.BIG_ENDIAN)));
            } else {
                Utils.writeFile(this.getDataPath() + "players/" + name.toLowerCase() + ".dat", new ByteArrayInputStream(NBTIO.writeGZIPCompressed(tag, ByteOrder.BIG_ENDIAN)));
            }
        } catch (Exception e) {
            this.logger.critical(this.getLanguage().translateString("nukkit.data.saveError", new String[]{name, e.getMessage()}));
            if (Nukkit.DEBUG > 1) {
                this.logger.logException(e);
            }
        }
    }
}
 
开发者ID:CoreXDevelopment,项目名称:CoreX,代码行数:17,代码来源:Server.java


示例16: initEntity

import cn.nukkit.nbt.NBTIO; //导入依赖的package包/类
@Override
protected void initEntity() {
    super.initEntity();

    this.setMaxHealth(5);
    this.setHealth(this.namedTag.getShort("Health"));

    if (this.namedTag.contains("Age")) {
        this.age = this.namedTag.getShort("Age");
    }

    if (this.namedTag.contains("PickupDelay")) {
        this.pickupDelay = this.namedTag.getShort("PickupDelay");
    }

    if (this.namedTag.contains("Owner")) {
        this.owner = this.namedTag.getString("Owner");
    }

    if (this.namedTag.contains("Thrower")) {
        this.thrower = this.namedTag.getString("Thrower");
    }

    if (!this.namedTag.contains("Item")) {
        this.close();
        return;
    }

    this.item = NBTIO.getItemHelper(this.namedTag.getCompound("Item"));
    this.setDataFlag(DATA_FLAGS, DATA_FLAG_IMMOBILE, true);

    this.server.getPluginManager().callEvent(new ItemSpawnEvent(this));
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:34,代码来源:EntityItem.java


示例17: parseCompoundTag

import cn.nukkit.nbt.NBTIO; //导入依赖的package包/类
public static CompoundTag parseCompoundTag(byte[] tag) {
    try {
        return NBTIO.read(tag, ByteOrder.LITTLE_ENDIAN);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:8,代码来源:Item.java


示例18: writeCompoundTag

import cn.nukkit.nbt.NBTIO; //导入依赖的package包/类
public byte[] writeCompoundTag(CompoundTag tag) {
    try {
        tag.setName("");
        return NBTIO.write(tag, ByteOrder.LITTLE_ENDIAN);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:9,代码来源:Item.java


示例19: saveLevelData

import cn.nukkit.nbt.NBTIO; //导入依赖的package包/类
@Override
public void saveLevelData() {
    try {
        byte[] data = NBTIO.write(levelData, ByteOrder.LITTLE_ENDIAN);
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        outputStream.write(Binary.writeLInt(3));
        outputStream.write(Binary.writeLInt(data.length));
        outputStream.write(data);

        Utils.writeFile(path + "level.dat", new ByteArrayInputStream(outputStream.toByteArray()));
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:15,代码来源:LevelDB.java


示例20: getItem

import cn.nukkit.nbt.NBTIO; //导入依赖的package包/类
@Override
public Item getItem(int index) {
    int i = this.getSlotIndex(index);
    if (i < 0) {
        return new ItemBlock(new BlockAir(), 0, 0);
    } else {
        CompoundTag data = (CompoundTag) this.namedTag.getList("Items").get(i);
        return NBTIO.getItemHelper(data);
    }
}
 
开发者ID:CoreXDevelopment,项目名称:CoreX,代码行数:11,代码来源:BlockEntityChest.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java LearnerHandler类代码示例发布时间:2022-05-21
下一篇:
Java Descriptor类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap