Java Code Examples for net.minecraft.network.PacketBuffer#writeVarInt()

The following examples show how to use net.minecraft.network.PacketBuffer#writeVarInt() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RpcCallCodec.java    From OpenModsLib with MIT License 6 votes vote down vote up
@Override
protected void encode(ChannelHandlerContext ctx, RpcCall call, List<Object> out) throws Exception {
	final PacketBuffer output = new PacketBuffer(Unpooled.buffer());

	{
		final IRpcTarget targetWrapper = call.target;
		int targetId = CommonRegistryCallbacks.mapObjectToId(targetRegistry, targetWrapper.getClass());
		output.writeVarInt(targetId);
		targetWrapper.writeToStream(output);
	}

	{
		final BiMap<MethodEntry, Integer> eventIdMap = CommonRegistryCallbacks.getEntryIdMap(methodRegistry);
		int methodId = eventIdMap.get(call.method);
		output.writeVarInt(methodId);
		MethodParamsCodec paramsCodec = call.method.paramsCodec;
		paramsCodec.writeArgs(output, call.args);
	}

	FMLProxyPacket packet = new FMLProxyPacket(output, RpcCallDispatcher.CHANNEL_NAME);
	out.add(packet);
}
 
Example 2
Source File: GameProfileSerializer.java    From OpenModsLib with MIT License 6 votes vote down vote up
public static void write(GameProfile o, PacketBuffer output) {
	final UUID uuid = o.getId();
	output.writeString(uuid == null? "" : uuid.toString());
	output.writeString(Strings.nullToEmpty(o.getName()));
	final PropertyMap properties = o.getProperties();
	output.writeVarInt(properties.size());
	for (Property p : properties.values()) {
		output.writeString(p.getName());
		output.writeString(p.getValue());

		final String signature = p.getSignature();
		if (signature != null) {
			output.writeBoolean(true);
			output.writeString(signature);
		} else {
			output.writeBoolean(false);
		}
	}
}
 
Example 3
Source File: LongItemStack.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void writeItemStack(PacketBuffer packetBuffer) {
    if (itemStack.isEmpty()) {
        packetBuffer.writeShort(-1);
    } else {
        packetBuffer.writeShort(Item.getIdFromItem(itemStack.getItem()));
        packetBuffer.writeVarInt(itemStack.getCount());
        packetBuffer.writeShort(itemStack.getMetadata());
        NBTTagCompound nbttagcompound = null;

        if (itemStack.getItem().isDamageable() ||
            itemStack.getItem().getShareTag()) {
            nbttagcompound = itemStack.getItem().getNBTShareTag(itemStack);
        }
        packetBuffer.writeCompoundTag(nbttagcompound);
    }
}
 
Example 4
Source File: PipeCoverableImplementation.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void writeInitialSyncData(PacketBuffer buf) {
    for (EnumFacing coverSide : EnumFacing.VALUES) {
        CoverBehavior coverBehavior = getCoverAtSide(coverSide);
        if (coverBehavior != null) {
            int coverId = CoverDefinition.getNetworkIdForCover(coverBehavior.getCoverDefinition());
            buf.writeVarInt(coverId);
            coverBehavior.writeInitialSyncData(buf);
        } else {
            buf.writeVarInt(-1);
        }
    }
}
 
Example 5
Source File: ChoppingRecipe.java    From Survivalist with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void write(PacketBuffer buffer, ChoppingRecipe recipe)
{
    buffer.writeString(recipe.group);
    recipe.input.write(buffer);
    buffer.writeItemStack(recipe.output);
    buffer.writeDouble(recipe.outputMultiplier);
    buffer.writeDouble(recipe.hitCountMultiplier);
    buffer.writeVarInt(recipe.maxOutput);
    buffer.writeVarInt(recipe.sawingTime);
}
 
Example 6
Source File: LaserParticleData.java    From MiningGadgets with MIT License 5 votes vote down vote up
@Override
public void write(PacketBuffer buf) {
    buf.writeVarInt(Block.BLOCK_STATE_IDS.get(state));
    buf.writeFloat(size);
    buf.writeFloat(r);
    buf.writeFloat(g);
    buf.writeFloat(b);
    buf.writeFloat(maxAgeMul);
    buf.writeBoolean(depthTest);
}
 
Example 7
Source File: MetaTileEntityLockedSafe.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void writeInitialSyncData(PacketBuffer buf) {
    super.writeInitialSyncData(buf);
    buf.writeVarInt(unlockComponentTier);
    buf.writeBoolean(isSafeUnlocked);
    buf.writeFloat(doorAngle);
    buf.writeVarLong(unlockComponentsSeed);
}
 
Example 8
Source File: ByteBufUtils.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void writeRelativeBlockList(PacketBuffer buf, BlockPos origin, List<BlockPos> blockList) {
    buf.writeVarInt(blockList.size());
    for (BlockPos blockPos1 : blockList) {
        BlockPos blockPos = blockPos1.subtract(origin);
        buf.writeVarInt(blockPos.getX());
        buf.writeVarInt(blockPos.getY());
        buf.writeVarInt(blockPos.getZ());
    }
}
 
Example 9
Source File: ByteBufUtils.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void writeFluidStackDelta(PacketBuffer buf, FluidStack oldFluidStack, FluidStack newFluidStack) {
    if (oldFluidStack != null && oldFluidStack.isFluidEqual(newFluidStack)) {
        buf.writeBoolean(true);
        buf.writeVarInt(newFluidStack.amount);
    } else {
        buf.writeBoolean(false);
        writeFluidStack(buf, newFluidStack);
    }
}
 
Example 10
Source File: Command.java    From OpenModsLib with MIT License 5 votes vote down vote up
@Override
protected void writeDataToStream(PacketBuffer output) {
	output.writeVarInt(elementCount);
	output.writeVarInt(minElementId);
	output.writeVarInt(maxElementId);
	output.writeVarInt(containerCount);
	output.writeVarInt(minContainerId);
	output.writeVarInt(maxContainerId);
}
 
Example 11
Source File: ModularUIContainer.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void writeClientAction(Widget widget, int updateId, Consumer<PacketBuffer> payloadWriter) {
    int widgetId = modularUI.guiWidgets.inverse().get(widget);
    PacketBuffer packetBuffer = new PacketBuffer(Unpooled.buffer());
    packetBuffer.writeVarInt(updateId);
    payloadWriter.accept(packetBuffer);
    if (modularUI.entityPlayer instanceof EntityPlayerSP) {
        PacketUIClientAction widgetUpdate = new PacketUIClientAction(windowId, widgetId, packetBuffer);
        NetworkHandler.channel.sendToServer(NetworkHandler.packet2proxy(widgetUpdate));
    }
}
 
Example 12
Source File: TypeRW.java    From OpenModsLib with MIT License 4 votes vote down vote up
@Override
public void writeToStream(Integer o, PacketBuffer output) {
	output.writeVarInt(o);
}
 
Example 13
Source File: MetaTileEntityChest.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void writeInitialSyncData(PacketBuffer buf) {
    super.writeInitialSyncData(buf);
    buf.writeVarInt(numPlayersUsing);
}
 
Example 14
Source File: SyncableVarInt.java    From OpenModsLib with MIT License 4 votes vote down vote up
@Override
public void writeToStream(PacketBuffer stream) {
	stream.writeVarInt(value);
}
 
Example 15
Source File: SyncableBlockState.java    From OpenModsLib with MIT License 4 votes vote down vote up
@Override
public void writeToStream(PacketBuffer buf) {
	final int id = Block.getStateId(state);
	buf.writeVarInt(id);
}
 
Example 16
Source File: SyncableBlock.java    From OpenModsLib with MIT License 4 votes vote down vote up
@Override
public void writeToStream(PacketBuffer stream) {
	int blockId = Block.getIdFromBlock(block);
	if (blockId < 0) blockId = 0;
	stream.writeVarInt(blockId);
}
 
Example 17
Source File: SyncableEnum.java    From OpenModsLib with MIT License 4 votes vote down vote up
@Override
public void writeToStream(PacketBuffer buf) {
	buf.writeVarInt(0);
}
 
Example 18
Source File: SyncableEnum.java    From OpenModsLib with MIT License 4 votes vote down vote up
@Override
public void writeToStream(PacketBuffer stream) {
	stream.writeVarInt(value.ordinal());
}
 
Example 19
Source File: TileEntityMaterialPipeBase.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void writeInitialSyncData(PacketBuffer buf) {
    super.writeInitialSyncData(buf);
    buf.writeVarInt(Material.MATERIAL_REGISTRY.getIDForObject(pipeMaterial));
}
 
Example 20
Source File: VSGuiButtonMessage.java    From Valkyrien-Skies with Apache License 2.0 4 votes vote down vote up
@Override
public void toBytes(ByteBuf buf) {
    PacketBuffer packetBuffer = new PacketBuffer(buf);
    packetBuffer.writeBlockPos(tileEntityPos);
    packetBuffer.writeVarInt(buttonId);
}