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

Java BinaryStream类代码示例

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

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



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

示例1: writeShapedRecipe

import cn.nukkit.utils.BinaryStream; //导入依赖的package包/类
private static int writeShapedRecipe(ShapedRecipe recipe, BinaryStream stream) {
    stream.putVarInt(recipe.getWidth());
    stream.putVarInt(recipe.getHeight());

    for (int z = 0; z < recipe.getHeight(); ++z) {
        for (int x = 0; x < recipe.getWidth(); ++x) {
            stream.putSlot(recipe.getIngredient(x, z));
        }
    }

    stream.putUnsignedVarInt(1);
    stream.putSlot(recipe.getResult());

    stream.putUUID(recipe.getId());

    return CraftingDataPacket.ENTRY_SHAPED;
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:18,代码来源:CraftingDataPacket.java


示例2: encode

import cn.nukkit.utils.BinaryStream; //导入依赖的package包/类
@Override
public void encode() {
    this.reset();
    this.putUnsignedVarInt(entries.size());

    BinaryStream writer = new BinaryStream();

    for (Object entry : entries) {
        int entryType = writeEntry(entry, writer);
        if (entryType >= 0) {
            this.putVarInt(entryType);
            this.put(writer.getBuffer());
        } else {
            this.putVarInt(-1);
        }

        writer.reset();
    }

    this.putBoolean(cleanRecipes);
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:22,代码来源:CraftingDataPacket.java


示例3: toFastBinary

import cn.nukkit.utils.BinaryStream; //导入依赖的package包/类
@Override
public byte[] toFastBinary() {
    BinaryStream stream = new BinaryStream(new byte[65536]);
    stream.put(Binary.writeInt(this.x));
    stream.put(Binary.writeInt(this.z));
    stream.put(this.getBlockIdArray());
    stream.put(this.getBlockDataArray());
    stream.put(this.getBlockSkyLightArray());
    stream.put(this.getBlockLightArray());
    for (int height : this.getHeightMapArray()) {
        stream.putByte((byte) height);
    }
    for (int color : this.getBiomeColorArray()) {
        stream.put(Binary.writeInt(color));
    }
    stream.putByte((byte) ((this.isLightPopulated() ? 1 << 2 : 0) + (this.isPopulated() ? 1 << 2 : 0) + (this.isGenerated() ? 1 : 0)));
    return stream.getBuffer();
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:19,代码来源:Chunk.java


示例4: writeShapedRecipe

import cn.nukkit.utils.BinaryStream; //导入依赖的package包/类
private static int writeShapedRecipe(ShapedRecipe recipe, BinaryStream stream) {
    stream.putInt(recipe.getWidth());
    stream.putInt(recipe.getHeight());

    for (int z = 0; z < recipe.getHeight(); ++z) {
        for (int x = 0; x < recipe.getWidth(); ++x) {
            stream.putSlot(recipe.getIngredient(x, z));
        }
    }

    stream.putInt(1);
    stream.putSlot(recipe.getResult());

    stream.putUUID(recipe.getId());

    return CraftingDataPacket.ENTRY_SHAPED;
}
 
开发者ID:Creeperface01,项目名称:NukkitGT,代码行数:18,代码来源:CraftingDataPacket.java


示例5: encode

import cn.nukkit.utils.BinaryStream; //导入依赖的package包/类
@Override
public void encode() {
    reset();
    putInt(entries.size());

    BinaryStream writer = new BinaryStream();

    for (Object entry : entries) {
        int entryType = writeEntry(entry, writer);
        if (entryType >= 0) {
            putInt(entryType);
            putInt(writer.getCount());
            put(writer.getBuffer());
        } else {
            putInt(-1);
            putInt(0);
        }

        writer.reset();
    }

    putByte((byte) (cleanRecipes ? 1 : 0));
}
 
开发者ID:Creeperface01,项目名称:NukkitGT,代码行数:24,代码来源:CraftingDataPacket.java


示例6: toFastBinary

import cn.nukkit.utils.BinaryStream; //导入依赖的package包/类
@Override
public byte[] toFastBinary() {
    BinaryStream stream = new BinaryStream(new byte[65536]);
    stream.put(Binary.writeInt(this.x));
    stream.put(Binary.writeInt(this.z));
    stream.put(this.getBlockIdArray());
    stream.put(this.getBlockDataArray());
    stream.put(this.getBlockSkyLightArray());
    stream.put(this.getBlockLightArray());
    for (int height : this.getHeightMapArray()) {
        stream.putByte((byte) (height & 0xff));
    }
    for (int color : this.getBiomeColorArray()) {
        stream.put(Binary.writeInt(color));
    }
    stream.putByte((byte) ((this.isLightPopulated() ? 1 << 2 : 0) + (this.isPopulated() ? 1 << 2 : 0) + (this.isGenerated() ? 1 : 0)));
    return stream.getBuffer();
}
 
开发者ID:Creeperface01,项目名称:NukkitGT,代码行数:19,代码来源:Chunk.java


示例7: getEmptyChunkPayload

import cn.nukkit.utils.BinaryStream; //导入依赖的package包/类
public static byte[] getEmptyChunkPayload() {
    BaseFullChunk chunk = new Chunk(McRegion.class);

    byte[] tiles = new byte[0];

    BinaryStream extraData = new BinaryStream();

    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 & 0xff));
    }
    for (int color : chunk.getBiomeColorArray()) {
        stream.put(Binary.writeInt(color));
    }
    stream.put(extraData.getBuffer());
    stream.put(tiles);

    return stream.getBuffer();
}
 
开发者ID:PrismarineMC,项目名称:MagmaBlock,代码行数:24,代码来源:LevelUtil.java


示例8: writeEntry

import cn.nukkit.utils.BinaryStream; //导入依赖的package包/类
private static int writeEntry(Object entry, BinaryStream stream) {
    if (entry instanceof ShapelessRecipe) {
        return writeShapelessRecipe(((ShapelessRecipe) entry), stream);
    } else if (entry instanceof ShapedRecipe) {
        return writeShapedRecipe(((ShapedRecipe) entry), stream);
    } else if (entry instanceof FurnaceRecipe) {
        return writeFurnaceRecipe(((FurnaceRecipe) entry), stream);
    } else if (entry instanceof EnchantmentList) {
        return writeEnchantList(((EnchantmentList) entry), stream);
    }
    return -1;
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:13,代码来源:CraftingDataPacket.java


示例9: writeShapelessRecipe

import cn.nukkit.utils.BinaryStream; //导入依赖的package包/类
private static int writeShapelessRecipe(ShapelessRecipe recipe, BinaryStream stream) {
    stream.putUnsignedVarInt(recipe.getIngredientCount());

    for (Item item : recipe.getIngredientList()) {
        stream.putSlot(item);
    }

    stream.putUnsignedVarInt(1);
    stream.putSlot(recipe.getResult());
    stream.putUUID(recipe.getId());

    return CraftingDataPacket.ENTRY_SHAPELESS;
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:14,代码来源:CraftingDataPacket.java


示例10: writeFurnaceRecipe

import cn.nukkit.utils.BinaryStream; //导入依赖的package包/类
private static int writeFurnaceRecipe(FurnaceRecipe recipe, BinaryStream stream) {
    if (recipe.getInput().hasMeta()) { //Data recipe
        stream.putVarInt(recipe.getInput().getId());
        stream.putVarInt(recipe.getInput().getDamage());
        stream.putSlot(recipe.getResult());

        return CraftingDataPacket.ENTRY_FURNACE_DATA;
    } else {
        stream.putVarInt(recipe.getInput().getId());
        stream.putSlot(recipe.getResult());

        return CraftingDataPacket.ENTRY_FURNACE;
    }
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:15,代码来源:CraftingDataPacket.java


示例11: writeEnchantList

import cn.nukkit.utils.BinaryStream; //导入依赖的package包/类
private static int writeEnchantList(EnchantmentList list, BinaryStream stream) {
    stream.putByte((byte) list.getSize());
    for (int i = 0; i < list.getSize(); ++i) {
        EnchantmentEntry entry = list.getSlot(i);
        stream.putUnsignedVarInt(entry.getCost());
        stream.putUnsignedVarInt(entry.getEnchantments().length);
        for (Enchantment enchantment : entry.getEnchantments()) {
            stream.putUnsignedVarInt(enchantment.getId());
            stream.putUnsignedVarInt(enchantment.getLevel());
        }
        stream.putString(entry.getRandomName());
    }
    return CraftingDataPacket.ENTRY_ENCHANT_LIST;
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:15,代码来源:CraftingDataPacket.java


示例12: encode

import cn.nukkit.utils.BinaryStream; //导入依赖的package包/类
@Override
public void encode() {
    this.reset();
    BinaryStream commandsStream = new BinaryStream();
    this.commands.forEach((name, versions) -> {
        if (name.equals("help")) return;
        ArrayList<String> aliases = new ArrayList<>();
        aliases.addAll(Arrays.asList(versions.versions.get(0).aliases));
        aliases.add(name);
        for (String alias : aliases) {
            commandsStream.putString(alias);
            commandsStream.putString(versions.versions.get(0).description);
            commandsStream.putByte((byte) 0);
            commandsStream.putByte((byte) 0);
            commandsStream.putLInt(-1);
            commandsStream.putUnsignedVarInt(versions.versions.get(0).overloads.size());
            for (CommandOverload overload : versions.versions.get(0).overloads.values()) {
                commandsStream.putUnsignedVarInt(overload.input.parameters.length);
                for (CommandParameter parameter : overload.input.parameters) {
                    commandsStream.putString(parameter.name);
                    commandsStream.putLInt(ARG_FLAG_VALID | getFlag(parameter.type));
                    commandsStream.putBoolean(parameter.optional);
                }
            }
        }
        aliasCommands += (aliases.size() - 1);
    });

    this.putUnsignedVarInt(0);
    this.putUnsignedVarInt(0);
    this.putUnsignedVarInt(0);
    this.putUnsignedVarInt(this.commands.size() + aliasCommands);
    this.put(commandsStream.getBuffer());
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:35,代码来源:AvailableCommandsPacket.java


示例13: handleSplit

import cn.nukkit.utils.BinaryStream; //导入依赖的package包/类
private void handleSplit(EncapsulatedPacket packet) throws Exception {
    if (packet.splitCount >= MAX_SPLIT_SIZE || packet.splitIndex >= MAX_SPLIT_SIZE || packet.splitIndex < 0) {
        return;
    }

    if (!this.splitPackets.containsKey(packet.splitID)) {
        if (this.splitPackets.size() >= MAX_SPLIT_COUNT) {
            return;
        }
        this.splitPackets.put(packet.splitID, new HashMap<Integer, EncapsulatedPacket>() {{
            put(packet.splitIndex, packet);
        }});
    } else {
        this.splitPackets.get(packet.splitID).put(packet.splitIndex, packet);
    }

    if (this.splitPackets.get(packet.splitID).size() == packet.splitCount) {
        EncapsulatedPacket pk = new EncapsulatedPacket();
        BinaryStream stream = new BinaryStream();
        for (int i = 0; i < packet.splitCount; i++) {
            stream.put(this.splitPackets.get(packet.splitID).get(i).buffer);
        }
        pk.buffer = stream.getBuffer();
        pk.length = pk.buffer.length;
        this.splitPackets.remove(packet.splitID);

        this.handleEncapsulatedPacketRoute(pk);
    }
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:30,代码来源:Session.java


示例14: testWrite

import cn.nukkit.utils.BinaryStream; //导入依赖的package包/类
@DisplayName("Writing")
@Test
void testWrite() throws IOException {
	BinaryStream bs = new BinaryStream();
	VarInt.writeUnsignedVarInt(bs, 237356812);
	VarInt.writeVarInt(bs, 0xea3eca71);
	VarInt.writeUnsignedVarLong(bs, 0x1234567812345678L);
	VarInt.writeVarLong(bs, 0xea3eca710becececL);
	assertAll(
			() -> assertEquals(237356812, VarInt.readUnsignedVarInt(bs)),
			() -> assertEquals(0xea3eca71, VarInt.readVarInt(bs)),
			() -> assertEquals(0x1234567812345678L, VarInt.readUnsignedVarLong(bs)),
			() -> assertEquals(0xea3eca710becececL, VarInt.readVarLong(bs))
	);
	ByteArrayOutputStream os = new ByteArrayOutputStream();
	VarInt.writeUnsignedVarInt(os, 237356812);
	VarInt.writeVarInt(os, 0xea3eca71);
	VarInt.writeUnsignedVarLong(os, 0x1234567812345678L);
	VarInt.writeVarLong(os, 0xea3eca710becececL);
	ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
	assertAll(
			() -> assertEquals(237356812, VarInt.readUnsignedVarInt(is)),
			() -> assertEquals(0xea3eca71, VarInt.readVarInt(is)),
			() -> assertEquals(0x1234567812345678L, VarInt.readUnsignedVarLong(is)),
			() -> assertEquals(0xea3eca710becececL, VarInt.readVarLong(is))
	);
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:28,代码来源:VarIntTest.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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