本文整理汇总了Java中cn.nukkit.nbt.NBTIO.write方法的典型用法代码示例。如果您正苦于以下问题:Java NBTIO.write方法的具体用法?Java NBTIO.write怎么用?Java NBTIO.write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cn.nukkit.nbt.NBTIO
的用法示例。
在下文中一共展示了NBTIO.write方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: onOpen
import cn.nukkit.nbt.NBTIO; //导入方法依赖的package包/类
@Override
public void onOpen(Player who) {
CompoundTag nbt = this.getHolder().getOffers();
if (nbt != null) {
super.onOpen(who);
UpdateTradePacket pk1 = new UpdateTradePacket();
pk1.windowId = (byte) who.getWindowId(this);
pk1.windowType = 15;
pk1.unknownVarInt1 = 0;
pk1.unknownVarInt2 = 0;
pk1.isWilling = false;
pk1.trader = this.getHolder().getId();
pk1.player = who.getId();
pk1.displayName = this.getHolder().getName();
try {
pk1.offers = NBTIO.write(nbt, ByteOrder.LITTLE_ENDIAN, true);
} catch (IOException e) {
e.printStackTrace();
}
who.dataPacket(pk1);
} else {
super.onClose(who);
}
}
示例3: 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);
}
}
示例4: 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);
}
}
示例5: writeCompoundTag
import cn.nukkit.nbt.NBTIO; //导入方法依赖的package包/类
private byte[] writeCompoundTag(CompoundTag tag) {
try {
return NBTIO.write(tag, ByteOrder.LITTLE_ENDIAN);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例6: generate
import cn.nukkit.nbt.NBTIO; //导入方法依赖的package包/类
public static void generate(String path, String name, long seed, Class<? extends Generator> generator, Map<String, String> options) throws IOException {
if (!new File(path + "/db").exists()) {
new File(path + "/db").mkdirs();
}
CompoundTag levelData = new CompoundTag("")
.putLong("currentTick", 0)
.putInt("DayCycleStopTime", -1)
.putInt("GameType", 0)
.putInt("Generator", Generator.getGeneratorType(generator))
.putBoolean("hasBeenLoadedInCreative", false)
.putLong("LastPlayed", System.currentTimeMillis() / 1000)
.putString("LevelName", name)
.putFloat("lightningLevel", 0)
.putInt("lightningTime", new Random().nextInt())
.putInt("limitedWorldOriginX", 128)
.putInt("limitedWorldOriginY", 70)
.putInt("limitedWorldOriginZ", 128)
.putInt("Platform", 0)
.putFloat("rainLevel", 0)
.putInt("rainTime", new Random().nextInt())
.putLong("RandomSeed", seed)
.putByte("spawnMobs", 0)
.putInt("SpawnX", 128)
.putInt("SpawnY", 70)
.putInt("SpawnZ", 128)
.putInt("storageVersion", 4)
.putLong("Time", 0)
.putLong("worldStartCount", ((long) Integer.MAX_VALUE) & 0xffffffffL);
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()));
DB db = Iq80DBFactory.factory.open(new File(path + "/db"), new Options().createIfMissing(true));
db.close();
}
示例7: requestChunkTask
import cn.nukkit.nbt.NBTIO; //导入方法依赖的package包/类
@Override
public AsyncTask requestChunkTask(int x, int z) {
FullChunk chunk = this.getChunk(x, z, false);
if (chunk == null) {
throw new ChunkException("Invalid Chunk sent");
}
byte[] tiles = new byte[0];
if (!chunk.getBlockEntities().isEmpty()) {
List<CompoundTag> tagList = new ArrayList<>();
for (BlockEntity blockEntity : chunk.getBlockEntities().values()) {
if (blockEntity instanceof BlockEntitySpawnable) {
tagList.add(((BlockEntitySpawnable) blockEntity).getSpawnCompound());
}
}
try {
tiles = NBTIO.write(tagList, ByteOrder.LITTLE_ENDIAN);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
Map<Integer, Integer> extra = chunk.getBlockExtraDataArray();
BinaryStream extraData;
if (!extra.isEmpty()) {
extraData = new BinaryStream();
extraData.putLInt(extra.size());
for (Integer key : extra.values()) {
extraData.putLInt(key);
extraData.putLShort(extra.get(key));
}
} else {
extraData = null;
}
BinaryStream stream = new BinaryStream();
stream.put(chunk.getBlockIdArray());
stream.put(chunk.getBlockDataArray());
stream.put(chunk.getBlockSkyLightArray());
stream.put(chunk.getBlockLightArray());
for (int height : chunk.getHeightMapArray()) {
stream.putByte((byte) height);
}
for (int color : chunk.getBiomeColorArray()) {
stream.put(Binary.writeInt(color));
}
if (extraData != null) {
stream.put(extraData.getBuffer());
} else {
stream.putLInt(0);
}
stream.put(tiles);
this.getLevel().chunkRequestCallback(x, z, stream.getBuffer());
return null;
}
示例8: toFastBinary
import cn.nukkit.nbt.NBTIO; //导入方法依赖的package包/类
@Override
public byte[] toFastBinary() {
CompoundTag nbt = this.getNBT().copy();
nbt.putInt("xPos", this.x);
nbt.putInt("zPos", this.z);
nbt.putIntArray("BiomeColors", this.getBiomeColorArray());
nbt.putIntArray("HeightMap", this.getHeightMapArray());
for (cn.nukkit.level.format.ChunkSection section : this.getSections()) {
if (section instanceof EmptyChunkSection) {
continue;
}
CompoundTag s = new CompoundTag(null);
s.putByte("Y", section.getY());
s.putByteArray("Blocks", section.getIdArray());
s.putByteArray("Data", section.getDataArray());
s.putByteArray("BlockLight", section.getLightArray());
s.putByteArray("SkyLight", section.getSkyLightArray());
nbt.getList("Sections", CompoundTag.class).add(s);
}
ArrayList<CompoundTag> entities = new ArrayList<>();
for (Entity entity : this.getEntities().values()) {
if (!(entity instanceof Player) && !entity.closed) {
entity.saveNBT();
entities.add(entity.namedTag);
}
}
ListTag<CompoundTag> entityListTag = new ListTag<>("Entities");
entityListTag.setAll(entities);
nbt.putList(entityListTag);
ArrayList<CompoundTag> tiles = new ArrayList<>();
for (BlockEntity blockEntity : this.getBlockEntities().values()) {
blockEntity.saveNBT();
tiles.add(blockEntity.namedTag);
}
ListTag<CompoundTag> tileListTag = new ListTag<>("TileEntities");
tileListTag.setAll(tiles);
nbt.putList(tileListTag);
BinaryStream extraData = new BinaryStream();
Map<Integer, Integer> extraDataArray = this.getBlockExtraDataArray();
extraData.putInt(extraDataArray.size());
for (Integer key : extraDataArray.keySet()) {
extraData.putInt(key);
extraData.putShort(extraDataArray.get(key));
}
nbt.putByteArray("ExtraData", extraData.getBuffer());
CompoundTag chunk = new CompoundTag("");
chunk.putCompound("Level", nbt);
try {
return NBTIO.write(chunk, ByteOrder.BIG_ENDIAN);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例9: requestChunkTask
import cn.nukkit.nbt.NBTIO; //导入方法依赖的package包/类
@Override
public byte[] requestChunkTask(int x, int z) {
FullChunk chunk = this.getChunk(x, z, false);
if (chunk == null) {
throw new ChunkException("Invalid Chunk sent");
}
byte[] tiles = new byte[0];
if (!chunk.getBlockEntities().isEmpty()) {
List<CompoundTag> tagList = new ArrayList<>();
for (BlockEntity blockEntity : chunk.getBlockEntities().values()) {
if (blockEntity instanceof BlockEntitySpawnable) {
tagList.add(((BlockEntitySpawnable) blockEntity).getSpawnCompound());
}
}
try {
tiles = NBTIO.write(tagList, ByteOrder.LITTLE_ENDIAN);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
Map<Integer, Integer> extra = chunk.getBlockExtraDataArray();
BinaryStream extraData;
if (!extra.isEmpty()) {
extraData = new BinaryStream();
extraData.putLInt(extra.size());
for (Integer key : extra.values()) {
extraData.putLInt(key);
extraData.putLShort(extra.get(key));
}
} else {
extraData = null;
}
BinaryStream stream = new BinaryStream();
stream.put(chunk.getBlockIdArray());
stream.put(chunk.getBlockDataArray());
stream.put(chunk.getBlockSkyLightArray());
stream.put(chunk.getBlockLightArray());
for (int height : chunk.getHeightMapArray()) {
stream.putByte((byte) height);
}
for (int color : chunk.getBiomeColorArray()) {
stream.put(Binary.writeInt(color));
}
if (extraData != null) {
stream.put(extraData.getBuffer());
} else {
stream.putLInt(0);
}
stream.put(tiles);
return stream.getBuffer();
}