本文整理汇总了Java中cn.nukkit.nbt.NBTIO类的典型用法代码示例。如果您正苦于以下问题:Java NBTIO类的具体用法?Java NBTIO怎么用?Java NBTIO使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
NBTIO类属于cn.nukkit.nbt包,在下文中一共展示了NBTIO类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
}
}
示例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", "");
}
}
示例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);
}
}
示例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;
}
示例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);
}
}
示例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);
}
示例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());
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
示例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);
}
}
示例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);
}
示例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);
}
}
}
}
示例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);
}
}
}
}