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


Java ByteBufUtils.readVarShort方法代码示例

本文整理汇总了Java中cpw.mods.fml.common.network.ByteBufUtils.readVarShort方法的典型用法代码示例。如果您正苦于以下问题:Java ByteBufUtils.readVarShort方法的具体用法?Java ByteBufUtils.readVarShort怎么用?Java ByteBufUtils.readVarShort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cpw.mods.fml.common.network.ByteBufUtils的用法示例。


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

示例1: fromBytes

import cpw.mods.fml.common.network.ByteBufUtils; //导入方法依赖的package包/类
@Override
public void fromBytes(ByteBuf buf)
{
	slotCount = (short) ByteBufUtils.readVarShort(buf);
	itemStacks = new ItemStack[slotCount];
	stackSizes = new int[slotCount];
	for (int i = 0; i < slotCount; i++) {
		itemStacks[i] = ByteBufUtils.readItemStack(buf);
		stackSizes[i] = ByteBufUtils.readVarInt(buf, 5);
		if (itemStacks[i] != null)
			itemStacks[i].stackSize = stackSizes[i];
	}
}
 
开发者ID:WanionCane,项目名称:Avaritiaddons,代码行数:14,代码来源:InfinityChestSyncAllSlots.java

示例2: fromBytes

import cpw.mods.fml.common.network.ByteBufUtils; //导入方法依赖的package包/类
@Override
public void fromBytes(final ByteBuf buf)
{
	windowId = ByteBufUtils.readVarInt(buf, 4);
	slotNumber = ByteBufUtils.readVarShort(buf);
	if (slotNumber < 0 || slotNumber > 279)
		slotNumber = -999;
	mouseButton = ByteBufUtils.readVarInt(buf, 4);
	modifier = ByteBufUtils.readVarInt(buf, 4);
	itemStack = ByteBufUtils.readItemStack(buf);
	stackSize = ByteBufUtils.readVarInt(buf, 5);
	if (itemStack != null)
		itemStack.stackSize = stackSize;
	transactionID = (short) ByteBufUtils.readVarShort(buf);
}
 
开发者ID:WanionCane,项目名称:Avaritiaddons,代码行数:16,代码来源:InfinityChestClick.java

示例3: fromBytes

import cpw.mods.fml.common.network.ByteBufUtils; //导入方法依赖的package包/类
@Override
public void fromBytes(final ByteBuf buf)
{
	itemStack = ByteBufUtils.readItemStack(buf);
	slot = ByteBufUtils.readVarShort(buf);
	stackSize = ByteBufUtils.readVarInt(buf, 5);
}
 
开发者ID:WanionCane,项目名称:Avaritiaddons,代码行数:8,代码来源:InfinityChestSlotSync.java

示例4: fromBytes

import cpw.mods.fml.common.network.ByteBufUtils; //导入方法依赖的package包/类
@Override
public void fromBytes(final ByteBuf buf)
{
	windowID = ByteBufUtils.readVarInt(buf, 4);
	transactionID = (short) ByteBufUtils.readVarShort(buf);
	confirmed = ByteBufUtils.readVarShort(buf) == 1;
}
 
开发者ID:WanionCane,项目名称:Avaritiaddons,代码行数:8,代码来源:InfinityChestConfirmation.java

示例5: testVarShort

import cpw.mods.fml.common.network.ByteBufUtils; //导入方法依赖的package包/类
@Test
public void testVarShort()
{
    ByteBuf buf = Unpooled.buffer(3,3);
    ByteBufUtils.writeVarShort(buf, 32766);
    assertArrayEquals("Two byte short written", new byte[] { 127, -2, 0}, buf.array());
    assertEquals("Two byte short written", 2, buf.readableBytes());

    buf.clear();
    buf.writeZero(3);
    buf.clear();

    buf.writeShort(32766);
    assertArrayEquals("Two byte short written", new byte[] { 127, -2, 0}, buf.array());
    int val = ByteBufUtils.readVarShort(buf);

    assertEquals("Two byte short read correctly", 32766, val);

    buf.clear();
    buf.writeZero(3);
    buf.clear();

    ByteBufUtils.writeVarShort(buf, 32768);
    assertArrayEquals("Three byte short written", new byte[] { -128, 0, 1}, buf.array());
    assertEquals("Three byte short written", 3, buf.readableBytes());

    buf.clear();
    buf.writeZero(3);
    buf.clear();
    buf.writeShort(-32768);
    buf.writeByte(1);
    val = ByteBufUtils.readVarShort(buf);
    assertEquals("Three byte short read correctly", 32768, val);

    buf.clear();
    buf.writeZero(3);
    buf.clear();

    ByteBufUtils.writeVarShort(buf, 8388607);
    assertArrayEquals("Three byte short written", new byte[] { -1, -1, -1}, buf.array());
    assertEquals("Three byte short written", 3, buf.readableBytes());

    buf.clear();
    buf.writeZero(3);
    buf.clear();
    buf.writeShort(-1);
    buf.writeByte(-1);
    val = ByteBufUtils.readVarShort(buf);
    assertEquals("Three byte short read correctly", 8388607, val);
}
 
开发者ID:alexandrage,项目名称:CauldronGit,代码行数:51,代码来源:TestNetStuff.java


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