Java 类cpw.mods.fml.common.network.ByteBufUtils 实例源码

项目:TRHS_Club_Mod_2016    文件:ForgeMessage.java   
@Override
void fromBytes(ByteBuf bytes)
{
    int listSize = bytes.readInt();
    for (int i = 0; i < listSize; i++) {
        String fluidName = ByteBufUtils.readUTF8String(bytes);
        int fluidId = bytes.readInt();
        fluidIds.put(FluidRegistry.getFluid(fluidName), fluidId);
    }
    // do we have a defaults list?

    if (bytes.isReadable())
    {
        for (int i = 0; i < listSize; i++)
        {
            defaultFluids.add(ByteBufUtils.readUTF8String(bytes));
        }
    }
    else
    {
        FMLLog.getLogger().log(Level.INFO, "Legacy server message contains no default fluid list - there may be problems with fluids");
        defaultFluids.clear();
    }
}
项目:VivecraftForgeExtensions    文件:PacketVRPlayerList.java   
@Override
public void encodePacket(ChannelHandlerContext context, ByteBuf buffer) {
    ByteBufUtils.writeVarInt(buffer, entityIds.size(), 5);
    for (Map.Entry<Integer, VRPlayerData> entry : entityIds.entrySet()) {
        VRPlayerData data = entry.getValue();
        ByteBufUtils.writeVarInt(buffer, entry.getKey(), 5);
        buffer.writeBoolean(data.newAPI);
        buffer.writeBoolean(data.reverseHands);
        buffer.writeFloat(data.worldScale);
        buffer.writeBoolean(data.seated);
        buffer.writeByte(data.entityIds.size());
        for (int id : data.entityIds) {
            ByteBufUtils.writeVarInt(buffer, id, 5);
        }
    }
}
项目:VivecraftForgeExtensions    文件:PacketVRPlayerList.java   
@Override
public void decodePacket(ChannelHandlerContext context, ByteBuf buffer) {
    int size = ByteBufUtils.readVarInt(buffer, 5);
    entityIds = new HashMap<Integer, VRPlayerData>(size);
    for (int i = 0; i < size; i++) {
        VRPlayerData data = new VRPlayerData();
        entityIds.put(ByteBufUtils.readVarInt(buffer, 5), data);
        data.newAPI = buffer.readBoolean();
        data.reverseHands = buffer.readBoolean();
        data.worldScale = buffer.readFloat();
        data.seated = buffer.readBoolean();
        int size2 = buffer.readUnsignedByte();
        for (int j = 0; j < size2; j++) {
            data.entityIds.add(ByteBufUtils.readVarInt(buffer, 5));
        }
    }
}
项目:EnderCore    文件:PacketConfigSync.java   
@Override
public void toBytes(ByteBuf buf) {
  ByteArrayOutputStream obj = new ByteArrayOutputStream();

  try {
    GZIPOutputStream gzip = new GZIPOutputStream(obj);
    ObjectOutputStream objStream = new ObjectOutputStream(gzip);
    objStream.writeObject(configValues);
    objStream.close();
  } catch (IOException e) {
    Throwables.propagate(e);
  }

  buf.writeShort(obj.size());
  buf.writeBytes(obj.toByteArray());

  ByteBufUtils.writeUTF8String(buf, modid);
}
项目:EnderCore    文件:PacketConfigSync.java   
@SuppressWarnings("unchecked")
@Override
public void fromBytes(ByteBuf buf) {
  short len = buf.readShort();
  byte[] compressedBody = new byte[len];

  for (short i = 0; i < len; i++)
    compressedBody[i] = buf.readByte();

  try {
    ObjectInputStream obj = new ObjectInputStream(new GZIPInputStream(new ByteArrayInputStream(compressedBody)));
    configValues = (Map<String, Object>) obj.readObject();
    obj.close();
  } catch (Exception e) {
    Throwables.propagate(e);
  }

  modid = ByteBufUtils.readUTF8String(buf);
}
项目:TRHS_Club_Mod_2016    文件:FMLHandshakeMessage.java   
@Override
public void toBytes(ByteBuf buffer)
{
    super.toBytes(buffer);
    ByteBufUtils.writeVarInt(buffer, modTags.size(), 2);
    for (Map.Entry<String,String> modTag: modTags.entrySet())
    {
        ByteBufUtils.writeUTF8String(buffer, modTag.getKey());
        ByteBufUtils.writeUTF8String(buffer, modTag.getValue());
    }
}
项目:TRHS_Club_Mod_2016    文件:FMLHandshakeMessage.java   
@Override
public void fromBytes(ByteBuf buffer)
{
    super.fromBytes(buffer);
    int modCount = ByteBufUtils.readVarInt(buffer, 2);
    for (int i = 0; i < modCount; i++)
    {
        modTags.put(ByteBufUtils.readUTF8String(buffer), ByteBufUtils.readUTF8String(buffer));
    }
}
项目:TRHS_Club_Mod_2016    文件:FMLHandshakeMessage.java   
@Override
public void fromBytes(ByteBuf buffer)
{
    int length = ByteBufUtils.readVarInt(buffer, 3);
    modIds = Maps.newHashMap();
    blockSubstitutions = Sets.newHashSet();
    itemSubstitutions = Sets.newHashSet();

    for (int i = 0; i < length; i++)
    {
        modIds.put(ByteBufUtils.readUTF8String(buffer),ByteBufUtils.readVarInt(buffer, 3));
    }
    // we don't have any more data to read
    if (!buffer.isReadable())
    {
        return;
    }
    length = ByteBufUtils.readVarInt(buffer, 3);
    for (int i = 0; i < length; i++)
    {
        blockSubstitutions.add(ByteBufUtils.readUTF8String(buffer));
    }
    length = ByteBufUtils.readVarInt(buffer, 3);
    for (int i = 0; i < length; i++)
    {
        itemSubstitutions.add(ByteBufUtils.readUTF8String(buffer));
    }
}
项目:TRHS_Club_Mod_2016    文件:FMLRuntimeCodec.java   
@Override
protected void testMessageValidity(FMLProxyPacket msg)
{
    if (msg.payload().getByte(0) == 0 && msg.payload().readableBytes() > 2)
    {
        FMLLog.severe("The connection appears to have sent an invalid FML packet of type 0, this is likely because it think's it's talking to 1.6.4 FML");
        FMLLog.info("Bad data :");
        for (String l : Splitter.on('\n').split(ByteBufUtils.getContentDump(msg.payload()))) {
            FMLLog.info("\t%s",l);
        }
        throw new FMLNetworkException("Invalid FML packet");
    }
}
项目:TRHS_Club_Mod_2016    文件:FMLMessage.java   
@Override
void toBytes(ByteBuf buf)
{
    buf.writeInt(windowId);
    ByteBufUtils.writeUTF8String(buf, modId);
    buf.writeInt(modGuiId);
    buf.writeInt(x);
    buf.writeInt(y);
    buf.writeInt(z);
}
项目:TRHS_Club_Mod_2016    文件:FMLMessage.java   
@Override
void fromBytes(ByteBuf buf)
{
    windowId = buf.readInt();
    modId = ByteBufUtils.readUTF8String(buf);
    modGuiId = buf.readInt();
    x = buf.readInt();
    y = buf.readInt();
    z = buf.readInt();
}
项目:TRHS_Club_Mod_2016    文件:FMLMessage.java   
@Override
void fromBytes(ByteBuf dat)
{
    super.fromBytes(dat);
    modId = ByteBufUtils.readUTF8String(dat);
    modEntityTypeId = dat.readInt();
    rawX = dat.readInt();
    rawY = dat.readInt();
    rawZ = dat.readInt();
    scaledX = rawX / 32D;
    scaledY = rawY / 32D;
    scaledZ = rawZ / 32D;
    scaledYaw = dat.readByte() * 360F / 256F;
    scaledPitch = dat.readByte() * 360F / 256F;
    scaledHeadYaw = dat.readByte() * 360F / 256F;
    try
    {
        dataWatcherList = DataWatcher.func_151508_b(new PacketBuffer(dat));
    } catch (IOException e)
    {
        FMLLog.log(Level.FATAL, e, "There was a critical error decoding the datawatcher stream for a mod entity.");
        throw Throwables.propagate(e);
    }

    throwerId = dat.readInt();
    if (throwerId != 0)
    {
        speedScaledX = dat.readInt() / 8000D;
        speedScaledY = dat.readInt() / 8000D;
        speedScaledZ = dat.readInt() / 8000D;
    }
    this.dataStream = dat;
}
项目:RFUtilities    文件:PacketSetTransferMode.java   
@Override
public void fromBytes(ByteBuf buf)
{
    NBTTagCompound data = ByteBufUtils.readTag(buf);
    x = data.getInteger("x");
    y = data.getInteger("y");
    z = data.getInteger("z");
    once = data.getBoolean("once");
}
项目:RFUtilities    文件:PacketSetTransferMode.java   
@Override
public void toBytes(ByteBuf buf)
{
    NBTTagCompound data = new NBTTagCompound();
    data.setInteger("x", x);
    data.setInteger("y", y);
    data.setInteger("z", z);
    data.setBoolean("once", once);
    ByteBufUtils.writeTag(buf, data);
}
项目:Avaritiaddons    文件:InfinityChestSyncAllSlots.java   
@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];
    }
}
项目:Avaritiaddons    文件:InfinityChestSyncAllSlots.java   
@Override
public void toBytes(final ByteBuf buf)
{
    ByteBufUtils.writeVarShort(buf, slotCount);
    for (int i = 0; i < slotCount; i++) {
        ByteBufUtils.writeItemStack(buf, itemStacks[i]);
        ByteBufUtils.writeVarInt(buf, stackSizes[i], 5);
    }
}
项目:Avaritiaddons    文件:InfinityChestClick.java   
@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);
}
项目:Avaritiaddons    文件:InfinityChestClick.java   
@Override
public void toBytes(final ByteBuf buf)
{
    ByteBufUtils.writeVarInt(buf, windowId, 4);
    ByteBufUtils.writeVarShort(buf, slotNumber);
    ByteBufUtils.writeVarInt(buf, mouseButton, 4);
    ByteBufUtils.writeVarInt(buf, modifier, 4);
    ByteBufUtils.writeItemStack(buf, itemStack);
    ByteBufUtils.writeVarInt(buf, stackSize, 5);
    ByteBufUtils.writeVarShort(buf, transactionID);
}
项目:Avaritiaddons    文件:InfinityChestSlotSync.java   
@Override
public void fromBytes(final ByteBuf buf)
{
    itemStack = ByteBufUtils.readItemStack(buf);
    slot = ByteBufUtils.readVarShort(buf);
    stackSize = ByteBufUtils.readVarInt(buf, 5);
}
项目:Avaritiaddons    文件:InfinityChestSlotSync.java   
@Override
public void toBytes(final ByteBuf buf)
{
    ByteBufUtils.writeItemStack(buf, itemStack);
    ByteBufUtils.writeVarShort(buf, slot);
    ByteBufUtils.writeVarInt(buf, stackSize, 5);
}
项目:Avaritiaddons    文件:InfinityChestConfirmation.java   
@Override
public void fromBytes(final ByteBuf buf)
{
    windowID = ByteBufUtils.readVarInt(buf, 4);
    transactionID = (short) ByteBufUtils.readVarShort(buf);
    confirmed = ByteBufUtils.readVarShort(buf) == 1;
}
项目:Avaritiaddons    文件:InfinityChestConfirmation.java   
@Override
public void toBytes(final ByteBuf buf)
{
    ByteBufUtils.writeVarInt(buf, windowID, 4);
    ByteBufUtils.writeVarShort(buf, transactionID);
    ByteBufUtils.writeVarShort(buf, confirmed ? 1 : 0);
}
项目:PopularMMOS-EpicProportions-Mod    文件:MessageSyncEntityToServer.java   
@Override
public void fromBytes(ByteBuf buf) 
{
 entityId = ByteBufUtils.readVarInt(buf, 4);
 entitySyncDataCompound = ByteBufUtils.readTag(buf); // this class is very useful in general for writing more complex objects
 // DEBUG
 System.out.println("fromBytes");
}
项目:PopularMMOS-EpicProportions-Mod    文件:MessageSyncEntityToServer.java   
@Override
public void toBytes(ByteBuf buf) 
{
 ByteBufUtils.writeVarInt(buf, entityId, 4);
 ByteBufUtils.writeTag(buf, entitySyncDataCompound);
    // DEBUG
    System.out.println("toBytes encoded");
}
项目:CollectiveFramework    文件:TimeUpdatePacket.java   
@Override
public void fromBytes(ByteBuf buf) {
    NBTTagCompound tag = ByteBufUtils.readTag(buf);
    startTime = tag.getLong("startTime");
    time = tag.getInteger("time");
    profile = new GameProfile(UUID.fromString(tag.getString("uuid")), tag.getString("name"));
}
项目:CollectiveFramework    文件:TimeUpdatePacket.java   
@Override
public void toBytes(ByteBuf buf) {
    NBTTagCompound tag = new NBTTagCompound();
    tag.setLong("startTime", startTime);
    tag.setInteger("time", time);
    tag.setString("uuid", profile.getId().toString());
    tag.setString("name", profile.getName());
    ByteBufUtils.writeTag(buf, tag);
}
项目:Guide-Legacy    文件:S00PageInformation.java   
@Override
public void toBytes(ByteBuf buf) {
    ByteBufUtils.writeUTF8String(buf, identifier);
    buf.writeInt(index);
    ByteBufUtils.writeUTF8String(buf, title);
    buf.writeLong(created.getTime());
    ByteBufUtils.writeUTF8String(buf, author);
    buf.writeLong(lastModified.getTime());
    ByteBufUtils.writeUTF8String(buf, lastContributor);
    ByteBufUtils.writeUTF8String(buf, contents);
}
项目:CollectiveFramework    文件:TileEntityClientUpdatePacket.java   
@Override
public void toBytes(ByteBuf buf) {
    NBTTagCompound tag = new NBTTagCompound();
    tag.setInteger("dim", world.provider.dimensionId);
    tag.setInteger("x", x);
    tag.setInteger("y", y);
    tag.setInteger("z", z);
    tag.setTag("tag", updateData);
    ByteBufUtils.writeTag(buf, tag);
}
项目:CollectiveFramework    文件:ConfigPacket.java   
@Override
public void fromBytes(ByteBuf buf) {
    NBTTagCompound tag = ByteBufUtils.readTag(buf);
    configName = tag.getString("configName");
    config = tag.getString("config");
    isRevert = tag.getBoolean("isRevert");
}
项目:CollectiveFramework    文件:TileEntityServerUpdatePacket.java   
@Override
public void toBytes(ByteBuf buf) {
    NBTTagCompound tag = new NBTTagCompound();
    tag.setInteger("dim", world.provider.dimensionId);
    tag.setInteger("x", x);
    tag.setInteger("y", y);
    tag.setInteger("z", z);
    tag.setTag("tag", updateData);
    ByteBufUtils.writeTag(buf, tag);
}
项目:IngressCraft    文件:MessageSyncScanner.java   
@Override
public void toBytes(ByteBuf buf) {

    ByteBufUtils.writeUTF8String(buf, Codename);
    buf.writeInt(Faction);
    buf.writeInt(Level);
    buf.writeInt(AP);
    buf.writeInt(XM);

}
项目:IngressCraft    文件:EntityPortal.java   
@Override
public void writeSpawnData(ByteBuf buffer) {

    ByteBufUtils.writeUTF8String(buffer, UUID);
    ByteBufUtils.writeUTF8String(buffer, Name);
    ByteBufUtils.writeUTF8String(buffer, String.valueOf(Faction));
    ByteBufUtils.writeUTF8String(buffer, Owner);

}
项目:PowerLines    文件:AbstractGridNodeMessage.java   
@Override
public void toBytes(ByteBuf buf) {
    super.toBytes(buf);

    ByteBufUtils.writeUTF8String(buf, this.node_uuid.toString());
    buf.writeInt(this.getX());
    buf.writeInt(this.getY());
    buf.writeInt(this.getZ());
}
项目:Cooking-with-TFC    文件:MessageFoodRecord.java   
@Override
public void encodeInto(ChannelHandlerContext ctx, ByteBuf buffer) 
{
    buffer.writeInt(this.RecordSize);
    buffer.writeInt(this.FoodListRef);
    for(int i = 0; i < this.RecordSize; ++i)
    {
        if(this.foodrecord.FoodsEaten[i] != null)
            ByteBufUtils.writeUTF8String(buffer, this.foodrecord.FoodsEaten[i]);
    }       
}
项目:PowerLines    文件:SetNodeUUIDMessage.java   
@Override
public void toBytes(ByteBuf buf) {
    ByteBufUtils.writeUTF8String(buf, this.node_uuid.toString());
    buf.writeInt(this.getX());
    buf.writeInt(this.getY());
    buf.writeInt(this.getZ());
}
项目:PowerLines    文件:SetGridUUIDMessage.java   
@Override
public void fromBytes(ByteBuf buf) {
    this.grid_uuid = UUID.fromString(ByteBufUtils.readUTF8String(buf));
    this.x = buf.readInt();
    this.y = buf.readInt();
    this.z = buf.readInt();
}
项目:BinaryCraft    文件:ScriptPacketClient.java   
@Override
public void fromBytes(ByteBuf buf) {
    x = buf.readInt();
    y = buf.readInt();
    z = buf.readInt();
    scripts = new ArrayList<ComputerScript>();
    while (buf.readableBytes() > 1) {
        scripts.add(new ComputerScript(new ScriptComputer((TileEntityComputer) Minecraft.getMinecraft().theWorld.getTileEntity(x, y, z)), ByteBufUtils.readUTF8String(buf), ByteBufUtils.readUTF8String(buf)));
    }
}
项目:CCFactoryManager    文件:MessageNameChange.java   
@Override
public void fromBytes(ByteBuf buf) {
    super.fromBytes(buf);
    relX = buf.readInt();
    relY = buf.readInt();
    relZ = buf.readInt();
    name = ByteBufUtils.readUTF8String(buf);
}
项目:LookingGlass    文件:PacketTileEntityNBT.java   
public static FMLProxyPacket createPacket(int xPos, int yPos, int zPos, NBTTagCompound nbt, int dim) {
    // This line may look like black magic (and, well, it is), but it's actually just returning a class reference for this class. Copy-paste safe.
    ByteBuf data = PacketHandlerBase.createDataBuffer((Class<? extends PacketHandlerBase>) new Object() {}.getClass().getEnclosingClass());

    data.writeInt(dim);
    data.writeInt(xPos);
    data.writeInt(yPos);
    data.writeInt(zPos);
    ByteBufUtils.writeTag(data, nbt);

    return buildPacket(data);
}
项目:LookingGlass    文件:PacketTileEntityNBT.java   
@Override
public void handle(ByteBuf data, EntityPlayer player) {
    int dimension = data.readInt();
    int xPos = data.readInt();
    int yPos = data.readInt();
    int zPos = data.readInt();
    NBTTagCompound nbt = ByteBufUtils.readTag(data);

    WorldClient proxyworld = ProxyWorldManager.getProxyworld(dimension);
    if (proxyworld == null) return;
    if (proxyworld.provider.dimensionId != dimension) return;
    if (proxyworld.blockExists(xPos, yPos, zPos)) {
        TileEntity tileentity = proxyworld.getTileEntity(xPos, yPos, zPos);

        if (tileentity != null) {
            tileentity.readFromNBT(nbt);
        } else {
            //Create tile entity from data
            tileentity = TileEntity.createAndLoadEntity(nbt);
            if (tileentity != null) {
                proxyworld.addTileEntity(tileentity);
            }
        }
        proxyworld.markTileEntityChunkModified(xPos, yPos, zPos, tileentity);
        proxyworld.setTileEntity(xPos, yPos, zPos, tileentity);
        proxyworld.markBlockForUpdate(xPos, yPos, zPos);
    }
}