當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。